diff --git a/Gemfile b/Gemfile index 2d2a53fea..0381bfc6b 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' git_source(:github) { |repo| "https://github.com/#{repo}.git" } @@ -38,23 +40,22 @@ gem 'bootsnap', '>= 1.1.0', require: false group :development, :test do gem 'capybara' - gem 'shoulda-matchers' gem 'launchy' gem 'orderly' gem 'pry' gem 'rspec-rails' + gem 'shoulda-matchers' gem 'simplecov' end group :development do # Access an interactive console on exception pages or by calling 'console' anywhere in the code. - gem 'web-console', '>= 3.3.0' gem 'listen', '>= 3.0.5', '< 3.2' + gem 'web-console', '>= 3.3.0' # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring' gem 'spring-watcher-listen', '~> 2.0.0' end - # Windows does not include zoneinfo files, so bundle the tzinfo-data gem -gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] +gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby] diff --git a/Rakefile b/Rakefile index 9a5ea7383..488c551fe 100644 --- a/Rakefile +++ b/Rakefile @@ -1,6 +1,8 @@ +# frozen_string_literal: true + # Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. -require_relative "config/application" +require_relative 'config/application' Rails.application.load_tasks diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index d05ea0f51..af03b3940 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -13,3 +13,49 @@ *= require_tree . *= require_self */ + +li { + margin: 10px; +} + +.wide { + height: 90px; + width: 50%; +} + +.flash { + color: rgb(107, 107, 107); + font-size: 20px; + font-weight: bold; + text-decoration: underline dotted darkblue; +} + +.topnav a { + float: left; + background-color: rgb(146, 194, 149); + color: rgb(14, 0, 105); + text-align: center; + padding: 14px 16px; + font-size: 22px; + font-family: Georgia, 'Times New Roman', Times, serif; + font-weight: bold; + } + +.topnav a:hover { + background-color: #ddd; + color: black; + } + +h1 { + margin: 10px; +} + +a { + padding: 10px +} + +.right_list { + float: right; + margin: 10px; + background-color: blanchedalmond; + } \ No newline at end of file diff --git a/app/channels/application_cable/channel.rb b/app/channels/application_cable/channel.rb index d67269728..9aec23053 100644 --- a/app/channels/application_cable/channel.rb +++ b/app/channels/application_cable/channel.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ApplicationCable class Channel < ActionCable::Channel::Base end diff --git a/app/channels/application_cable/connection.rb b/app/channels/application_cable/connection.rb index 0ff5442f4..8d6c2a1bf 100644 --- a/app/channels/application_cable/connection.rb +++ b/app/channels/application_cable/connection.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ApplicationCable class Connection < ActionCable::Connection::Base end diff --git a/app/controllers/admin_petitions_controller.rb b/app/controllers/admin_petitions_controller.rb new file mode 100644 index 000000000..052b8e5ad --- /dev/null +++ b/app/controllers/admin_petitions_controller.rb @@ -0,0 +1,12 @@ +class AdminPetitionsController < ApplicationController + def show + @petition = Petition.find(params[:id]) + @associated_pet_petitions = @petition.associated_pet_petitions + if params[:approval] + @pet = Pet.find(params[:pet]) + @pet_petition = PetPetition.select(@pet.id, @petition.id) + @pet_petition.status = params[:approval] + @pet_petition.save + end + end +end diff --git a/app/controllers/admin_shelters_controller.rb b/app/controllers/admin_shelters_controller.rb new file mode 100644 index 000000000..0e77b87d5 --- /dev/null +++ b/app/controllers/admin_shelters_controller.rb @@ -0,0 +1,10 @@ +class AdminSheltersController < ApplicationController + def index + @shelters = Shelter.reverse_alphabet + @pending = Shelter.with_pending + end + + def show + @shelter = Shelter.find(params[:id]) + end +end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 91cee2e54..7969f6fc9 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,6 +1,7 @@ +# frozen_string_literal: true + class ApplicationController < ActionController::Base - def welcome - end + def welcome; end private diff --git a/app/controllers/pet_petitions_controller.rb b/app/controllers/pet_petitions_controller.rb new file mode 100644 index 000000000..e69de29bb diff --git a/app/controllers/petitions_controller.rb b/app/controllers/petitions_controller.rb new file mode 100644 index 000000000..ec1c77c66 --- /dev/null +++ b/app/controllers/petitions_controller.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +class PetitionsController < ApplicationController + def new; end + + def create + @petition = Petition.new(petition_params) + if @petition.save + redirect_to "/petitions/#{@petition.id}" + flash[:status] = 'In Progress' + else + flash[:incomplete] = ' Must Fill In All Fields' + redirect_to '/petitions/new' + end + end + + def show + @petition = Petition.find(params[:id]) + @pets = Pet.all + + @pets = Pet.search(params[:search]) if params[:search] + if params[:pet_id] + new_pet = Pet.find(params[:pet_id]) + @pet_petition = PetPetition.create(petition: @petition, pet: new_pet) + @associated_pets = PetPetition.associated_pets(@petition.id) + end + end + + def submit + @petition = Petition.find(params[:id]) + @petition.goodhome = params[:goodhome] + @petition.status = 'Pending' + @petition.save + redirect_to "/petitions/#{@petition.id}" + end + + private + + def petition_params + params.permit( + :name, + :street_address, + :city, + :state, + :zipcode + ) + end +end diff --git a/app/controllers/pets_controller.rb b/app/controllers/pets_controller.rb index 595602b8f..8922b142e 100644 --- a/app/controllers/pets_controller.rb +++ b/app/controllers/pets_controller.rb @@ -1,10 +1,9 @@ +# frozen_string_literal: true + class PetsController < ApplicationController def index - if params[:search].present? - @pets = Pet.search(params[:search]) - else - @pets = Pet.adoptable - end + @pets = Pet.adoptable + @pets = Pet.search(params[:search]) if params[:search] end def show diff --git a/app/controllers/shelters_controller.rb b/app/controllers/shelters_controller.rb index 036e44995..b2881911c 100644 --- a/app/controllers/shelters_controller.rb +++ b/app/controllers/shelters_controller.rb @@ -1,32 +1,33 @@ +# frozen_string_literal: true + class SheltersController < ApplicationController def index - if params[:sort].present? && params[:sort] == "pet_count" - @shelters = Shelter.order_by_number_of_pets - elsif params[:search].present? - @shelters = Shelter.search(params[:search]) - else - @shelters = Shelter.order_by_recently_created - end + @shelters = if params[:sort].present? && params[:sort] == 'pet_count' + Shelter.order_by_number_of_pets + elsif params[:search].present? + Shelter.search(params[:search]) + else + Shelter.order_by_recently_created + end end def pets @shelter = Shelter.find(params[:shelter_id]) - if params[:sort] == 'alphabetical' - @shelter_pets = @shelter.alphabetical_pets - elsif params[:age] - @shelter_pets = @shelter.shelter_pets_filtered_by_age(params[:age]) - else - @shelter_pets = @shelter.adoptable_pets - end + @shelter_pets = if params[:sort] == 'alphabetical' + @shelter.alphabetical_pets + elsif params[:age] + @shelter.shelter_pets_filtered_by_age(params[:age]) + else + @shelter.adoptable_pets + end end def show @shelter = Shelter.find(params[:id]) end - def new - end + def new; end def create shelter = Shelter.new(shelter_params) diff --git a/app/controllers/veterinarians_controller.rb b/app/controllers/veterinarians_controller.rb index 7aa023976..96e7e3c21 100644 --- a/app/controllers/veterinarians_controller.rb +++ b/app/controllers/veterinarians_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class VeterinariansController < ApplicationController def index @veterinarians = Veterinarian.on_call diff --git a/app/controllers/veterinary_offices_controller.rb b/app/controllers/veterinary_offices_controller.rb index e6d16c9e1..b26858284 100644 --- a/app/controllers/veterinary_offices_controller.rb +++ b/app/controllers/veterinary_offices_controller.rb @@ -1,32 +1,33 @@ +# frozen_string_literal: true + class VeterinaryOfficesController < ApplicationController def index - if params[:sort].present? && params[:sort]== "veterinarian_count" - @veterinary_offices = VeterinaryOffice.order_by_number_of_vets - else - @veterinary_offices = VeterinaryOffice.order_by_recently_created - end + @veterinary_offices = if params[:sort].present? && params[:sort] == 'veterinarian_count' + VeterinaryOffice.order_by_number_of_vets + else + VeterinaryOffice.order_by_recently_created + end end def veterinarians @veterinary_office = VeterinaryOffice.find(params[:veterinary_office_id]) - if params[:sort] == 'alphabetical' - @office_vets = @veterinary_office.alphabetical_vets - elsif params[:review_rating] - @office_vets = @veterinary_office.office_vets_filtered_by_rating( - params[:review_rating] - ) - else - @office_vets = @veterinary_office.on_call_vets - end + @office_vets = if params[:sort] == 'alphabetical' + @veterinary_office.alphabetical_vets + elsif params[:review_rating] + @veterinary_office.office_vets_filtered_by_rating( + params[:review_rating] + ) + else + @veterinary_office.on_call_vets + end end def show @veterinary_office = VeterinaryOffice.find(params[:id]) end - def new - end + def new; end def create vet_office = VeterinaryOffice.new(vet_office_params) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be7945..15b06f0f6 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + module ApplicationHelper end diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb index d394c3d10..bef395997 100644 --- a/app/jobs/application_job.rb +++ b/app/jobs/application_job.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ApplicationJob < ActiveJob::Base # Automatically retry jobs that encountered a deadlock # retry_on ActiveRecord::Deadlocked diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 286b2239d..d84cb6e71 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ApplicationMailer < ActionMailer::Base default from: 'from@example.com' layout 'mailer' diff --git a/app/models/application_record.rb b/app/models/application_record.rb index a5d389403..a65c2be93 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -1,7 +1,9 @@ +# frozen_string_literal: true + class ApplicationRecord < ActiveRecord::Base self.abstract_class = true def self.search(search_params) - where("name ILIKE ?", "%#{search_params}%") + where('name ILIKE ?', "%#{search_params}%") end end diff --git a/app/models/pet.rb b/app/models/pet.rb index 26dfb8e3f..6e0d798e5 100644 --- a/app/models/pet.rb +++ b/app/models/pet.rb @@ -1,7 +1,11 @@ +# frozen_string_literal: true + class Pet < ApplicationRecord validates :name, presence: true validates :age, presence: true, numericality: true belongs_to :shelter + has_many :pet_petitions, dependent: :destroy + has_many :petitions, through: :pet_petitions def shelter_name shelter.name diff --git a/app/models/pet_petition.rb b/app/models/pet_petition.rb new file mode 100644 index 000000000..c8a82deff --- /dev/null +++ b/app/models/pet_petition.rb @@ -0,0 +1,13 @@ +class PetPetition < ApplicationRecord + belongs_to :pet + belongs_to :petition + + def self.associated_pets(id) + pet_ids = where('petition_id = ?', id).pluck(:pet_id) + Pet.find(pet_ids) + end + + def self.select(pet_id, petition_id) + where('pet_id = ? AND petition_id = ?', pet_id, petition_id).first + end +end diff --git a/app/models/petition.rb b/app/models/petition.rb new file mode 100644 index 000000000..c4938b332 --- /dev/null +++ b/app/models/petition.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class Petition < ApplicationRecord + has_many :pet_petitions, dependent: :destroy + has_many :pets, through: :pet_petitions + validates :name, :street_address, :city, :state, :zipcode, presence: true + + def associated_pet_petitions + pet_petitions.all + end +end diff --git a/app/models/shelter.rb b/app/models/shelter.rb index 49dc25421..131df64e7 100644 --- a/app/models/shelter.rb +++ b/app/models/shelter.rb @@ -1,19 +1,32 @@ +# frozen_string_literal: true + class Shelter < ApplicationRecord validates :name, presence: true validates :rank, presence: true, numericality: true validates :city, presence: true has_many :pets, dependent: :destroy + has_many :pet_petitions, through: :pets + has_many :petitions, through: :pet_petitions def self.order_by_recently_created order(created_at: :desc) end def self.order_by_number_of_pets - select("shelters.*, count(pets.id) AS pets_count") - .joins("LEFT OUTER JOIN pets ON pets.shelter_id = shelters.id") - .group("shelters.id") - .order("pets_count DESC") + select('shelters.*, count(pets.id) AS pets_count') + .joins('LEFT OUTER JOIN pets ON pets.shelter_id = shelters.id') + .group('shelters.id') + .order('pets_count DESC') + end + + def self.reverse_alphabet + Shelter.find_by_sql('SELECT * FROM shelters ORDER BY name DESC') + end + + def self.with_pending + pending = joins(:pets).joins(:pet_petitions).joins(:petitions).where(petitions: { status: 'Pending' }).distinct + pending.order(:name) end def pet_count diff --git a/app/models/veterinarian.rb b/app/models/veterinarian.rb index 1112f3369..449ea08bd 100644 --- a/app/models/veterinarian.rb +++ b/app/models/veterinarian.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Veterinarian < ApplicationRecord validates :name, presence: true validates :review_rating, presence: true, numericality: true diff --git a/app/models/veterinary_office.rb b/app/models/veterinary_office.rb index d35f61a0c..e08c5b37d 100644 --- a/app/models/veterinary_office.rb +++ b/app/models/veterinary_office.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class VeterinaryOffice < ApplicationRecord validates :name, presence: true validates :max_patient_capacity, presence: true, numericality: true @@ -9,10 +11,10 @@ def self.order_by_recently_created end def self.order_by_number_of_vets - select("veterinary_offices.*, count(veterinarians.id) AS vets_count") - .joins("LEFT OUTER JOIN veterinarians ON veterinarians.veterinary_office_id = veterinary_offices.id") - .group("veterinary_offices.id") - .order("vets_count DESC") + select('veterinary_offices.*, count(veterinarians.id) AS vets_count') + .joins('LEFT OUTER JOIN veterinarians ON veterinarians.veterinary_office_id = veterinary_offices.id') + .group('veterinary_offices.id') + .order('vets_count DESC') end def vet_count diff --git a/app/views/admin_petitions/show.html.erb b/app/views/admin_petitions/show.html.erb new file mode 100644 index 000000000..96c4b738e --- /dev/null +++ b/app/views/admin_petitions/show.html.erb @@ -0,0 +1,15 @@ +

