diff --git a/Gemfile b/Gemfile index 7b72571..adb2fdf 100644 --- a/Gemfile +++ b/Gemfile @@ -24,6 +24,12 @@ group :development, :test do gem "byebug", "~> 11.0", platform: :mri gem "decidim-dev", DECIDIM_VERSION gem "decidim-sms-telia", github: "mainio/decidim-sms-telia", branch: "main" + + # rubocop & rubocop-rspec are set to the following versions because of a change where FactoryBot/CreateList + # must be a boolean instead of contextual. These version locks can be removed when this problem is handled + # through decidim-dev. + gem "rubocop", "~>1.28" + gem "rubocop-rspec", "2.20" end group :development do diff --git a/Gemfile.lock b/Gemfile.lock index 88fba7f..11b236d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -666,8 +666,6 @@ GEM parser (>= 3.3.1.0) rubocop-capybara (2.21.0) rubocop (~> 1.41) - rubocop-factory_bot (2.26.0) - rubocop (~> 1.41) rubocop-faker (1.1.0) faker (>= 2.12.0) rubocop (>= 0.82.0) @@ -676,13 +674,9 @@ GEM rack (>= 1.1) rubocop (>= 1.33.0, < 2.0) rubocop-ast (>= 1.31.1, < 2.0) - rubocop-rspec (2.31.0) - rubocop (~> 1.40) + rubocop-rspec (2.20.0) + rubocop (~> 1.33) rubocop-capybara (~> 2.17) - rubocop-factory_bot (~> 2.22) - rubocop-rspec_rails (~> 2.28) - rubocop-rspec_rails (2.29.0) - rubocop (~> 1.40) ruby-progressbar (1.13.0) ruby-vips (2.2.2) ffi (~> 1.12) @@ -799,7 +793,9 @@ DEPENDENCIES letter_opener_web (~> 2.0) listen (~> 3.1) puma (>= 5.6.2) + rubocop (~> 1.28) rubocop-faker + rubocop-rspec (= 2.20) spring (~> 2.0) spring-watcher-listen (~> 2.0) web-console (~> 4.2) diff --git a/app/commands/decidim/helsinki_smsauth/send_verification_code.rb b/app/commands/decidim/helsinki_smsauth/send_verification_code.rb index 3b34606..741adcb 100644 --- a/app/commands/decidim/helsinki_smsauth/send_verification_code.rb +++ b/app/commands/decidim/helsinki_smsauth/send_verification_code.rb @@ -66,7 +66,7 @@ def gateway code = generate_code gateway = Decidim.config.sms_gateway_service.constantize if gateway.instance_method(:initialize).parameters.length > 2 - gateway.new(phone_number, code, organization: organization) + gateway.new(phone_number, code, organization:) else gateway.new(phone_number, code) end diff --git a/app/commands/decidim/helsinki_smsauth/verifications/confirm_user_phone_authorization.rb b/app/commands/decidim/helsinki_smsauth/verifications/confirm_user_phone_authorization.rb index 93faad9..a01446b 100644 --- a/app/commands/decidim/helsinki_smsauth/verifications/confirm_user_phone_authorization.rb +++ b/app/commands/decidim/helsinki_smsauth/verifications/confirm_user_phone_authorization.rb @@ -20,7 +20,7 @@ def call invalid! end rescue StandardError => e - puts e + Rails.logger.debug e invalid!(e.message) end diff --git a/app/commands/decidim/helsinki_smsauth/verify_access_code.rb b/app/commands/decidim/helsinki_smsauth/verify_access_code.rb index ee2b851..4381afd 100644 --- a/app/commands/decidim/helsinki_smsauth/verify_access_code.rb +++ b/app/commands/decidim/helsinki_smsauth/verify_access_code.rb @@ -79,7 +79,7 @@ def prefix def access_code_instance(code) digest = "#{code}-#{Rails.application.secrets.secret_key_base}" code_hash = Digest::MD5.hexdigest(digest) - ::Decidim::HelsinkiSmsauth::SigninCode.find_by(code_hash: code_hash) + ::Decidim::HelsinkiSmsauth::SigninCode.find_by(code_hash:) end def destroy_access_code! diff --git a/app/controllers/decidim/helsinki_smsauth/omniauth_controller.rb b/app/controllers/decidim/helsinki_smsauth/omniauth_controller.rb index b3bcbcf..bd5c256 100644 --- a/app/controllers/decidim/helsinki_smsauth/omniauth_controller.rb +++ b/app/controllers/decidim/helsinki_smsauth/omniauth_controller.rb @@ -7,7 +7,7 @@ class OmniauthController < ::Decidim::Devise::OmniauthRegistrationsController helper Decidim::HelsinkiSmsauth::Engine.routes.url_helpers helper Decidim::HelsinkiSmsauth::RegistrationHelper - before_action :ensure_authorized, only: [:new, :registration, :user_registry] + before_action :ensure_authorized, only: [:new, :user_registry] def new @form = form(OmniauthForm).instance @@ -101,7 +101,7 @@ def school_info def user_registry user = find_user! - @form = SchoolMetadataForm.from_params(user_params.merge(current_locale: current_locale, organization: current_organization, user: user)) + @form = SchoolMetadataForm.from_params(user_params.merge(current_locale:, organization: current_organization, user:)) RegisterByPhone.call(@form) do on(:ok) do |new_user| @@ -157,7 +157,7 @@ def access_code end def access_code_validation - @form = AccessCodeForm.from_params(params.merge(current_locale: current_locale, organization: current_organization)) + @form = AccessCodeForm.from_params(params.merge(current_locale:, organization: current_organization)) VerifyAccessCode.call(@form) do on(:ok) do |user, access_hash| update_sessions!(**access_hash) @@ -202,7 +202,7 @@ def authorize_user!(user) def generated_metadata(authorization, phone_number) metadata = authorization.metadata || {} - metadata.merge!({ phone_number: phone_number }) + metadata.merge!({ phone_number: }) metadata.merge!({ school: auth_session["school"] }) if metadata["school"].nil? metadata.merge!({ grade: auth_session["grade"] }) if metadata["grade"].nil? metadata @@ -316,7 +316,7 @@ def update_authorization!(user, auth_session) def find_authorization(user) Decidim::Authorization.find_or_initialize_by( - user: user, + user:, name: "helsinki_smsauth_id" ) end diff --git a/app/controllers/decidim/helsinki_smsauth/verifications/admin/signin_codes_controller.rb b/app/controllers/decidim/helsinki_smsauth/verifications/admin/signin_codes_controller.rb index 3c52333..d8405b5 100644 --- a/app/controllers/decidim/helsinki_smsauth/verifications/admin/signin_codes_controller.rb +++ b/app/controllers/decidim/helsinki_smsauth/verifications/admin/signin_codes_controller.rb @@ -89,7 +89,7 @@ def expiration_time end def set_expiration_info - t("expiration_note", scope: "decidim.helsinki_smsauth.verifications.admin.signin_codes.view_generated_codes", expiration_time: expiration_time) + t("expiration_note", scope: "decidim.helsinki_smsauth.verifications.admin.signin_codes.view_generated_codes", expiration_time:) end def global_expiration_period diff --git a/app/controllers/decidim/helsinki_smsauth/verifications/authorizations_controller.rb b/app/controllers/decidim/helsinki_smsauth/verifications/authorizations_controller.rb index 177fa3a..d6be194 100644 --- a/app/controllers/decidim/helsinki_smsauth/verifications/authorizations_controller.rb +++ b/app/controllers/decidim/helsinki_smsauth/verifications/authorizations_controller.rb @@ -13,16 +13,23 @@ def new # We use the :update action here because this is also where the user # is redirected to in case they previously started the authorization # but did not finish it (i.e. the authorization is "pending"). - enforce_permission_to :update, :authorization, authorization: authorization + enforce_permission_to(:update, :authorization, authorization:) @form = form(AuthorizationForm).instance end + def edit + enforce_permission_to(:update, :authorization, authorization:) + + @form = ConfirmationForm.new + verification_code + end + def create # We use the :update action here because this is also where the user # is redirected to in case they previously started the authorization # but did not finish it (i.e. the authorization is "pending"). - enforce_permission_to :update, :authorization, authorization: authorization + enforce_permission_to(:update, :authorization, authorization:) @form = AuthorizationForm.from_params(params.merge(user: current_user, school: nil, grade: nil, organization: current_organization)) Decidim::Verifications::PerformAuthorizationStep.call(authorization, @form) do @@ -38,13 +45,6 @@ def create end end - def edit - enforce_permission_to :update, :authorization, authorization: authorization - - @form = ConfirmationForm.new - verification_code - end - def resend_code return unless eligible_to? @@ -54,7 +54,7 @@ def resend_code on(:ok) do flash_message_for_resend(last_request_time) authorization_method = Decidim::Verifications::Adapter.from_element(authorization.name) - redirect_to authorization_method.resume_authorization_path(redirect_url: redirect_url) + redirect_to authorization_method.resume_authorization_path(redirect_url:) end on(:invalid) do flash.now[:alert] = I18n.t(".error", scope: "decidim.helsinki_smsauth.omniauth.sms.authenticate_user") @@ -64,13 +64,13 @@ def resend_code end def school_info - enforce_permission_to :update, :authorization, authorization: authorization + enforce_permission_to(:update, :authorization, authorization:) @form = form(::Decidim::HelsinkiSmsauth::SchoolMetadataForm).instance end def school_validation - enforce_permission_to :update, :authorization, authorization: authorization + enforce_permission_to(:update, :authorization, authorization:) @form = form(::Decidim::HelsinkiSmsauth::SchoolMetadataForm).from_params(params) ValidateSchoolInfo.call(@form, authorization) do @@ -81,7 +81,7 @@ def school_validation end def update - enforce_permission_to :update, :authorization, authorization: authorization + enforce_permission_to(:update, :authorization, authorization:) @form = ConfirmationForm.from_params(params) ConfirmUserPhoneAuthorization.call(authorization, @form, session) do @@ -100,7 +100,7 @@ def update end def destroy - enforce_permission_to :destroy, :authorization, authorization: authorization + enforce_permission_to(:destroy, :authorization, authorization:) DestroyAuthorization.call(authorization) do on(:ok) do @@ -111,13 +111,13 @@ def destroy end def access_code - enforce_permission_to :update, :authorization, authorization: authorization + enforce_permission_to(:update, :authorization, authorization:) @form = form(::Decidim::HelsinkiSmsauth::AccessCodeForm).instance end def access_code_validation - @form = form(::Decidim::HelsinkiSmsauth::AccessCodeForm).from_params(params.merge({ current_locale: current_locale, organization: current_organization })) + @form = form(::Decidim::HelsinkiSmsauth::AccessCodeForm).from_params(params.merge({ current_locale:, organization: current_organization })) ValidateAccessCode.call(@form, authorization, current_user) do on(:ok) do handle_redirect @@ -167,7 +167,7 @@ def ensure_sending_limit def redirect_smsauth authorization_method = Decidim::Verifications::Adapter.from_element(authorization.name) - authorization_method.resume_authorization_path(redirect_url: redirect_url) + authorization_method.resume_authorization_path(redirect_url:) end def handle_redirect diff --git a/app/forms/decidim/helsinki_smsauth/verifications/authorization_form.rb b/app/forms/decidim/helsinki_smsauth/verifications/authorization_form.rb index 79eb301..807ed5b 100644 --- a/app/forms/decidim/helsinki_smsauth/verifications/authorization_form.rb +++ b/app/forms/decidim/helsinki_smsauth/verifications/authorization_form.rb @@ -37,7 +37,7 @@ def phone_number # The verification metadata to validate in the next step. def verification_metadata { - verification_code: verification_code, + verification_code:, code_sent_at: Time.current } end @@ -45,8 +45,8 @@ def verification_metadata def metadata { phone_number: phone_with_country_code, - school: school, - grade: grade + school:, + grade: } end @@ -58,7 +58,7 @@ def gateway mobile_number = phone_with_country_code gateway = Decidim.config.sms_gateway_service.constantize if gateway.instance_method(:initialize).parameters.length > 2 - gateway.new(mobile_number, generated_code, organization: organization) + gateway.new(mobile_number, generated_code, organization:) else gateway.new(mobile_number, generated_code) end diff --git a/app/models/decidim/helsinki_smsauth/signin_code.rb b/app/models/decidim/helsinki_smsauth/signin_code.rb index 4e0167d..4ef36ff 100644 --- a/app/models/decidim/helsinki_smsauth/signin_code.rb +++ b/app/models/decidim/helsinki_smsauth/signin_code.rb @@ -19,7 +19,7 @@ def generate! code = generated_code digest = "#{code}-#{Rails.application.secrets.secret_key_base}" self.code_hash = Digest::MD5.hexdigest(digest) - return code if ::Decidim::HelsinkiSmsauth::SigninCode.find_by(code_hash: code_hash).blank? + return code if ::Decidim::HelsinkiSmsauth::SigninCode.find_by(code_hash:).blank? end end diff --git a/lib/decidim/helsinki_smsauth/test/factories.rb b/lib/decidim/helsinki_smsauth/test/factories.rb index 540d9e0..8c429cb 100644 --- a/lib/decidim/helsinki_smsauth/test/factories.rb +++ b/lib/decidim/helsinki_smsauth/test/factories.rb @@ -8,7 +8,7 @@ def code_count(total, used) end FactoryBot.define do factory :signin_code_set, class: "Decidim::HelsinkiSmsauth::SigninCodeSet" do - creator { create(:user, :confirmed, :admin, organization: organization) } + creator { create(:user, :confirmed, :admin, organization:) } generated_code_amount { 1 } used_code_amount { 0 } metadata do @@ -22,7 +22,7 @@ def code_count(total, used) create_list( :signin_code, code_count(evaluator.generated_code_amount, evaluator.used_code_amount), - signin_code_set: signin_code_set + signin_code_set: ) end diff --git a/spec/shared/authenticate_with_phone_process_examples.rb b/spec/shared/authenticate_with_phone_process_examples.rb index d1bc28c..0f2961c 100644 --- a/spec/shared/authenticate_with_phone_process_examples.rb +++ b/spec/shared/authenticate_with_phone_process_examples.rb @@ -8,29 +8,33 @@ expect(page).to have_content("Problems?") expect(page).to have_link("Log in with a code given by your teacher", href: "/users/auth/sms/access_code") fill_in "Phone number", with: "45887874" - click_button "Send code" + click_on "Send code" within_flash_messages do expect(page).to have_content(/The code has been sent to/) end expect(page).to have_content("Log in via text message") - click_link("Resend the code") + click_on "Resend the code" within_flash_messages do expect(page).to have_content("Please wait at least 1 minute to resend the code.") end allow(Time).to receive(:current).and_return(2.minutes.from_now) - click_link("Resend the code") + click_on "Resend the code" expect(page).to have_content(/The code has been sent to/) fill_in "Login code", with: "000000" - click_button "Log in" + within ".new_sms_verification" do + click_on "Log in" + end within_flash_messages do expect(page).to have_content("Failed to verify the phone number. Please try again and check that you have entered the login code correctly.") end - code = page.find("#hint").text + code = page.find_by_id("hint").text fill_in "Login code", with: code - click_button "Log in" - expect(page).not_to have_current_path decidim_helsinki_smsauth.users_auth_sms_edit_path + within ".new_sms_verification" do + click_on "Log in" + end + expect(page).to have_no_current_path decidim_helsinki_smsauth.users_auth_sms_edit_path within_flash_messages do - expect(page).not_to have_content("Failed to verify the phone number. Please try again and check that you have entered the login code correctly.") + expect(page).to have_no_content("Failed to verify the phone number. Please try again and check that you have entered the login code correctly.") end end end diff --git a/spec/shared/filterable_login_code_examples.rb b/spec/shared/filterable_login_code_examples.rb index bec390e..a2fe436 100644 --- a/spec/shared/filterable_login_code_examples.rb +++ b/spec/shared/filterable_login_code_examples.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true shared_examples "filterable login code" do - let!(:creators) { create_list(:user, 2, :confirmed, :admin, organization: organization) } + let!(:creators) { create_list(:user, 2, :confirmed, :admin, organization:) } let!(:unused_codes) do 10.times do create_list(:signin_code_set, 1, generated_code_amount: code_amount, creator: creators[0]) @@ -45,9 +45,9 @@ end it "filters based on used codes" do - click_link "Filter" + click_on "Filter" find("a", text: "Includes used codes").hover - click_link "Yes" + click_on "Yes" table = find("table.stack.table-list") rows = table.find("tbody").all("tr") expect(rows.count).to eq(10) @@ -56,9 +56,9 @@ expect(used_codes.text).to eq("0") end - click_link "Filter" + click_on "Filter" find("a", text: "Includes used codes").hover - click_link "No" + click_on "No" rows = table.find("tbody").all("tr") expect(rows.count).to eq(5) rows.each do |row| diff --git a/spec/shared/school_select_examples.rb b/spec/shared/school_select_examples.rb index 826d33e..2ab3cf3 100644 --- a/spec/shared/school_select_examples.rb +++ b/spec/shared/school_select_examples.rb @@ -5,7 +5,7 @@ expect(page).to have_current_path(decidim_helsinki_smsauth.users_auth_sms_school_info_path) expect(page).to have_content("Login successful") - click_button "Save and continue" + click_on "Save and continue" expect(page).to have_current_path(decidim_helsinki_smsauth.users_auth_sms_school_info_path) within ".user-person" do expect(page).to have_content("There is an error in this field.") diff --git a/spec/shared/shared_context.rb b/spec/shared/shared_context.rb index 6a4eed8..2de8b55 100644 --- a/spec/shared/shared_context.rb +++ b/spec/shared/shared_context.rb @@ -25,14 +25,14 @@ def initialize(phone_number, code, organization: nil, queued: false) end shared_context "with single access code" do - let!(:creator) { create(:user, :confirmed, :admin, organization: organization) } - let!(:signin_code_set) { create(:signin_code_set, creator: creator) } - let!(:signin_code) { create(:signin_code, code: access_code, signin_code_set: signin_code_set) } + let!(:creator) { create(:user, :confirmed, :admin, organization:) } + let!(:signin_code_set) { create(:signin_code_set, creator:) } + let!(:signin_code) { create(:signin_code, code: access_code, signin_code_set:) } end shared_context "with helsinki_smsauth_id authorization" do - let!(:organization) { create(:organization, omniauth_settings: omniauth_settings, available_authorizations: available_authorizations) } - let!(:user) { create(:user, :confirmed, organization: organization) } + let!(:organization) { create(:organization, omniauth_settings:, available_authorizations:) } + let!(:user) { create(:user, :confirmed, organization:) } let(:available_authorizations) { ["helsinki_smsauth_id"] } let(:omniauth_settings) do { diff --git a/spec/system/admin/verification_code_generation_spec.rb b/spec/system/admin/verification_code_generation_spec.rb index 5923d4a..d68bf4c 100644 --- a/spec/system/admin/verification_code_generation_spec.rb +++ b/spec/system/admin/verification_code_generation_spec.rb @@ -2,10 +2,10 @@ require "spec_helper" -describe "verification code generation", type: :system do +describe "CodeGenerationVerification" do include_context "with helsinki_smsauth_id authorization" - let!(:admin) { create(:user, :admin, :confirmed, organization: organization) } + let!(:admin) { create(:user, :admin, :confirmed, organization:) } it_behaves_like "filterable login code" describe "login code generation" do @@ -20,15 +20,15 @@ expect(page).to have_link("Login via text message") end - click_link("Login via text message") + click_on "Login via text message" expect(page).to have_current_path("/admin/helsinki_smsauth_id/") expect(page).to have_content("Alternative login codes") - click_link "Create codes" + click_on "Create codes" expect(page).to have_current_path("/admin/helsinki_smsauth_id/signin_codes/new") expect(page).to have_content("Create codes") - click_button "Create" + click_on "Create" expect(page).to have_content("is not included in the list") end end diff --git a/spec/system/log_in_with_access_code_spec.rb b/spec/system/log_in_with_access_code_spec.rb index cbfd65d..bac134e 100644 --- a/spec/system/log_in_with_access_code_spec.rb +++ b/spec/system/log_in_with_access_code_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" -describe "log in with access code", type: :system do +describe "AccessCodeLogin" do let!(:organization) { create(:organization) } let(:access_code) { "ABCDE12345" } let(:incorrect_code) { "FalseCode" } @@ -11,12 +11,14 @@ before do switch_to_host(organization.host) visit_helsinki_smsauth - click_link "Log in with a code given by your teacher" + click_on "Log in with a code given by your teacher" end it "does not authenticate when incorrect code" do fill_in "sms_verification[access_code]", with: incorrect_code - click_button "Log in" + within ".new_sms_verification" do + click_on "Log in" + end within_flash_messages do expect(page).to have_content("Failed to verify the access code. Make sure that you have entered the correct code and try again.") end @@ -24,15 +26,17 @@ end context "when correct code" do - let!(:creator) { create(:user, :confirmed, :admin, organization: organization) } - let!(:signin_code_set) { create(:signin_code_set, creator: creator) } - let!(:signin_code) { create(:signin_code, code: access_code, signin_code_set: signin_code_set) } + let!(:creator) { create(:user, :confirmed, :admin, organization:) } + let!(:signin_code_set) { create(:signin_code_set, creator:) } + let!(:signin_code) { create(:signin_code, code: access_code, signin_code_set:) } it "creates users and signs in with correct code" do expect(signin_code_set.used_code_amount).to eq(0) fill_in "sms_verification[access_code]", with: access_code - click_button "Log in" + within ".new_sms_verification" do + click_on "Log in" + end expect(page).to have_content("Login successful.") signin_code_set.reload expect(signin_code_set.used_code_amount).to eq(1) diff --git a/spec/system/log_in_with_phone_number_spec.rb b/spec/system/log_in_with_phone_number_spec.rb index 3370eda..04b02ed 100644 --- a/spec/system/log_in_with_phone_number_spec.rb +++ b/spec/system/log_in_with_phone_number_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" -describe "log in with phone number", type: :system do +describe "PhoneLogin" do let(:organization) { create(:organization) } let(:auth_metadata) { { school: "0004", grade: 1, phone_number: "+3584551122334" } } @@ -18,7 +18,7 @@ let(:phone) { 4_551_122_334 } context "when user exists" do - let!(:user) { create(:user, organization: organization, phone_number: "+3584551122334") } + let!(:user) { create(:user, organization:, phone_number: "+3584551122334") } context "when authorization with school info exists" do let!(:authorization) do @@ -26,7 +26,7 @@ :authorization, :granted, name: "helsinki_smsauth_id", - user: user, + user:, metadata: auth_metadata ) end @@ -49,7 +49,7 @@ end fill_in "Grade", with: 1 - click_button "Save and continue" + click_on "Save and continue" expect(page).to have_current_path decidim.root_path user = Decidim::User.last expect(user.phone_number).to eq("+3584551122334") @@ -71,9 +71,11 @@ def verify_phone fill_in "Phone number", with: phone - click_button "Send code" - code = page.find("#hint").text + click_on "Send code" + code = page.find_by_id("hint").text fill_in "Login code", with: code - click_button "Log in" + within ".new_sms_verification" do + click_on "Log in" + end end end diff --git a/spec/system/verification_with_access_code_spec.rb b/spec/system/verification_with_access_code_spec.rb index 173df79..6ba2e0b 100644 --- a/spec/system/verification_with_access_code_spec.rb +++ b/spec/system/verification_with_access_code_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" -describe "verification with access code", type: :system do +describe "AccessCodeVerification" do include_context "with helsinki_smsauth_id authorization" include_context "with single access code" @@ -66,6 +66,6 @@ def fill_in_with(code = nil) fill_in("sms_verification[access_code]", with: code) if code - click_button "Verify your account" + click_on "Verify your account" end end diff --git a/spec/system/verification_with_phone_number_spec.rb b/spec/system/verification_with_phone_number_spec.rb index 70f4e1d..65e8bcf 100644 --- a/spec/system/verification_with_phone_number_spec.rb +++ b/spec/system/verification_with_phone_number_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" -describe "verification with phone number", type: :system do +describe "PhoneVerification" do include_context "with helsinki_smsauth_id authorization" include_context "with telia gateway" @@ -12,7 +12,7 @@ it "Adds the sms login method to authorization methods" do visit "/users/sign_in" - expect(page).to have_link('Sms', href: '/users/auth/sms', title: 'Log in with Sms') + expect(page).to have_link("Sms", href: "/users/auth/sms", title: "Log in with Sms") within ".login__omniauth-separator" do expect(page).to have_content "Or" end @@ -28,7 +28,7 @@ within "#dropdown-menu-profile" do expect(page).to have_css("a", text: "Authorizations") end - click_link "Authorization" + click_on "Authorization" expect(page).to have_content "Participant settings - Authorizations" within ".verification__container" do expect(page).to have_css("svg.verification__icon", count: 1) @@ -40,12 +40,12 @@ before do sign_in user, scope: :user visit decidim.account_path - click_link "Authorization" + click_on "Authorization" click_on "Login via text message" end context "when authorization belongs to someone else" do - let!(:another_user) { create(:user, :confirmed, organization: organization, phone_number: "+3584567890") } + let!(:another_user) { create(:user, :confirmed, organization:, phone_number: "+3584567890") } let(:auth_metadata) { { school: "0004", grade: 1, phone_number: "+3584567890" } } let!(:authorization) do create( @@ -62,7 +62,7 @@ # visit current_path expect(page).to have_content("Verify your phone number") fill_in "Phone number", with: 4_567_890 - click_button "Send code" + click_on "Send code" expect(page).to have_content "There was a problem with your request" expect(page).to have_content "A participant is already authorized with the same data. An administrator will contact you to verify your details." @@ -72,14 +72,14 @@ it "shows phone number authorization" do expect(page).to have_content("Verify your phone number") expect(page).to have_link("Log in with a code given by your teacher or youth worker", href: "/helsinki_smsauth_id/authorizations/access_code") - click_button "Send code" + click_on "Send code" expect(page).to have_content "There is an error in this field." end context "with valid phone number" do before do fill_in "Phone number", with: 4_567_891 - click_button "Send code" + click_on "Send code" end it "generates the authorization process" do @@ -91,15 +91,15 @@ expect(page).to have_link("Resend the code", href: "/helsinki_smsauth_id/authorizations/resend_code") expect(page).to have_link("Re-enter the phone number", href: "/helsinki_smsauth_id/authorizations") fill_in "Login code", with: "wrong code" - click_button "Continue" + click_on "Continue" expect(page).to have_content("Failed to authorize. Please try again.") end it "Verifies accont when everything is ok" do - code = page.find("#hint").text + code = page.find_by_id("hint").text fill_in "Login code", with: code authorization = Decidim::Authorization.find_by(decidim_user_id: user.id) - click_button "Continue" + click_on "Continue" expect(authorization.metadata["phone_number"]).to eq("+3584567891") expect(authorization).not_to be_granted @@ -110,16 +110,16 @@ context "when adding school info" do before do - code = page.find("#hint").text + code = page.find_by_id("hint").text fill_in "Login code", with: code - click_button "Continue" + click_on "Continue" end it "renders the school info correctly" do expect(page).to have_current_path("/helsinki_smsauth_id/authorizations/school_info") expect(page).to have_content("Text message verification successful. Please enter few more details and you are done.") - click_button "Save and continue" + click_on "Save and continue" expect(page).to have_current_path("/helsinki_smsauth_id/authorizations/school_info") within ".user-person" do expect(page).to have_content("There is an error in this field.") @@ -136,7 +136,7 @@ fill_in "Grade", with: 1 expect(Decidim::Authorization.find_by(decidim_user_id: user.id)).not_to be_granted - click_button "Save and continue" + click_on "Save and continue" authorization = Decidim::Authorization.find_by(decidim_user_id: user.id) expect(authorization).to be_granted expect(authorization.metadata["grade"]).to eq(1)