diff --git a/app/mailers/group_mailer.rb b/app/mailers/group_mailer.rb index b60bb7422..e9d24e415 100644 --- a/app/mailers/group_mailer.rb +++ b/app/mailers/group_mailer.rb @@ -19,8 +19,9 @@ def event_created_confirmation event ) end - def event_joined_confirmation event - user = event.user + def event_joined_confirmation event_id, user_id + event = Outing.find(event_id) + user = User.find(user_id) IcalService.attach_ical(group: event, for_user: user, to: self) diff --git a/app/observers/join_request_observer.rb b/app/observers/join_request_observer.rb index af998438e..17bb37c5c 100644 --- a/app/observers/join_request_observer.rb +++ b/app/observers/join_request_observer.rb @@ -32,8 +32,9 @@ def action(verb, record) end def mailer(record) - if record.joinable.respond_to?(:outing?) && record.joinable.outing? - GroupMailer.event_joined_confirmation(record.joinable).deliver_later - end + return unless record.user + return unless record.joinable.respond_to?(:outing?) && record.joinable.outing? + + GroupMailer.event_joined_confirmation(record.joinable_id, record.user_id).deliver_later end end diff --git a/spec/mailers/group_mailer_spec.rb b/spec/mailers/group_mailer_spec.rb index 3e594cffa..80cb19127 100644 --- a/spec/mailers/group_mailer_spec.rb +++ b/spec/mailers/group_mailer_spec.rb @@ -1,15 +1,15 @@ require 'rails_helper' describe GroupMailer, type: :mailer do - let(:user) { create :public_user } - let(:outing) { create :outing, user: user } + let(:participant) { create :public_user, first_name: 'Alice' } + let(:organizer) { create :public_user, first_name: 'Bob' } + let(:outing) { create :outing, user: organizer } describe ".event_joined_confirmation" do - let(:user) { create :public_user } - let(:mail) { GroupMailer.event_joined_confirmation(outing) } + let(:mail) { GroupMailer.event_joined_confirmation(outing.id, participant.id) } let(:json_variables) { JSON.parse(mail['X-MJ-Vars'].value) } - it { expect(json_variables['first_name']).to eq(user.first_name) } + it { expect(json_variables['first_name']).to eq(participant.first_name) } it { expect(json_variables).to have_key("outing") } it { expect(json_variables['outing']['name']).to eq(outing.title) } it { expect(json_variables['outing']['calendar_url']).to match("agenda") }