[Git][noosfero/noosfero][master] 2 commits: add primary key to article follower table to fox has many through association
Bráulio Bhavamitra
gitlab at mg.gitlab.com
Wed Mar 9 14:28:27 BRT 2016
Bráulio Bhavamitra pushed to branch master at Noosfero / noosfero
Commits:
981f8354 by Leandro Nunes dos Santos at 2016-03-09T10:05:21-03:00
add primary key to article follower table to fox has many through association
- - - - -
48167ee1 by Bráulio Bhavamitra at 2016-03-09T17:28:12+00:00
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
- - - - -
3 changed files:
- + db/migrate/20160309122141_add_id_to_article_follower.rb
- db/schema.rb
- test/unit/article_test.rb
Changes:
=====================================
db/migrate/20160309122141_add_id_to_article_follower.rb
=====================================
--- /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
=====================================
db/schema.rb
=====================================
--- 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"
=====================================
test/unit/article_test.rb
=====================================
--- 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
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/e8f4fd2b75a6ad182c74eb9d9cd80eb74f8d895f...48167ee181e7a33d835e2f8aa2f695a235b81a54
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20160309/4521ebfb/attachment.html>
More information about the Noosfero-dev
mailing list