From b8e41551f98222d5937241bbdfb85eb7e30b494d Mon Sep 17 00:00:00 2001 From: rgarcia Date: Sat, 18 Jul 2015 18:09:48 +0200 Subject: [PATCH] configures acts_as_votable [#9] --- Gemfile | 1 + Gemfile.lock | 2 ++ ...0150717180105_acts_as_votable_migration.rb | 22 +++++++++++++++++++ db/schema.rb | 17 +++++++++++++- 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20150717180105_acts_as_votable_migration.rb diff --git a/Gemfile b/Gemfile index 45f16f7b4..3f6d2b90e 100644 --- a/Gemfile +++ b/Gemfile @@ -34,6 +34,7 @@ gem 'devise' gem "responders" gem 'foundation-rails' +gem 'acts_as_votable' group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console diff --git a/Gemfile.lock b/Gemfile.lock index 01408b9c2..d0dfefaaa 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -36,6 +36,7 @@ GEM minitest (~> 5.1) thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) + acts_as_votable (0.10.0) arel (6.0.2) bcrypt (3.1.10) binding_of_caller (0.7.2) @@ -188,6 +189,7 @@ PLATFORMS ruby DEPENDENCIES + acts_as_votable byebug capybara coffee-rails (~> 4.1.0) diff --git a/db/migrate/20150717180105_acts_as_votable_migration.rb b/db/migrate/20150717180105_acts_as_votable_migration.rb new file mode 100644 index 000000000..4bdcbe377 --- /dev/null +++ b/db/migrate/20150717180105_acts_as_votable_migration.rb @@ -0,0 +1,22 @@ +class ActsAsVotableMigration < ActiveRecord::Migration + def self.up + create_table :votes do |t| + + t.references :votable, :polymorphic => true + t.references :voter, :polymorphic => true + + t.boolean :vote_flag + t.string :vote_scope + t.integer :vote_weight + + t.timestamps + end + + add_index :votes, [:voter_id, :voter_type, :vote_scope] + add_index :votes, [:votable_id, :votable_type, :vote_scope] + end + + def self.down + drop_table :votes + end +end diff --git a/db/schema.rb b/db/schema.rb index 61fb86a58..3ead9ea4e 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: 20150716174358) do +ActiveRecord::Schema.define(version: 20150717180105) do create_table "debates", force: :cascade do |t| t.string "title" @@ -39,4 +39,19 @@ ActiveRecord::Schema.define(version: 20150716174358) do add_index "users", ["email"], name: "index_users_on_email", unique: true add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true + create_table "votes", force: :cascade do |t| + t.integer "votable_id" + t.string "votable_type" + t.integer "voter_id" + t.string "voter_type" + t.boolean "vote_flag" + t.string "vote_scope" + t.integer "vote_weight" + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "votes", ["votable_id", "votable_type", "vote_scope"], name: "index_votes_on_votable_id_and_votable_type_and_vote_scope" + add_index "votes", ["voter_id", "voter_type", "vote_scope"], name: "index_votes_on_voter_id_and_voter_type_and_vote_scope" + end