|
12 | 12 | it { is_expected.to validate_inclusion_of(:role).in_array(%w[Student Coach]) } |
13 | 13 | end |
14 | 14 |
|
15 | | - context '#student_spaces?' do |
| 15 | + describe '#student_spaces?' do |
16 | 16 | it 'checks if there are any available spaces for students at the event' do |
17 | 17 | student_invitation = Fabricate(:invitation) |
18 | 18 |
|
19 | 19 | expect(student_invitation.student_spaces?).to eq(true) |
20 | 20 | end |
21 | 21 | end |
22 | 22 |
|
23 | | - context '#coach_spaces?' do |
| 23 | + describe '#coach_spaces?' do |
24 | 24 | it 'checks if there are any available spaces for coaches at the event' do |
25 | 25 | coach_invitation = Fabricate(:coach_invitation) |
26 | 26 |
|
27 | 27 | expect(coach_invitation.coach_spaces?).to eq(true) |
28 | 28 | end |
29 | 29 | end |
| 30 | + |
| 31 | + describe '#accept!' do |
| 32 | + let(:invitation) { Fabricate(:invitation, attending: false) } |
| 33 | + |
| 34 | + it 'sets attending to true' do |
| 35 | + invitation.accept! |
| 36 | + expect(invitation.reload.attending).to be true |
| 37 | + end |
| 38 | + |
| 39 | + it 'does not verify by default' do |
| 40 | + invitation.accept! |
| 41 | + expect(invitation.reload.verified).to be false |
| 42 | + end |
| 43 | + |
| 44 | + it 'allows immediate verification' do |
| 45 | + invitation.accept!(verified: true) |
| 46 | + expect(invitation.reload.verified).to be true |
| 47 | + end |
| 48 | + |
| 49 | + it 'raises RecordInvalid on validation failure' do |
| 50 | + allow(invitation).to receive(:valid?).and_return(false) |
| 51 | + expect { invitation.accept! }.to raise_error(ActiveRecord::RecordInvalid) |
| 52 | + end |
| 53 | + end |
| 54 | + |
| 55 | + describe '#verify!' do |
| 56 | + let(:invitation) { Fabricate(:invitation, verified: false) } |
| 57 | + |
| 58 | + it 'sets verified to true' do |
| 59 | + invitation.verify! |
| 60 | + expect(invitation.reload.verified).to be true |
| 61 | + end |
| 62 | + |
| 63 | + it 'raises RecordInvalid on validation failure' do |
| 64 | + allow(invitation).to receive(:valid?).and_return(false) |
| 65 | + expect { invitation.verify! }.to raise_error(ActiveRecord::RecordInvalid) |
| 66 | + end |
| 67 | + end |
| 68 | + |
| 69 | + describe '#decline!' do |
| 70 | + let(:invitation) { Fabricate(:invitation, attending: true) } |
| 71 | + |
| 72 | + it 'sets attending to false' do |
| 73 | + invitation.decline! |
| 74 | + expect(invitation.reload.attending).to be false |
| 75 | + end |
| 76 | + |
| 77 | + it 'raises RecordInvalid on validation failure' do |
| 78 | + allow(invitation).to receive(:valid?).and_return(false) |
| 79 | + expect { invitation.decline! }.to raise_error(ActiveRecord::RecordInvalid) |
| 80 | + end |
| 81 | + end |
30 | 82 | end |
0 commit comments