Commit b601289830c8710ea29fea6aeebd68882e438107

Authored by Leandro Santos
2 parents d31534b1 68dae8a2

Merge branch 'staging' into production

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 &lt; 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?
... ...