From 64eda093b32fa9535ee7da8148c2745510c997be Mon Sep 17 00:00:00 2001 From: Braulio Bhavamitra Date: Tue, 8 Sep 2015 18:57:42 -0300 Subject: [PATCH] rails4: fix tests on edge cases --- app/models/profile_activity.rb | 4 ++-- test/unit/comment_test.rb | 15 ++++++++++----- test/unit/uploaded_file_test.rb | 3 ++- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/app/models/profile_activity.rb b/app/models/profile_activity.rb index 8f7c804..4492390 100644 --- a/app/models/profile_activity.rb +++ b/app/models/profile_activity.rb @@ -24,8 +24,8 @@ class ProfileActivity < ActiveRecord::Base protected def copy_timestamps - self.created_at = self.activity.created_at - self.updated_at = self.activity.updated_at + self.created_at = self.activity.created_at if self.activity.created_at + self.updated_at = self.activity.updated_at if self.activity.updated_at end end diff --git a/test/unit/comment_test.rb b/test/unit/comment_test.rb index ca033cd..729f703 100644 --- a/test/unit/comment_test.rb +++ b/test/unit/comment_test.rb @@ -73,7 +73,8 @@ class CommentTest < ActiveSupport::TestCase end should 'update counter cache in article activity' do - owner = create_user('testuser').person + User.current = user = create_user 'testuser' + owner = user.person article = create(TextileArticle, :profile_id => owner.id) action = article.activity @@ -286,7 +287,8 @@ class CommentTest < ActiveSupport::TestCase end should "return activities comments as a thread" do - person = create_user.person + User.current = user = create_user + person = user.person a = TextileArticle.create!(:profile => person, :name => 'My article', :body => 'Article body') c0 = Comment.create!(:source => a, :body => 'My comment', :author => person) c1 = Comment.create!(:reply_of_id => c0.id, :source => a, :body => 'bla', :author => person) @@ -303,7 +305,8 @@ class CommentTest < ActiveSupport::TestCase end should "return activities comments when some comment on thread is spam and not display its replies" do - person = create_user.person + User.current = user = create_user + person = user.person a = TextileArticle.create!(:profile => person, :name => 'My article', :body => 'Article body') c0 = Comment.create(:source => a, :body => 'Root comment', :author => person) c1 = Comment.create(:reply_of_id => c0.id, :source => a, :body => 'c1', :author => person) @@ -381,7 +384,8 @@ class CommentTest < ActiveSupport::TestCase now = Time.now Time.stubs(:now).returns(now) - profile = create_user('testuser').person + User.current = user = create_user 'testuser' + profile = user.person article = create(TinyMceArticle, :profile => profile) ActionTracker::Record.record_timestamps = false @@ -395,7 +399,8 @@ class CommentTest < ActiveSupport::TestCase end should 'create a new activity when add a comment and the activity was removed' do - profile = create_user('testuser').person + User.current = user = create_user 'testuser' + profile = user.person article = create(TinyMceArticle, :profile => profile) article.activity.destroy diff --git a/test/unit/uploaded_file_test.rb b/test/unit/uploaded_file_test.rb index 4c12f77..03e1799 100644 --- a/test/unit/uploaded_file_test.rb +++ b/test/unit/uploaded_file_test.rb @@ -3,7 +3,8 @@ require_relative "../test_helper" class UploadedFileTest < ActiveSupport::TestCase def setup - @profile = create_user('testinguser').person + User.current = user = create_user 'testinguser' + @profile = user.person end attr_reader :profile -- libgit2 0.21.2