From cf3ee6171dd58c236536d43b95b9df13aa7d589b 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 | 26 ++++++++++++++++++- ...haves_like_managing_workshop_attendance.rb | 5 +++- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 6e1c0ce0a..056d35101 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -123,11 +123,6 @@ Naming/PredicatePrefix: - 'app/policies/event_policy.rb' - 'app/policies/workshop_policy.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..3319b4661 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.toggle!(:can_log_in) 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..9e4fb3157 100644 --- a/spec/support/helpers/login_helpers.rb +++ b/spec/support/helpers/login_helpers.rb @@ -1,6 +1,26 @@ module LoginHelpers + module LoginStub + class << self + attr_accessor :current_user + end + + 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 +51,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 0d970b088969f04d3625d38c4472627386e8a424 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 9652a7f5d..a069419db 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