Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
chsweet committed Jul 18, 2021
1 parent 8b3d744 commit 61cd14c
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 28 deletions.
12 changes: 9 additions & 3 deletions app/controllers/applications_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
class ApplicationsController < ApplicationController

def index
end

def show
@application = Application.find(params[:id])

Expand All @@ -27,6 +24,15 @@ def create
end
end

def update
application = Application.find(params[:id])
if params[:pet_id]
pet = Pet.find(params[:pet_id])
PetApplication.create(pet: pet, application: application)
redirect_to "/applications/#{application.id}"
end
end

private
def application_params
params.permit(:name, :address, :city, :state, :zip_code, :description, :status)
Expand Down
23 changes: 14 additions & 9 deletions app/views/applications/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
<section = id="Add a Pet to this Application" >
<%= form_with url: "/applications/#{@application.id}", method: :get, local: true do |f| %>
<%= f.label :search, "Search by pet name:" %>
<%= f.text_field :search %>
<%= f.submit "Search" %>
<% end %>
</section>
<h2>Add a Pet to this Application</h2>
<%= form_with url: "/applications/#{@application.id}", method: :get, local: true do |f| %>
<%= f.label :search, "Search by pet name:" %>
<%= f.text_field :search %>
<%= f.submit "Search" %>
<% end %>

<br>

<% if @searched_pets.any? == true %>
<% @searched_pets.each do |pet| %>
<%= pet.name %> <%= button_to "Adopt this Pet", "/applications/#{@application.id}", method: :patch%>
<% end %>
<section id= "searched_pets-<%= pet.id %>" >
<%= pet.name %>
<%= button_to "Adopt this Pet", "/applications/#{@application.id}?pet_id=#{pet.id}", method: :patch%>
<% end %>
</section>
<% end %>


<h1><%= @application.name %></h1>
<h3>Address: <%= @application.address %></h3>
<h3>City: <%= @application.city %></h3>
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@
get '/applications/new', to: 'applications#new'
get '/applications/:id', to: 'applications#show'
post '/applications', to: 'applications#create'
patch '/applications/:id', to: 'applications#update'

end
17 changes: 1 addition & 16 deletions spec/features/applications/show_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@pet_1 = Pet.create!(adoptable: true, age: 1, breed: 'sphynx', name: 'Lucille Bald', shelter_id: @shelter.id)
@pet_2 = Pet.create!(adoptable: true, age: 3, breed: 'doberman', name: 'Lobster', shelter_id: @shelter.id)
@pet_3 = Pet.create!(adoptable: true, age: 4, breed: 'chihuahua', name: 'Elle', shelter_id: @shelter.id)
@pet_4 = Pet.create!(adoptable: true, age: 1, breed: 'retriever/mix', name: 'Miley', shelter_id: @shelter_2.id)
@pet_4 = Pet.create!(adoptable: true, age: 1, breed: 'retriever/mix', name: 'Miley', shelter_id: @shelter.id)


@application_1 = Application.create!(name: 'Ashley', address: '1215 Perrine', city: 'Rawlins', state: 'WY', zip_code: 82301, description: 'I want a puppy', status: 'In Progress')
Expand Down Expand Up @@ -52,19 +52,4 @@
expect(current_path).to eq("/applications/#{@application_1.id}")
expect(@pet_1.name).to appear_before(@pet_3.name)
end

it 'displays button next to searched pets' do
visit "/applications/#{@application_1.id}"

fill_in 'Search by pet name:', with: "Lucille"
click_on("Search")
fill_in 'Search by pet name:', with: "Miley"
click_on("Search")

expect(page).to have_button("Adopt this Pet")
end

xit 'add pet to pets list on the application when button selected' do

end
end
41 changes: 41 additions & 0 deletions spec/features/applications/update_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
require 'rails_helper'

RSpec.describe 'the applications updates' do
before :each do
@shelter = Shelter.create(name: 'Mystery Building', city: 'Irvine CA', foster_program: false, rank: 9)
@pet_1 = Pet.create!(adoptable: true, age: 1, breed: 'sphynx', name: 'Lucille Bald', shelter_id: @shelter.id)
@pet_2 = Pet.create!(adoptable: true, age: 3, breed: 'doberman', name: 'Lobster', shelter_id: @shelter.id)
@pet_3 = Pet.create!(adoptable: true, age: 4, breed: 'chihuahua', name: 'Elle', shelter_id: @shelter.id)
@pet_4 = Pet.create!(adoptable: true, age: 1, breed: 'retriever/mix', name: 'Miley', shelter_id: @shelter.id)


@application_1 = Application.create!(name: 'Ashley', address: '1215 Perrine', city: 'Rawlins', state: 'WY', zip_code: 82301, description: 'I want a puppy', status: 'In Progress')

PetApplication.create!(pet: @pet_2, application: @application_1)
PetApplication.create!(pet: @pet_3, application: @application_1)
end

it 'displays button next to searched pets' do
visit "/applications/#{@application_1.id}"

fill_in 'Search by pet name:', with: "Miley"
click_on("Search")

expect(page).to have_button("Adopt this Pet")
end

it 'add pet to pets list on the application when button selected' do
visit "/applications/#{@application_1.id}"

fill_in 'Search by pet name:', with: "Miley"
click_on("Search")

within("#searched_pets-#{@pet_4.id}") do
click_button('Adopt this Pet')
end
save_and_open_page
expect(current_path).to eq("/applications/#{@application_1.id}")
find_link("#{@pet_4.name}")
end

end

0 comments on commit 61cd14c

Please sign in to comment.