Skip to content

Commit

Permalink
Use published_at for month/year instead of current date.
Browse files Browse the repository at this point in the history
  • Loading branch information
bgilham committed May 9, 2012
1 parent 77a87d3 commit 064a4d3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions app/models/blog/post.rb
Expand Up @@ -36,8 +36,8 @@ class Blog::Post < ActiveRecord::Base

# -- Callbacks ------------------------------------------------------------
before_validation :set_slug,
:set_date,
:set_published_at
:set_published_at,
:set_date
after_save :sync_tags,
:sync_categories

Expand All @@ -58,8 +58,8 @@ def set_slug
end

def set_date
self.year ||= Time.zone.now.year
self.month ||= Time.zone.now.month
self.year = self.published_at.year
self.month = self.published_at.month
end

def set_published_at
Expand Down
4 changes: 2 additions & 2 deletions test/unit/post_test.rb
Expand Up @@ -16,12 +16,12 @@ def test_validation

def test_validation_of_slug_uniqueness
old_post = blog_posts(:default)
old_post.update_attributes!(:year => Time.now.year, :month => Time.now.month)
old_post.update_attributes!(:published_at => Time.now)
post = Blog::Post.new(:title => old_post.title, :content => 'Test Content')
assert post.invalid?
assert_has_errors_on post, [:slug]

old_post.update_attributes!(:year => 1.year.ago.year, :month => Time.now.month)
old_post.update_attributes!(:published_at => 1.year.ago)
assert post.valid?
end

Expand Down

0 comments on commit 064a4d3

Please sign in to comment.