diff --git a/README.md b/README.md index 9e9d64e54..68e1acfbf 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ During your Check In, you should be prepared to review your database schema for ## Evaluation -Before your evaluation, choose 2 user stories to present in a small group. Try to pick user stories that you think will deliever the highest value in terms of feedback from the instructor and peers. +Before your evaluation, choose 2 user stories to present in a small group. Try to pick user stories that you think will deliever the highest value in terms of feedback from the instructor and peers. During the evaluation, you will present your user story: @@ -45,7 +45,7 @@ During the evaluation, you will present your user story: ## Deploy ``` -[ ] done +[X] done Deploy your application to Heroku @@ -63,8 +63,8 @@ Use these guides: https://devcenter.heroku.com/articles/getting-started-with-rai Visitors to the site will be able to create applications to adopt pets. An application has many pets. Pets can have many applications. ``` -[ ] done - +[X] done +User Story 3 Application Show Page As a visitor @@ -78,10 +78,10 @@ Then I can see the following: ``` ``` -[ ] done +[X] done Starting an Application - +User Story 4 As a visitor When I visit the pet index page Then I see a link to "Start an Application" @@ -100,8 +100,8 @@ And I see an indicator that this application is "In Progress" ``` ``` -[ ] done - +[X] done +User Story 5 Starting an Application, Form not Completed As a visitor @@ -113,8 +113,8 @@ And I see a message that I must fill in those fields. ``` ``` -[ ] done - +[X] done +User Story 6 Searching for Pets for an Application As a visitor @@ -129,8 +129,8 @@ And under the search bar I see any Pet whose name matches my search ``` ``` -[ ] done - +[X] done +User Story 7 Add a Pet to an Application As a visitor @@ -144,8 +144,8 @@ And I see the Pet I want to adopt listed on this application ``` ``` -[ ] done - +[X] done +User Story 8 Submit an Application As a visitor @@ -162,8 +162,8 @@ And I do not see a section to add more pets to this application ``` ``` -[ ] done - +[X] done +User Story 9 No Pets on an Application As a visitor diff --git a/app/controllers/applications_controller.rb b/app/controllers/applications_controller.rb index 20c07be2c..5c80c9176 100644 --- a/app/controllers/applications_controller.rb +++ b/app/controllers/applications_controller.rb @@ -1,10 +1,13 @@ class ApplicationsController < ApplicationController - def index - end - def show @application = Application.find(params[:id]) + + if params[:search].present? + @searched_pets = Pet.search(params[:search]) + else + @searched_pets = [] + end end def new @@ -21,6 +24,19 @@ 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}" + elsif params[:status] + application.update(status: params[:status]) + redirect_to "/applications/#{application.id}" + end + end + private def application_params params.permit(:name, :address, :city, :state, :zip_code, :description, :status) diff --git a/app/views/applications/show.html.erb b/app/views/applications/show.html.erb index f3cf1234c..08962c0a9 100644 --- a/app/views/applications/show.html.erb +++ b/app/views/applications/show.html.erb @@ -1,10 +1,34 @@ +

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

<%= @application.name %>

Address: <%= @application.address %>

City: <%= @application.city %>

State: <%= @application.state %>

Zip Code: <%= @application.zip_code %>

-

Description: <%= @application.description %>

+

Pet(s):

<% @application.pets.each do |pet| %> -

Pet(s): <%= link_to "#{pet.name}", "/pets/#{pet.id}" %>

+ <%= link_to "#{pet.name}", "/pets/#{pet.id}" %> <% end %>

Application Status: <%= @application.status %>

