From ab4b4bde124a7d72fad4184c6a0ecb534c07f299 Mon Sep 17 00:00:00 2001 From: Joonas Date: Fri, 17 May 2024 15:15:27 +0300 Subject: [PATCH] Fix rubocop --- decidim-suomifi.gemspec | 5 --- lib/tasks/suomifi_tasks.rake | 2 +- .../suomifi/sessions_controller_spec.rb | 2 +- .../generators/install_generator_spec.rb | 11 +++---- spec/lib/decidim/suomifi_spec.rb | 31 ++++++------------- 5 files changed, 17 insertions(+), 34 deletions(-) diff --git a/decidim-suomifi.gemspec b/decidim-suomifi.gemspec index d335906..4080ae3 100644 --- a/decidim-suomifi.gemspec +++ b/decidim-suomifi.gemspec @@ -31,9 +31,4 @@ Gem::Specification.new do |spec| spec.add_dependency "decidim-core", Decidim::Suomifi::DECIDIM_VERSION spec.add_dependency "henkilotunnus", "~> 1.2.0" spec.add_dependency "omniauth-suomifi", "~> 0.7.0" - - spec.add_development_dependency "decidim-dev", Decidim::Suomifi::DECIDIM_VERSION - - # Required for encoding the SAML responses - spec.add_development_dependency "xmlenc", "~> 0.7.1" end diff --git a/lib/tasks/suomifi_tasks.rake b/lib/tasks/suomifi_tasks.rake index c0c87ad..734a082 100644 --- a/lib/tasks/suomifi_tasks.rake +++ b/lib/tasks/suomifi_tasks.rake @@ -4,7 +4,7 @@ namespace :decidim do namespace :suomifi do desc "Copy pin digest from metadata to its own column" task copy_pin_digests: :environment do - ::Decidim::Authorization.all.each do |authorization| + Decidim::Authorization.all.each do |authorization| next if authorization.name != "suomifi_eid" || authorization.pseudonymized_pin.present? authorization.update( diff --git a/spec/controllers/decidim/suomifi/sessions_controller_spec.rb b/spec/controllers/decidim/suomifi/sessions_controller_spec.rb index ef2eaf0..fba1d2f 100644 --- a/spec/controllers/decidim/suomifi/sessions_controller_spec.rb +++ b/spec/controllers/decidim/suomifi/sessions_controller_spec.rb @@ -14,7 +14,7 @@ module Suomifi # For testing with signed in user let(:confirmed_user) do - create(:user, :confirmed, organization: organization) + create(:user, :confirmed, organization:) end before do diff --git a/spec/lib/decidim/suomifi/generators/install_generator_spec.rb b/spec/lib/decidim/suomifi/generators/install_generator_spec.rb index 5d6d14b..a32c971 100644 --- a/spec/lib/decidim/suomifi/generators/install_generator_spec.rb +++ b/spec/lib/decidim/suomifi/generators/install_generator_spec.rb @@ -102,10 +102,10 @@ let(:secrets_yml) do secrets_yml_template.gsub( - /%SUOMIFI_INJECTION_DEFAULT%/, + "%SUOMIFI_INJECTION_DEFAULT%", "" ).gsub( - /%SUOMIFI_INJECTION_DEVELOPMENT%/, + "%SUOMIFI_INJECTION_DEVELOPMENT%", "" ) end @@ -120,17 +120,16 @@ development += " icon: globe-line\n" secrets_yml_template.gsub( - /%SUOMIFI_INJECTION_DEFAULT%/, + "%SUOMIFI_INJECTION_DEFAULT%", default ).gsub( - /%SUOMIFI_INJECTION_DEVELOPMENT%/, + "%SUOMIFI_INJECTION_DEVELOPMENT%", development ) end it "enables the Suomi.fi authentication by modifying the secrets.yml file" do - allow(File).to receive(:read).and_return(secrets_yml) - allow(File).to receive(:readlines).and_return(secrets_yml.lines) + allow(File).to receive_messages(read: secrets_yml, readlines: secrets_yml.lines) expect(File).to receive(:open).with(anything, "w") do |&block| file = double expect(file).to receive(:puts).with(secrets_yml_modified) diff --git a/spec/lib/decidim/suomifi_spec.rb b/spec/lib/decidim/suomifi_spec.rb index 437caa3..4cdd6ee 100644 --- a/spec/lib/decidim/suomifi_spec.rb +++ b/spec/lib/decidim/suomifi_spec.rb @@ -80,8 +80,7 @@ let(:certificate) { double } it "returns what is set by the module configuration" do - allow(config).to receive(:certificate_file).and_return(nil) - allow(config).to receive(:certificate).and_return(certificate) + allow(config).to receive_messages(certificate_file: nil, certificate:) expect(subject.certificate).to eq(certificate) end @@ -102,8 +101,7 @@ let(:private_key) { double } it "returns what is set by the module configuration" do - allow(config).to receive(:private_key_file).and_return(nil) - allow(config).to receive(:private_key).and_return(private_key) + allow(config).to receive_messages(private_key_file: nil, private_key:) expect(subject.private_key).to eq(private_key) end @@ -120,23 +118,15 @@ let(:extra) { { extra1: "abc", extra2: 123 } } it "returns the expected omniauth configuration hash" do - allow(config).to receive(:mode).and_return(mode) - allow(config).to receive(:scope_of_data).and_return(scope_of_data) - allow(config).to receive(:sp_entity_id).and_return(sp_entity_id) - allow(config).to receive(:certificate_file).and_return(nil) - allow(config).to receive(:certificate).and_return(certificate) - allow(config).to receive(:private_key_file).and_return(nil) - allow(config).to receive(:private_key).and_return(private_key) - allow(config).to receive(:idp_slo_session_destroy).and_return(idp_slo_session_destroy) - allow(config).to receive(:extra).and_return(extra) + allow(config).to receive_messages(mode:, scope_of_data:, sp_entity_id:, certificate_file: nil, certificate:, private_key_file: nil, private_key:, idp_slo_session_destroy:, extra:) expect(subject.omniauth_settings).to include( - mode: mode, - scope_of_data: scope_of_data, - sp_entity_id: sp_entity_id, - certificate: certificate, - private_key: private_key, - idp_slo_session_destroy: idp_slo_session_destroy, + mode:, + scope_of_data:, + sp_entity_id:, + certificate:, + private_key:, + idp_slo_session_destroy:, extra1: "abc", extra2: 123 ) @@ -153,8 +143,7 @@ before do allow(Rails.application).to receive(:config).and_return(rails_config) - allow(rails_config).to receive(:action_controller).and_return(controller_config) - allow(rails_config).to receive(:action_mailer).and_return(mailer_config) + allow(rails_config).to receive_messages(action_controller: controller_config, action_mailer: mailer_config) allow(controller_config).to receive(:default_url_options).and_return(controller_defaults) allow(mailer_config).to receive(:default_url_options).and_return(mailer_defaults) end