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 | 24 | protected |
25 | 25 | |
26 | 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 | 29 | end |
30 | 30 | |
31 | 31 | end | ... | ... |
test/unit/comment_test.rb
... | ... | @@ -73,7 +73,8 @@ class CommentTest < ActiveSupport::TestCase |
73 | 73 | end |
74 | 74 | |
75 | 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 | 78 | article = create(TextileArticle, :profile_id => owner.id) |
78 | 79 | |
79 | 80 | action = article.activity |
... | ... | @@ -286,7 +287,8 @@ class CommentTest < ActiveSupport::TestCase |
286 | 287 | end |
287 | 288 | |
288 | 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 | 292 | a = TextileArticle.create!(:profile => person, :name => 'My article', :body => 'Article body') |
291 | 293 | c0 = Comment.create!(:source => a, :body => 'My comment', :author => person) |
292 | 294 | c1 = Comment.create!(:reply_of_id => c0.id, :source => a, :body => 'bla', :author => person) |
... | ... | @@ -303,7 +305,8 @@ class CommentTest < ActiveSupport::TestCase |
303 | 305 | end |
304 | 306 | |
305 | 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 | 310 | a = TextileArticle.create!(:profile => person, :name => 'My article', :body => 'Article body') |
308 | 311 | c0 = Comment.create(:source => a, :body => 'Root comment', :author => person) |
309 | 312 | c1 = Comment.create(:reply_of_id => c0.id, :source => a, :body => 'c1', :author => person) |
... | ... | @@ -381,7 +384,8 @@ class CommentTest < ActiveSupport::TestCase |
381 | 384 | now = Time.now |
382 | 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 | 389 | article = create(TinyMceArticle, :profile => profile) |
386 | 390 | |
387 | 391 | ActionTracker::Record.record_timestamps = false |
... | ... | @@ -395,7 +399,8 @@ class CommentTest < ActiveSupport::TestCase |
395 | 399 | end |
396 | 400 | |
397 | 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 | 404 | article = create(TinyMceArticle, :profile => profile) |
400 | 405 | article.activity.destroy |
401 | 406 | ... | ... |
test/unit/uploaded_file_test.rb
... | ... | @@ -3,7 +3,8 @@ require_relative "../test_helper" |
3 | 3 | class UploadedFileTest < ActiveSupport::TestCase |
4 | 4 | |
5 | 5 | def setup |
6 | - @profile = create_user('testinguser').person | |
6 | + User.current = user = create_user 'testinguser' | |
7 | + @profile = user.person | |
7 | 8 | end |
8 | 9 | attr_reader :profile |
9 | 10 | ... | ... |