Commit 981f835406be2c438054d093b4b0446c775db521
1 parent
e8f4fd2b
Exists in
web_steps_improvements
and in
9 other branches
add primary key to article follower table to fox has many through association
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 |