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 browse species button unconditionally #1345

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ def index
@hide_footer = true
@application_count = @user.person.adopter_applications.count.to_i

@adoptable_unique_species = Pet.adoptable_unique_species

authorize! :adopter_foster_dashboard, context: {organization: @organization}
end
end
2 changes: 2 additions & 0 deletions app/controllers/organizations/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ def index
.unadopted
.includes(images_attachments: :blob)
.sample(4)

@adoptable_unique_species = Pet.adoptable_unique_species
end
end
9 changes: 9 additions & 0 deletions app/helpers/adoptable_unique_species_for_tenant_helper.rb
kasugaijin marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module AdoptableUniqueSpeciesForTenantHelper
kasugaijin marked this conversation as resolved.
Show resolved Hide resolved
def adoptable_unique_species(organization)
organization.pets
kasugaijin marked this conversation as resolved.
Show resolved Hide resolved
.unadopted
.where(placement_type: ["Adoptable", "Adoptable and Fosterable"])
.distinct.
pluck(:species)
end
end
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 :adoptable_unique_species, -> { unadopted.where(placement_type: ["Adoptable", "Adoptable and Fosterable"]).distinct.pluck(:species) }

attr_writer :toggle

# check if pet has any applications with adoption pending status
Expand Down
14 changes: 5 additions & 9 deletions app/views/layouts/shared/_navbar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,11 @@
<%= t(".pets") %>
</a>
<ul class="dropdown-menu">
<li>
<%= link_to t("general.dogs"),
adoptable_pets_path(species: "dog"),
class: "dropdown-item" %></li>

<li>
<%= link_to t("general.cats"),
adoptable_pets_path(species: "cat"),
class: "dropdown-item" %></li>
<% adoptable_unique_species(Current.organization).each do |species| %>
<li>
<%= link_to t("general.#{species.downcase}s"), adoptable_pets_path(species: "#{species.downcase}"), class: "dropdown-item" %>
</li>
<% end %>
</ul>
</li>
<li class='nav-item'>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@
<div>
<h1 class="fw-bold"><%= t('.header', organization_name: @organization.name) %></h1>
<p class="fs-4 mb-4"><%= t('.body_text', organization_name: @organization.name) %></p>
<%= link_to "#{t("general.browse")} #{t("general.dogs")}",
adoptable_pets_path(species: "dog"),
class: "btn btn-primary btn-lg rounded-1 ms-2 mt-sm-2 mt-1" %>
<%= link_to "#{t("general.browse")} #{t("general.cats")}",
adoptable_pets_path(species: "cat"),
class: "btn btn-primary btn-lg rounded-1 ms-2 mt-sm-2 mt-1" %>
<%= render partial: "organizations/shared/unique_species" %>
</div>
</div>
<div class="col-xxl-5 offset-xxl-1 col-xl-6 col-lg-6 col-12 d-lg-flex justify-content-end">
Expand Down
8 changes: 1 addition & 7 deletions app/views/organizations/home/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,7 @@
</div>
<div class="d-flex justify-content-center">
<% if user_signed_in? %>

<%= link_to "#{t("general.browse")} #{t("general.dogs")}",
adoptable_pets_path(species: "dog"),
class: "btn btn-primary btn-lg rounded-1 ms-2" %>
<%= link_to "#{t("general.browse")} #{t("general.cats")}",
adoptable_pets_path(species: "cat"),
class: "btn btn-primary btn-lg rounded-1 ms-2" %>
<%= render partial: "organizations/shared/unique_species" %>
<% else %>
<%= link_to t("general.become_an_adopter"),
new_user_registration_path,
Expand Down
3 changes: 3 additions & 0 deletions app/views/organizations/shared/_unique_species.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<% @adoptable_unique_species.each do |species| %>
kasugaijin marked this conversation as resolved.
Show resolved Hide resolved
<%= link_to "#{t("general.browse")} #{t("general.#{species.downcase}s")}", adoptable_pets_path(species: "#{species.downcase}"), class: "btn btn-primary btn-lg rounded-1 ms-2" %>
<% end %>
32 changes: 32 additions & 0 deletions test/models/pet_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,38 @@ class PetTest < ActiveSupport::TestCase
assert_not Pet.with_photo.include?(pet_without_image)
end
end

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

unique_species = Pet.adoptable_unique_species

assert_equal ["Cat", "Dog"], unique_species.sort
end

kasugaijin marked this conversation as resolved.
Show resolved Hide resolved
should "exclude species that are not adoptable" do
create(:pet, species: "Dog", placement_type: "Adoptable")
create(:pet, species: "Cat", placement_type: "Fosterable")
create(:pet, species: "Dog", placement_type: "Adoptable and Fosterable")

unique_species = Pet.adoptable_unique_species

assert_equal ["Dog"], unique_species
end

should "exclude species that have already been adopted" do
create(:pet, species: "Dog", placement_type: "Adoptable")
create(:pet, :adopted, species: "Cat", placement_type: "Adoptable")
create(:pet, species: "Dog", placement_type: "Adoptable and Fosterable")

unique_species = Pet.adoptable_unique_species

assert_equal ["Dog"], unique_species
end
end
end

context "#has_adoption_pending?" do
Expand Down
Loading