Commit 48167ee181e7a33d835e2f8aa2f695a235b81a54
Exists in
web_steps_improvements
and in
9 other branches
Merge branch 'article_follower_fix' into 'master'
Add primary key to article follower table to fix has many through association The article follower table does not have the primary key. When we have has_many through association this key is needed. I made some tests for increase and decrease followers_count column that was not working properly because of this See merge request !805
Showing
3 changed files
with
25 additions
and
2 deletions
Show diff stats
db/schema.rb
| @@ -11,7 +11,7 @@ | @@ -11,7 +11,7 @@ | ||
| 11 | # | 11 | # |
| 12 | # It's strongly recommended that you check this file into your version control system. | 12 | # It's strongly recommended that you check this file into your version control system. |
| 13 | 13 | ||
| 14 | -ActiveRecord::Schema.define(version: 20160224132937) do | 14 | +ActiveRecord::Schema.define(version: 20160309122141) do |
| 15 | 15 | ||
| 16 | # These are extensions that must be enabled in order to support this database | 16 | # These are extensions that must be enabled in order to support this database |
| 17 | enable_extension "plpgsql" | 17 | enable_extension "plpgsql" |
| @@ -51,7 +51,7 @@ ActiveRecord::Schema.define(version: 20160224132937) do | @@ -51,7 +51,7 @@ ActiveRecord::Schema.define(version: 20160224132937) do | ||
| 51 | 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 | 51 | 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 |
| 52 | add_index "action_tracker_notifications", ["profile_id"], name: "index_action_tracker_notifications_on_profile_id", using: :btree | 52 | add_index "action_tracker_notifications", ["profile_id"], name: "index_action_tracker_notifications_on_profile_id", using: :btree |
| 53 | 53 | ||
| 54 | - create_table "article_followers", id: false, force: :cascade do |t| | 54 | + create_table "article_followers", force: :cascade do |t| |
| 55 | t.integer "person_id" | 55 | t.integer "person_id" |
| 56 | t.integer "article_id" | 56 | t.integer "article_id" |
| 57 | t.datetime "since" | 57 | t.datetime "since" |
test/unit/article_test.rb
| @@ -2252,4 +2252,22 @@ class ArticleTest < ActiveSupport::TestCase | @@ -2252,4 +2252,22 @@ class ArticleTest < ActiveSupport::TestCase | ||
| 2252 | assert_equal "/#{a2.path}", a2.full_path | 2252 | assert_equal "/#{a2.path}", a2.full_path |
| 2253 | end | 2253 | end |
| 2254 | 2254 | ||
| 2255 | + should "increment followers count when a person follow an article" do | ||
| 2256 | + a = fast_create(Article) | ||
| 2257 | + p = fast_create(Person) | ||
| 2258 | + assert_difference "a.reload.followers_count" do | ||
| 2259 | + a.person_followers << p | ||
| 2260 | + end | ||
| 2261 | + end | ||
| 2262 | + | ||
| 2263 | + should "decrement followers count when a person unfollow an article" do | ||
| 2264 | + p = fast_create(Person) | ||
| 2265 | + a = fast_create(Article, :profile_id => p) | ||
| 2266 | + a.person_followers << p | ||
| 2267 | + assert_difference "a.reload.followers_count", -1 do | ||
| 2268 | + a.person_followers.destroy_all | ||
| 2269 | + end | ||
| 2270 | + end | ||
| 2271 | + | ||
| 2272 | + | ||
| 2255 | end | 2273 | end |