Commit 64eda093b32fa9535ee7da8148c2745510c997be
1 parent
c5a6b574
Exists in
master
and in
20 other branches
rails4: fix tests on edge cases
Showing
3 changed files
with
14 additions
and
8 deletions
Show diff stats
app/models/profile_activity.rb
@@ -24,8 +24,8 @@ class ProfileActivity < ActiveRecord::Base | @@ -24,8 +24,8 @@ class ProfileActivity < ActiveRecord::Base | ||
24 | protected | 24 | protected |
25 | 25 | ||
26 | def copy_timestamps | 26 | def copy_timestamps |
27 | - self.created_at = self.activity.created_at | ||
28 | - self.updated_at = self.activity.updated_at | 27 | + self.created_at = self.activity.created_at if self.activity.created_at |
28 | + self.updated_at = self.activity.updated_at if self.activity.updated_at | ||
29 | end | 29 | end |
30 | 30 | ||
31 | end | 31 | end |
test/unit/comment_test.rb
@@ -73,7 +73,8 @@ class CommentTest < ActiveSupport::TestCase | @@ -73,7 +73,8 @@ class CommentTest < ActiveSupport::TestCase | ||
73 | end | 73 | end |
74 | 74 | ||
75 | should 'update counter cache in article activity' do | 75 | should 'update counter cache in article activity' do |
76 | - owner = create_user('testuser').person | 76 | + User.current = user = create_user 'testuser' |
77 | + owner = user.person | ||
77 | article = create(TextileArticle, :profile_id => owner.id) | 78 | article = create(TextileArticle, :profile_id => owner.id) |
78 | 79 | ||
79 | action = article.activity | 80 | action = article.activity |
@@ -286,7 +287,8 @@ class CommentTest < ActiveSupport::TestCase | @@ -286,7 +287,8 @@ class CommentTest < ActiveSupport::TestCase | ||
286 | end | 287 | end |
287 | 288 | ||
288 | should "return activities comments as a thread" do | 289 | should "return activities comments as a thread" do |
289 | - person = create_user.person | 290 | + User.current = user = create_user |
291 | + person = user.person | ||
290 | a = TextileArticle.create!(:profile => person, :name => 'My article', :body => 'Article body') | 292 | a = TextileArticle.create!(:profile => person, :name => 'My article', :body => 'Article body') |
291 | c0 = Comment.create!(:source => a, :body => 'My comment', :author => person) | 293 | c0 = Comment.create!(:source => a, :body => 'My comment', :author => person) |
292 | c1 = Comment.create!(:reply_of_id => c0.id, :source => a, :body => 'bla', :author => person) | 294 | c1 = Comment.create!(:reply_of_id => c0.id, :source => a, :body => 'bla', :author => person) |
@@ -303,7 +305,8 @@ class CommentTest < ActiveSupport::TestCase | @@ -303,7 +305,8 @@ class CommentTest < ActiveSupport::TestCase | ||
303 | end | 305 | end |
304 | 306 | ||
305 | should "return activities comments when some comment on thread is spam and not display its replies" do | 307 | should "return activities comments when some comment on thread is spam and not display its replies" do |
306 | - person = create_user.person | 308 | + User.current = user = create_user |
309 | + person = user.person | ||
307 | a = TextileArticle.create!(:profile => person, :name => 'My article', :body => 'Article body') | 310 | a = TextileArticle.create!(:profile => person, :name => 'My article', :body => 'Article body') |
308 | c0 = Comment.create(:source => a, :body => 'Root comment', :author => person) | 311 | c0 = Comment.create(:source => a, :body => 'Root comment', :author => person) |
309 | c1 = Comment.create(:reply_of_id => c0.id, :source => a, :body => 'c1', :author => person) | 312 | c1 = Comment.create(:reply_of_id => c0.id, :source => a, :body => 'c1', :author => person) |
@@ -381,7 +384,8 @@ class CommentTest < ActiveSupport::TestCase | @@ -381,7 +384,8 @@ class CommentTest < ActiveSupport::TestCase | ||
381 | now = Time.now | 384 | now = Time.now |
382 | Time.stubs(:now).returns(now) | 385 | Time.stubs(:now).returns(now) |
383 | 386 | ||
384 | - profile = create_user('testuser').person | 387 | + User.current = user = create_user 'testuser' |
388 | + profile = user.person | ||
385 | article = create(TinyMceArticle, :profile => profile) | 389 | article = create(TinyMceArticle, :profile => profile) |
386 | 390 | ||
387 | ActionTracker::Record.record_timestamps = false | 391 | ActionTracker::Record.record_timestamps = false |
@@ -395,7 +399,8 @@ class CommentTest < ActiveSupport::TestCase | @@ -395,7 +399,8 @@ class CommentTest < ActiveSupport::TestCase | ||
395 | end | 399 | end |
396 | 400 | ||
397 | should 'create a new activity when add a comment and the activity was removed' do | 401 | should 'create a new activity when add a comment and the activity was removed' do |
398 | - profile = create_user('testuser').person | 402 | + User.current = user = create_user 'testuser' |
403 | + profile = user.person | ||
399 | article = create(TinyMceArticle, :profile => profile) | 404 | article = create(TinyMceArticle, :profile => profile) |
400 | article.activity.destroy | 405 | article.activity.destroy |
401 | 406 |
test/unit/uploaded_file_test.rb
@@ -3,7 +3,8 @@ require_relative "../test_helper" | @@ -3,7 +3,8 @@ require_relative "../test_helper" | ||
3 | class UploadedFileTest < ActiveSupport::TestCase | 3 | class UploadedFileTest < ActiveSupport::TestCase |
4 | 4 | ||
5 | def setup | 5 | def setup |
6 | - @profile = create_user('testinguser').person | 6 | + User.current = user = create_user 'testinguser' |
7 | + @profile = user.person | ||
7 | end | 8 | end |
8 | attr_reader :profile | 9 | attr_reader :profile |
9 | 10 |