diff --git a/app/models/pet.rb b/app/models/pet.rb index 300386b3d..0932786e3 100644 --- a/app/models/pet.rb +++ b/app/models/pet.rb @@ -31,6 +31,7 @@ class Pet < ApplicationRecord has_many :adopter_applications, dependent: :destroy has_one :match, dependent: :destroy has_many_attached :images + enum species: ["dog", "cat"] validates :name, presence: true validates :birth_date, presence: true diff --git a/db/migrate/20231003182930_add_species2_pets.rb b/db/migrate/20231003182930_add_species2_pets.rb new file mode 100644 index 000000000..a5c98dfd7 --- /dev/null +++ b/db/migrate/20231003182930_add_species2_pets.rb @@ -0,0 +1,5 @@ +class AddSpecies2Pets < ActiveRecord::Migration[7.0] + def change + add_column :pets, :species, :integer, null: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 2a78463f9..cbe474e01 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[7.0].define(version: 2023_10_03_095748) do +ActiveRecord::Schema[7.0].define(version: 2023_10_03_182930) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -180,6 +180,7 @@ t.integer "weight_from", null: false t.integer "weight_to", null: false t.string "weight_unit", null: false + t.integer "species", null: false t.index ["organization_id"], name: "index_pets_on_organization_id" end diff --git a/db/seeds/01_alta.rb b/db/seeds/01_alta.rb index 2ac7dd803..dbeec330a 100644 --- a/db/seeds/01_alta.rb +++ b/db/seeds/01_alta.rb @@ -218,7 +218,8 @@ weight_to: from_weight + 15, weight_unit: Pet::WEIGHT_UNITS.sample, breed: Faker::Creature::Dog.breed, - description: "He just loves a run and a bum scratch at the end of the day" + description: "He just loves a run and a bum scratch at the end of the day", + species: 0 ) pet.images.attach(io: File.open(path), filename: "hero.jpg") end diff --git a/db/seeds/02_baja.rb b/db/seeds/02_baja.rb index 48e535039..06202c7af 100644 --- a/db/seeds/02_baja.rb +++ b/db/seeds/02_baja.rb @@ -217,7 +217,8 @@ weight_to: from_weight + 15, weight_unit: Pet::WEIGHT_UNITS.sample, breed: Faker::Creature::Dog.breed, - description: "He just loves a run and a bum scratch at the end of the day" + description: "He just loves a run and a bum scratch at the end of the day", + species: 0 ) pet.images.attach(io: File.open(path), filename: "hero.jpg") end diff --git a/test/factories.rb b/test/factories.rb index 9b3f7536b..5cb0242e9 100644 --- a/test/factories.rb +++ b/test/factories.rb @@ -101,7 +101,7 @@ weight_from { 10 } weight_to { 20 } weight_unit { "lb" } - + species { Faker::Number.within(range: 0..1) } organization trait :adoption_pending do diff --git a/test/models/pet_test.rb b/test/models/pet_test.rb index dad6a70a6..cce2374da 100644 --- a/test/models/pet_test.rb +++ b/test/models/pet_test.rb @@ -22,6 +22,7 @@ class PetTest < ActiveSupport::TestCase should validate_numericality_of(:weight_to).only_integer should validate_presence_of(:weight_unit) should validate_inclusion_of(:weight_unit).in_array(["lb", "kg"]) + should define_enum_for(:species) end context "#has_adoption_pending?" do