<%= "#{@petition.name}'s Application for Pets" %>

+ +

Pets Applied For

+<% @associated_pet_petitions.each do |pet_petition| %> + <% if pet_petition.status != 'Undecided' %> +

<%= " #{pet_petition.pet.name} -- #{pet_petition.pet.breed}: #{pet_petition.pet.age} years old." %>

+

<%= "Application Status: #{pet_petition.status}" %>

+

<%= "Is #{pet_petition.pet.name} adoptable? #{pet_petition.pet.adoptable} " %>

+ <% elsif pet_petition.status == 'Undecided' %> +

<%= " #{pet_petition.pet.name} -- #{pet_petition.pet.breed}: #{pet_petition.pet.age} years old." %>

+

<%= "Is #{pet_petition.pet.name} adoptable? #{pet_petition.pet.adoptable} " %>

+ <%= button_to "Approve #{@petition.name} for #{pet_petition.pet.name}", "/admin/petitions/#{@petition.id}", method: :get, params: { approval: 'Approved', pet: pet_petition.pet.id} %> + <%= button_to "Reject #{@petition.name} for #{pet_petition.pet.name}", "/admin/petitions/#{@petition.id}", method: :get, params: { approval: 'Rejected', pet: pet_petition.pet.id} %> + <% end %> +<% end %> \ No newline at end of file diff --git a/app/views/admin_shelters/index.html.erb b/app/views/admin_shelters/index.html.erb new file mode 100644 index 000000000..2d96a091c --- /dev/null +++ b/app/views/admin_shelters/index.html.erb @@ -0,0 +1,11 @@ +
+

With Pending Applications

+ <% @pending.each do |shelter| %> +

<%= shelter.name %>

+ <% end %> +
+ +

All Shelters

+<% @shelters.each do |shelter| %> +

<%= link_to "#{shelter.name}", "/admin/shelters/#{shelter.id}" %>

+<% end %> \ No newline at end of file diff --git a/app/views/admin_shelters/show.html.erb b/app/views/admin_shelters/show.html.erb new file mode 100644 index 000000000..154444d5a --- /dev/null +++ b/app/views/admin_shelters/show.html.erb @@ -0,0 +1,4 @@ +

<%= "#{@shelter.name}'s Information" %>

+ +<%= "Shelter Name: #{@shelter.name}" %> +<%= "Shelter Location: #{@shelter.city}" %> \ No newline at end of file diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 1ab72e289..5d2749f87 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -1,26 +1,31 @@ - - Adopt, Don't Shop - - <%= csrf_meta_tags %> - <%= csp_meta_tag %> - <%= stylesheet_link_tag 'application', media: 'all' %> - + + Adopt, Don't Shop + + <%= csrf_meta_tags %> + <%= csp_meta_tag %> - - <% flash.each do |type, msg| %> -
- <%= msg %> -
- <% end %> -
-

<%= link_to "Pets", "/pets" %>

-

<%= link_to "Shelters", "/shelters" %>

-

<%= link_to "Veterinarians", "/veterinarians" %>

-

<%= link_to "Veterinary Offices", "/veterinary_offices" %>

-
- <%= yield %> - - + <%= stylesheet_link_tag 'application', media: 'all' %> + +
+ <%= link_to "Pets", "/pets" %> + <%= link_to "Shelters", "/shelters" %> + <%= link_to "Veterinarians", "/veterinarians" %> + <%= link_to "Veterinary Offices", "/veterinary_offices" %> +
+
+
+
+ + + + <% flash.each do |type, message| %> +

<%= message %>

+ <% end %> + + <%= yield %> + + + \ No newline at end of file diff --git a/app/views/petitions/new.html.erb b/app/views/petitions/new.html.erb new file mode 100644 index 000000000..592a0b81b --- /dev/null +++ b/app/views/petitions/new.html.erb @@ -0,0 +1,15 @@ +
+

Apply to Adopt a Pet!

