diff --git a/test/unit/comment_test.rb b/test/unit/comment_test.rb
index f103282..2670dc8 100644
--- a/test/unit/comment_test.rb
+++ b/test/unit/comment_test.rb
@@ -60,7 +60,7 @@ class CommentTest < ActiveSupport::TestCase
c1.name = 'my name'
c1.valid?
assert c1.errors[:name.to_s].present?
- assert_no_match /\{fn\}/, c1.errors.on(:name)
+ assert_no_match /\{fn\}/, c1.errors[:name].first
end
should 'update counter cache in article' do
@@ -86,7 +86,7 @@ class CommentTest < ActiveSupport::TestCase
person = fast_create(Person)
community = fast_create(Community)
- activity = ActionTracker::Record.create :user => person, :target => community, :verb => 'add_member_in_community'
+ activity = create ActionTracker::Record, :user => person, :target => community, :verb => 'add_member_in_community'
cc = activity.comments_count
@@ -96,40 +96,40 @@ class CommentTest < ActiveSupport::TestCase
should 'provide author name for authenticated authors' do
owner = create_user('testuser').person
- assert_equal 'testuser', Comment.new(:author => owner).author_name
+ assert_equal 'testuser', build(Comment, :author => owner).author_name
end
should 'provide author name for unauthenticated author' do
- assert_equal 'anonymous coward', Comment.new(:name => 'anonymous coward').author_name
+ assert_equal 'anonymous coward', build(Comment, :name => 'anonymous coward').author_name
end
should 'provide empty text for author name if user was removed ' do
- assert_equal '', Comment.new(:author_id => 9999).author_name
+ assert_equal '', build(Comment, :author_id => 9999).author_name
end
should "provide author e-mail for athenticated authors" do
owner = create_user('testuser').person
- assert_equal owner.email, Comment.new(:author => owner).author_email
+ assert_equal owner.email, build(Comment, :author => owner).author_email
end
should "provide author e-mail for unauthenticated author" do
- assert_equal 'my@email.com', Comment.new(:email => 'my@email.com').author_email
+ assert_equal 'my@email.com', build(Comment, :email => 'my@email.com').author_email
end
should 'provide author link for authenticated author' do
author = Person.new
author.expects(:url).returns('http://blabla.net/author')
- assert_equal 'http://blabla.net/author', Comment.new(:author => author).author_link
+ assert_equal 'http://blabla.net/author', build(Comment, :author => author).author_link
end
should 'provide author e-mail as author link for unauthenticated author' do
- assert_equal 'my@email.com', Comment.new(:email => 'my@email.com').author_link
+ assert_equal 'my@email.com', build(Comment, :email => 'my@email.com').author_link
end
should 'provide url to comment' do
art = Article.new
art.expects(:url).returns({ :controller => 'lala', :action => 'something' })
- comment = Comment.new(:article => art)
+ comment = build(Comment, :article => art)
comment.expects(:id).returns(9876)
assert_equal({ :controller => 'lala', :action => 'something', :anchor => 'comment-9876'}, comment.url)
@@ -148,7 +148,7 @@ class CommentTest < ActiveSupport::TestCase
art = owner.articles.build(:name => 'ytest'); art.save!
comments = []
3.times do
- comments.unshift art.comments.create!(:title => 'a test comment', :body => 'bla', :author => owner)
+ comments.unshift create(Comment, :article => art, :title => 'a test comment', :body => 'bla', :author => owner)
end
assert_equal comments, Comment.recent
@@ -161,7 +161,7 @@ class CommentTest < ActiveSupport::TestCase
art = owner.articles.build(:name => 'ytest'); art.save!
comments = []
3.times do
- comments.unshift art.comments.create!(:title => 'a test comment', :body => 'bla', :author => owner)
+ comments.unshift create(Comment, :article => art, :title => 'a test comment', :body => 'bla', :author => owner)
end
comments.pop
@@ -170,15 +170,15 @@ class CommentTest < ActiveSupport::TestCase
end
should 'not accept invalid email' do
- c = Comment.new(:name => 'My Name', :email => 'my@invalid')
+ c = build(Comment, :name => 'My Name', :email => 'my@invalid')
c.valid?
assert c.errors[:email.to_s].present?
end
should 'generate links to comments on images with view set to true' do
owner = create_user('testuser').person
- image = UploadedFile.create!(:profile => owner, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'))
- comment = image.comments.create!(:article => image, :author => owner, :title => 'a random comment', :body => 'just another comment')
+ image = create(UploadedFile, :profile => owner, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'))
+ comment = create(Comment, :article => image, :author => owner, :title => 'a random comment', :body => 'just another comment')
assert comment.url[:view]
end
@@ -187,14 +187,14 @@ class CommentTest < ActiveSupport::TestCase
owner = create_user('testuser').person
article = owner.articles.create!(:name => 'test', :body => '...')
javascript = ""
- comment = article.comments.create!(:article => article, :name => javascript, :title => javascript, :body => javascript, :email => 'cracker@test.org')
+ comment = create(Comment, :article => article, :name => javascript, :title => javascript, :body => javascript, :email => 'cracker@test.org')
assert_no_match(/