|
9 | 9 |
|
10 | 10 | describe 'PATCH #update' do |
11 | 11 | context 'with valid params' do |
12 | | - it 'updates how_you_found_us with checkbox options' do |
| 12 | + it 'updates how_you_found_us with radio option' do |
13 | 13 | patch :update, params: { |
14 | 14 | id: member.id, |
15 | 15 | member: { |
16 | | - how_you_found_us: ['Social Media', 'From a friend'], |
| 16 | + how_you_found_us: 'social_media', |
17 | 17 | newsletter: 'true' |
18 | 18 | } |
19 | 19 | } |
20 | 20 |
|
21 | 21 | member.reload |
22 | | - expect(member.how_you_found_us).to contain_exactly('Social Media', 'From a friend') |
| 22 | + expect(I18n.t("member.details.edit.how_you_found_us_options.#{member.how_you_found_us}")).to eq('Social media') |
| 23 | + expect(member.how_you_found_us_other_reason).to eq(nil) |
23 | 24 | expect(response).to redirect_to(step2_member_path) |
24 | 25 | end |
25 | 26 |
|
26 | 27 | it 'adds other_reason to how_you_found_us when provided' do |
27 | 28 | patch :update, params: { |
28 | 29 | id: member.id, |
29 | 30 | member: { |
30 | | - how_you_found_us: ['Search engine (Google etc.)'], |
| 31 | + how_you_found_us: 'other', |
31 | 32 | how_you_found_us_other_reason: 'Saw a pamphlet', |
32 | 33 | newsletter: 'false' |
33 | 34 | }, |
34 | 35 | } |
35 | 36 |
|
36 | 37 | member.reload |
37 | | - expect(member.how_you_found_us).to contain_exactly('Search engine (Google etc.)', 'Saw a pamphlet') |
| 38 | + expect(member.how_you_found_us).to eq('other') |
| 39 | + expect(member.how_you_found_us_other_reason).to eq('Saw a pamphlet') |
38 | 40 | expect(response).to redirect_to(step2_member_path) |
39 | 41 | end |
40 | 42 |
|
41 | 43 | it 'updates how_you_found_us with only other_reason' do |
42 | 44 | patch :update, params: { |
43 | 45 | id: member.id, |
44 | 46 | member: { |
45 | | - how_you_found_us: [], |
| 47 | + how_you_found_us: 'other', |
46 | 48 | how_you_found_us_other_reason: 'At a meetup', |
47 | 49 | newsletter: 'true' |
48 | 50 | }, |
49 | 51 | } |
50 | 52 |
|
51 | 53 | member.reload |
52 | | - expect(member.how_you_found_us).to eq(['At a meetup']) |
| 54 | + expect(member.how_you_found_us).to eq('other') |
| 55 | + expect(member.how_you_found_us_other_reason).to eq('At a meetup') |
53 | 56 | expect(response).to redirect_to(step2_member_path) |
54 | 57 | end |
55 | 58 |
|
56 | 59 | it 'removes duplicates and blank entries' do |
57 | 60 | patch :update, params: { |
58 | 61 | id: member.id, |
59 | 62 | member: { |
60 | | - how_you_found_us: ['From a friend', '', 'From a friend'], |
61 | | - how_you_found_us_other_reason: 'From a friend', |
| 63 | + how_you_found_us: 'other', |
| 64 | + how_you_found_us_other_reason: 'From a colleague', |
62 | 65 | newsletter: 'true' |
63 | 66 | }, |
64 | 67 | } |
65 | 68 |
|
66 | 69 | member.reload |
67 | | - expect(member.how_you_found_us).to eq(['From a friend']) |
| 70 | + expect(member.how_you_found_us).to eq('other') |
| 71 | + expect(member.how_you_found_us_other_reason).to eq('From a colleague') |
68 | 72 | expect(response).to redirect_to(step2_member_path) |
69 | 73 | end |
70 | 74 | end |
71 | 75 |
|
72 | 76 | context 'when update fails (invalid data)' do |
73 | | - it 'renders the edit template' do |
| 77 | + it 'error raised when no how you found us selection given' do |
74 | 78 | patch :update, params: { |
75 | 79 | id: member.id, |
76 | 80 | member: { |
77 | | - how_you_found_us: [] |
| 81 | + how_you_found_us: 'other', |
| 82 | + how_you_found_us_other_reason: nil, |
78 | 83 | } |
79 | 84 | } |
80 | 85 |
|
81 | | - expect(response.body).to include('You must select at least one option') |
| 86 | + expect(response.body).to include('You must select one option') |
| 87 | + end |
| 88 | + |
| 89 | + it 'error raised when both how you found us fields popoulated' do |
| 90 | + patch :update, params: { |
| 91 | + id: member.id, |
| 92 | + member: { |
| 93 | + how_you_found_us: 'from_a_friend', |
| 94 | + how_you_found_us_other_reason: 'something else', |
| 95 | + } |
| 96 | + } |
| 97 | + |
| 98 | + expect(response.body).to include('You must select one option') |
82 | 99 | end |
83 | 100 | end |
84 | 101 | end |
|
0 commit comments