diff --git a/app/commands/decidim/half_signup/admin/update_auth_settings.rb b/app/commands/decidim/half_signup/admin/update_auth_settings.rb index bc2669f..16cfc96 100644 --- a/app/commands/decidim/half_signup/admin/update_auth_settings.rb +++ b/app/commands/decidim/half_signup/admin/update_auth_settings.rb @@ -17,7 +17,7 @@ def initialize(auth_settings, form) def call return broadcast(:invalid) if form.invalid? - return broadcast(:sms_service_not_configured) if form.enable_partial_sms_signup && !check_sms_service + return broadcast(:sms_service_not_configured) if form.enable_partial_sms_signup && !sms_gateway_service_configured? update_auth_settings broadcast(:ok) @@ -27,7 +27,7 @@ def call attr_reader :form - def check_sms_service + def sms_gateway_service_configured? Decidim.config.sms_gateway_service.present? end diff --git a/spec/commands/decidim/half_signup/admin/update_auth_settings_spec.rb b/spec/commands/decidim/half_signup/admin/update_auth_settings_spec.rb index 2bcc95d..54a8f65 100644 --- a/spec/commands/decidim/half_signup/admin/update_auth_settings_spec.rb +++ b/spec/commands/decidim/half_signup/admin/update_auth_settings_spec.rb @@ -16,12 +16,14 @@ ) end let(:command) { described_class.new(auth_settings, form) } - let(:sms_gateway_service) { "Decidim::Verifications::Sms::ExampleGateway" } + let(:sms_gateway_service) { instance_double(Decidim::Verifications::Sms::ExampleGateway, present?: true) } before do - Decidim.configure do |config| - config.sms_gateway_service = sms_gateway_service - end + allow(Decidim.config).to receive(:sms_gateway_service).and_return(sms_gateway_service) + end + + after do + allow(Decidim.config).to receive(:sms_gateway_service).and_call_original end describe "#call" do diff --git a/spec/commands/decidim/half_signup/send_verification_spec.rb b/spec/commands/decidim/half_signup/send_verification_spec.rb index 55c2cdf..84ca16d 100644 --- a/spec/commands/decidim/half_signup/send_verification_spec.rb +++ b/spec/commands/decidim/half_signup/send_verification_spec.rb @@ -34,6 +34,10 @@ end end + after do + allow(Decidim.config).to receive(:sms_gateway_service).and_call_original + end + describe "when email" do let!(:auth_method) { "email" } diff --git a/spec/controllers/decidim/half_signup/quick_auth_controller_spec.rb b/spec/controllers/decidim/half_signup/quick_auth_controller_spec.rb index cfcdd47..c504750 100644 --- a/spec/controllers/decidim/half_signup/quick_auth_controller_spec.rb +++ b/spec/controllers/decidim/half_signup/quick_auth_controller_spec.rb @@ -36,9 +36,11 @@ request.env["devise.mapping"] = ::Devise.mappings[:user] request.session[:auth_attempt] = auth_session - Decidim.configure do |config| - config.sms_gateway_service = sms_gateway_service - end + allow(Decidim.config).to receive(:sms_gateway_service).and_return(sms_gateway_service) + end + + after do + allow(Decidim.config).to receive(:sms_gateway_service).and_call_original end describe "GET #sms" do diff --git a/spec/system/add_update_phone_number_spec.rb b/spec/system/add_update_phone_number_spec.rb index 536584c..ed665d1 100644 --- a/spec/system/add_update_phone_number_spec.rb +++ b/spec/system/add_update_phone_number_spec.rb @@ -15,9 +15,11 @@ switch_to_host(organization.host) visit decidim.account_path - Decidim.configure do |config| - config.sms_gateway_service = sms_gateway_service - end + allow(Decidim.config).to receive(:sms_gateway_service).and_return(sms_gateway_service) + end + + after do + allow(Decidim.config).to receive(:sms_gateway_service).and_call_original end context "when sms_auth is not enabled" do diff --git a/spec/system/admin_manage_auth_settings_spec.rb b/spec/system/admin_manage_auth_settings_spec.rb index 21390a7..c7ff933 100644 --- a/spec/system/admin_manage_auth_settings_spec.rb +++ b/spec/system/admin_manage_auth_settings_spec.rb @@ -15,9 +15,11 @@ switch_to_host(organization.host) visit decidim_admin.edit_organization_path - Decidim.configure do |config| - config.sms_gateway_service = sms_gateway_service - end + allow(Decidim.config).to receive(:sms_gateway_service).and_return(sms_gateway_service) + end + + after do + allow(Decidim.config).to receive(:sms_gateway_service).and_call_original end it "shows the menu in the admin panel in a correct place" do @@ -54,41 +56,42 @@ expect(auth_settings.enable_partial_sms_signup).to be(true) end - it "shows a warning message when the SMS gateway service is not configured" do - Decidim.configure do |config| - config.sms_gateway_service = nil + context "when sms gateway service is not present" do + before do + allow(Decidim.config).to receive(:sms_gateway_service).and_return(nil) end - click_link "Authentication settings" - expect(page).to have_current_path(decidim_half_signup_admin.edit_auth_setting_path(slug: "authentication_settings")) - expect(page).to have_css(".is-active", text: "Authentication settings") - expect(page.find("#auth_setting_enable_partial_sms_signup")).to be_disabled - expect(page).to have_content("This option is disabled please contact the host of the platform to enable it.") - end - - it "shows an error message when the SMS gateway service is not configured if the user tries to force the change" do - click_link "Authentication settings" - expect(page).to have_current_path(decidim_half_signup_admin.edit_auth_setting_path(slug: "authentication_settings")) - expect(page).to have_css(".is-active", text: "Authentication settings") - check "Enable partial sign up and sign in using SMS verification" - check "Enable partial sign up and sign in using email verification" - Decidim.configure do |config| - config.sms_gateway_service = nil + it "shows a warning message when the SMS gateway service is not configured" do + click_link "Authentication settings" + expect(page).to have_current_path(decidim_half_signup_admin.edit_auth_setting_path(slug: "authentication_settings")) + expect(page).to have_css(".is-active", text: "Authentication settings") + expect(page.find("#auth_setting_enable_partial_sms_signup")).to be_disabled + expect(page).to have_content("This option is disabled please contact the host of the platform to enable it.") end - click_button "Update" - expect(page).to have_current_path(decidim_half_signup_admin.edit_auth_setting_path(slug: "authentication_settings")) - within ".callout-wrapper" do - expect(page).not_to have_content("Organization updated successfully.") - expect(page).to have_content("The SMS gateway service is not defined.") - end - expect(page).to have_content("Settings available through code") - within "code" do - expect(page).to have_content("Decidim::HalfSignup.configure do |config|") + it "shows an error message when the SMS gateway service is not configured if the user tries to force the change" do + click_link "Authentication settings" + expect(page).to have_current_path(decidim_half_signup_admin.edit_auth_setting_path(slug: "authentication_settings")) + expect(page).to have_css(".is-active", text: "Authentication settings") + check "Enable partial sign up and sign in using SMS verification" + check "Enable partial sign up and sign in using email verification" + + allow(Decidim.config).to receive(:sms_gateway_service).and_return(nil) + + click_button "Update" + expect(page).to have_current_path(decidim_half_signup_admin.edit_auth_setting_path(slug: "authentication_settings")) + within ".callout-wrapper" do + expect(page).not_to have_content("Organization updated successfully.") + expect(page).to have_content("The SMS gateway service is not defined.") + end + expect(page).to have_content("Settings available through code") + within "code" do + expect(page).to have_content("Decidim::HalfSignup.configure do |config|") + end + expect(page.find("#auth_setting_enable_partial_sms_signup")).not_to be_checked + auth_settings = Decidim::HalfSignup::AuthSetting.last + expect(auth_settings.enable_partial_email_signup).to be(false) + expect(auth_settings.enable_partial_sms_signup).to be(false) end - expect(page.find("#auth_setting_enable_partial_sms_signup")).not_to be_checked - auth_settings = Decidim::HalfSignup::AuthSetting.last - expect(auth_settings.enable_partial_email_signup).to be(false) - expect(auth_settings.enable_partial_sms_signup).to be(false) end end diff --git a/spec/system/budgets_view_spec.rb b/spec/system/budgets_view_spec.rb index 01cf80c..5d8e445 100644 --- a/spec/system/budgets_view_spec.rb +++ b/spec/system/budgets_view_spec.rb @@ -12,9 +12,11 @@ before do switch_to_host(organization.host) - Decidim.configure do |config| - config.sms_gateway_service = sms_gateway_service - end + allow(Decidim.config).to receive(:sms_gateway_service).and_return(sms_gateway_service) + end + + after do + allow(Decidim.config).to receive(:sms_gateway_service).and_call_original end context "with multiple budgets" do