Commit 68dae8a224ec8c651d1b826680365ab026221797
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
Merge branch 'following' into staging
Conflicts: app/models/article_follower.rb test/unit/article_test.rb
Showing
2 changed files
with
17 additions
and
9 deletions
Show diff stats
app/models/article_follower.rb
1 | 1 | class ArticleFollower < ActiveRecord::Base |
2 | 2 | |
3 | - extend CacheCounterHelper | |
4 | - | |
5 | 3 | attr_accessible :article_id, :person_id, :since |
6 | 4 | belongs_to :article, :counter_cache => :followers_count |
7 | 5 | belongs_to :person |
8 | 6 | |
9 | - after_create do |article_follower| | |
10 | - ArticleFollower.update_cache_counter(:followers_count, article_follower.article, 1) | |
11 | - end | |
12 | - | |
13 | - after_destroy do |article_follower| | |
14 | - ArticleFollower.update_cache_counter(:followers_count, article_follower.article, -1) | |
15 | - end | |
16 | 7 | end | ... | ... |
test/unit/article_test.rb
... | ... | @@ -2202,6 +2202,23 @@ class ArticleTest < ActiveSupport::TestCase |
2202 | 2202 | article.destroy |
2203 | 2203 | end |
2204 | 2204 | |
2205 | + should "increment followers count when a person follow an article" do | |
2206 | + a = fast_create(Article) | |
2207 | + p = fast_create(Person) | |
2208 | + assert_difference "a.reload.followers_count" do | |
2209 | + a.person_followers << p | |
2210 | + end | |
2211 | + end | |
2212 | + | |
2213 | + should "decrement followers count when a person unfollow an article" do | |
2214 | + p = fast_create(Person) | |
2215 | + a = fast_create(Article, :profile_id => p) | |
2216 | + a.person_followers << p | |
2217 | + assert_difference "a.reload.followers_count", -1 do | |
2218 | + a.person_followers.destroy_all | |
2219 | + end | |
2220 | + end | |
2221 | + | |
2205 | 2222 | should 'have can_display_media_panel with default false' do |
2206 | 2223 | a = Article.new |
2207 | 2224 | assert !a.can_display_media_panel? | ... | ... |