summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/models/activity.rb1
-rw-r--r--app/models/location.rb3
-rw-r--r--data/activities.yml1
-rw-r--r--data/locations.yml4
-rw-r--r--db/migrate/20210503221405_create_locations.rb15
-rw-r--r--db/schema.rb14
-rw-r--r--db/seeds.rb13
-rw-r--r--test/fixtures/locations.yml13
-rw-r--r--test/models/location_test.rb7
9 files changed, 66 insertions, 5 deletions
diff --git a/app/models/activity.rb b/app/models/activity.rb
index 2f93564..be5b573 100644
--- a/app/models/activity.rb
+++ b/app/models/activity.rb
@@ -1,3 +1,4 @@
class Activity < ApplicationRecord
+ belongs_to :location
validates :gid, :name, :description, presence: true
end
diff --git a/app/models/location.rb b/app/models/location.rb
new file mode 100644
index 0000000..8816274
--- /dev/null
+++ b/app/models/location.rb
@@ -0,0 +1,3 @@
+class Location < ApplicationRecord
+ validates :gid, :name, presence: true
+end
diff --git a/data/activities.yml b/data/activities.yml
index 15bd3e2..f03c15e 100644
--- a/data/activities.yml
+++ b/data/activities.yml
@@ -1,6 +1,7 @@
quarry_floret_mines:
name: "Quarry Floret Mines"
description: "Planequarry at the Floret Mines."
+ location: "floret_region"
whatnot:
duration:
base: 70
diff --git a/data/locations.yml b/data/locations.yml
new file mode 100644
index 0000000..480fc30
--- /dev/null
+++ b/data/locations.yml
@@ -0,0 +1,4 @@
+floret_region:
+ name: "Floret Region"
+ description: "A land not too far from the great city of Morning nestled against the Sor River."
+ whatnot:
diff --git a/db/migrate/20210503221405_create_locations.rb b/db/migrate/20210503221405_create_locations.rb
new file mode 100644
index 0000000..83bd143
--- /dev/null
+++ b/db/migrate/20210503221405_create_locations.rb
@@ -0,0 +1,15 @@
+class CreateLocations < ActiveRecord::Migration[6.1]
+ def change
+ create_table :locations do |t|
+ t.string :gid
+ t.string :name
+ t.text :description
+ t.jsonb :whatnot
+
+ t.timestamps
+ end
+
+ add_index :locations, :gid
+ add_reference :activities, :location
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 8dd6dcc..bddf880 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 2021_05_03_215828) do
+ActiveRecord::Schema.define(version: 2021_05_03_221405) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -22,7 +22,9 @@ ActiveRecord::Schema.define(version: 2021_05_03_215828) do
t.jsonb "whatnot"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
+ t.bigint "location_id"
t.index ["gid"], name: "index_activities_on_gid"
+ t.index ["location_id"], name: "index_activities_on_location_id"
end
create_table "character_items", force: :cascade do |t|
@@ -59,6 +61,16 @@ ActiveRecord::Schema.define(version: 2021_05_03_215828) do
t.index ["gid"], name: "index_items_on_gid"
end
+ create_table "locations", force: :cascade do |t|
+ t.string "gid"
+ t.string "name"
+ t.text "description"
+ t.jsonb "whatnot"
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.index ["gid"], name: "index_locations_on_gid"
+ end
+
create_table "skills", force: :cascade do |t|
t.string "gid"
t.string "name"
diff --git a/db/seeds.rb b/db/seeds.rb
index 00a0566..7fcd125 100644
--- a/db/seeds.rb
+++ b/db/seeds.rb
@@ -17,15 +17,20 @@ end
load_data_file("data/items.yml").map do |gid, hash|
item = Item.find_or_create_by(gid: gid)
- item.name = hash[:name]
- item.description = hash[:description]
+ item.assign_attributes(hash.except(:equip_slot, :usable))
item.equip_slot = hash[:equip_slot]&.to_sym
item.usable = hash[:usable] || false
- item.whatnot = hash[:whatnot]
item.save
end
+load_data_file("data/locations.yml").map do |gid, hash|
+ location = Location.find_or_create_by(gid: gid)
+ location.update(hash)
+end
+
load_data_file("data/activities.yml").map do |gid, hash|
activity = Activity.find_or_create_by(gid: gid)
- activity.update(hash)
+ activity.assign_attributes(hash.except(:location))
+ activity.location = Location.find_by_gid(hash[:location])
+ activity.save
end
diff --git a/test/fixtures/locations.yml b/test/fixtures/locations.yml
new file mode 100644
index 0000000..6a7ba8a
--- /dev/null
+++ b/test/fixtures/locations.yml
@@ -0,0 +1,13 @@
+# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+one:
+ gid: MyString
+ name: MyString
+ description: MyText
+ whatnot:
+
+two:
+ gid: MyString
+ name: MyString
+ description: MyText
+ whatnot:
diff --git a/test/models/location_test.rb b/test/models/location_test.rb
new file mode 100644
index 0000000..3c813e8
--- /dev/null
+++ b/test/models/location_test.rb
@@ -0,0 +1,7 @@
+require "test_helper"
+
+class LocationTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end