+ +<% if @application.pets != [] %> + <%= button_to "Submit Application", "/applications/#{@application.id}?status=Pending", method: :patch%> + <% else @application.pets == []%> +<% end %> diff --git a/config/routes.rb b/config/routes.rb index 9e20a35fe..0c03b5369 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/db/seeds.rb b/db/seeds.rb index f3a0480d1..ae87bd52e 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -5,3 +5,39 @@ # # movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) # Character.create(name: 'Luke', movie: movies.first) +PetApplication.destroy_all +Application.destroy_all +Pet.destroy_all +Shelter.destroy_all +#shelters +@shelter_1 = Shelter.create(name: 'Denver Dumb Friends Leauge', city: 'Denver, CO', foster_program: true, rank: 8) +@shelter_2 = Shelter.create(name: 'Rocky Mountain Puppy Rescue', city: 'Westminster, CO', foster_program: true, rank: 9) + +#pets +@pet_1 = Pet.create!(adoptable: true, age: 7, breed: 'dane-shepard', name: 'Koop', shelter_id: @shelter_2.id) +@pet_2 = Pet.create!(adoptable: true, age: 9, breed: 'pitbull', name: 'Nola', shelter_id: @shelter_1.id) +@pet_3 = Pet.create!(adoptable: true, age: 6, breed: 'lab', name: 'Mona', shelter_id: @shelter_1.id) +@pet_4 = Pet.create!(adoptable: true, age: 1, breed: 'retriever/mix', name: 'Miley', shelter_id: @shelter_2.id) +@pet_5 = Pet.create!(adoptable: true, age: 3, breed: 'saint bernard', name: 'Truck', shelter_id: @shelter_2.id) +@pet_6 = Pet.create!(adoptable: true, age: 4, breed: 'australian shepard', name: 'Jackson', shelter_id: @shelter_2.id) + +#applications +@application_1 = Application.create!(name: 'Isabella', address: '1234 Drive', city: 'Denver', state: 'CO', zip_code: 80221, description: 'I want a friend', status: 'In Progress') +@application_2 = Application.create!(name: 'Molly', address: '6831 ', city: 'Aurora', state: 'CO', zip_code: 80023, description: 'My other dog wants a friend', status: 'Approved') +@application_3 = Application.create!(name: 'Fiona', address: '1215 Perrine', city: 'Rawlins', state: 'WY', zip_code: 82301, description: 'I want a puppy', status: 'In Progress') +@application_4 = Application.create!(name: 'Felipe', address: '6835 Carrick Dr', city: 'Fort Collins', state: 'CO', zip_code: 80525, description: 'I would be the best dog parent!', status: 'Pending') +@application_5 = Application.create!(name: 'Bailey', address: '2323 Platte Street', city: 'Saratoga', state: 'WY', zip_code: 82311, description: 'I want a puppy', status: 'Pending') + +#pet_applications +PetApplication.create!(pet: @pet_2, application: @application_1) +PetApplication.create!(pet: @pet_3, application: @application_1) +PetApplication.create!(pet: @pet_5, application: @application_1) +PetApplication.create!(pet: @pet_2, application: @application_2) +PetApplication.create!(pet: @pet_3, application: @application_2) +PetApplication.create!(pet: @pet_4, application: @application_2) +PetApplication.create!(pet: @pet_4, application: @application_3) +PetApplication.create!(pet: @pet_6, application: @application_3) +PetApplication.create!(pet: @pet_1, application: @application_4) +PetApplication.create!(pet: @pet_3, application: @application_4) +PetApplication.create!(pet: @pet_5, application: @application_4) +PetApplication.create!(pet: @pet_6, application: @application_5) diff --git a/spec/features/applications/create_spec.rb b/spec/features/applications/create_spec.rb index 2ef292e91..d776e5aa2 100644 --- a/spec/features/applications/create_spec.rb +++ b/spec/features/applications/create_spec.rb @@ -9,6 +9,7 @@ end describe 'new application' do + #User story 4 it 'links to the new page from the pet index page' do visit '/pets' @@ -16,7 +17,7 @@ expect(current_path).to eq('/applications/new') end - + #User story 4 it 'can create a new application when all fields are filled out' do visit '/applications/new' @@ -40,7 +41,7 @@ expect(page).to have_content("Application Status: In Progress") end end - + #User story 5 describe 'not all fields are filled out' do it 're-renders the new form' do visit '/applications/new' diff --git a/spec/features/applications/index_spec.rb b/spec/features/applications/index_spec.rb deleted file mode 100644 index 4f56a1c6e..000000000 --- a/spec/features/applications/index_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require 'rails_helper' - -RSpec.describe 'the applications index' do - before :each do - shelter = Shelter.create(name: 'Aurora shelter', city: 'Aurora, CO', 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) - - end -end diff --git a/spec/features/applications/show_spec.rb b/spec/features/applications/show_spec.rb index 0ac47a1c3..99997f1c7 100644 --- a/spec/features/applications/show_spec.rb +++ b/spec/features/applications/show_spec.rb @@ -6,8 +6,12 @@ @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') + @application_2 = Application.create!(name: 'Sarah', address: '8734 Drive Dr', city: 'Denver', state: 'CO', zip_code: 80221, description: 'I love dogs!', status: 'In Progress') + PetApplication.create!(pet: @pet_2, application: @application_1) PetApplication.create!(pet: @pet_3, application: @application_1) @@ -21,13 +25,12 @@ expect(page).to have_content("City: #{@application_1.city}") expect(page).to have_content("State: #{@application_1.state}") expect(page).to have_content("Zip Code: #{@application_1.zip_code}") - expect(page).to have_content("Description: #{@application_1.description}") - expect(page).to_not have_content("Pet(s): #{@pet_1.name}") - expect(page).to have_content("Pet(s): #{@pet_2.name}") - expect(page).to have_content("Pet(s): #{@pet_3.name}") + expect(page).to_not have_content("#{@pet_1.name}") + find_link("#{@pet_2.name}") + find_link("#{@pet_3.name}") expect(page).to have_content("Application Status: #{@application_1.status}") end - + #User story 3 it 'had link to pet show page from pet name' do visit "/applications/#{@application_1.id}" @@ -35,4 +38,26 @@ expect(current_path).to eq("/pets/#{@pet_2.id}") end + #User story 6 + it 'has a text box to filter results by keyword' do + visit "/applications/#{@application_1.id}" + + expect(page).to have_button("Search") + end + #User story 6 + it 'lists partial matches of search results' do + visit "/applications/#{@application_1.id}" + + fill_in 'Search by pet name:', with: "Lucille" + click_on("Search") + + expect(current_path).to eq("/applications/#{@application_1.id}") + expect(@pet_1.name).to appear_before(@pet_3.name) + end + #User story 9 + it 'does not display "Submit Application" button when no pets are on the application' do + visit "/applications/#{@application_2.id}" + + expect(page).to_not have_button("Submit Application") + end end diff --git a/spec/features/applications/update_spec.rb b/spec/features/applications/update_spec.rb new file mode 100644 index 000000000..01c9f7043 --- /dev/null +++ b/spec/features/applications/update_spec.rb @@ -0,0 +1,56 @@ +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 + #User story 7 + 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 + #User story 7 + 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 + + expect(current_path).to eq("/applications/#{@application_1.id}") + find_link("#{@pet_4.name}") + end + #User story 8 + it 'displays a "Submit Application" button when application has pets' do + visit "/applications/#{@application_1.id}" + + expect(page).to have_button("Submit Application") + end + #User story 8 + it 'updates application to "Pending" when the "Submit Application" is pushed' do + visit "/applications/#{@application_1.id}" + + click_button('Submit Application') + + expect(current_path).to eq("/applications/#{@application_1.id}") + expect(page).to have_content("Application Status: Pending") + end + +end