diff --git a/app/models/assignment_participant.rb b/app/models/assignment_participant.rb index 6814ece261b..3196a430b96 100644 --- a/app/models/assignment_participant.rb +++ b/app/models/assignment_participant.rb @@ -210,7 +210,7 @@ def self.import(row_hash, _row_header = nil, session, id) new_part.set_handle end prepared_mail = MailerHelper.send_mail_to_user(user, "Your Expertiza account and password have been created.", "user_welcome", "password") - prepared_mail.deliver + prepared_mail.deliver_now end # provide export functionality for Assignment Participants diff --git a/spec/models/assignment_particpant_spec.rb b/spec/models/assignment_particpant_spec.rb index 6a1d62951d6..89b1fb8fb2d 100644 --- a/spec/models/assignment_particpant_spec.rb +++ b/spec/models/assignment_particpant_spec.rb @@ -283,7 +283,7 @@ {name: 'no one', fullname: 'no one', email: 'name@email.com', role:'user_role_name', parent: 'user_parent_name'} end let(:attributes) do - {role_id: 1, name: 'no one', fullname: 'no one', email: '', email_on_submission: 'name@email.com', + {role_id: 1, name: 'no one', fullname: 'no one', email: 'name@email.com', email_on_submission: 'name@email.com', email_on_review: 'name@email.com', email_on_review_of_review: 'name@email.com'} end before(:each) do @@ -308,6 +308,35 @@ end end end + + context "when participant is added to assignment using csv" do + let(:row) do + {name: 'no one', fullname: 'no one', email: 'name@email.com', role:'user_role_name', parent: 'user_parent_name'} + end + let(:attributes) do + {role_id: 1, name: 'no one', fullname: 'no one', email: 'name@email.com', email_on_submission: 'name@email.com', + email_on_review: 'name@email.com', email_on_review_of_review: 'name@email.com'} + end + + it "should send an email to the participant", :mailer => true do + allow(ImportFileHelper).to receive(:define_attributes).with(row).and_return(attributes) + allow(ImportFileHelper).to receive(:create_new_user).with(attributes, {}).and_return(double('User', id: 1, email: 'name@email.com', first_name: 'no name', last_name: 'no name', name: 'no name')) + allow(Assignment).to receive(:find).with(1).and_return(assignment) + allow(AssignmentParticipant).to receive(:exists?).with(user_id: 1, parent_id: 1).and_return(false) + allow(AssignmentParticipant).to receive(:create).with(user_id: 1, parent_id: 1).and_return(participant) + allow(participant).to receive(:set_handle).and_return('handle') + + # Check that ActionMailer::Base.deliveries list is updated when email is set by import method. + # The last element in the deliveries list will be the email that was just sent when import method was invoked + # We need to verify the email was correct by checking its subject, from and to. + # In development/test mode, all mails go to expertiza.development@gmail.com and not actual user.to + expect { AssignmentParticipant.import(row, nil, {}, 1) }.to change { ActionMailer::Base.deliveries.count }.by(1) + email = ActionMailer::Base.deliveries.last + expect(email.from[0]).to eq('expertiza.development@gmail.com') + expect(email.to[0]).to eq('expertiza.development@gmail.com') + expect(email.subject).to eq('Your Expertiza account and password have been created.') + end + end end end