Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 10 additions & 4 deletions app/controllers/member/details_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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
2 changes: 1 addition & 1 deletion spec/features/member_joining_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 25 additions & 1 deletion spec/support/helpers/login_helpers.rb
Original file line number Diff line number Diff line change
@@ -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')
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down