From b0035ffdbeb82007ce093897bea4e5bd78920895 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 31 Jan 2018 00:21:36 -0600 Subject: [PATCH] add magic link to items --- app/controllers/items_controller.rb | 1 + app/models/content_groupers/item_magic.rb | 5 +++++ .../location_capital_town.rb | 0 .../{ => content_groupers}/location_landmark.rb | 0 .../location_largest_town.rb | 0 .../location_notable_town.rb | 0 app/models/content_types/item.rb | 1 + config/attributes/item.yml | 2 ++ db/migrate/20180131061902_create_item_magics.rb | 11 +++++++++++ db/schema.rb | 14 +++++++++++++- test/fixtures/item_magics.yml | 11 +++++++++++ test/models/item_magic_test.rb | 7 +++++++ 12 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 app/models/content_groupers/item_magic.rb rename app/models/{ => content_groupers}/location_capital_town.rb (100%) rename app/models/{ => content_groupers}/location_landmark.rb (100%) rename app/models/{ => content_groupers}/location_largest_town.rb (100%) rename app/models/{ => content_groupers}/location_notable_town.rb (100%) create mode 100644 db/migrate/20180131061902_create_item_magics.rb create mode 100644 test/fixtures/item_magics.yml create mode 100644 test/models/item_magic_test.rb diff --git a/app/controllers/items_controller.rb b/app/controllers/items_controller.rb index 2a94b611..7338ca5f 100644 --- a/app/controllers/items_controller.rb +++ b/app/controllers/items_controller.rb @@ -21,6 +21,7 @@ class ItemsController < ContentController current_ownerships_attributes: [:id, :current_owner_id, :_destroy], past_ownerships_attributes: [:id, :past_owner_id, :_destroy], maker_relationships_attributes: [:id, :maker_id, :_destroy], + item_magics_attributes: [:id, :magic_id, :_destroy], ] end end diff --git a/app/models/content_groupers/item_magic.rb b/app/models/content_groupers/item_magic.rb new file mode 100644 index 00000000..aee842d1 --- /dev/null +++ b/app/models/content_groupers/item_magic.rb @@ -0,0 +1,5 @@ +class ItemMagic < ActiveRecord::Base + belongs_to :item + belongs_to :magic + belongs_to :user +end diff --git a/app/models/location_capital_town.rb b/app/models/content_groupers/location_capital_town.rb similarity index 100% rename from app/models/location_capital_town.rb rename to app/models/content_groupers/location_capital_town.rb diff --git a/app/models/location_landmark.rb b/app/models/content_groupers/location_landmark.rb similarity index 100% rename from app/models/location_landmark.rb rename to app/models/content_groupers/location_landmark.rb diff --git a/app/models/location_largest_town.rb b/app/models/content_groupers/location_largest_town.rb similarity index 100% rename from app/models/location_largest_town.rb rename to app/models/content_groupers/location_largest_town.rb diff --git a/app/models/location_notable_town.rb b/app/models/content_groupers/location_notable_town.rb similarity index 100% rename from app/models/location_notable_town.rb rename to app/models/content_groupers/location_notable_town.rb diff --git a/app/models/content_types/item.rb b/app/models/content_types/item.rb index aa3240eb..3a31338c 100644 --- a/app/models/content_types/item.rb +++ b/app/models/content_types/item.rb @@ -30,6 +30,7 @@ class Item < ActiveRecord::Base relates :past_owners, with: :past_ownerships relates :current_owners, with: :current_ownerships relates :makers, with: :maker_relationships + relates :magics, with: :item_magics def self.color 'amber' diff --git a/config/attributes/item.yml b/config/attributes/item.yml index 1f1dca07..543283f0 100644 --- a/config/attributes/item.yml +++ b/config/attributes/item.yml @@ -37,6 +37,8 @@ :icon: flash_on :attributes: - :name: magic + :label: Magical effects + - :name: magics :label: Magic :gallery: :label: Gallery diff --git a/db/migrate/20180131061902_create_item_magics.rb b/db/migrate/20180131061902_create_item_magics.rb new file mode 100644 index 00000000..eb2e1adb --- /dev/null +++ b/db/migrate/20180131061902_create_item_magics.rb @@ -0,0 +1,11 @@ +class CreateItemMagics < ActiveRecord::Migration + def change + create_table :item_magics do |t| + t.references :item, index: true, foreign_key: true + t.references :magic, index: true, foreign_key: true + t.references :user, index: true, foreign_key: true + + t.timestamps null: false + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 6a036a48..3b59a16f 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: 20180131061726) do +ActiveRecord::Schema.define(version: 20180131061902) do create_table "archenemyships", force: :cascade do |t| t.integer "user_id" @@ -933,6 +933,18 @@ ActiveRecord::Schema.define(version: 20180131061726) do add_index "image_uploads", ["content_type", "content_id"], name: "index_image_uploads_on_content_type_and_content_id" add_index "image_uploads", ["user_id"], name: "index_image_uploads_on_user_id" + create_table "item_magics", force: :cascade do |t| + t.integer "item_id" + t.integer "magic_id" + t.integer "user_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + add_index "item_magics", ["item_id"], name: "index_item_magics_on_item_id" + add_index "item_magics", ["magic_id"], name: "index_item_magics_on_magic_id" + add_index "item_magics", ["user_id"], name: "index_item_magics_on_user_id" + create_table "items", force: :cascade do |t| t.string "name", null: false t.string "item_type" diff --git a/test/fixtures/item_magics.yml b/test/fixtures/item_magics.yml new file mode 100644 index 00000000..7aad1638 --- /dev/null +++ b/test/fixtures/item_magics.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + item_id: + magic_id: + user_id: + +two: + item_id: + magic_id: + user_id: diff --git a/test/models/item_magic_test.rb b/test/models/item_magic_test.rb new file mode 100644 index 00000000..a97ac6f5 --- /dev/null +++ b/test/models/item_magic_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class ItemMagicTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end