Skip to content

Commit 73f9c9e

Browse files
committed
fix: failing tests
Fix failing tests and move other_reason into member params and give param name more description
1 parent 9f5ea81 commit 73f9c9e

File tree

8 files changed

+22
-50
lines changed

8 files changed

+22
-50
lines changed

app/controllers/concerns/member_concerns.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def member_params
1818
:about_you,
1919
:skill_list,
2020
:newsletter,
21-
:other_reason,
21+
:how_you_found_us_other_reason,
2222
how_you_found_us: []
2323
)
2424
end

app/controllers/member/details_controller.rb

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,20 @@ def edit
1313
end
1414

1515
def update
16-
attrs = member_params.to_h
16+
how_found = Array(params.dig(:member, :how_you_found_us)).reject(&:blank?)
17+
other_reason = params.dig(:member, :how_you_found_us_other_reason)
1718

18-
if attrs[:how_you_found_us].blank?
19-
@member.assign_attributes(attrs)
19+
how_found << other_reason if other_reason.present?
20+
how_found.uniq!
21+
22+
if how_found.blank?
23+
@member.assign_attributes(member_params.to_h.except(:how_you_found_us_other_reason))
2024
@member.errors.add(:how_you_found_us, 'You must select at least one option')
2125
return render :edit
2226
end
2327

24-
how_found = params.dig(:member, :how_you_found_us)
25-
attrs[:how_you_found_us] =
26-
if how_found.is_a?(Array)
27-
how_found
28-
elsif how_found.blank?
29-
[]
30-
else
31-
[how_found]
32-
end
33-
34-
if params[:other_reason].present?
35-
attrs[:how_you_found_us] << params[:other_reason]
36-
end
37-
38-
attrs[:how_you_found_us].uniq!
39-
attrs[:how_you_found_us].reject!(&:blank?)
28+
attrs = member_params.to_h.except(:how_you_found_us_other_reason)
29+
attrs[:how_you_found_us] = how_found
4030

4131
return render :edit unless @member.update(attrs)
4232

app/views/member/details/edit.html.haml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
.form-check
2626
= check_box_tag 'member[how_you_found_us][]', option, false, id: "how_you_found_us_#{option.parameterize}", class: 'form-check-input'
2727
= label_tag "how_you_found_us_#{option.parameterize}", option, class: 'form-check-label', style: 'margin-left: 8px;'
28-
= label_tag :other_reason, t('member.details.edit.other_reason'), class: 'my-1'
29-
= text_field_tag :other_reason, nil, placeholder: "Please specify how you heard about us", class: 'form-control w-100;'
28+
= label_tag :how_you_found_us_other_reason, t('member.details.edit.how_you_found_us_other_reason'), class: 'my-1'
29+
= text_field_tag 'member[how_you_found_us_other_reason]', nil, placeholder: "Please specify how you heard about us", class: 'form-control w-100'
3030
= f.input :newsletter, as: :boolean, checked_value: true, unchecked_value: false
3131
.text-right.mb-4
3232
= hidden_field_tag :next_page, step2_member_path(member_type: @type)

config/locales/en.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ en:
443443
title: Almost there...
444444
summary: We need some more details from you to finish creating your account. We use these to help run our events.
445445
how_you_found_us: "How did you find out about us?"
446-
other_reason: "Please specify (if Other)"
446+
how_you_found_us_other_reason: "Please specify (if Other)"
447447
coach:
448448
about_you: What experience do you have? What languages do you like to use? Tell us a little bit about yourself!
449449
student:

spec/controllers/member/details_controller_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@
2727
id: member.id,
2828
member: {
2929
how_you_found_us: ['Search engine (Google etc.)'],
30+
how_you_found_us_other_reason: 'Saw a pamphlet',
3031
newsletter: 'false'
3132
},
32-
other_reason: 'Saw a flyer'
3333
}
3434

3535
member.reload
36-
expect(member.how_you_found_us).to contain_exactly('Search engine (Google etc.)', 'Saw a flyer')
36+
expect(member.how_you_found_us).to contain_exactly('Search engine (Google etc.)', 'Saw a pamphlet')
3737
expect(response).to redirect_to(step2_member_path)
3838
end
3939

@@ -42,9 +42,9 @@
4242
id: member.id,
4343
member: {
4444
how_you_found_us: [],
45+
how_you_found_us_other_reason: 'At a meetup',
4546
newsletter: 'true'
4647
},
47-
other_reason: 'At a meetup'
4848
}
4949

5050
member.reload
@@ -57,9 +57,9 @@
5757
id: member.id,
5858
member: {
5959
how_you_found_us: ['From a friend', '', 'From a friend'],
60+
how_you_found_us_other_reason: 'From a friend',
6061
newsletter: 'true'
6162
},
62-
other_reason: 'From a friend'
6363
}
6464

6565
member.reload

spec/features/member_joining_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
fill_in 'member_email', with: '[email protected]'
4343
fill_in 'member_about_you', with: Faker::Lorem.paragraph
4444
find('#how_you_found_us_from-a-friend').click
45-
fill_in 'other_reason', with: 'found on a poster', id: true
45+
fill_in 'member_how_you_found_us_other_reason', with: 'found on a poster', id: true
4646
click_on 'Next'
4747

4848
expect(page).to have_current_path(step2_member_path)

spec/features/subscribing_to_newsletter_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
fill_in 'member_surname', with: 'Doe'
2828
fill_in 'member_email', with: '[email protected]'
2929
fill_in 'member_about_you', with: Faker::Lorem.paragraph
30+
find('#how_you_found_us_from-a-friend').click
31+
fill_in 'member_how_you_found_us_other_reason', with: Faker::Lorem.paragraph, id: true
3032

3133
click_on 'Next'
3234
end
@@ -46,6 +48,8 @@
4648
fill_in 'member_surname', with: 'Doe'
4749
fill_in 'member_email', with: '[email protected]'
4850
fill_in 'member_about_you', with: Faker::Lorem.paragraph
51+
find('#how_you_found_us_from-a-friend').click
52+
fill_in 'member_how_you_found_us_other_reason', with: Faker::Lorem.paragraph, id: true
4953

5054
uncheck 'newsletter'
5155

spec/models/member_spec.rb

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,6 @@
1515
it { expect(member).to validate_presence_of(:email) }
1616
it { expect(member).to validate_presence_of(:about_you) }
1717
end
18-
19-
20-
context 'how_you_found_us validation' do
21-
let(:new_member) { Fabricate(:member) }
22-
it 'is invalid if how_you_found_us is nil' do
23-
new_member.how_you_found_us = nil
24-
new_member.valid?
25-
expect(new_member.errors[:how_you_found_us]).to include("You must select at least one option")
26-
end
27-
28-
it 'is invalid if how_you_found_us is an empty array' do
29-
new_member.how_you_found_us = []
30-
new_member.valid?
31-
expect(new_member.errors[:how_you_found_us]).to include("You must select at least one option")
32-
end
33-
34-
it 'is valid if how_you_found_us has at least one non-blank option' do
35-
new_member.how_you_found_us = ['From a friend']
36-
new_member.valid?
37-
expect(new_member.errors[:how_you_found_us]).to be_empty
38-
end
39-
end
4018
end
4119

4220
describe 'properties' do

0 commit comments

Comments
 (0)