Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## test_unit.rb
- test "should create a comment" do
- user = Factory.create_user
- ballot = Factory.create_with_requirements(:ballot)
- assert user.comments_count == 0
- assert ballot.comments_count == 0
- first_post = Comment.create(
- :body => "this is a test",
- :user => user,
- :ballot => ballot)
- assert first_post.save
- user.reload
- ballot.reload
- assert user.comments_count == 1
- assert ballot.comments_count == 1
- ## factory.rb
- module Factory
- def self.create_user(attributes = {})
- default_attributes = {
- :login => rand_str,
- :email => "#{rand_str}@test.com",
- :password => "test",
- :password_confirmation => "test"
- }
- user = User.new(default_attributes.merge(attributes))
- user.save
- user
- end
Add Comment
Please, Sign In to add comment