File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed
Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -11,4 +11,12 @@ class MeetingInvitation < ApplicationRecord
1111 scope :attended , -> { where ( attended : true ) }
1212
1313 alias event meeting
14+
15+ def accept!
16+ update! ( attending : true )
17+ end
18+
19+ def decline!
20+ update! ( attending : false )
21+ end
1422end
Original file line number Diff line number Diff line change 1111 it { is_expected . to validate_presence_of ( :member ) }
1212 it { is_expected . to validate_uniqueness_of ( :member_id ) . scoped_to ( :meeting_id ) }
1313 end
14+
15+ describe '#accept!' do
16+ let ( :invitation ) { Fabricate ( :meeting_invitation , attending : false ) }
17+
18+ it 'sets attending to true' do
19+ invitation . accept!
20+ expect ( invitation . reload . attending ) . to be true
21+ end
22+
23+ it 'raises RecordInvalid on validation failure' do
24+ allow ( invitation ) . to receive ( :valid? ) . and_return ( false )
25+ expect { invitation . accept! } . to raise_error ( ActiveRecord ::RecordInvalid )
26+ end
27+ end
28+
29+ describe '#decline!' do
30+ let ( :invitation ) { Fabricate ( :meeting_invitation , attending : true ) }
31+
32+ it 'sets attending to false' do
33+ invitation . decline!
34+ expect ( invitation . reload . attending ) . to be false
35+ end
36+
37+ it 'raises RecordInvalid on validation failure' do
38+ allow ( invitation ) . to receive ( :valid? ) . and_return ( false )
39+ expect { invitation . decline! } . to raise_error ( ActiveRecord ::RecordInvalid )
40+ end
41+ end
1442end
You can’t perform that action at this time.
0 commit comments