Skip to content

Commit

Permalink
Touch article when new tag was added
Browse files Browse the repository at this point in the history
  • Loading branch information
reyesyang committed Jan 6, 2014
1 parent 8d9c918 commit eb3171b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion app/models/tagging.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,7 @@
# encoding: UTF-8 # encoding: UTF-8
class Tagging < ActiveRecord::Base 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 # :touch used to update tag when tagging was destroyed
belongs_to :tag, counter_cache: :articles_count, touch: true belongs_to :tag, counter_cache: :articles_count, touch: true
Expand Down
11 changes: 10 additions & 1 deletion spec/models/article_spec.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
expect(tag.updated_at).to be > tag_updated_at expect(tag.updated_at).to be > tag_updated_at
end 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 = create :article, tag_list: 'tag1,tag2'
article_updated_at = article.updated_at article_updated_at = article.updated_at
tag = Tag.find_by_name 'tag2' tag = Tag.find_by_name 'tag2'
Expand All @@ -37,6 +37,15 @@
expect(tag.reload.articles_count).to eq (tag_articles_count - 1) expect(tag.reload.articles_count).to eq (tag_articles_count - 1)
expect(tag.updated_at).to be > tag_updated_at expect(tag.updated_at).to be > tag_updated_at
end 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 end


describe '#tag_list' do describe '#tag_list' do
Expand Down

0 comments on commit eb3171b

Please sign in to comment.