summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/models/ptu_nature.rb4
-rw-r--r--db/migrate/20210408001502_create_ptu_natures.rb11
-rw-r--r--db/schema.rb10
-rw-r--r--db/seeds.rb9
-rw-r--r--test/fixtures/ptu_natures.yml11
-rw-r--r--test/models/ptu_nature_test.rb9
6 files changed, 53 insertions, 1 deletions
diff --git a/app/models/ptu_nature.rb b/app/models/ptu_nature.rb
new file mode 100644
index 0000000..797d71b
--- /dev/null
+++ b/app/models/ptu_nature.rb
@@ -0,0 +1,4 @@
+class PtuNature < ApplicationRecord
+ validates :name, :raises, :lowers, presence: true
+ validates :raises, :lowers, inclusion: %w[hp atk def spatk spdef speed]
+end
diff --git a/db/migrate/20210408001502_create_ptu_natures.rb b/db/migrate/20210408001502_create_ptu_natures.rb
new file mode 100644
index 0000000..57692fd
--- /dev/null
+++ b/db/migrate/20210408001502_create_ptu_natures.rb
@@ -0,0 +1,11 @@
+class CreatePtuNatures < ActiveRecord::Migration[6.1]
+ def change
+ create_table :ptu_natures do |t|
+ t.string :name
+ t.string :raises
+ t.string :lowers
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 927a80f..33dd112 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_04_07_005347) do
+ActiveRecord::Schema.define(version: 2021_04_08_001502) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -27,6 +27,14 @@ ActiveRecord::Schema.define(version: 2021_04_07_005347) do
t.datetime "updated_at", precision: 6, null: false
end
+ create_table "ptu_natures", force: :cascade do |t|
+ t.string "name"
+ t.string "raises"
+ t.string "lowers"
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ end
+
create_table "ptu_pokemons", force: :cascade do |t|
t.string "name"
t.integer "base_hp"
diff --git a/db/seeds.rb b/db/seeds.rb
index 6d2b152..62656d5 100644
--- a/db/seeds.rb
+++ b/db/seeds.rb
@@ -14,3 +14,12 @@
end
%w[Standard Shift Swift Free].each { |name| PtuActionType.find_or_create_by(name: name) }
+
+[%w[Cuddly hp atk], %w[Distracted hp def], %w[Proud hp spatk], %w[Decisive hp spdef], %w[Patient hp speed],
+ %w[Desperate atk hp], %w[Lonely atk def], %w[Adamant atk spatk], %w[Naughty atk spdef], %w[Brave atk speed],
+ %w[Stark def hp], %w[Bold def atk], %w[Impish def spatk], %w[Lax def spdef], %w[Relaxed def speed],
+ %w[Curious spatk hp], %w[Modest spatk atk], %w[Mild spatk def], %w[Rash spatk spdef], %w[Quiet spatk speed],
+ %w[Dreamy spdef hp], %w[Calm spdef atk], %w[Gentle spdef def], %w[Careful spdef spatk], %w[Sassy spdef speed],
+ %w[Skittish speed hp], %w[Timid speed atk], %w[Hasty speed def], %w[Jolly speed spatk], %w[Naive speed spdef],
+ %w[Composed hp hp], %w[Hardy atk atk], %w[Docile def def], %w[Bashful spatk spatk], %w[Quirky spdef spdef],
+ %w[Serious speed speed]].each { |n| PtuNature.find_or_create_by(name: n[0], raises: n[1], lowers: n[2]) }
diff --git a/test/fixtures/ptu_natures.yml b/test/fixtures/ptu_natures.yml
new file mode 100644
index 0000000..f71def4
--- /dev/null
+++ b/test/fixtures/ptu_natures.yml
@@ -0,0 +1,11 @@
+# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+one:
+ name: Cuddly
+ raises: hp
+ lowers: atk
+
+two:
+ name: Careful
+ raises: spdef
+ lowers: spatk
diff --git a/test/models/ptu_nature_test.rb b/test/models/ptu_nature_test.rb
new file mode 100644
index 0000000..a343a9a
--- /dev/null
+++ b/test/models/ptu_nature_test.rb
@@ -0,0 +1,9 @@
+require "test_helper"
+
+class PtuNatureTest < ActiveSupport::TestCase
+ test "can create" do
+ assert_difference("PtuNature.count", 1) do
+ PtuNature.create(name: "Inconceivable", raises: "atk", lowers: "def")
+ end
+ end
+end