Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add species to pets table and set up enum in the pet model #233

Merged
merged 8 commits into from
Oct 6, 2023
1 change: 1 addition & 0 deletions app/models/pet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


validates :name, presence: true
validates :birth_date, presence: true
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20231003182930_add_species2_pets.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddSpecies2Pets < ActiveRecord::Migration[7.0]
def change
add_column :pets, :species, :integer, null: false
end
end
3 changes: 2 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion db/seeds/01_alta.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion db/seeds/02_baja.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/models/pet_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down