From 981f835406be2c438054d093b4b0446c775db521 Mon Sep 17 00:00:00 2001 From: Leandro Nunes dos Santos Date: Wed, 9 Mar 2016 10:05:21 -0300 Subject: [PATCH] add primary key to article follower table to fox has many through association --- db/migrate/20160309122141_add_id_to_article_follower.rb | 5 +++++ db/schema.rb | 4 ++-- test/unit/article_test.rb | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20160309122141_add_id_to_article_follower.rb diff --git a/db/migrate/20160309122141_add_id_to_article_follower.rb b/db/migrate/20160309122141_add_id_to_article_follower.rb new file mode 100644 index 0000000..1c4e208 --- /dev/null +++ b/db/migrate/20160309122141_add_id_to_article_follower.rb @@ -0,0 +1,5 @@ +class AddIdToArticleFollower < ActiveRecord::Migration + def change + add_column :article_followers, :id, :primary_key + end +end diff --git a/db/schema.rb b/db/schema.rb index 33950c9..0940d44 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20160224132937) do +ActiveRecord::Schema.define(version: 20160309122141) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -51,7 +51,7 @@ ActiveRecord::Schema.define(version: 20160224132937) do add_index "action_tracker_notifications", ["profile_id", "action_tracker_id"], name: "index_action_tracker_notif_on_prof_id_act_tracker_id", unique: true, using: :btree add_index "action_tracker_notifications", ["profile_id"], name: "index_action_tracker_notifications_on_profile_id", using: :btree - create_table "article_followers", id: false, force: :cascade do |t| + create_table "article_followers", force: :cascade do |t| t.integer "person_id" t.integer "article_id" t.datetime "since" diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index 11fa473..96b411d 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -2252,4 +2252,22 @@ class ArticleTest < ActiveSupport::TestCase assert_equal "/#{a2.path}", a2.full_path end + should "increment followers count when a person follow an article" do + a = fast_create(Article) + p = fast_create(Person) + assert_difference "a.reload.followers_count" do + a.person_followers << p + end + end + + should "decrement followers count when a person unfollow an article" do + p = fast_create(Person) + a = fast_create(Article, :profile_id => p) + a.person_followers << p + assert_difference "a.reload.followers_count", -1 do + a.person_followers.destroy_all + end + end + + end -- libgit2 0.21.2