Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/models/concerns/invitation_concerns.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module InvitationConcerns
scope :taken_place, -> { where('date_and_time < ?', Time.zone.now) }

before_create :set_token
after_save :clear_member_cache, if: :saved_change_to_attending?
end

module InstanceMethods
Expand All @@ -36,6 +37,10 @@ def for_participant?

private

def clear_member_cache
member.clear_attending_event_ids_cache!
end

def set_token
self.token = loop do
random_token = SecureRandom.urlsafe_base64(nil, false)
Expand Down
8 changes: 0 additions & 8 deletions app/models/invitation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ class Invitation < ApplicationRecord
scope :coaches, -> { where(role: 'Coach') }
scope :verified, -> { where(verified: true).order(:updated_at) }

after_save :clear_member_cache, if: :saved_change_to_attending?

def student_spaces?
for_student? && event.student_spaces?
end
Expand All @@ -26,10 +24,4 @@ def coach_spaces?
def to_param
token
end

private

def clear_member_cache
member.clear_attending_event_ids_cache!
end
end
8 changes: 0 additions & 8 deletions app/models/meeting_invitation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,5 @@ class MeetingInvitation < ApplicationRecord
scope :accepted, -> { where(attending: true) }
scope :attended, -> { where(attended: true) }

after_save :clear_member_cache, if: :saved_change_to_attending?

alias event meeting

private

def clear_member_cache
member.clear_attending_event_ids_cache!
end
end
8 changes: 0 additions & 8 deletions app/models/workshop_invitation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ class WorkshopInvitation < ApplicationRecord
scope :on_waiting_list, -> { joins(:waiting_list) }
scope :with_notes_and_their_authors, -> { includes(member: [{ member_notes: :author }, :attendance_warnings]).includes(:overrider) }

after_save :clear_member_cache, if: :saved_change_to_attending?

def waiting_list_position
@waiting_list_position ||= WaitingList.by_workshop(workshop)
.where_role(role)
Expand All @@ -49,10 +47,4 @@ def student_attending?
def not_attending?
attending == false
end

private

def clear_member_cache
member.clear_attending_event_ids_cache!
end
end
11 changes: 0 additions & 11 deletions spec/models/invitation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,4 @@
expect(coach_invitation.coach_spaces?).to eq(true)
end
end

describe 'cache invalidation' do
let(:member) { Fabricate(:member) }
let(:event) { Fabricate(:event) }

it 'clears member cache when attending changes' do
invitation = Fabricate(:invitation, member: member, event: event, attending: false)
expect(member).to receive(:clear_attending_event_ids_cache!)
invitation.update!(attending: true)
end
end
end
7 changes: 7 additions & 0 deletions spec/support/shared_examples/behaves_like_an_invitation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
expect(invitation.token).not_to be_nil
end

describe 'cache invalidation' do
it 'clears member cache when attending changes' do
expect(invitation.member).to receive(:clear_attending_event_ids_cache!)
invitation.update!(attending: !invitation.attending)
end
end

describe '#scopes' do
describe '#not_accepted' do
it 'selects when attended nil' do
Expand Down