Guest User

Untitled

a guest
Mar 15th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. # Code
  2.  
  3. def create
  4. email_addresses = params[:email_addresses].split(/\s*,\s*/)
  5. invitations = email_addresses.map do |recipient|
  6. Invitation.create!(:project => @project, :inviter => current_user, :recipient => recipient,
  7. :code => UniqueCodeGenerator.generate(recipient),
  8. :message => params[:email_body])
  9. end
  10. invitations.each do |invitation|
  11. invitation.accept_invitation_url = login_url(:code => invitation.code)
  12. InvitationMailer.deliver_invitation invitation
  13. end
  14.  
  15. redirect_to @project
  16. end
  17.  
  18.  
  19. # Test
  20. def test_create
  21. Invitation.destroy_all
  22.  
  23. login_as :joe
  24.  
  25. post :create,
  26. 'project_id' => projects(:project1).id,
  27. 'email_addresses' => "foo@bar.com, bar@baz.com",
  28. 'email_body' => "Finish my project."
  29.  
  30. assert_redirected_to project_path(projects(:project1))
  31.  
  32. invitation0 = Invitation.find_by_inviter_id_and_recipient(users(:joe).id, "foo@bar.com")
  33. assert_not_nil invitation0, "no invitation was created for foo@bar.com"
  34. assert !invitation0.code.blank?, "invitation had blank code"
  35. assert @emails[0].to.include?("foo@bar.com"), "first email not sent to the right recipient"
  36. assert @emails[0].subject.include?(projects(:project1).name), "first email did not mention project in the subject"
  37. assert @emails[0].body.include?(projects(:project1).name), "first email did not mention project in the body"
  38. assert @emails[0].body.include?("Finish my project."), "first email did not mention project in the body"
  39.  
  40. invitation1 = Invitation.find_by_inviter_id_and_recipient(users(:joe).id, "bar@baz.com")
  41. assert_not_nil invitation1, "no invitation was created for bar@baz.com"
  42. assert !invitation1.code.blank?, "invitation had blank code"
  43. assert @emails[1].to.include?("bar@baz.com"), "second email not sent to the right recipient"
  44. assert @emails[1].subject.include?(projects(:project1).name), "second email did not mention project in the subject"
  45. assert @emails[1].body.include?(projects(:project1).name), "second email did not mention project in the body"
  46. assert @emails[1].body.include?("Finish my project."), "second email did not mention project in the body"
  47.  
  48. assert_not_equal invitation0.code, invitation1.code, "invitations had the same code!"
  49. end
Add Comment
Please, Sign In to add comment