Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Code
- def create
- email_addresses = params[:email_addresses].split(/\s*,\s*/)
- invitations = email_addresses.map do |recipient|
- Invitation.create!(:project => @project, :inviter => current_user, :recipient => recipient,
- :code => UniqueCodeGenerator.generate(recipient),
- :message => params[:email_body])
- end
- invitations.each do |invitation|
- invitation.accept_invitation_url = login_url(:code => invitation.code)
- InvitationMailer.deliver_invitation invitation
- end
- redirect_to @project
- end
- # Test
- def test_create
- Invitation.destroy_all
- login_as :joe
- post :create,
- 'project_id' => projects(:project1).id,
- 'email_addresses' => "foo@bar.com, bar@baz.com",
- 'email_body' => "Finish my project."
- assert_redirected_to project_path(projects(:project1))
- invitation0 = Invitation.find_by_inviter_id_and_recipient(users(:joe).id, "foo@bar.com")
- assert_not_nil invitation0, "no invitation was created for foo@bar.com"
- assert !invitation0.code.blank?, "invitation had blank code"
- assert @emails[0].to.include?("foo@bar.com"), "first email not sent to the right recipient"
- assert @emails[0].subject.include?(projects(:project1).name), "first email did not mention project in the subject"
- assert @emails[0].body.include?(projects(:project1).name), "first email did not mention project in the body"
- assert @emails[0].body.include?("Finish my project."), "first email did not mention project in the body"
- invitation1 = Invitation.find_by_inviter_id_and_recipient(users(:joe).id, "bar@baz.com")
- assert_not_nil invitation1, "no invitation was created for bar@baz.com"
- assert !invitation1.code.blank?, "invitation had blank code"
- assert @emails[1].to.include?("bar@baz.com"), "second email not sent to the right recipient"
- assert @emails[1].subject.include?(projects(:project1).name), "second email did not mention project in the subject"
- assert @emails[1].body.include?(projects(:project1).name), "second email did not mention project in the body"
- assert @emails[1].body.include?("Finish my project."), "second email did not mention project in the body"
- assert_not_equal invitation0.code, invitation1.code, "invitations had the same code!"
- end
Add Comment
Please, Sign In to add comment