Skip to content

Commit

Permalink
Remove adoptable pets policy (#1233)
Browse files Browse the repository at this point in the history
* Remove adoptable pets policy as it is an entirely public route

* lint

* fix tests

* update apply button and change copy when pet application_paused is true
  • Loading branch information
kasugaijin authored Dec 10, 2024
1 parent ac2cbd1 commit 0fb5052
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 204 deletions.
26 changes: 15 additions & 11 deletions app/controllers/organizations/adoptable_pets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,21 @@ class AdoptablePetsController < Organizations::BaseController
include ::Pagy::Backend

skip_before_action :authenticate_user!
skip_verify_authorized only: %i[index]
skip_verify_authorized only: %i[index show]
before_action :set_likes, only: %i[index show],
if: -> { allowed_to?(:index?, Like) }
before_action :set_species, only: %i[index]
before_action :set_pet, only: %i[show]

def index
@q = authorized_scope(
@q =
case @species
when "dog"
Pet.Dog.unadopted
Pet.Dog.unadopted.published
when "cat"
Pet.Cat.unadopted
else
redirect_back_or_to root_path and return
end,
with: Organizations::AdoptablePetPolicy
).ransack(params[:q])
Pet.Cat.unadopted.published
end
.ransack(params[:q])

@pagy, paginated_adoptable_pets = pagy(
@q.result.includes(:adopter_applications, :matches, images_attachments: :blob),
Expand All @@ -31,8 +29,6 @@ def index

def show
@adoptable_pet_info = CustomPage.first&.adoptable_pet_info
@pet = Pet.find(params[:id])
authorize! @pet, with: Organizations::AdoptablePetPolicy

if current_user&.latest_form_submission
@adoption_application =
Expand All @@ -55,6 +51,14 @@ def set_likes

def set_species
@species = params[:species]

redirect_back_or_to root_path if @species.nil?
end

def set_pet
@pet = Pet.find(params[:id])

redirect_back_or_to root_path if @pet.is_adopted? || !@pet.published?
end
end
end
19 changes: 0 additions & 19 deletions app/policies/organizations/adoptable_pet_policy.rb

This file was deleted.

10 changes: 4 additions & 6 deletions app/views/organizations/adoptable_pets/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,12 @@
<div class='text-center d-flex flex-column align-items-center mt-1'>
<% if user_signed_in? %>
<% if allowed_to?(:create?, with: AdopterApplicationPolicy, context: {pet: @pet, user: current_user}) %>
<h4 class="mb-4 mt-3">In love with this pooch?</h4>
<h4 class="mb-4 mt-3"><%= t('.in_love') %></h4>
<%= form_with model: [:adopter_fosterer, @adoption_application] do |form| %>
<%= form.hidden_field :pet_id, value: @adoption_application.pet_id %>
<%= form.hidden_field :form_submission_id, value: @adoption_application.form_submission_id %>
<%= form.submit t(".apply_to_adopt"),
class: "custom-btn-pink",
class: "btn btn-primary",
data: {turbo: false}
%>
<% end %>
Expand All @@ -161,12 +161,10 @@
<%# FIXME: This section was missed during the remove of AdopterFosterProfile but I think it requires FormSubmission to be ready to refactor %>
<%# Once the form_submission CRUD and policy are created, should use conditional like the below %>
<%# elsif allowed_to?(:create?, FormSubmission) %>
<% else %>
<% elsif @pet.application_paused? %>
<h4 class='mb-4 mt-3'>
<%= t('.complete_your_profile') %>
<%= t('.application_paused', pet_name: @pet.name) %>
</h4>
<%= link_to t('.complete_my_profile'), "#", class: 'custom-btn-pink' %>
<%# else %>
<% end %>
<% else %>
<h4 class="mb-4 mt-3">
Expand Down
4 changes: 2 additions & 2 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,8 @@ en:
adoption_made: Adoption Made
default: "Application submitted"
apply_to_adopt: "Apply to Adopt"
complete_your_profile: "Complete your profile to apply for this pet"
complete_my_profile: "Complete my profile"
in_love: "In love with this furball?"
application_paused: "We are not currently accepting applications for %{pet_name}"
adopt: "Adopt"
login: "Log in"
important_info: "Important Information"
Expand Down
16 changes: 0 additions & 16 deletions test/controllers/organizations/adoptable_pets_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@ class AdoptablePetsControllerTest < ActionDispatch::IntegrationTest
end

context "#index" do
should "have authorized scope" do
assert_have_authorized_scope(
type: :active_record_relation, with: Organizations::AdoptablePetPolicy
) do
get adoptable_pets_url(species: "dog")
end
end

should "assign only unadopted pets" do
adopted_pet = create(:pet, :adopted, species: "Dog")

Expand All @@ -38,13 +30,5 @@ class AdoptablePetsControllerTest < ActionDispatch::IntegrationTest
assert_select(".card li:nth-of-type(5)", text: "Weight range: #{@pet.weight_from}-#{@pet.weight_to} #{@pet.weight_unit}")
end
end

context "#show" do
should "be authorized" do
assert_authorized_to(:show?, @pet, with: Organizations::AdoptablePetPolicy) do
get adoptable_pet_url(@pet)
end
end
end
end
end
15 changes: 11 additions & 4 deletions test/integration/adoptable_pet_show_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class AdoptablePetShowTest < ActionDispatch::IntegrationTest
set_organization(@available_pet.organization)
@pet_in_draft = create(:pet, published: false)
@pet_pending_adoption = create(:pet, :adoption_pending)
@pet_current_foster = create(:pet, :current_foster)
@adopted_pet = create(:pet, :adopted)
end

Expand All @@ -28,6 +29,12 @@ class AdoptablePetShowTest < ActionDispatch::IntegrationTest
assert_response :success
end

should "see a pet with a current foster" do
get adoptable_pet_path(@pet_current_foster)

assert_response :success
end

should "not see an unpublished pet" do
get adoptable_pet_path(@pet_in_draft)

Expand Down Expand Up @@ -59,16 +66,16 @@ class AdoptablePetShowTest < ActionDispatch::IntegrationTest
assert_select "input[type='submit']", value: "Apply to Adopt", count: 0
end

should "see an unpublished pet" do
should "not see an unpublished pet" do
get adoptable_pet_path(@pet_in_draft)

assert_response :success
assert_response :redirect
end

should "see an adopted pet" do
should "not see an adopted pet" do
get adoptable_pet_path(@adopted_pet)

assert_response :success
assert_response :redirect
end

context "an adopter with form submission" do
Expand Down
146 changes: 0 additions & 146 deletions test/policies/organizations/adoptable_pet_policy_test.rb

This file was deleted.

0 comments on commit 0fb5052

Please sign in to comment.