Permalink
Browse files

Touch article when new tag was added

  • Loading branch information...
1 parent 8d9c918 commit eb3171bad7fb1b18d3d0062e1a4ddba3282aa2d6 @reyesyang committed Jan 6, 2014
Showing with 12 additions and 2 deletions.
  1. +2 −1 app/models/tagging.rb
  2. +10 −1 spec/models/article_spec.rb
@@ -1,6 +1,7 @@
# encoding: UTF-8
class Tagging < ActiveRecord::Base
- belongs_to :article
+ # :touch used to update article when new tag was added
+ belongs_to :article, touch: true
# :touch used to update tag when tagging was destroyed
belongs_to :tag, counter_cache: :articles_count, touch: true
@@ -24,7 +24,7 @@
expect(tag.updated_at).to be > tag_updated_at
end
- it "touch related article and tag when edit a article's tag_list" do
+ it "touch related article and tag when remove a tag from tag_list" do
article = create :article, tag_list: 'tag1,tag2'
article_updated_at = article.updated_at
tag = Tag.find_by_name 'tag2'
@@ -37,6 +37,15 @@
expect(tag.reload.articles_count).to eq (tag_articles_count - 1)
expect(tag.updated_at).to be > tag_updated_at
end
+
+ it "touch related article when add a tag to tag_list" do
+ article = create :article, tag_list: 'tag1'
+ article_updated_at = article.updated_at
+
+ sleep 1
+ article.update_attribute :tag_list, 'tag1,tag2'
+ expect(article.reload.updated_at).to be > article_updated_at
+ end
end
describe '#tag_list' do

0 comments on commit eb3171b

Please sign in to comment.