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 unique species scope and test #1306

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/models/pet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ class Pet < ApplicationRecord
query.where(published: true).order(:breed).distinct.pluck(:breed)
}

# Returns an array of unique species of an organization
scope :unique_species, -> { distinct.pluck(:species) }

attr_writer :toggle

# check if pet has any applications with adoption pending status
Expand Down
13 changes: 13 additions & 0 deletions test/models/pet_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,19 @@ class PetTest < ActiveSupport::TestCase
assert_not Pet.with_photo.include?(pet_without_image)
end
end

context ".unique_species" do
should "returns an array of unique species" do
create(:pet, species: "Dog")
create(:pet, species: "Cat")
create(:pet, species: "Dog")

unique_species = Pet.unique_species

assert_equal ["Cat", "Dog"], unique_species.sort
assert_equal 1, unique_species.count("Dog")
end
end
end

context "#has_adoption_pending?" do
Expand Down
Loading