From 7a5873603d09358d9779bd018a4d95d954748baf Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Fri, 2 Feb 2018 00:19:14 -0600 Subject: [PATCH] Add deity and character siblings to deities --- app/controllers/deities_controller.rb | 2 ++ .../deity_character_sibling.rb | 7 ++++++ .../content_groupers/deity_deity_sibling.rb | 23 ++++++++++++++++++ app/models/content_types/deity.rb | 4 +++- config/attributes/deity.yml | 4 ++++ ...2055802_create_deity_character_siblings.rb | 11 +++++++++ ...80202055822_create_deity_deity_siblings.rb | 11 +++++++++ db/schema.rb | 24 ++++++++++++++++++- test/fixtures/deity_character_siblings.yml | 11 +++++++++ test/fixtures/deity_deity_siblings.yml | 11 +++++++++ test/models/deity_character_sibling_test.rb | 7 ++++++ test/models/deity_deity_sibling_test.rb | 7 ++++++ 12 files changed, 120 insertions(+), 2 deletions(-) create mode 100644 app/models/content_groupers/deity_character_sibling.rb create mode 100644 app/models/content_groupers/deity_deity_sibling.rb create mode 100644 db/migrate/20180202055802_create_deity_character_siblings.rb create mode 100644 db/migrate/20180202055822_create_deity_deity_siblings.rb create mode 100644 test/fixtures/deity_character_siblings.yml create mode 100644 test/fixtures/deity_deity_siblings.yml create mode 100644 test/models/deity_character_sibling_test.rb create mode 100644 test/models/deity_deity_sibling_test.rb diff --git a/app/controllers/deities_controller.rb b/app/controllers/deities_controller.rb index c9d8ab54d..df57a14b0 100644 --- a/app/controllers/deities_controller.rb +++ b/app/controllers/deities_controller.rb @@ -12,9 +12,11 @@ def content_param_list deity_character_parents_attributes: [:id, :character_parent_id, :_destroy], deity_character_partners_attributes: [:id, :character_partner_id, :_destroy], deity_character_children_attributes: [:id, :character_child_id, :_destroy], + deity_character_siblings_attributes: [:id, :character_sibling_id, :_destroy], deity_deity_parents_attributes: [:id, :deity_parent_id, :_destroy], deity_deity_partners_attributes: [:id, :deity_partner_id, :_destroy], deity_deity_children_attributes: [:id, :deity_child_id, :_destroy], + deity_deity_siblings_attributes: [:id, :deity_sibling_id, :_destroy], deity_creatures_attributes: [:id, :creature_id, :_destroy], deity_floras_attributes: [:id, :flora_id, :_destroy], deity_religions_attributes: [:id, :religion_id, :_destroy], diff --git a/app/models/content_groupers/deity_character_sibling.rb b/app/models/content_groupers/deity_character_sibling.rb new file mode 100644 index 000000000..ad4589dfd --- /dev/null +++ b/app/models/content_groupers/deity_character_sibling.rb @@ -0,0 +1,7 @@ +class DeityCharacterSibling < ActiveRecord::Base + include HasContentLinking + + belongs_to :deity + belongs_to :character_sibling, class_name: Character.name + belongs_to :user +end diff --git a/app/models/content_groupers/deity_deity_sibling.rb b/app/models/content_groupers/deity_deity_sibling.rb new file mode 100644 index 000000000..3c32c85b6 --- /dev/null +++ b/app/models/content_groupers/deity_deity_sibling.rb @@ -0,0 +1,23 @@ +class DeityDeitySibling < ActiveRecord::Base + include HasContentLinking + + belongs_to :deity + belongs_to :deity_sibling, class_name: Deity.name + belongs_to :user + + after_create do + self.reciprocate( + relation: :deity_deity_siblings, + parent_object_ref: :deity, + added_object_ref: :deity_sibling + ) + end + + after_destroy do + # This is a two-way relation, so we should also delete the reverse association + this_object = Deity.find_by(id: self.deity_id) + other_object = Deity.find_by(id: self.deity_sibling_id) + + other_object.deity_siblings.delete(this_object) unless other_object.nil? + end +end diff --git a/app/models/content_types/deity.rb b/app/models/content_types/deity.rb index b10e7909f..73e64379c 100644 --- a/app/models/content_types/deity.rb +++ b/app/models/content_types/deity.rb @@ -19,9 +19,11 @@ class Deity < ActiveRecord::Base relates :character_parents, with: :deity_character_parents relates :character_partners, with: :deity_character_partners relates :character_children, with: :deity_character_children + relates :character_siblings, with: :deity_character_siblings relates :deity_parents, with: :deity_deity_parents relates :deity_partners, with: :deity_deity_partners relates :deity_children, with: :deity_deity_children + relates :deity_siblings, with: :deity_deity_siblings relates :creatures, with: :deity_creatures relates :floras, with: :deity_floras relates :religions, with: :deity_religions @@ -31,7 +33,7 @@ class Deity < ActiveRecord::Base relates :related_landmarks, with: :deity_related_landmarks def self.color - 'text-lighten-1 grey' + 'text-lighten-4 blue' end def self.icon diff --git a/config/attributes/deity.yml b/config/attributes/deity.yml index 200ad5164..8efb18a04 100644 --- a/config/attributes/deity.yml +++ b/config/attributes/deity.yml @@ -31,12 +31,16 @@ :label: Partners - :name: character_children :label: Children + - :name: character_siblings + :label: Siblings - :name: deity_parents :label: Parents - :name: deity_partners :label: Partners - :name: deity_children :label: Children + - :name: deity_siblings + :label: Siblings :symbolism: :label: Symbolism :icon: thumbs_up_down diff --git a/db/migrate/20180202055802_create_deity_character_siblings.rb b/db/migrate/20180202055802_create_deity_character_siblings.rb new file mode 100644 index 000000000..49f31633a --- /dev/null +++ b/db/migrate/20180202055802_create_deity_character_siblings.rb @@ -0,0 +1,11 @@ +class CreateDeityCharacterSiblings < ActiveRecord::Migration + def change + create_table :deity_character_siblings do |t| + t.references :deity, index: true, foreign_key: true + t.integer :character_sibling_id + t.references :user, index: true, foreign_key: true + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20180202055822_create_deity_deity_siblings.rb b/db/migrate/20180202055822_create_deity_deity_siblings.rb new file mode 100644 index 000000000..cc110a8cc --- /dev/null +++ b/db/migrate/20180202055822_create_deity_deity_siblings.rb @@ -0,0 +1,11 @@ +class CreateDeityDeitySiblings < ActiveRecord::Migration + def change + create_table :deity_deity_siblings do |t| + t.references :deity, index: true, foreign_key: true + t.integer :deity_sibling_id + 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 8fc46dc77..8441207a4 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: 20180131064902) do +ActiveRecord::Schema.define(version: 20180202055822) do create_table "archenemyships", force: :cascade do |t| t.integer "user_id" @@ -545,6 +545,17 @@ add_index "deity_character_partners", ["deity_id"], name: "index_deity_character_partners_on_deity_id" add_index "deity_character_partners", ["user_id"], name: "index_deity_character_partners_on_user_id" + create_table "deity_character_siblings", force: :cascade do |t| + t.integer "deity_id" + t.integer "character_sibling_id" + t.integer "user_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + add_index "deity_character_siblings", ["deity_id"], name: "index_deity_character_siblings_on_deity_id" + add_index "deity_character_siblings", ["user_id"], name: "index_deity_character_siblings_on_user_id" + create_table "deity_creatures", force: :cascade do |t| t.integer "user_id" t.integer "deity_id" @@ -590,6 +601,17 @@ add_index "deity_deity_partners", ["deity_id"], name: "index_deity_deity_partners_on_deity_id" add_index "deity_deity_partners", ["user_id"], name: "index_deity_deity_partners_on_user_id" + create_table "deity_deity_siblings", force: :cascade do |t| + t.integer "deity_id" + t.integer "deity_sibling_id" + t.integer "user_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + add_index "deity_deity_siblings", ["deity_id"], name: "index_deity_deity_siblings_on_deity_id" + add_index "deity_deity_siblings", ["user_id"], name: "index_deity_deity_siblings_on_user_id" + create_table "deity_floras", force: :cascade do |t| t.integer "user_id" t.integer "deity_id" diff --git a/test/fixtures/deity_character_siblings.yml b/test/fixtures/deity_character_siblings.yml new file mode 100644 index 000000000..3fc014ba9 --- /dev/null +++ b/test/fixtures/deity_character_siblings.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + deity_id: + character_sibling_id: 1 + user_id: + +two: + deity_id: + character_sibling_id: 1 + user_id: diff --git a/test/fixtures/deity_deity_siblings.yml b/test/fixtures/deity_deity_siblings.yml new file mode 100644 index 000000000..6d0f47b1d --- /dev/null +++ b/test/fixtures/deity_deity_siblings.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + deity_id: + deity_sibling_id: 1 + user_id: + +two: + deity_id: + deity_sibling_id: 1 + user_id: diff --git a/test/models/deity_character_sibling_test.rb b/test/models/deity_character_sibling_test.rb new file mode 100644 index 000000000..00de5842a --- /dev/null +++ b/test/models/deity_character_sibling_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class DeityCharacterSiblingTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/deity_deity_sibling_test.rb b/test/models/deity_deity_sibling_test.rb new file mode 100644 index 000000000..b976b41a1 --- /dev/null +++ b/test/models/deity_deity_sibling_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class DeityDeitySiblingTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end