summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/models/ptu_type.rb3
-rw-r--r--db/migrate/20210406234544_create_ptu_types.rb9
-rw-r--r--db/schema.rb8
-rw-r--r--db/seeds.rb3
-rw-r--r--test/fixtures/ptu_types.yml7
-rw-r--r--test/models/ptu_type_test.rb9
6 files changed, 38 insertions, 1 deletions
diff --git a/app/models/ptu_type.rb b/app/models/ptu_type.rb
new file mode 100644
index 0000000..52a2e99
--- /dev/null
+++ b/app/models/ptu_type.rb
@@ -0,0 +1,3 @@
+class PtuType < ApplicationRecord
+ validates :name, presence: true
+end
diff --git a/db/migrate/20210406234544_create_ptu_types.rb b/db/migrate/20210406234544_create_ptu_types.rb
new file mode 100644
index 0000000..56a13f3
--- /dev/null
+++ b/db/migrate/20210406234544_create_ptu_types.rb
@@ -0,0 +1,9 @@
+class CreatePtuTypes < ActiveRecord::Migration[6.1]
+ def change
+ create_table :ptu_types do |t|
+ t.string :name
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 4603022..3e9fd9d 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,9 +10,15 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 0) do
+ActiveRecord::Schema.define(version: 2021_04_06_234544) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
+ create_table "ptu_types", force: :cascade do |t|
+ t.string "name"
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ end
+
end
diff --git a/db/seeds.rb b/db/seeds.rb
index f3a0480..929b525 100644
--- a/db/seeds.rb
+++ b/db/seeds.rb
@@ -5,3 +5,6 @@
#
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Character.create(name: 'Luke', movie: movies.first)
+
+%w[Normal Fire Water Grass Electric Ice Fighting Poison Ground Flying Psychic
+ Bug Rock Ghost Dark Dragon Steel Fairy].each { |name| PtuType.find_or_create_by(name: name) }
diff --git a/test/fixtures/ptu_types.yml b/test/fixtures/ptu_types.yml
new file mode 100644
index 0000000..81d46fd
--- /dev/null
+++ b/test/fixtures/ptu_types.yml
@@ -0,0 +1,7 @@
+# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+one:
+ name: Normal
+
+two:
+ name: Fighting
diff --git a/test/models/ptu_type_test.rb b/test/models/ptu_type_test.rb
new file mode 100644
index 0000000..f7666df
--- /dev/null
+++ b/test/models/ptu_type_test.rb
@@ -0,0 +1,9 @@
+require "test_helper"
+
+class PtuTypeTest < ActiveSupport::TestCase
+ test "can create type" do
+ assert_difference("PtuType.count", 1) do
+ PtuType.create(name: "TestType")
+ end
+ end
+end