+ <%= form_with url: '/petitions', method: :post, local: true do |form| %> +
  • <%= form.label :name %> + <%= form.text_field :name %>
  • +
  • <%= form.label :street_address, 'Street Address' %> + <%= form.text_field :street_address %>
  • +
  • <%= form.label :city %> + <%= form.text_field :city %>
  • +
  • <%= form.label :state %> + <%= form.text_field :state %>
  • +
  • <%= form.label :zipcode %> + <%= form.number_field :zipcode %>
  • + <%= form.submit 'Start Application' %> + <% end %> \ No newline at end of file diff --git a/app/views/petitions/show.html.erb b/app/views/petitions/show.html.erb new file mode 100644 index 000000000..95ff24bac --- /dev/null +++ b/app/views/petitions/show.html.erb @@ -0,0 +1,41 @@ +

    Application Details

    + + +<%= "Your name: #{@petition.name}" %> +
    +<%= "Your address: #{@petition.street_address} #{@petition.city}, #{@petition.state} #{@petition.zipcode}" %> +
    +<%= "Why you'd make a great home for these pets: #{@petition.goodhome}" %> +
    +<%= "Your application status: #{@petition.status}" %> +
    +<% if !@pet_petition.nil? %> +<%= "Pets you'd like to adopt:" %> +<% @associated_pets.each do |pet| %> +<%= pet.name %> +<% end %> +<%= form_with url: "/petitions/#{@petition.id}/submit", method: :patch, local: true do |f| %> +<%= f.label :goodhome, 'Say a bit about why you would make a good owner for these pets:' %> +<%= f.text_area :goodhome, size:"80X80" %> +<%= f.submit 'Submit Your Application' %> +<% end %> + +<% end %> + + +<% if @petition.status == 'In Progress' %> +<%= form_with url: "/petitions/#{@petition.id}", method: :get, local: true do |f| %> +<%= f.label :search, 'Add a Pet to this Application' %> +<%= f.text_field :search %> +<%= f.submit "Search" %> +<% end %> + +<% @pets.each do |pet| %> +

    <%= pet.name %>

    +

    Age: <%= pet.age %>

    +

    Breed: <%= pet.breed %>

    +

    Adoptable: <%= pet.adoptable %>

    +

    You can find <%= pet.name %> at <%= pet.shelter_name %>!

    +

    <%= button_to "Adopt #{pet.name}", "/petitions/#{@petition.id}", method: :get, params: { pet_id: pet.id }%> +<% end %> +<% end %> diff --git a/app/views/pets/edit.html.erb b/app/views/pets/edit.html.erb index 6cb83b504..7a50babc3 100644 --- a/app/views/pets/edit.html.erb +++ b/app/views/pets/edit.html.erb @@ -1,3 +1,4 @@ +

    Edit Veterinarian

    <%= form_with url: "/pets/#{@pet.id}", method: :patch, local: true do |f| %> <%= f.label :name %> diff --git a/app/views/pets/index.html.erb b/app/views/pets/index.html.erb index e093aa324..474783d70 100644 --- a/app/views/pets/index.html.erb +++ b/app/views/pets/index.html.erb @@ -1,3 +1,4 @@ +

    All pets

    <%= form_with url: "/pets", method: :get, local: true do |f| %> @@ -6,12 +7,14 @@ <%= f.submit "Search" %> <% end %> +

    <%= button_to "Start an Application", '/petitions/new', method: :get %>

    + <% @pets.each do |pet| %>

    <%= pet.name %>

    Age: <%= pet.age %>

    Breed: <%= pet.breed %>

    -

    Adoptable:

    +

    Adoptable: <%= pet.adoptable %>

    You can find <%= pet.name %> at <%= pet.shelter_name %>!

    <%= link_to "Edit #{pet.name}", "/pets/#{pet.id}/edit" %> <%= link_to "Delete #{pet.name}", "/pets/#{pet.id}", method: :delete %> diff --git a/app/views/pets/new.html.erb b/app/views/pets/new.html.erb index 64591c5e0..f8728d5fb 100644 --- a/app/views/pets/new.html.erb +++ b/app/views/pets/new.html.erb @@ -1,3 +1,4 @@ +

    New Pet

    <%= form_with url: "/shelters/#{@shelter.id}/pets", method: :post, local: true do |f| %> <%= f.label :name %> diff --git a/app/views/pets/show.html.erb b/app/views/pets/show.html.erb index ab795517f..482a699e2 100644 --- a/app/views/pets/show.html.erb +++ b/app/views/pets/show.html.erb @@ -1,3 +1,4 @@ +

    <%= @pet.name %>

    <%= @pet.age %> years old

    <%= @pet.breed %>

    diff --git a/bin/bundle b/bin/bundle index f19acf5b5..2dbb71769 100755 --- a/bin/bundle +++ b/bin/bundle @@ -1,3 +1,5 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) load Gem.bin_path('bundler', 'bundle') diff --git a/bin/rails b/bin/rails index 073966023..a31728ab9 100755 --- a/bin/rails +++ b/bin/rails @@ -1,4 +1,6 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + APP_PATH = File.expand_path('../config/application', __dir__) require_relative '../config/boot' require 'rails/commands' diff --git a/bin/rake b/bin/rake index 17240489f..c19995500 100755 --- a/bin/rake +++ b/bin/rake @@ -1,4 +1,6 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + require_relative '../config/boot' require 'rake' Rake.application.run diff --git a/bin/setup b/bin/setup index 94fd4d797..c2e43ceb2 100755 --- a/bin/setup +++ b/bin/setup @@ -1,4 +1,6 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + require 'fileutils' include FileUtils diff --git a/bin/update b/bin/update index 58bfaed51..313c74b38 100755 --- a/bin/update +++ b/bin/update @@ -1,4 +1,6 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + require 'fileutils' include FileUtils diff --git a/bin/yarn b/bin/yarn index 460dd565b..4cac416a1 100755 --- a/bin/yarn +++ b/bin/yarn @@ -1,11 +1,11 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + APP_ROOT = File.expand_path('..', __dir__) Dir.chdir(APP_ROOT) do - begin - exec "yarnpkg", *ARGV - rescue Errno::ENOENT - $stderr.puts "Yarn executable was not detected in the system." - $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install" - exit 1 - end + exec 'yarnpkg', *ARGV +rescue Errno::ENOENT + warn 'Yarn executable was not detected in the system.' + warn 'Download Yarn at https://yarnpkg.com/en/docs/install' + exit 1 end diff --git a/config.ru b/config.ru index 12feed6fb..3d7373b8e 100644 --- a/config.ru +++ b/config.ru @@ -1,6 +1,8 @@ +# frozen_string_literal: true + # This file is used by Rack-based servers to start the application. -require_relative "config/environment" +require_relative 'config/environment' run Rails.application Rails.application.load_seed diff --git a/config/application.rb b/config/application.rb index e91827052..57ca8c317 100644 --- a/config/application.rb +++ b/config/application.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative 'boot' require 'rails/all' diff --git a/config/boot.rb b/config/boot.rb index b9e460cef..c04863fa7 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) require 'bundler/setup' # Set up gems listed in the Gemfile. diff --git a/config/environment.rb b/config/environment.rb index 426333bb4..d5abe5580 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Load the Rails application. require_relative 'application' diff --git a/config/environments/development.rb b/config/environments/development.rb index 1311e3e4e..33c8acfe1 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. diff --git a/config/environments/production.rb b/config/environments/production.rb index 425ce5e98..4173de51e 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. @@ -54,7 +56,7 @@ config.log_level = :debug # Prepend all log lines with the following tags. - config.log_tags = [ :request_id ] + config.log_tags = [:request_id] # Use a different cache store in production. # config.cache_store = :mem_cache_store @@ -83,8 +85,8 @@ # require 'syslog/logger' # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') - if ENV["RAILS_LOG_TO_STDOUT"].present? - logger = ActiveSupport::Logger.new(STDOUT) + if ENV['RAILS_LOG_TO_STDOUT'].present? + logger = ActiveSupport::Logger.new($stdout) logger.formatter = config.log_formatter config.logger = ActiveSupport::TaggedLogging.new(logger) end diff --git a/config/environments/test.rb b/config/environments/test.rb index 0a38fd3ce..3091ac4b7 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. diff --git a/config/initializers/application_controller_renderer.rb b/config/initializers/application_controller_renderer.rb index 89d2efab2..f4556db39 100644 --- a/config/initializers/application_controller_renderer.rb +++ b/config/initializers/application_controller_renderer.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Be sure to restart your server when you modify this file. # ActiveSupport::Reloader.to_prepare do diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index 4b828e80c..a9b0d0f10 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Version of your assets, change this if you want to expire all your assets. diff --git a/config/initializers/backtrace_silencers.rb b/config/initializers/backtrace_silencers.rb index 59385cdf3..d0f0d3b5d 100644 --- a/config/initializers/backtrace_silencers.rb +++ b/config/initializers/backtrace_silencers.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Be sure to restart your server when you modify this file. # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. diff --git a/config/initializers/content_security_policy.rb b/config/initializers/content_security_policy.rb index d3bcaa5ec..497f5667c 100644 --- a/config/initializers/content_security_policy.rb +++ b/config/initializers/content_security_policy.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Be sure to restart your server when you modify this file. # Define an application-wide content security policy diff --git a/config/initializers/cookies_serializer.rb b/config/initializers/cookies_serializer.rb index 5a6a32d37..ee8dff9c9 100644 --- a/config/initializers/cookies_serializer.rb +++ b/config/initializers/cookies_serializer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Specify a serializer for the signed and encrypted cookie jars. diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb index 4a994e1e7..7a4f47b4c 100644 --- a/config/initializers/filter_parameter_logging.rb +++ b/config/initializers/filter_parameter_logging.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Configure sensitive parameters which will be filtered from the log file. diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index ac033bf9d..aa7435fbc 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Be sure to restart your server when you modify this file. # Add new inflection rules using the following format. Inflections diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb index dc1899682..6e1d16f02 100644 --- a/config/initializers/mime_types.rb +++ b/config/initializers/mime_types.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Be sure to restart your server when you modify this file. # Add new mime types for use in respond_to blocks: diff --git a/config/initializers/new_framework_defaults_5_2.rb b/config/initializers/new_framework_defaults_5_2.rb index c383d072b..7df9ce8f4 100644 --- a/config/initializers/new_framework_defaults_5_2.rb +++ b/config/initializers/new_framework_defaults_5_2.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Be sure to restart your server when you modify this file. # # This file contains migration options to ease your Rails 5.2 upgrade. diff --git a/config/initializers/permissions_policy.rb b/config/initializers/permissions_policy.rb index 00f64d71b..50bcf4ead 100644 --- a/config/initializers/permissions_policy.rb +++ b/config/initializers/permissions_policy.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Define an application-wide HTTP permissions policy. For further # information see https://developers.google.com/web/updates/2018/06/feature-policy # diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb index bbfc3961b..2f3c0db47 100644 --- a/config/initializers/wrap_parameters.rb +++ b/config/initializers/wrap_parameters.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # This file contains settings for ActionController::ParamsWrapper which diff --git a/config/puma.rb b/config/puma.rb index b2102072b..b5afac5e3 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -1,22 +1,24 @@ +# frozen_string_literal: true + # Puma can serve each request in a thread from an internal thread pool. # The `threads` method setting takes two numbers: a minimum and maximum. # Any libraries that use thread pools should be configured to match # the maximum value specified for Puma. Default is set to 5 threads for minimum # and maximum; this matches the default thread size of Active Record. # -threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } +threads_count = ENV.fetch('RAILS_MAX_THREADS', 5) threads threads_count, threads_count # Specifies the `port` that Puma will listen on to receive requests; default is 3000. # -port ENV.fetch("PORT") { 3000 } +port ENV.fetch('PORT', 3000) # Specifies the `environment` that Puma will run in. # -environment ENV.fetch("RAILS_ENV") { "development" } +environment ENV.fetch('RAILS_ENV', 'development') # Specifies the `pidfile` that Puma will use. -pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" } +pidfile ENV.fetch('PIDFILE', 'tmp/pids/server.pid') # Specifies the number of `workers` to boot in clustered mode. # Workers are forked webserver processes. If using threads and workers together diff --git a/config/routes.rb b/config/routes.rb index 28f609d90..6a91d89c9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Rails.application.routes.draw do get '/', to: 'application#welcome' @@ -33,7 +35,18 @@ get '/shelters/:shelter_id/pets/new', to: 'pets#new' post '/shelters/:shelter_id/pets', to: 'pets#create' + get 'admin/shelters', to: 'admin_shelters#index' + get 'admin/shelters/:id', to: 'admin_shelters#show' + get '/veterinary_offices/:veterinary_office_id/veterinarians', to: 'veterinary_offices#veterinarians' get '/veterinary_offices/:veterinary_office_id/veterinarians/new', to: 'veterinarians#new' post '/veterinary_offices/:veterinary_office_id/veterinarians', to: 'veterinarians#create' + + get '/petitions/new', to: 'petitions#new' + get '/petitions/:id/add_pet', to: 'petitions#add_pet' + get '/petitions/:id', to: 'petitions#show' + patch '/petitions/:id/submit', to: 'petitions#submit' + post '/petitions', to: 'petitions#create' + + get 'admin/petitions/:id', to: 'admin_petitions#show' end diff --git a/config/spring.rb b/config/spring.rb index 9fa7863f9..c5933e491 100644 --- a/config/spring.rb +++ b/config/spring.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + %w[ .ruby-version .rbenv-vars diff --git a/db/migrate/20210212235502_create_shelters.rb b/db/migrate/20210212235502_create_shelters.rb index b57280633..c128d3a1f 100644 --- a/db/migrate/20210212235502_create_shelters.rb +++ b/db/migrate/20210212235502_create_shelters.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateShelters < ActiveRecord::Migration[5.2] def change create_table :shelters do |t| diff --git a/db/migrate/20210212235735_create_pets.rb b/db/migrate/20210212235735_create_pets.rb index 28e70a28e..4f36f77a5 100644 --- a/db/migrate/20210212235735_create_pets.rb +++ b/db/migrate/20210212235735_create_pets.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreatePets < ActiveRecord::Migration[5.2] def change create_table :pets do |t| diff --git a/db/migrate/20210213001632_create_veterinary_offices.rb b/db/migrate/20210213001632_create_veterinary_offices.rb index b1017a4f8..cf5651349 100644 --- a/db/migrate/20210213001632_create_veterinary_offices.rb +++ b/db/migrate/20210213001632_create_veterinary_offices.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateVeterinaryOffices < ActiveRecord::Migration[5.2] def change create_table :veterinary_offices do |t| diff --git a/db/migrate/20210213001717_create_veterinarians.rb b/db/migrate/20210213001717_create_veterinarians.rb index 2cd966dca..d110ebeb5 100644 --- a/db/migrate/20210213001717_create_veterinarians.rb +++ b/db/migrate/20210213001717_create_veterinarians.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateVeterinarians < ActiveRecord::Migration[5.2] def change create_table :veterinarians do |t| diff --git a/db/migrate/20210521005026_create_petitons.rb b/db/migrate/20210521005026_create_petitons.rb new file mode 100644 index 000000000..1066719b4 --- /dev/null +++ b/db/migrate/20210521005026_create_petitons.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +class CreatePetitons < ActiveRecord::Migration[5.2] + def change + create_table :petitions do |t| + t.string :name + t.string :street_address + t.string :city + t.string :state + t.integer :zipcode + t.timestamps + end + end +end diff --git a/db/migrate/20210523215218_create_pet_petitions.rb b/db/migrate/20210523215218_create_pet_petitions.rb new file mode 100644 index 000000000..cc694fef5 --- /dev/null +++ b/db/migrate/20210523215218_create_pet_petitions.rb @@ -0,0 +1,10 @@ +class CreatePetPetitions < ActiveRecord::Migration[5.2] + def change + create_table :pet_petitions do |t| + t.references :pet, foreign_key: true + t.references :petition, foreign_key: true + t.string :good_home + t.timestamps + end + end +end diff --git a/db/migrate/20210524222246_add_goodhome_to_petitions.rb b/db/migrate/20210524222246_add_goodhome_to_petitions.rb new file mode 100644 index 000000000..bea2c8b6f --- /dev/null +++ b/db/migrate/20210524222246_add_goodhome_to_petitions.rb @@ -0,0 +1,5 @@ +class AddGoodhomeToPetitions < ActiveRecord::Migration[5.2] + def change + add_column :petitions, :goodhome, :string, default: 'I love dogs' + end +end diff --git a/db/migrate/20210524222622_remove_good_home_from_pet_petitions.rb b/db/migrate/20210524222622_remove_good_home_from_pet_petitions.rb new file mode 100644 index 000000000..f66534886 --- /dev/null +++ b/db/migrate/20210524222622_remove_good_home_from_pet_petitions.rb @@ -0,0 +1,5 @@ +class RemoveGoodHomeFromPetPetitions < ActiveRecord::Migration[5.2] + def change + remove_column :pet_petitions, :good_home, :string + end +end diff --git a/db/migrate/20210524224024_add_status_to_petition.rb b/db/migrate/20210524224024_add_status_to_petition.rb new file mode 100644 index 000000000..756b4130f --- /dev/null +++ b/db/migrate/20210524224024_add_status_to_petition.rb @@ -0,0 +1,5 @@ +class AddStatusToPetition < ActiveRecord::Migration[5.2] + def change + add_column :petitions, :status, :string, default: 'In Progress' + end +end diff --git a/db/migrate/20210527022109_add_status_to_pet_petitions.rb b/db/migrate/20210527022109_add_status_to_pet_petitions.rb new file mode 100644 index 000000000..039ed1c22 --- /dev/null +++ b/db/migrate/20210527022109_add_status_to_pet_petitions.rb @@ -0,0 +1,5 @@ +class AddStatusToPetPetitions < ActiveRecord::Migration[5.2] + def change + add_column :pet_petitions, :status, :string, default: 'Undecided' + end +end diff --git a/db/schema.rb b/db/schema.rb index 9207aacc2..a080cb50c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,49 +10,72 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_02_13_001717) do - +ActiveRecord::Schema.define(version: 20_210_527_022_109) do # These are extensions that must be enabled in order to support this database - enable_extension "plpgsql" - - create_table "pets", force: :cascade do |t| - t.boolean "adoptable" - t.integer "age" - t.string "breed" - t.string "name" - t.bigint "shelter_id", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["shelter_id"], name: "index_pets_on_shelter_id" + enable_extension 'plpgsql' + + create_table 'pet_petitions', force: :cascade do |t| + t.bigint 'pet_id' + t.bigint 'petition_id' + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false + t.string 'status', default: 'Undecided' + t.index ['pet_id'], name: 'index_pet_petitions_on_pet_id' + t.index ['petition_id'], name: 'index_pet_petitions_on_petition_id' + end + + create_table 'petitions', force: :cascade do |t| + t.string 'name' + t.string 'street_address' + t.string 'city' + t.string 'state' + t.integer 'zipcode' + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false + t.string 'goodhome', default: 'I love dogs' + t.string 'status', default: 'In Progress' + end + + create_table 'pets', force: :cascade do |t| + t.boolean 'adoptable' + t.integer 'age' + t.string 'breed' + t.string 'name' + t.bigint 'shelter_id', null: false + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false + t.index ['shelter_id'], name: 'index_pets_on_shelter_id' end - create_table "shelters", force: :cascade do |t| - t.boolean "foster_program" - t.string "name" - t.string "city" - t.integer "rank" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + create_table 'shelters', force: :cascade do |t| + t.boolean 'foster_program' + t.string 'name' + t.string 'city' + t.integer 'rank' + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false end - create_table "veterinarians", force: :cascade do |t| - t.boolean "on_call" - t.integer "review_rating" - t.string "name" - t.bigint "veterinary_office_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["veterinary_office_id"], name: "index_veterinarians_on_veterinary_office_id" + create_table 'veterinarians', force: :cascade do |t| + t.boolean 'on_call' + t.integer 'review_rating' + t.string 'name' + t.bigint 'veterinary_office_id' + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false + t.index ['veterinary_office_id'], name: 'index_veterinarians_on_veterinary_office_id' end - create_table "veterinary_offices", force: :cascade do |t| - t.boolean "boarding_services" - t.integer "max_patient_capacity" - t.string "name" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + create_table 'veterinary_offices', force: :cascade do |t| + t.boolean 'boarding_services' + t.integer 'max_patient_capacity' + t.string 'name' + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false end - add_foreign_key "pets", "shelters" - add_foreign_key "veterinarians", "veterinary_offices" + add_foreign_key 'pet_petitions', 'petitions' + add_foreign_key 'pet_petitions', 'pets' + add_foreign_key 'pets', 'shelters' + add_foreign_key 'veterinarians', 'veterinary_offices' end diff --git a/db/seeds.rb b/db/seeds.rb index f3a0480d1..8bf958942 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This file should contain all the record creation needed to seed the database with its default values. # The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup). # @@ -5,3 +7,62 @@ # # movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) # Character.create(name: 'Luke', movie: movies.first) +Shelter.destroy_all +Pet.destroy_all +Petition.destroy_all +VeterinaryOffice.destroy_all +Veterinarian.destroy_all +PetPetition.destroy_all + +denver = Shelter.create!(name: 'Denver Pet Shelter', city: 'Denver', rank: 1, foster_program: true) +greely = Shelter.create!(name: 'Greely Dumb Friends League', city: 'Greelyr', rank: 2, foster_program: true) +eagle = Shelter.create!(name: 'Eagle Pet Sanctuary', city: 'Eagle', rank: 3, foster_program: true) + +fluffy = denver.pets.create!(name: 'Fluffy', breed: 'Siamese Cat', age: 12, adoptable: true) +scruffy = denver.pets.create!(name: 'Scruffy', breed: 'Bulldog', age: 1, adoptable: true) +tig = denver.pets.create!(name: 'Tig', breed: 'Calico Cat', age: 2, adoptable: true) + +deborah = greely.pets.create!(name: 'Deborah', breed: 'Goldfish', age: 6, adoptable: true) +terrence = greely.pets.create!(name: 'Terrence', breed: 'Parrot', age: 7, adoptable: true) +paul = greely.pets.create!(name: 'Paul', breed: 'Kimodo Dragon', age: 8, adoptable: true) + +daisy = eagle.pets.create!(name: 'Daisy', breed: 'Maine Coon Cat', age: 2, adoptable: true) +moon = eagle.pets.create!(name: 'Moon', breed: 'Dacshund', age: 3, adoptable: true) +chalky = eagle.pets.create!(name: 'Chalky', breed: 'Pekingese', age: 4, adoptable: true) +chomper = eagle.pets.create!(name: 'Chomper', breed: 'Pig', age: 5, adoptable: true) + +hospital = VeterinaryOffice.create!(name: 'Denver Pet Hospital', max_patient_capacity: 12, boarding_services: false) +vet = VeterinaryOffice.create!(name: 'Bettes Vets', max_patient_capacity: 2, boarding_services: true) +doctor = VeterinaryOffice.create!(name: 'Doctor Paws', max_patient_capacity: 7, boarding_services: true) + +ramesh = hospital.veterinarians.create!(name: 'Ramesh Ranganathan', review_rating: 10, on_call: false) +nish = hospital.veterinarians.create!(name: 'Nish Kumar', review_rating: 1, on_call: true) +aislin = hospital.veterinarians.create!(name: 'Aislin Bea', review_rating: 6, on_call: true) + +greg = vet.veterinarians.create!(name: 'Greg Davies', review_rating: 4, on_call: true) +sarah = vet.veterinarians.create!(name: 'Sarah Pascoe', review_rating: 8, on_call: true) + +victoria = doctor.veterinarians.create!(name: 'Victoria Coren Mitchell', review_rating: 10, on_call: true) +david = doctor.veterinarians.create!(name: 'David Mitchell', review_rating: 7, on_call: false) +lolly = doctor.veterinarians.create!(name: 'Lolly Adefope', review_rating: 9, on_call: true) +mel = doctor.veterinarians.create!(name: 'Mel Gedroic', review_rating: 2, on_call: true) + +ted = Petition.create!(name: 'Ted Leo', + street_address: '123 Pharmacist Ln', + city: 'Denver', + state: 'Co', + zipcode: 12_345, + goodhome: 'Lurv Fluffers', + status: 'Pending') +thao = Petition.create!(name: 'Thao Nguyen', + street_address: '456 Getdown St', + city: 'Los Angeles', + state: 'CA', + zipcode: 23_456, + goodhome: 'Need Dragons', + status: 'Pending') + +application_1 = PetPetition.create!(petition: ted, pet: chomper) +application_2 = PetPetition.create!(petition: ted, pet: paul) +application_3 = PetPetition.create!(petition: thao, pet: paul) +application_4 = PetPetition.create!(petition: thao, pet: daisy) diff --git a/spec/features/admin/petitions/admin_petitions_show_spec.rb b/spec/features/admin/petitions/admin_petitions_show_spec.rb new file mode 100644 index 000000000..9c881ee98 --- /dev/null +++ b/spec/features/admin/petitions/admin_petitions_show_spec.rb @@ -0,0 +1,76 @@ +require 'rails_helper' + +describe 'admin petitions show' do + before :each do + @denver = Shelter.create!(name: 'Denver Pet Shelter', city: 'Denver', rank: 1, foster_program: true) + @eagle = Shelter.create!(name: 'Eagle Pet Sanctuary', city: 'Eagle', rank: 3, foster_program: true) + @pet_1 = @denver.pets.create(name: 'Mr. Pirate', breed: 'tuxedo shorthair', age: 5, adoptable: false) + @pet_2 = @eagle.pets.create(name: 'Clawdia', breed: 'shorthair', age: 3, adoptable: true) + @petition = Petition.create!(name: 'Ted Leo', + street_address: '123 Pharmacist Ln', + city: 'Denver', + state: 'Co', + zipcode: 12_345, + goodhome: 'Lurv Fluffers', + status: 'Pending') + @pet_petition = PetPetition.create!(petition: @petition, pet: @pet_1) + @pet_petition2 = PetPetition.create!(petition: @petition, pet: @pet_2) + visit "/admin/petitions/#{@petition.id}" + end + + it 'lists every pet associated with petition' do + expect(page).to have_content('Mr. Pirate -- tuxedo shorthair: 5 years old.') + expect(page).to have_content('Clawdia -- shorthair: 3 years old.') + end + + it 'contains a button next to each of those pets to approve or reject application' do + expect(page).to have_button('Approve Ted Leo for Mr. Pirate') + expect(page).to have_button('Reject Ted Leo for Mr. Pirate') + expect(page).to have_button('Approve Ted Leo for Clawdia') + expect(page).to have_button('Reject Ted Leo for Clawdia') + end + + it 'clicking approve approves a pet for adoption' do + click_button('Approve Ted Leo for Mr. Pirate') + + expect(current_path).to eq "/admin/petitions/#{@petition.id}" + expect(page).to have_content 'Application Status: Approved' + end + + it 'clicking reject rejects the adoption' do + click_button('Reject Ted Leo for Mr. Pirate') + + expect(current_path).to eq "/admin/petitions/#{@petition.id}" + expect(page).to have_content 'Application Status: Rejected' + end + + it 'clicking approve or reject removes button' do + click_button('Approve Ted Leo for Mr. Pirate') + click_button('Reject Ted Leo for Clawdia') + + expect(page).not_to have_button('Approve Ted Leo for Mr. Pirate') + expect(page).not_to have_button('Reject Ted Leo for Mr. Pirate') + expect(page).not_to have_button('Approve Ted Leo for Clawdia') + expect(page).not_to have_button('Reject Ted Leo for Clawdia') + end + + it 'clicking approve or reject does not affect other applications' do + @petition_2 = Petition.create!(name: 'Thao Nguyen', + street_address: '456 Getdown St', + city: 'Los Angeles', + state: 'CA', + zipcode: 12_345, + goodhome: 'Need a dragon', + status: 'Pending') + @pet_petition_3 = PetPetition.create!(petition: @petition_2, pet: @pet_1) + @pet_petition_4 = PetPetition.create!(petition: @petition_2, pet: @pet_2) + click_button('Approve Ted Leo for Mr. Pirate') + click_button('Reject Ted Leo for Clawdia') + visit "/admin/petitions/#{@petition_2.id}" + + expect(page).to have_button('Approve Thao Nguyen for Mr. Pirate') + expect(page).to have_button('Reject Thao Nguyen for Mr. Pirate') + expect(page).to have_button('Approve Thao Nguyen for Clawdia') + expect(page).to have_button('Reject Thao Nguyen for Clawdia') + end +end diff --git a/spec/features/admin/shelters/admin_shelters_index_spec.rb b/spec/features/admin/shelters/admin_shelters_index_spec.rb new file mode 100644 index 000000000..74fcb508c --- /dev/null +++ b/spec/features/admin/shelters/admin_shelters_index_spec.rb @@ -0,0 +1,54 @@ +require 'rails_helper' + +describe 'admin shelters index' do + before :each do + @denver = Shelter.create!(name: 'Denver Pet Shelter', city: 'Denver', rank: 1, foster_program: true) + @greely = Shelter.create!(name: 'Greely Dumb Friends League', city: 'Greelyr', rank: 2, foster_program: true) + @eagle = Shelter.create!(name: 'Eagle Pet Sanctuary', city: 'Eagle', rank: 3, foster_program: true) + visit 'admin/shelters' + end + + it 'lists all shelters in reverse alphabetical order' do + expect('Greely Dumb Friends League').to appear_before('Eagle Pet Sanctuary') + expect('Eagle Pet Sanctuary').to appear_before('Denver Pet Shelter') + end + + it 'lists shelters with pending applications' do + @pet_1 = @denver.pets.create(name: 'Mr. Pirate', breed: 'tuxedo shorthair', age: 5, adoptable: false) + @pet_2 = @eagle.pets.create(name: 'Clawdia', breed: 'shorthair', age: 3, adoptable: true) + petition = Petition.create!(name: 'Ted Leo', + street_address: '123 Pharmacist Ln', + city: 'Denver', + state: 'Co', + zipcode: 12_345, + goodhome: 'Lurv Fluffers', + status: 'Pending') + pet_petition = PetPetition.create!(petition: petition, pet: @pet_1) + pet_petition2 = PetPetition.create!(petition: petition, pet: @pet_2) + + expect(page).to have_content('Denver Pet Shelter') + expect(page).to have_content('Eagle Pet Sanctuary') + end + + it 'lists shelters with pending applications in alphabetical order' do + @pet_1 = @denver.pets.create(name: 'Mr. Pirate', breed: 'tuxedo shorthair', age: 5, adoptable: false) + @pet_2 = @eagle.pets.create(name: 'Clawdia', breed: 'shorthair', age: 3, adoptable: true) + petition = Petition.create!(name: 'Ted Leo', + street_address: '123 Pharmacist Ln', + city: 'Denver', + state: 'Co', + zipcode: 12_345, + goodhome: 'Lurv Fluffers', + status: 'Pending') + pet_petition = PetPetition.create!(petition: petition, pet: @pet_1) + pet_petition2 = PetPetition.create!(petition: petition, pet: @pet_2) + + within(".right_list", text: 'With Pending Applications') + expect('Eagle Pet Sanctuary').to appear_before('Denver Pet Shelter') + end + + it 'contains links to each shelter by name' do + expect(page).to have_link('Denver Pet Shelter', :href => "/admin/shelters/#{@denver.id}") + expect(page).to have_link('Eagle Pet Sanctuary', :href => "/admin/shelters/#{@eagle.id}") + end +end diff --git a/spec/features/admin/shelters/admin_shelters_show_spec.rb b/spec/features/admin/shelters/admin_shelters_show_spec.rb new file mode 100644 index 000000000..f10e1b71d --- /dev/null +++ b/spec/features/admin/shelters/admin_shelters_show_spec.rb @@ -0,0 +1,13 @@ +require 'rails_helper' + +describe 'admin shelters show' do + before :each do + @shelter = Shelter.create!(foster_program: true, name: "Aurora Pet Home", city: "Aurora, CO", rank:5) + visit "/admin/shelters/#{@shelter.id}" + end + + it 'displays the name and full address of the shelter' do + expect(page).to have_content('Shelter Name: Aurora Pet Home') + expect(page).to have_content('Shelter Location: Aurora, CO') + end +end \ No newline at end of file diff --git a/spec/features/application_spec.rb b/spec/features/application_spec.rb index 04aadcdee..9198f28b9 100644 --- a/spec/features/application_spec.rb +++ b/spec/features/application_spec.rb @@ -1,47 +1,49 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe 'application' do it 'displays a link to all pets' do visit '/' expect(page).to have_content("Adopt, don't shop!") - expect(page).to have_link("Pets") - click_link("Pets") + expect(page).to have_link('Pets') + click_link('Pets') expect(page).to have_current_path('/pets') end it 'displays a link to all shelters' do visit '/' - expect(page).to have_link("Shelters") - click_link("Shelters") + expect(page).to have_link('Shelters') + click_link('Shelters') expect(page).to have_current_path('/shelters') - expect(page).to have_link("Shelters") - expect(page).to have_link("Pets") - expect(page).to have_link("Veterinarians") - expect(page).to have_link("Veterinary Offices") + expect(page).to have_link('Shelters') + expect(page).to have_link('Pets') + expect(page).to have_link('Veterinarians') + expect(page).to have_link('Veterinary Offices') end it 'displays a link to all veterinary offices' do visit '/' - expect(page).to have_link("Veterinary Offices") - click_link("Veterinary Offices") + expect(page).to have_link('Veterinary Offices') + click_link('Veterinary Offices') expect(page).to have_current_path('/veterinary_offices') - expect(page).to have_link("Shelters") - expect(page).to have_link("Pets") - expect(page).to have_link("Veterinarians") - expect(page).to have_link("Veterinary Offices") + expect(page).to have_link('Shelters') + expect(page).to have_link('Pets') + expect(page).to have_link('Veterinarians') + expect(page).to have_link('Veterinary Offices') end it 'displays a link to all veterinarians' do visit '/' - expect(page).to have_link("Veterinarians") - click_link("Veterinarians") + expect(page).to have_link('Veterinarians') + click_link('Veterinarians') expect(page).to have_current_path('/veterinarians') - expect(page).to have_link("Shelters") - expect(page).to have_link("Pets") - expect(page).to have_link("Veterinarians") - expect(page).to have_link("Veterinary Offices") + expect(page).to have_link('Shelters') + expect(page).to have_link('Pets') + expect(page).to have_link('Veterinarians') + expect(page).to have_link('Veterinary Offices') end end diff --git a/spec/features/petitions/new_spec.rb b/spec/features/petitions/new_spec.rb new file mode 100644 index 000000000..51bdf2eb3 --- /dev/null +++ b/spec/features/petitions/new_spec.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe 'petitions creation' do + describe 'petitions new' do + it 'renders the form for new petitions' do + visit '/petitions/new' + + expect(page).to have_content('Apply to Adopt a Pet!') + expect(find('form')).to have_content('Name') + expect(find('form')).to have_content('Street Address') + expect(find('form')).to have_content('City') + expect(find('form')).to have_content('State') + expect(find('form')).to have_content('Zipcode') + expect(page).to have_button('Start Application') + end + + it 'creates a new application when button is clicked' do + visit '/petitions/new' + fill_in 'Name', with: 'Ted Leo' + fill_in 'Street Address', with: '123 Pharmacist Ln' + fill_in 'City', with: 'Denver' + fill_in 'State', with: 'CO' + fill_in 'Zipcode', with: '80210' + result = click_button 'Start Application' + id = Petition.last.id + + expect(current_path).to eq "/petitions/#{id}" + end + + it 'rejects the application if it is incomplete' do + visit '/petitions/new' + fill_in 'Name', with: 'Ted Leo' + fill_in 'Street Address', with: '123 Pharmacist Ln' + fill_in 'City', with: 'Denver' + fill_in 'State', with: 'CO' + click_button 'Start Application' + + expect(current_path).to eq '/petitions/new' + expect(page).to have_content('Must Fill In All Fields') + end + end +end diff --git a/spec/features/petitions/show_spec.rb b/spec/features/petitions/show_spec.rb new file mode 100644 index 000000000..61fb0d62a --- /dev/null +++ b/spec/features/petitions/show_spec.rb @@ -0,0 +1,72 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe 'petition show' 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: 'Fluffy', shelter_id: @shelter.id) + visit '/petitions/new' + fill_in 'Name', with: 'Ted Leo' + fill_in 'Street Address', with: '123 Pharmacist Ln' + fill_in 'City', with: 'Denver' + fill_in 'State', with: 'CO' + fill_in 'Zipcode', with: '80210' + click_button 'Start Application' + @id = Petition.last.id + end + it 'displays applicant name and address' do + expect(page).to have_content('Your name: Ted Leo') + expect(page).to have_content('Your address: 123 Pharmacist Ln Denver, CO 80210') + expect(page).to have_content('In Progress') + end + + it 'displays option to search for pets and add to petition' do + expect(page).to have_content('Add a Pet to this Application') + end + + it 'displays the default good home message by default' do + expect(page).to have_content("Why you'd make a great home for these pets: I love dogs") + end + + it 'starts off as status in progress' do + expect(page).to have_content('Your application status: In Progress') + end + + it 'shows all pets by default' do + expect(page).to have_content 'Lucille Bald' + expect(page).to have_content 'Fluffy' + end + + it 'searching returns a list of pets on existing show page' do + fill_in 'Add a Pet to this Application', with: 'Fluffy' + click_button 'Search' + + expect(current_path).to eq "/petitions/#{@id}" + expect(page).to have_content('Fluffy') + expect(page).not_to have_content('Lucille Bald') + end + + it 'has a link to adopt a pet' do + expect(page).to have_button('Adopt Fluffy') + expect(page).to have_button('Adopt Lucille Bald') + end + + it 'after clicking adopt button lists pets you want to adopt' do + click_button('Adopt Fluffy') + + expect(page).to have_content("Pets you'd like to adopt: Fluffy") + end + + it 'allows for submitting application' do + click_button('Adopt Fluffy') + fill_in 'Say a bit about why you would make a good owner for these pets:', with: 'I love fluffy' + click_button('Submit Your Application') + + expect(page).to have_content('Your application status: Pending') + expect(page).to have_content("Why you'd make a great home for these pets: I love fluffy") + expect(page).not_to have_content('Adopt Lucille Bald') + expect(page).not_to have_content('Submit Your Application') + end +end diff --git a/spec/features/pets/create_spec.rb b/spec/features/pets/create_spec.rb index e34e119f0..47ece6c93 100644 --- a/spec/features/pets/create_spec.rb +++ b/spec/features/pets/create_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe 'pet creation' do diff --git a/spec/features/pets/index_spec.rb b/spec/features/pets/index_spec.rb index b4000ddec..a73112422 100644 --- a/spec/features/pets/index_spec.rb +++ b/spec/features/pets/index_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe 'the pets index' do @@ -6,7 +8,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) - visit "/pets" + visit '/pets' expect(page).to have_content(pet_1.name) expect(page).to have_content(pet_1.breed) @@ -25,7 +27,7 @@ pet_2 = Pet.create(adoptable: true, age: 3, breed: 'doberman', name: 'Lobster', shelter_id: shelter.id) pet_3 = Pet.create(adoptable: false, age: 2, breed: 'saint bernard', name: 'Beethoven', shelter_id: shelter.id) - visit "/pets" + visit '/pets' expect(page).to_not have_content(pet_3.name) end @@ -57,13 +59,13 @@ click_link("Delete #{pet_1.name}") - expect(page).to have_current_path("/pets") + expect(page).to have_current_path('/pets') expect(page).to_not have_content(pet_1.name) end it 'has a text box to filter results by keyword' do - visit "/pets" - expect(page).to have_button("Search") + visit '/pets' + expect(page).to have_button('Search') end it 'lists partial matches as search results' do @@ -72,13 +74,36 @@ pet_2 = Pet.create(adoptable: true, age: 3, breed: 'domestic pig', name: 'Babe', shelter_id: shelter.id) pet_3 = Pet.create(adoptable: true, age: 4, breed: 'chihuahua', name: 'Elle', shelter_id: shelter.id) - visit "/pets" + visit '/pets' - fill_in 'Search', with: "Ba" - click_on("Search") + fill_in 'Search', with: 'Ba' + click_on('Search') expect(page).to have_content(pet_1.name) expect(page).to have_content(pet_2.name) expect(page).to_not have_content(pet_3.name) end + + it 'contains a link to start an application' do + shelter = Shelter.create(name: 'Aurora shelter', city: 'Aurora, CO', foster_program: false, rank: 9) + pet_1 = Pet.create(adoptable: true, age: 7, breed: 'sphynx', name: 'Bare-y Manilow', shelter_id: shelter.id) + pet_2 = Pet.create(adoptable: true, age: 3, breed: 'domestic pig', name: 'Babe', shelter_id: shelter.id) + pet_3 = Pet.create(adoptable: true, age: 4, breed: 'chihuahua', name: 'Elle', shelter_id: shelter.id) + + visit '/pets' + + expect(page).to have_button('Start an Application') + end + + it 'clicking application button navigates to new application page' do + shelter = Shelter.create(name: 'Aurora shelter', city: 'Aurora, CO', foster_program: false, rank: 9) + pet_1 = Pet.create(adoptable: true, age: 7, breed: 'sphynx', name: 'Bare-y Manilow', shelter_id: shelter.id) + pet_2 = Pet.create(adoptable: true, age: 3, breed: 'domestic pig', name: 'Babe', shelter_id: shelter.id) + pet_3 = Pet.create(adoptable: true, age: 4, breed: 'chihuahua', name: 'Elle', shelter_id: shelter.id) + + visit '/pets' + click_button 'Start an Application' + + expect(current_path).to eq('/petitions/new') + end end diff --git a/spec/features/pets/show_spec.rb b/spec/features/pets/show_spec.rb index d84593014..29bd7fe61 100644 --- a/spec/features/pets/show_spec.rb +++ b/spec/features/pets/show_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe 'the shelter show' do @@ -14,7 +16,7 @@ expect(page).to have_content(pet.shelter_name) end - it "allows the user to delete a pet" do + it 'allows the user to delete a pet' do shelter = Shelter.create(name: 'Mystery Building', city: 'Irvine CA', foster_program: false, rank: 9) pet = Pet.create(name: 'Scrappy', age: 1, breed: 'Great Dane', adoptable: true, shelter_id: shelter.id) diff --git a/spec/features/pets/update_spec.rb b/spec/features/pets/update_spec.rb index c79f1f84a..4e16cd196 100644 --- a/spec/features/pets/update_spec.rb +++ b/spec/features/pets/update_spec.rb @@ -1,7 +1,9 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe 'the veterinarian update' do - it "shows the veterinarian edit form" do + it 'shows the veterinarian edit form' do shelter = Shelter.create(name: 'Hollywood shelter', city: 'Irvine, CA', foster_program: false, rank: 7) pet = Pet.create(adoptable: true, age: 1, breed: 'sphynx', name: 'George Hairlesson', shelter_id: shelter.id) @@ -13,8 +15,8 @@ expect(find('form')).to have_content('Age') end - context "given valid data" do - it "submits the edit form and updates the veterinarian" do + context 'given valid data' do + it 'submits the edit form and updates the veterinarian' do shelter = Shelter.create(name: 'Heavenly pets', city: 'Aurora, CO', foster_program: true, rank: 7) pet = Pet.create(adoptable: true, age: 3, breed: 'GSD', name: 'Charlie', shelter_id: shelter.id) @@ -31,7 +33,7 @@ end end - context "given invalid data" do + context 'given invalid data' do it 're-renders the edit form' do shelter = Shelter.create(name: 'Heavenly pets', city: 'Aurora, CO', foster_program: false, rank: 7) pet = Pet.create(adoptable: false, age: 3, breed: 'Whippet', name: 'Annabelle', shelter_id: shelter.id) diff --git a/spec/features/shelters/create_spec.rb b/spec/features/shelters/create_spec.rb index 60565172f..848e4c3df 100644 --- a/spec/features/shelters/create_spec.rb +++ b/spec/features/shelters/create_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe 'shelter creation' do diff --git a/spec/features/shelters/index_spec.rb b/spec/features/shelters/index_spec.rb index 8068ff2d9..1637c2ee3 100644 --- a/spec/features/shelters/index_spec.rb +++ b/spec/features/shelters/index_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe 'the shelters index' do @@ -11,7 +13,7 @@ end it 'lists all the shelter names' do - visit "/shelters" + visit '/shelters' expect(page).to have_content(@shelter_1.name) expect(page).to have_content(@shelter_2.name) @@ -19,7 +21,7 @@ end it 'lists the shelters by most recently created first' do - visit "/shelters" + visit '/shelters' oldest = find("#shelter-#{@shelter_1.id}") mid = find("#shelter-#{@shelter_2.id}") @@ -44,8 +46,8 @@ it 'has a link to sort shelters by the number of pets they have' do visit '/shelters' - expect(page).to have_link("Sort by number of pets") - click_link("Sort by number of pets") + expect(page).to have_link('Sort by number of pets') + click_link('Sort by number of pets') expect(page).to have_current_path('/shelters?sort=pet_count') expect(@shelter_1.name).to appear_before(@shelter_3.name) @@ -53,7 +55,7 @@ end it 'has a link to update each shelter' do - visit "/shelters" + visit '/shelters' within "#shelter-#{@shelter_1.id}" do expect(page).to have_link("Update #{@shelter_1.name}") @@ -72,7 +74,7 @@ end it 'has a link to delete each shelter' do - visit "/shelters" + visit '/shelters' within "#shelter-#{@shelter_1.id}" do expect(page).to have_link("Delete #{@shelter_1.name}") @@ -87,20 +89,20 @@ end click_on("Delete #{@shelter_1.name}") - expect(page).to have_current_path("/shelters") + expect(page).to have_current_path('/shelters') expect(page).to_not have_content(@shelter_1.name) end it 'has a text box to filter results by keyword' do - visit "/shelters" - expect(page).to have_button("Search") + visit '/shelters' + expect(page).to have_button('Search') end it 'lists partial matches as search results' do - visit "/shelters" + visit '/shelters' - fill_in 'Search', with: "RGV" - click_on("Search") + fill_in 'Search', with: 'RGV' + click_on('Search') expect(page).to have_content(@shelter_2.name) expect(page).to_not have_content(@shelter_1.name) diff --git a/spec/features/shelters/pets_index_spec.rb b/spec/features/shelters/pets_index_spec.rb index 00e523279..2737012ec 100644 --- a/spec/features/shelters/pets_index_spec.rb +++ b/spec/features/shelters/pets_index_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe 'the shelters pets index' do @@ -6,8 +8,10 @@ @shelter_2 = Shelter.create(name: 'Boulder shelter', city: 'Boulder, CO', foster_program: false, rank: 9) @pet_1 = Pet.create(adoptable: true, age: 1, breed: 'sphynx', name: 'Bare-y Manilow', 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: 1, breed: 'domestic shorthair', name: 'Sylvester', shelter_id: @shelter_2.id) - @pet_4 = Pet.create(adoptable: true, age: 1, breed: 'orange tabby shorthair', name: 'Lasagna', shelter_id: @shelter.id) + @pet_3 = Pet.create(adoptable: true, age: 1, breed: 'domestic shorthair', name: 'Sylvester', + shelter_id: @shelter_2.id) + @pet_4 = Pet.create(adoptable: true, age: 1, breed: 'orange tabby shorthair', name: 'Lasagna', + shelter_id: @shelter.id) end it 'lists all the pets associated with the shelter, with their attributes' do @@ -30,8 +34,8 @@ it 'displays a link to create a new pet' do visit "/shelters/#{@shelter.id}/pets" - expect(page).to have_link("Create a Pet") - click_on("Create a Pet") + expect(page).to have_link('Create a Pet') + click_on('Create a Pet') expect(page).to have_current_path("/shelters/#{@shelter.id}/pets/new") end @@ -54,22 +58,22 @@ click_link("Delete #{@pet_1.name}") - expect(page).to have_current_path("/pets") + expect(page).to have_current_path('/pets') expect(page).to_not have_content(@pet_1.name) end it 'displays a form for a number value' do visit "/shelters/#{@shelter.id}/pets" - expect(page).to have_content("Only display pets with an age of at least...") - expect(page).to have_select("age") + expect(page).to have_content('Only display pets with an age of at least...') + expect(page).to have_select('age') end it 'only displays records above the given return value' do visit "/shelters/#{@shelter.id}/pets" find("#age option[value='3']").select_option - click_button("Filter") + click_button('Filter') expect(page).to have_content(@pet_2.name) expect(page).to_not have_content(@pet_1.name) expect(page).to_not have_content(@pet_3.name) @@ -81,8 +85,8 @@ expect(@pet_1.name).to appear_before(@pet_2.name) expect(@pet_2.name).to appear_before(@pet_4.name) - expect(page).to have_link("Sort alphabetically") - click_on("Sort alphabetically") + expect(page).to have_link('Sort alphabetically') + click_on('Sort alphabetically') expect(@pet_1.name).to appear_before(@pet_4.name) expect(@pet_4.name).to appear_before(@pet_2.name) diff --git a/spec/features/shelters/show_spec.rb b/spec/features/shelters/show_spec.rb index 60a901856..237930f5f 100644 --- a/spec/features/shelters/show_spec.rb +++ b/spec/features/shelters/show_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe 'the shelter show' do @@ -11,18 +13,18 @@ expect(page).to have_content(shelter.city) end - it "shows the number of pets associated with the shelter" do + it 'shows the number of pets associated with the shelter' do shelter = Shelter.create(name: 'Aurora shelter', city: 'Aurora, CO', foster_program: false, rank: 9) shelter.pets.create(name: 'garfield', breed: 'shorthair', adoptable: true, age: 1) visit "/shelters/#{shelter.id}" - within ".pet-count" do + within '.pet-count' do expect(page).to have_content(shelter.pets.count) end end - it "allows the user to delete a shelter" do + it 'allows the user to delete a shelter' do shelter = Shelter.create(name: 'Aurora shelter', city: 'Aurora, CO', foster_program: false, rank: 9) visit "/shelters/#{shelter.id}" diff --git a/spec/features/shelters/update_spec.rb b/spec/features/shelters/update_spec.rb index b74294964..0a4d21b87 100644 --- a/spec/features/shelters/update_spec.rb +++ b/spec/features/shelters/update_spec.rb @@ -1,7 +1,9 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe 'the shelter update' do - it "shows the shelter edit form" do + it 'shows the shelter edit form' do shelter = Shelter.create(name: 'Aurora shelter', city: 'Aurora, CO', foster_program: false, rank: 9) visit "/shelters/#{shelter.id}/edit" @@ -12,8 +14,8 @@ expect(find('form')).to have_content('Foster program') end - context "given valid data" do - it "submits the edit form and updates the shelter" do + context 'given valid data' do + it 'submits the edit form and updates the shelter' do shelter = Shelter.create(name: 'Aurora shelter', city: 'Aurora, CO', foster_program: false, rank: 9) visit "/shelters/#{shelter.id}/edit" @@ -30,7 +32,7 @@ end end - context "given invalid data" do + context 'given invalid data' do it 're-renders the edit form' do shelter = Shelter.create(name: 'Aurora shelter', city: 'Aurora, CO', foster_program: false, rank: 9) diff --git a/spec/features/veterinarians/create_spec.rb b/spec/features/veterinarians/create_spec.rb index 577e8a68d..40201936e 100644 --- a/spec/features/veterinarians/create_spec.rb +++ b/spec/features/veterinarians/create_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe 'veterinarian creation' do diff --git a/spec/features/veterinarians/index_spec.rb b/spec/features/veterinarians/index_spec.rb index 457ff110a..d95529fcb 100644 --- a/spec/features/veterinarians/index_spec.rb +++ b/spec/features/veterinarians/index_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe 'the veterinarians index' do @@ -54,7 +56,7 @@ click_link("Delete #{vet_1.name}") - expect(page).to have_current_path("/veterinarians") + expect(page).to have_current_path('/veterinarians') expect(page).to_not have_content(vet_1.name) end end diff --git a/spec/features/veterinarians/show_spec.rb b/spec/features/veterinarians/show_spec.rb index c3404ad43..a15181c74 100644 --- a/spec/features/veterinarians/show_spec.rb +++ b/spec/features/veterinarians/show_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe 'the veterinarian show' do @@ -9,11 +11,11 @@ expect(page).to have_content(vet.name) expect(page).to have_content(vet.review_rating) - expect(page).to have_content("Not on call") + expect(page).to have_content('Not on call') expect(page).to have_content(vet_office.name) end - it "allows the user to delete a veterinarian" do + it 'allows the user to delete a veterinarian' do vet_office = VeterinaryOffice.create(name: 'Best Vets', boarding_services: true, max_patient_capacity: 20) vet = Veterinarian.create(name: 'Taylor', review_rating: 10, on_call: false, veterinary_office_id: vet_office.id) diff --git a/spec/features/veterinarians/update_spec.rb b/spec/features/veterinarians/update_spec.rb index 8018b56da..cb03b10c3 100644 --- a/spec/features/veterinarians/update_spec.rb +++ b/spec/features/veterinarians/update_spec.rb @@ -1,7 +1,9 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe 'the veterinarian update' do - it "shows the veterinarian edit form" do + it 'shows the veterinarian edit form' do vet_office = VeterinaryOffice.create(name: 'Put a bird on it', boarding_services: true, max_patient_capacity: 5) vet = vet_office.veterinarians.create(name: 'Kelsey', on_call: true, review_rating: 9) @@ -12,8 +14,8 @@ expect(find('form')).to have_content('On call') end - context "given valid data" do - it "submits the edit form and updates the veterinarian" do + context 'given valid data' do + it 'submits the edit form and updates the veterinarian' do vet_office = VeterinaryOffice.create(name: 'Put a bird on it', boarding_services: true, max_patient_capacity: 5) vet = Veterinarian.create(name: 'Kelsey', on_call: true, review_rating: 9, veterinary_office_id: vet_office.id) @@ -30,7 +32,7 @@ end end - context "given invalid data" do + context 'given invalid data' do it 're-renders the edit form' do vet_office = VeterinaryOffice.create(name: 'Put a bird on it', boarding_services: true, max_patient_capacity: 5) vet = Veterinarian.create(name: 'Kelsey', on_call: true, review_rating: 9, veterinary_office_id: vet_office.id) diff --git a/spec/features/veterinary_offices/create_spec.rb b/spec/features/veterinary_offices/create_spec.rb index 662f07f6d..2e4838a74 100644 --- a/spec/features/veterinary_offices/create_spec.rb +++ b/spec/features/veterinary_offices/create_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe 'vet office creation' do diff --git a/spec/features/veterinary_offices/index_spec.rb b/spec/features/veterinary_offices/index_spec.rb index d80422248..edcc9f441 100644 --- a/spec/features/veterinary_offices/index_spec.rb +++ b/spec/features/veterinary_offices/index_spec.rb @@ -1,9 +1,12 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe 'the veterinary offices index' do before(:each) do @vet_office_1 = VeterinaryOffice.create(name: 'Special Friends', boarding_services: true, max_patient_capacity: 100) - @vet_office_2 = VeterinaryOffice.create(name: 'Pet Emergency Room', boarding_services: true, max_patient_capacity: 50) + @vet_office_2 = VeterinaryOffice.create(name: 'Pet Emergency Room', boarding_services: true, + max_patient_capacity: 50) @vet_office_3 = VeterinaryOffice.create(name: 'The Country Vet', boarding_services: true, max_patient_capacity: 200) @vet_office_1.veterinarians.create(name: 'Morgan', on_call: true, review_rating: 10) @vet_office_1.veterinarians.create(name: 'Heather', on_call: true, review_rating: 9) @@ -11,7 +14,7 @@ end it 'lists all the vet office names' do - visit "/veterinary_offices" + visit '/veterinary_offices' expect(page).to have_content(@vet_office_1.name) expect(page).to have_content(@vet_office_2.name) @@ -19,7 +22,7 @@ end it 'lists the veterinary offices by most recently created first' do - visit "/veterinary_offices" + visit '/veterinary_offices' oldest = find("#veterinary-office-#{@vet_office_1.id}") mid = find("#veterinary-office-#{@vet_office_2.id}") @@ -44,8 +47,8 @@ it 'has a link to sort offices by the number of vets they have' do visit '/veterinary_offices' - expect(page).to have_link("Sort by number of veterinarians") - click_link("Sort by number of veterinarians") + expect(page).to have_link('Sort by number of veterinarians') + click_link('Sort by number of veterinarians') expect(page).to have_current_path('/veterinary_offices?sort=veterinarian_count') expect(@vet_office_1.name).to appear_before(@vet_office_3.name) @@ -53,7 +56,7 @@ end it 'has a link to update each veterinary office' do - visit "/veterinary_offices" + visit '/veterinary_offices' within "#veterinary-office-#{@vet_office_1.id}" do expect(page).to have_link("Update #{@vet_office_1.name}") @@ -72,7 +75,7 @@ end it 'has a link to delete each veterinary office' do - visit "/veterinary_offices" + visit '/veterinary_offices' within "#veterinary-office-#{@vet_office_1.id}" do expect(page).to have_link("Delete #{@vet_office_1.name}") @@ -87,7 +90,7 @@ end click_on("Delete #{@vet_office_1.name}") - expect(page).to have_current_path("/veterinary_offices") + expect(page).to have_current_path('/veterinary_offices') expect(page).to_not have_content(@vet_office_1.name) end end diff --git a/spec/features/veterinary_offices/show_spec.rb b/spec/features/veterinary_offices/show_spec.rb index 1bcb77a38..821c718b4 100644 --- a/spec/features/veterinary_offices/show_spec.rb +++ b/spec/features/veterinary_offices/show_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe 'the vet office show' do @@ -10,17 +12,17 @@ expect(page).to have_content(vet_office.max_patient_capacity) end - it "shows the number of veterinarians associated with the vet office" do + it 'shows the number of veterinarians associated with the vet office' do vet_office = VeterinaryOffice.create(name: 'The Country Vet', boarding_services: true, max_patient_capacity: 200) visit "/veterinary_offices/#{vet_office.id}" - within ".veterinarian-count" do + within '.veterinarian-count' do expect(page).to have_content(vet_office.veterinarians.count) end end - it "allows the user to delete a vet office" do + it 'allows the user to delete a vet office' do vet_office = VeterinaryOffice.create(name: 'Aurora vet', boarding_services: true, max_patient_capacity: 90) visit "/veterinary_offices/#{vet_office.id}" diff --git a/spec/features/veterinary_offices/update_spec.rb b/spec/features/veterinary_offices/update_spec.rb index f525fa7ff..b7718d4a1 100644 --- a/spec/features/veterinary_offices/update_spec.rb +++ b/spec/features/veterinary_offices/update_spec.rb @@ -1,7 +1,9 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe 'the vet office update' do - it "shows the vet office edit form" do + it 'shows the vet office edit form' do vet_office = VeterinaryOffice.create(name: 'Aurora vet office', boarding_services: false, max_patient_capacity: 9) visit "/veterinary_offices/#{vet_office.id}/edit" @@ -11,8 +13,8 @@ expect(find('form')).to have_content('Boarding services') end - context "given valid data" do - it "submits the edit form and updates the vet office" do + context 'given valid data' do + it 'submits the edit form and updates the vet office' do vet_office = VeterinaryOffice.create(name: 'Aurora vet office', boarding_services: false, max_patient_capacity: 9) visit "/veterinary_offices/#{vet_office.id}/edit" @@ -28,7 +30,7 @@ end end - context "given invalid data" do + context 'given invalid data' do it 're-renders the edit form' do vet_office = VeterinaryOffice.create(name: 'Aurora vet office', boarding_services: false, max_patient_capacity: 9) diff --git a/spec/features/veterinary_offices/veterinarians_index_spec.rb b/spec/features/veterinary_offices/veterinarians_index_spec.rb index 001cabd41..a147b9851 100644 --- a/spec/features/veterinary_offices/veterinarians_index_spec.rb +++ b/spec/features/veterinary_offices/veterinarians_index_spec.rb @@ -1,11 +1,15 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe 'the veterinary offices veterinarians index' do before(:each) do @vet_office_1 = VeterinaryOffice.create(name: 'Best Vets', boarding_services: true, max_patient_capacity: 20) @vet_office_2 = VeterinaryOffice.create(name: 'Vets R Us', boarding_services: true, max_patient_capacity: 20) - @not_on_call_vet = Veterinarian.create(name: 'Taylor', review_rating: 10, on_call: false, veterinary_office_id: @vet_office_1.id) - @vet_1 = Veterinarian.create(name: 'Taylor', review_rating: 10, on_call: true, veterinary_office_id: @vet_office_1.id) + @not_on_call_vet = Veterinarian.create(name: 'Taylor', review_rating: 10, on_call: false, + veterinary_office_id: @vet_office_1.id) + @vet_1 = Veterinarian.create(name: 'Taylor', review_rating: 10, on_call: true, + veterinary_office_id: @vet_office_1.id) @vet_2 = Veterinarian.create(name: 'Jim', review_rating: 8, on_call: true, veterinary_office_id: @vet_office_1.id) @vet_3 = Veterinarian.create(name: 'Sarah', review_rating: 9, on_call: true, veterinary_office_id: @vet_office_2.id) @vet_4 = Veterinarian.create(name: 'John', review_rating: 2, on_call: true, veterinary_office_id: @vet_office_2.id) @@ -46,30 +50,30 @@ click_link("Delete #{@vet_1.name}") - expect(page).to have_current_path("/veterinarians") + expect(page).to have_current_path('/veterinarians') expect(page).to_not have_content(@vet_1.name) end it 'displays a link to create a new veterinarian' do visit "/veterinary_offices/#{@vet_office_1.id}/veterinarians" - expect(page).to have_link("Create a Veterinarian") - click_on("Create a Veterinarian") + expect(page).to have_link('Create a Veterinarian') + click_on('Create a Veterinarian') expect(page).to have_current_path("/veterinary_offices/#{@vet_office_1.id}/veterinarians/new") end it 'displays a form for a number value' do visit "/veterinary_offices/#{@vet_office_1.id}/veterinarians" - expect(page).to have_content("Only display veterinarians with a review rating of at least...") - expect(page).to have_select("review_rating") + expect(page).to have_content('Only display veterinarians with a review rating of at least...') + expect(page).to have_select('review_rating') end it 'only displays records above the given return value' do visit "/veterinary_offices/#{@vet_office_1.id}/veterinarians" find("#review_rating option[value='5']").select_option - click_button("Filter") + click_button('Filter') expect(page).to have_content(@vet_1.name) expect(page).to have_content(@vet_2.name) @@ -81,8 +85,8 @@ expect(@vet_3.name).to appear_before(@vet_4.name) - expect(page).to have_link("Sort alphabetically") - click_on("Sort alphabetically") + expect(page).to have_link('Sort alphabetically') + click_on('Sort alphabetically') expect(@vet_4.name).to appear_before(@vet_3.name) end diff --git a/spec/models/pet_petition_spec.rb b/spec/models/pet_petition_spec.rb new file mode 100644 index 000000000..8bf907b63 --- /dev/null +++ b/spec/models/pet_petition_spec.rb @@ -0,0 +1,35 @@ +require 'rails_helper' + +RSpec.describe PetPetition do + describe 'relationships' do + it { should belong_to(:pet) } + it { should belong_to(:petition) } + end + + describe 'class methods' do + before :each do + @ted = Petition.create!(name: 'Ted Leo', + street_address: '123 Pharmacist Ln', + city: 'Phoenix City', + state: 'Alabama', + zipcode: '12345') + @shelter_1 = Shelter.create!(name: 'Aurora shelter', city: 'Aurora, CO', foster_program: false, rank: 9) + @pet_1 = @shelter_1.pets.create!(name: 'Mr. Pirate', breed: 'tuxedo shorthair', age: 5, adoptable: true) + @pet_2 = @shelter_1.pets.create!(name: 'Clawdia', breed: 'shorthair', age: 3, adoptable: true) + @pet_3 = @shelter_1.pets.create!(name: 'Ann', breed: 'ragdoll', age: 3, adoptable: false) + @pet_petition_1 = PetPetition.create!(petition: @ted, pet: @pet_1) + @pet_petition_2 = PetPetition.create!(petition: @ted, pet: @pet_2) + end + describe '.associated_pets' do + it 'collects all pets associated with a petition' do + expect(PetPetition.associated_pets(@ted.id)).to eq([@pet_1, @pet_2]) + end + end + + describe '.select' do + it 'returns a specific pet_petition based on inputs' do + expect(PetPetition.select(@pet_1.id, @ted.id)).to eq @pet_petition_1 + end + end + end +end diff --git a/spec/models/pet_spec.rb b/spec/models/pet_spec.rb index 9bb3fafb2..1fa6a7d1e 100644 --- a/spec/models/pet_spec.rb +++ b/spec/models/pet_spec.rb @@ -1,8 +1,12 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe Pet, type: :model do describe 'relationships' do it { should belong_to(:shelter) } + it { should have_many(:pet_petitions) } + it { should have_many(:petitions).through(:pet_petitions) } end describe 'validations' do @@ -21,7 +25,7 @@ describe 'class methods' do describe '#search' do it 'returns partial matches' do - expect(Pet.search("Claw")).to eq([@pet_2]) + expect(Pet.search('Claw')).to eq([@pet_2]) end end diff --git a/spec/models/petition_spec.rb b/spec/models/petition_spec.rb new file mode 100644 index 000000000..c956212b0 --- /dev/null +++ b/spec/models/petition_spec.rb @@ -0,0 +1,37 @@ +require 'rails_helper' + +RSpec.describe Petition do + describe 'relationships' do + it { should have_many(:pet_petitions) } + it { should have_many(:pets).through(:pet_petitions) } + end + + describe 'validations' do + it { should validate_presence_of(:name) } + it { should validate_presence_of(:street_address) } + it { should validate_presence_of(:city) } + it { should validate_presence_of(:state) } + it { should validate_presence_of(:zipcode) } + end + + describe 'instance methods' do + before :each do + @ted = Petition.create!(name: 'Ted Leo', + street_address: '123 Pharmacist Ln', + city: 'Phoenix City', + state: 'Alabama', + zipcode: '12345') + @shelter_1 = Shelter.create!(name: 'Aurora shelter', city: 'Aurora, CO', foster_program: false, rank: 9) + @pet_1 = @shelter_1.pets.create!(name: 'Mr. Pirate', breed: 'tuxedo shorthair', age: 5, adoptable: true) + @pet_2 = @shelter_1.pets.create!(name: 'Clawdia', breed: 'shorthair', age: 3, adoptable: true) + @pet_3 = @shelter_1.pets.create!(name: 'Ann', breed: 'ragdoll', age: 3, adoptable: false) + @pet_petition_1 = PetPetition.create!(petition: @ted, pet: @pet_1) + @pet_petition_2 = PetPetition.create!(petition: @ted, pet: @pet_2) + end + describe '#associated_pet_petitions' do + it 'returns all associated pet petitions' do + expect(@ted.associated_pet_petitions).to eq([@pet_petition_1, @pet_petition_2]) + end + end + end +end diff --git a/spec/models/shelter_spec.rb b/spec/models/shelter_spec.rb index 79d97af79..ff4708001 100644 --- a/spec/models/shelter_spec.rb +++ b/spec/models/shelter_spec.rb @@ -1,8 +1,12 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe Shelter, type: :model do describe 'relationships' do it { should have_many(:pets) } + it { should have_many(:pet_petitions).through(:pets) } + it { should have_many(:petitions).through(:pet_petitions) } end describe 'validations' do @@ -21,12 +25,13 @@ @pet_2 = @shelter_1.pets.create(name: 'Clawdia', breed: 'shorthair', age: 3, adoptable: true) @pet_3 = @shelter_3.pets.create(name: 'Lucille Bald', breed: 'sphynx', age: 8, adoptable: true) @pet_4 = @shelter_1.pets.create(name: 'Ann', breed: 'ragdoll', age: 5, adoptable: true) + @pet_5 = @shelter_2.pets.create(name: 'Tann', breed: 'doll', age: 6, adoptable: true) end describe 'class methods' do describe '#search' do it 'returns partial matches' do - expect(Shelter.search("Fancy")).to eq([@shelter_3]) + expect(Shelter.search('Fancy')).to eq([@shelter_3]) end end @@ -38,7 +43,44 @@ describe '#order_by_number_of_pets' do it 'orders the shelters by number of pets they have, descending' do - expect(Shelter.order_by_number_of_pets).to eq([@shelter_1, @shelter_3, @shelter_2]) + expect(Shelter.order_by_number_of_pets).to eq([@shelter_1, @shelter_2, @shelter_3]) + end + end + + describe 'reverse_alphabet' do + it 'orders shelters by descending alphabetical order by name' do + expect(Shelter.reverse_alphabet).to eq([@shelter_2, @shelter_3, @shelter_1]) + end + end + + describe '.with_pending' do + it 'returns names of shelters with pending applications' do + petition = Petition.create!(name: 'Ted Leo', + street_address: '123 Pharmacist Ln', + city: 'Denver', + state: 'Co', + zipcode: 12_345, + goodhome: 'Lurv Fluffers', + status: 'Pending') + pet_petition = PetPetition.create!(petition: petition, pet: @pet_1) + pet_petition_2 = PetPetition.create!(petition: petition, pet: @pet_3) + + expect(Shelter.with_pending).to eq([@shelter_1, @shelter_3]) + end + + it 'returns shelters with pending in alphabetical order' do + petition = Petition.create!(name: 'Ted Leo', + street_address: '123 Pharmacist Ln', + city: 'Denver', + state: 'Co', + zipcode: 12_345, + goodhome: 'Lurv Fluffers', + status: 'Pending') + pet_petition = PetPetition.create!(petition: petition, pet: @pet_1) + pet_petition_2 = PetPetition.create!(petition: petition, pet: @pet_3) + pet_petition_3 = PetPetition.create!(petition: petition, pet: @pet_5) + + expect(Shelter.with_pending).to eq([@shelter_1, @shelter_3, @shelter_2]) end end end diff --git a/spec/models/veterinarian_spec.rb b/spec/models/veterinarian_spec.rb index 43ddab237..d84b632f1 100644 --- a/spec/models/veterinarian_spec.rb +++ b/spec/models/veterinarian_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe Veterinarian, type: :model do @@ -22,10 +24,10 @@ describe 'class methods' do describe '#search' do it 'returns partial matches' do - expect(Veterinarian.search("Ta")).to eq([@vet_1, @vet_2]) + expect(Veterinarian.search('Ta')).to eq([@vet_1, @vet_2]) end end - + describe '#on_call' do it 'returns on call veterinarians' do expect(Veterinarian.on_call).to eq([@vet_1, @vet_2, @vet_3]) diff --git a/spec/models/veterinary_office_spec.rb b/spec/models/veterinary_office_spec.rb index 3c7969f1e..8b7cca271 100644 --- a/spec/models/veterinary_office_spec.rb +++ b/spec/models/veterinary_office_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe VeterinaryOffice, type: :model do @@ -14,8 +16,10 @@ before(:each) do @vet_office_1 = VeterinaryOffice.create(name: 'Best Vets', boarding_services: true, max_patient_capacity: 20) @vet_office_2 = VeterinaryOffice.create(name: 'Vets R Us', boarding_services: true, max_patient_capacity: 20) - @not_on_call_vet = Veterinarian.create(name: 'Sam', review_rating: 10, on_call: false, veterinary_office_id: @vet_office_1.id) - @vet_1 = Veterinarian.create(name: 'Taylor', review_rating: 10, on_call: true, veterinary_office_id: @vet_office_1.id) + @not_on_call_vet = Veterinarian.create(name: 'Sam', review_rating: 10, on_call: false, + veterinary_office_id: @vet_office_1.id) + @vet_1 = Veterinarian.create(name: 'Taylor', review_rating: 10, on_call: true, + veterinary_office_id: @vet_office_1.id) @vet_2 = Veterinarian.create(name: 'Jim', review_rating: 8, on_call: true, veterinary_office_id: @vet_office_1.id) @vet_3 = Veterinarian.create(name: 'Sarah', review_rating: 9, on_call: true, veterinary_office_id: @vet_office_2.id) end @@ -24,24 +28,24 @@ describe '#search' do it 'returns partial matches' do expect(VeterinaryOffice.search('Vets')).to eq([ - @vet_office_1, @vet_office_2 - ]) + @vet_office_1, @vet_office_2 + ]) end end describe '#order_by_recently_created' do it 'orders the offices by those most recently created first' do expect(VeterinaryOffice.order_by_recently_created).to eq([ - @vet_office_2, @vet_office_1 - ]) + @vet_office_2, @vet_office_1 + ]) end end describe '#order_by_number_of_vets' do it 'orders the offices by those with most veterinarians to least' do expect(VeterinaryOffice.order_by_number_of_vets).to eq([ - @vet_office_1, @vet_office_2 - ]) + @vet_office_1, @vet_office_2 + ]) end end end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 6f3631f05..aac3ac2f1 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + # This file is copied to spec/ when you run 'rails generate rspec:install' require 'spec_helper' ENV['RAILS_ENV'] ||= 'test' require File.expand_path('../config/environment', __dir__) # Prevent database truncation if the environment is production -abort("The Rails environment is running in production mode!") if Rails.env.production? +abort('The Rails environment is running in production mode!') if Rails.env.production? require 'rspec/rails' # Add additional requires below this line. Rails is not loaded until this point! diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a05917890..8648eaca0 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This file was generated by the `rails generate rspec:install` command. Conventionally, all # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. # The generated `.rspec` file contains `--require spec_helper` which will cause @@ -13,7 +15,7 @@ # it. require 'simplecov' SimpleCov.start do - add_filter "spec/rails_helper.rb" + add_filter 'spec/rails_helper.rb' end # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration RSpec.configure do |config| @@ -47,53 +49,51 @@ # triggering implicit auto-inclusion in groups with matching metadata. config.shared_context_metadata_behavior = :apply_to_host_groups -# The settings below are suggested to provide a good initial experience -# with RSpec, but feel free to customize to your heart's content. -=begin - # This allows you to limit a spec run to individual examples or groups - # you care about by tagging them with `:focus` metadata. When nothing - # is tagged with `:focus`, all examples get run. RSpec also provides - # aliases for `it`, `describe`, and `context` that include `:focus` - # metadata: `fit`, `fdescribe` and `fcontext`, respectively. - config.filter_run_when_matching :focus - - # Allows RSpec to persist some state between runs in order to support - # the `--only-failures` and `--next-failure` CLI options. We recommend - # you configure your source control system to ignore this file. - config.example_status_persistence_file_path = "spec/examples.txt" - - # Limits the available syntax to the non-monkey patched syntax that is - # recommended. For more details, see: - # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ - # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ - # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode - config.disable_monkey_patching! - - # Many RSpec users commonly either run the entire suite or an individual - # file, and it's useful to allow more verbose output when running an - # individual spec file. - if config.files_to_run.one? - # Use the documentation formatter for detailed output, - # unless a formatter has already been configured - # (e.g. via a command-line flag). - config.default_formatter = "doc" - end - - # Print the 10 slowest examples and example groups at the - # end of the spec run, to help surface which specs are running - # particularly slow. - config.profile_examples = 10 - - # Run specs in random order to surface order dependencies. If you find an - # order dependency and want to debug it, you can fix the order by providing - # the seed, which is printed after each run. - # --seed 1234 - config.order = :random - - # Seed global randomization in this process using the `--seed` CLI option. - # Setting this allows you to use `--seed` to deterministically reproduce - # test failures related to randomization by passing the same `--seed` value - # as the one that triggered the failure. - Kernel.srand config.seed -=end + # The settings below are suggested to provide a good initial experience + # with RSpec, but feel free to customize to your heart's content. + # # This allows you to limit a spec run to individual examples or groups + # # you care about by tagging them with `:focus` metadata. When nothing + # # is tagged with `:focus`, all examples get run. RSpec also provides + # # aliases for `it`, `describe`, and `context` that include `:focus` + # # metadata: `fit`, `fdescribe` and `fcontext`, respectively. + # config.filter_run_when_matching :focus + # + # # Allows RSpec to persist some state between runs in order to support + # # the `--only-failures` and `--next-failure` CLI options. We recommend + # # you configure your source control system to ignore this file. + # config.example_status_persistence_file_path = "spec/examples.txt" + # + # # Limits the available syntax to the non-monkey patched syntax that is + # # recommended. For more details, see: + # # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ + # # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ + # # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode + # config.disable_monkey_patching! + # + # # Many RSpec users commonly either run the entire suite or an individual + # # file, and it's useful to allow more verbose output when running an + # # individual spec file. + # if config.files_to_run.one? + # # Use the documentation formatter for detailed output, + # # unless a formatter has already been configured + # # (e.g. via a command-line flag). + # config.default_formatter = "doc" + # end + # + # # Print the 10 slowest examples and example groups at the + # # end of the spec run, to help surface which specs are running + # # particularly slow. + # config.profile_examples = 10 + # + # # Run specs in random order to surface order dependencies. If you find an + # # order dependency and want to debug it, you can fix the order by providing + # # the seed, which is printed after each run. + # # --seed 1234 + # config.order = :random + # + # # Seed global randomization in this process using the `--seed` CLI option. + # # Setting this allows you to use `--seed` to deterministically reproduce + # # test failures related to randomization by passing the same `--seed` value + # # as the one that triggered the failure. + # Kernel.srand config.seed end