From b85c671ca482e9d36bd2ee94231f365e7e0d65a5 Mon Sep 17 00:00:00 2001 From: David Gay Date: Tue, 6 Apr 2021 21:04:37 -0400 Subject: Basic Pokemon setup for PTU --- app/models/ptu_pokemon.rb | 4 ++++ db/migrate/20210407005347_create_ptu_pokemons.rb | 17 +++++++++++++++++ db/schema.rb | 16 +++++++++++++++- test/fixtures/ptu_pokemons.yml | 23 +++++++++++++++++++++++ test/models/ptu_pokemon_test.rb | 14 ++++++++++++++ 5 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 app/models/ptu_pokemon.rb create mode 100644 db/migrate/20210407005347_create_ptu_pokemons.rb create mode 100644 test/fixtures/ptu_pokemons.yml create mode 100644 test/models/ptu_pokemon_test.rb diff --git a/app/models/ptu_pokemon.rb b/app/models/ptu_pokemon.rb new file mode 100644 index 0000000..1c57500 --- /dev/null +++ b/app/models/ptu_pokemon.rb @@ -0,0 +1,4 @@ +class PtuPokemon < ApplicationRecord + validates :name, :base_hp, :base_atk, :base_def, :base_spatk, :base_spdef, :base_speed, presence: true + validates :male_chance, inclusion: 0..100, allow_nil: true +end diff --git a/db/migrate/20210407005347_create_ptu_pokemons.rb b/db/migrate/20210407005347_create_ptu_pokemons.rb new file mode 100644 index 0000000..4bdbe29 --- /dev/null +++ b/db/migrate/20210407005347_create_ptu_pokemons.rb @@ -0,0 +1,17 @@ +class CreatePtuPokemons < ActiveRecord::Migration[6.1] + def change + create_table :ptu_pokemons do |t| + t.string :name + t.integer :base_hp + t.integer :base_atk + t.integer :base_def + t.integer :base_spatk + t.integer :base_spdef + t.integer :base_speed + t.decimal :male_chance + t.text :notes + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 354a229..927a80f 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_000858) do +ActiveRecord::Schema.define(version: 2021_04_07_005347) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -27,6 +27,20 @@ ActiveRecord::Schema.define(version: 2021_04_07_000858) do t.datetime "updated_at", precision: 6, null: false end + create_table "ptu_pokemons", force: :cascade do |t| + t.string "name" + t.integer "base_hp" + t.integer "base_atk" + t.integer "base_def" + t.integer "base_spatk" + t.integer "base_spdef" + t.integer "base_speed" + t.decimal "male_chance" + t.text "notes" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + end + create_table "ptu_types", force: :cascade do |t| t.string "name" t.datetime "created_at", precision: 6, null: false diff --git a/test/fixtures/ptu_pokemons.yml b/test/fixtures/ptu_pokemons.yml new file mode 100644 index 0000000..6c0db12 --- /dev/null +++ b/test/fixtures/ptu_pokemons.yml @@ -0,0 +1,23 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: Bulbasaur + base_hp: 5 + base_atk: 5 + base_def: 5 + base_spatk: 7 + base_spdef: 7 + base_speed: 5 + male_chance: 87.5 + notes: Some info + +two: + name: Charmander + base_hp: 4 + base_atk: 5 + base_def: 4 + base_spatk: 6 + base_spdef: 5 + base_speed: 7 + male_chance: 87.5 + notes: Blah blah diff --git a/test/models/ptu_pokemon_test.rb b/test/models/ptu_pokemon_test.rb new file mode 100644 index 0000000..0b4aa2f --- /dev/null +++ b/test/models/ptu_pokemon_test.rb @@ -0,0 +1,14 @@ +require "test_helper" + +class PtuPokemonTest < ActiveSupport::TestCase + test "can create" do + assert_difference("PtuPokemon.count", 1) do + PtuPokemon.create(name: "SomeMon", base_hp: 1, base_atk: 2, base_def: 3, base_spatk: 4, base_spdef: 5, + base_speed: 6) + end + end + + test "can't set a male chance greater than 100" do + assert_not ptu_pokemons(:one).update(male_chance: 150.20) + end +end -- cgit v1.2.3