From ec7f6ac55b19a6ab752b32c0fd24191ab5d54a52 Mon Sep 17 00:00:00 2001 From: Morgan Roderick Date: Fri, 31 Jul 2026 11:07:56 +0200 Subject: [PATCH 1/2] style(rubocop): resolve RSpec/AnyInstance todo entry --- .rubocop_todo.yml | 5 ---- spec/features/member_joining_spec.rb | 2 +- spec/support/helpers/login_helpers.rb | 24 ++++++++++++++++++- ...haves_like_managing_workshop_attendance.rb | 5 +++- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index d530b809e..0644bf7a7 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -102,11 +102,6 @@ Metrics/PerceivedComplexity: - 'app/services/invitation_manager.rb' - 'lib/omniauth/strategies/codebar.rb' -# Offense count: 2 -RSpec/AnyInstance: - Exclude: - - 'spec/support/helpers/login_helpers.rb' - # Offense count: 5 Rails/HasAndBelongsToMany: Exclude: diff --git a/spec/features/member_joining_spec.rb b/spec/features/member_joining_spec.rb index 8b1c67712..b5ad30bcf 100644 --- a/spec/features/member_joining_spec.rb +++ b/spec/features/member_joining_spec.rb @@ -16,7 +16,7 @@ scenario 'A visitor must fill in all mandatory fields in order to sign up' do member = Fabricate(:member, name: nil, surname: nil, email: nil, about_you: nil, how_you_found_us: nil, how_you_found_us_other_reason: nil) - member.update(can_log_in: true) + member.update_attribute(:can_log_in, true) login member visit edit_member_details_path diff --git a/spec/support/helpers/login_helpers.rb b/spec/support/helpers/login_helpers.rb index ea2864462..453d87a07 100644 --- a/spec/support/helpers/login_helpers.rb +++ b/spec/support/helpers/login_helpers.rb @@ -1,6 +1,24 @@ module LoginHelpers + module LoginStub + cattr_accessor :current_user + + def current_user + return LoginStub.current_user if LoginStub.current_user + + super + end + end + def login(member) - allow_any_instance_of(ApplicationController).to receive(:current_user).and_return(member) + if respond_to?(:visit) + visit '/logout' + mock_auth_hash(provider: member.auth_services.first.provider, + uid: member.auth_services.first.uid) + visit '/auth/github' + else + ApplicationController.prepend(LoginStub) unless ApplicationController < LoginStub + LoginStub.current_user = member + end end def login_mock_omniauth(member, login_link = 'Sign in') @@ -31,4 +49,8 @@ def accept_toc RSpec.configure do |config| config.include LoginHelpers, type: %i[feature controller] + + config.after do + LoginHelpers::LoginStub.current_user = nil + end end diff --git a/spec/support/shared_examples/behaves_like_managing_workshop_attendance.rb b/spec/support/shared_examples/behaves_like_managing_workshop_attendance.rb index a771f78d7..322f330e0 100644 --- a/spec/support/shared_examples/behaves_like_managing_workshop_attendance.rb +++ b/spec/support/shared_examples/behaves_like_managing_workshop_attendance.rb @@ -174,7 +174,10 @@ travel_into_the_future = Time.zone.now + 3.days allow(Time).to receive(:now).and_return(travel_into_the_future) - click_on 'Attend as a coach' + # The stubbed future Time expires the 24h session cookie, so log in again + login(coach) + visit workshop_path(workshop) + expect(page).to have_text('This event has already taken place') expect(page).to have_no_button('Attend as a coach') end From 1f5907f7324913c1e502ae4293c7d9c847071d04 Mon Sep 17 00:00:00 2001 From: Morgan Roderick Date: Fri, 31 Jul 2026 20:40:28 +0200 Subject: [PATCH 2/2] fix(member): show all validation errors on details form The early return for an invalid how_you_found_us selection skipped the model validations, so members only saw the selection error and had to resubmit to discover the remaining blank fields. Assign the attributes and run validations before rendering so every error shows at once. Exposed by switching feature specs from an allow_any_instance_of stub to a real OmniAuth login: the old stub reused the test's member object, leaking its stale validation errors into the render and masking this. --- app/controllers/member/details_controller.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/app/controllers/member/details_controller.rb b/app/controllers/member/details_controller.rb index 40cde7b6c..eff9fba53 100644 --- a/app/controllers/member/details_controller.rb +++ b/app/controllers/member/details_controller.rb @@ -15,10 +15,7 @@ def edit def update attrs = member_params - unless how_you_found_us_selections_valid?(attrs) - @member.errors.add(:how_you_found_us, 'You must select one option') - return render :edit - end + return render_with_all_errors(attrs) unless how_you_found_us_selections_valid?(attrs) attrs[:how_you_found_us_other_reason] = nil if attrs[:how_you_found_us] != 'other' @@ -27,4 +24,13 @@ def update attrs[:newsletter] ? subscribe_to_newsletter(@member) : unsubscribe_from_newsletter(@member) redirect_to step2_member_path end + + private + + def render_with_all_errors(attrs) + @member.assign_attributes(attrs) + @member.valid? + @member.errors.add(:how_you_found_us, 'You must select one option') + render :edit + end end