|
1 | 1 | RSpec.describe WorkshopInvitation do |
2 | 2 | subject(:workshop_invitation) { Fabricate(:workshop_invitation) } |
| 3 | + |
3 | 4 | it_behaves_like InvitationConcerns, :workshop_invitation, :workshop |
4 | 5 |
|
5 | 6 | context 'defaults' do |
|
14 | 15 |
|
15 | 16 | context 'if Student invitation' do |
16 | 17 | before { allow(subject).to receive(:student_attending?).and_return(true) } |
| 18 | + |
17 | 19 | it { is_expected.to validate_presence_of(:tutorial) } |
18 | 20 | it { is_expected.to validate_presence_of(:tutorial).on(:waitinglist) } |
19 | 21 | end |
20 | 22 | end |
21 | 23 |
|
22 | 24 | context 'scopes' do |
23 | | - context '#attended' do |
| 25 | + describe '#attended' do |
24 | 26 | it 'ignores when attended nil' do |
25 | 27 | Fabricate(:workshop_invitation, attended: nil) |
26 | 28 |
|
|
40 | 42 | end |
41 | 43 | end |
42 | 44 |
|
43 | | - context '#accepted_or_attended' do |
| 45 | + describe '#accepted_or_attended' do |
44 | 46 | it 'ignores when attending nil and attended nil' do |
45 | 47 | Fabricate(:workshop_invitation, attending: nil, attended: nil) |
46 | 48 |
|
|
83 | 85 | expect(WorkshopInvitation.year((Time.zone.now - 2.years).year).count).to eq(1) |
84 | 86 | end |
85 | 87 |
|
86 | | - context '#not_reminded' do |
| 88 | + describe '#not_reminded' do |
87 | 89 | it 'includes invitations without reminders' do |
88 | 90 | not_reminded = Fabricate(:student_workshop_invitation, reminded_at: nil) |
89 | 91 |
|
|
104 | 106 | expect(WorkshopInvitation.on_waiting_list).to eq(waiting_list) |
105 | 107 | end |
106 | 108 | end |
| 109 | + |
| 110 | + describe '#accept!' do |
| 111 | + let(:invitation) { Fabricate(:workshop_invitation, attending: false) } |
| 112 | + |
| 113 | + it 'sets attending to true' do |
| 114 | + invitation.accept! |
| 115 | + expect(invitation.reload.attending).to be true |
| 116 | + end |
| 117 | + |
| 118 | + it 'sets rsvp_time to current time by default' do |
| 119 | + invitation.accept! |
| 120 | + expect(invitation.reload.rsvp_time).to be_within(1.second).of(Time.zone.now) |
| 121 | + end |
| 122 | + |
| 123 | + it 'allows custom rsvp_time' do |
| 124 | + custom_time = 1.day.ago |
| 125 | + invitation.accept!(rsvp_time: custom_time) |
| 126 | + expect(invitation.reload.rsvp_time).to eq(custom_time) |
| 127 | + end |
| 128 | + |
| 129 | + it 'allows automated_rsvp flag' do |
| 130 | + invitation.accept!(automated_rsvp: true) |
| 131 | + expect(invitation.reload.automated_rsvp).to be true |
| 132 | + end |
| 133 | + |
| 134 | + it 'raises RecordInvalid on validation failure' do |
| 135 | + allow(invitation).to receive(:valid?).and_return(false) |
| 136 | + expect { invitation.accept! }.to raise_error(ActiveRecord::RecordInvalid) |
| 137 | + end |
| 138 | + end |
| 139 | + |
| 140 | + describe '#decline!' do |
| 141 | + let(:invitation) { Fabricate(:workshop_invitation, attending: true) } |
| 142 | + |
| 143 | + it 'sets attending to false' do |
| 144 | + invitation.decline! |
| 145 | + expect(invitation.reload.attending).to be false |
| 146 | + end |
| 147 | + |
| 148 | + it 'raises RecordInvalid on validation failure' do |
| 149 | + allow(invitation).to receive(:valid?).and_return(false) |
| 150 | + expect { invitation.decline! }.to raise_error(ActiveRecord::RecordInvalid) |
| 151 | + end |
| 152 | + end |
107 | 153 | end |
0 commit comments