Commit f09b7dcb3661ef20aac0264cd802533cb8a0bef5

Authored by Leandro Santos
1 parent a33cc1d9
Exists in staging

removing duplicated code

db/migrate/20150616200201_create_article_followers.rb
... ... @@ -1,20 +0,0 @@
1   -class CreateArticleFollowers < ActiveRecord::Migration
2   -
3   -def self.up
4   - create_table :article_followers do |t|
5   - t.integer :person_id, null: false
6   - t.integer :article_id, null: false
7   - t.datetime :since
8   -
9   - t.timestamps
10   - end
11   - add_index :article_followers, :person_id
12   - add_index :article_followers, :article_id
13   - add_index :article_followers, [:person_id, :article_id], :unique => true
14   - end
15   -
16   - def self.down
17   - drop_table :article_followers
18   - end
19   -
20   -end
db/migrate/20150909091347_add_followers_count_to_article.rb
... ... @@ -1,15 +0,0 @@
1   -class AddFollowersCountToArticle < ActiveRecord::Migration
2   -
3   - def self.up
4   - add_column :articles, :followers_count, :integer, :default => 0
5   - add_column :article_versions, :followers_count, :integer
6   -
7   - execute "update articles set followers_count = (select count(*) from article_followers where article_followers.article_id = articles.id)"
8   - end
9   -
10   - def self.down
11   - remove_column :article_versions, :followers_count
12   - remove_column :articles, :followers_count
13   - end
14   -
15   -end
test/unit/article_test.rb
... ... @@ -2216,23 +2216,6 @@ class ArticleTest &lt; ActiveSupport::TestCase
2216 2216 article.destroy
2217 2217 end
2218 2218  
2219   - should "increment followers count when a person follow an article" do
2220   - a = fast_create(Article)
2221   - p = fast_create(Person)
2222   - assert_difference "a.reload.followers_count" do
2223   - a.person_followers << p
2224   - end
2225   - end
2226   -
2227   - should "decrement followers count when a person unfollow an article" do
2228   - p = fast_create(Person)
2229   - a = fast_create(Article, :profile_id => p)
2230   - a.person_followers << p
2231   - assert_difference "a.reload.followers_count", -1 do
2232   - a.person_followers.destroy_all
2233   - end
2234   - end
2235   -
2236 2219 should 'be able to vote in an article without a user' do
2237 2220 article = create(Article, :name => 'Test', :profile => profile, :last_changed_by => nil)
2238 2221 assert_difference 'article.votes_for', 2 do
... ...