Commit 662babb3cdf5c4614b4c8e86c5da7b54dadc9ea3
1 parent
2716f355
Exists in
master
and in
28 other branches
Fix Article#published_at
That test was actually testing that published_at was equal to created_at by default, but what we actually want is to set published_at to the time of creation!
Showing
2 changed files
with
6 additions
and
4 deletions
Show diff stats
app/models/article.rb
... | ... | @@ -34,7 +34,7 @@ class Article < ActiveRecord::Base |
34 | 34 | before_destroy :rotate_translations |
35 | 35 | |
36 | 36 | before_create do |article| |
37 | - article.published_at = article.created_at if article.published_at.nil? | |
37 | + article.published_at ||= Time.now | |
38 | 38 | if article.reference_article && !article.parent |
39 | 39 | parent = article.reference_article.parent |
40 | 40 | if parent && parent.blog? && article.profile.has_blog? | ... | ... |
test/unit/article_test.rb
... | ... | @@ -707,9 +707,11 @@ class ArticleTest < ActiveSupport::TestCase |
707 | 707 | assert_respond_to Article.new, :published_at |
708 | 708 | end |
709 | 709 | |
710 | - should 'published_at is same as created_at if not set' do | |
711 | - a = fast_create(Article, :name => 'Published at', :profile_id => profile.id) | |
712 | - assert_equal a.created_at, a.published_at | |
710 | + should 'fill published_at with current date if not set' do | |
711 | + now = Time.now | |
712 | + Time.stubs(:now).returns(now) | |
713 | + a = create(Article, :name => 'Published at', :profile_id => profile.id) | |
714 | + assert_equal now, a.published_at | |
713 | 715 | end |
714 | 716 | |
715 | 717 | should 'use npage to compose cache key' do | ... | ... |