Guest User

Untitled

a guest
Mar 9th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. ## test_unit.rb
  2.  
  3. test "should create a comment" do
  4. user = Factory.create_user
  5. ballot = Factory.create_with_requirements(:ballot)
  6.  
  7. assert user.comments_count == 0
  8. assert ballot.comments_count == 0
  9.  
  10.  
  11. first_post = Comment.create(
  12. :body => "this is a test",
  13. :user => user,
  14. :ballot => ballot)
  15. assert first_post.save
  16.  
  17. user.reload
  18. ballot.reload
  19.  
  20. assert user.comments_count == 1
  21. assert ballot.comments_count == 1
  22.  
  23. ## factory.rb
  24. module Factory
  25. def self.create_user(attributes = {})
  26. default_attributes = {
  27. :login => rand_str,
  28. :email => "#{rand_str}@test.com",
  29. :password => "test",
  30. :password_confirmation => "test"
  31. }
  32. user = User.new(default_attributes.merge(attributes))
  33. user.save
  34. user
  35. end
Add Comment
Please, Sign In to add comment