diff --git a/.github/workflows/ruby-ci.yml b/.github/workflows/ruby-ci.yml index f4ee462..883480d 100644 --- a/.github/workflows/ruby-ci.yml +++ b/.github/workflows/ruby-ci.yml @@ -57,6 +57,10 @@ jobs: run: | gem install selenium-webdriver + - name: Run rubocop + run: | + bundle exec rubocop + - name: Run Tests env: PGHOST: localhost diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..ef6cb7d --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,18 @@ +require: + - rubocop-rails +Style/Documentation: + Enabled: false +Layout/LineLength: + Enabled: false +Metrics/BlockLength: + IgnoredMethods: + - test + - configure +Metrics/MethodLength: + Max: 40 +Rails/BulkChangeTable: + Enabled: false +Rails/HasManyOrHasOneDependent: + Enabled: false +Rails/HasAndBelongsToMany: + Enabled: false \ No newline at end of file diff --git a/Gemfile b/Gemfile index a36a34f..df7b3eb 100644 --- a/Gemfile +++ b/Gemfile @@ -1,49 +1,51 @@ -source "https://rubygems.org" +# frozen_string_literal: true + +source 'https://rubygems.org' git_source(:github) { |repo| "https://github.com/#{repo}.git" } -ruby "3.0.2" +ruby '3.0.2' # Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main" -gem "rails", "~> 7.0.2.2" +gem 'rails', '~> 7.0.2.2' # The traditional bundling and transpiling asset pipeline for Rails. -gem "sprockets-rails", ">= 2.0.0" +gem 'sprockets-rails', '>= 2.0.0' # Use the Puma web server [https://github.com/puma/puma] -gem "puma", "~> 5.6.4" +gem 'puma', '~> 5.6.4' # Bundle and transpile JavaScript [https://github.com/rails/jsbundling-rails] -gem "jsbundling-rails", "~> 1.0.3" +gem 'jsbundling-rails', '~> 1.0.3' # Easy React view integration -gem "react-rails", "~> 2.6.1" +gem 'react-rails', '~> 2.6.1' # Upgrade partials to allow for defining slots -gem "nice_partials" +gem 'nice_partials' # Bundle and process CSS [https://github.com/rails/cssbundling-rails] -gem "cssbundling-rails", ">= 1.1.1" +gem 'cssbundling-rails', '>= 1.1.1' # Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails] -gem "importmap-rails", ">= 1.1.2" +gem 'importmap-rails', '>= 1.1.2' # Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev] -gem "turbo-rails", ">= 1.1.1" +gem 'turbo-rails', '>= 1.1.1' # Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev] -gem "stimulus-rails", ">= 1.0.4" +gem 'stimulus-rails', '>= 1.0.4' # Build JSON APIs with ease [https://github.com/rails/jbuilder] -gem "jbuilder", "~> 2.11.5" +gem 'jbuilder', '~> 2.11.5' # Use Redis adapter to run Action Cable in production # gem "redis", "~> 4.0" # Windows does not include zoneinfo files, so bundle the tzinfo-data gem -gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ] +gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby] # Reduces boot times through caching; required in config/boot.rb -gem "bootsnap", ">= 1.12.0", require: false +gem 'bootsnap', '>= 1.12.0', require: false # Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword] # gem "bcrypt", "~> 3.1.7" @@ -53,12 +55,12 @@ gem "bootsnap", ">= 1.12.0", require: false group :development, :test do # Start debugger with binding.b [https://github.com/ruby/debug] - gem "debug", ">= 1.5.0", platforms: %i[ mri mingw x64_mingw ] + gem 'debug', '>= 1.5.0', platforms: %i[mri mingw x64_mingw] end group :development do # Use console on exceptions pages [https://github.com/rails/web-console] - gem "web-console", ">= 4.2.0" + gem 'web-console', '>= 4.2.0' # Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler] # gem "rack-mini-profiler", ">= 2.3.3" @@ -69,10 +71,10 @@ end group :test do # Use system testing [https://guides.rubyonrails.org/testing.html#system-testing] - gem "capybara", ">= 3.37.1" - gem "selenium-webdriver", ">= 4.1.0" - gem "webdrivers", "5.0.0" + gem 'capybara', '>= 3.37.1' gem 'rexml', '~> 3.2.5' + gem 'selenium-webdriver', '>= 4.1.0' + gem 'webdrivers', '5.0.0' # Provides extra assertions and matchers for testing controllers and views gem 'rails-controller-testing' @@ -83,7 +85,10 @@ group :test do end gem 'devise' -gem "passwordless", "~> 0.10.0" -gem "rolify" +gem 'passwordless', '~> 0.10.0' +gem 'rolify' + +gem 'pg', '~> 1.4.1' -gem "pg", "~> 1.4.1" +gem 'rubocop' +gem 'rubocop-rails' diff --git a/Gemfile.lock b/Gemfile.lock index a8de8e0..83d3563 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -68,6 +68,7 @@ GEM tzinfo (~> 2.0) addressable (2.8.0) public_suffix (>= 2.0.2, < 5.0) + ast (2.4.2) babel-source (5.8.35) babel-transpiler (0.7.0) babel-source (>= 4.0, < 6) @@ -119,6 +120,7 @@ GEM activesupport (>= 5.0.0) jsbundling-rails (1.0.3) railties (>= 6.0.0) + json (2.6.2) loofah (2.18.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) @@ -156,6 +158,9 @@ GEM nokogiri (1.13.6-x86_64-darwin) racc (~> 1.4) orm_adapter (0.5.0) + parallel (1.22.1) + parser (3.1.2.1) + ast (~> 2.4.1) passwordless (0.10.0) bcrypt (~> 3.1.11) rails (>= 5.1.4) @@ -197,6 +202,7 @@ GEM rake (>= 12.2) thor (~> 1.0) zeitwerk (~> 2.5) + rainbow (3.1.1) rake (13.0.6) react-rails (2.6.2) babel-transpiler (>= 0.7.0) @@ -212,6 +218,23 @@ GEM railties (>= 5.0) rexml (3.2.5) rolify (6.0.0) + rubocop (1.36.0) + json (~> 2.3) + parallel (~> 1.10) + parser (>= 3.1.2.1) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.20.1, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 1.4.0, < 3.0) + rubocop-ast (1.21.0) + parser (>= 3.1.1.0) + rubocop-rails (2.16.1) + activesupport (>= 4.2.0) + rack (>= 1.1) + rubocop (>= 1.33.0, < 2.0) + ruby-progressbar (1.11.0) rubyzip (2.3.2) selenium-webdriver (4.3.0) childprocess (>= 0.5, < 5.0) @@ -243,6 +266,7 @@ GEM railties (>= 6.0.0) tzinfo (2.0.4) concurrent-ruby (~> 1.0) + unicode-display_width (2.3.0) warden (1.2.9) rack (>= 2.0.9) web-console (4.2.0) @@ -285,6 +309,8 @@ DEPENDENCIES react-rails (~> 2.6.1) rexml (~> 3.2.5) rolify + rubocop + rubocop-rails selenium-webdriver (>= 4.1.0) shoulda shoulda-matchers diff --git a/Rakefile b/Rakefile index 9a5ea73..488c551 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/channels/application_cable/channel.rb b/app/channels/application_cable/channel.rb index d672697..9aec230 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 0ff5442..8d6c2a1 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/passwords_controller.rb b/app/controllers/admin/passwords_controller.rb index b3605a3..ac88dd5 100644 --- a/app/controllers/admin/passwords_controller.rb +++ b/app/controllers/admin/passwords_controller.rb @@ -1,34 +1,36 @@ # frozen_string_literal: true -class Admin::PasswordsController < Devise::PasswordsController - # GET /resource/password/new - # def new - # super - # end +module Admin + class PasswordsController < Devise::PasswordsController + # GET /resource/password/new + # def new + # super + # end - # POST /resource/password - # def create - # super - # end + # POST /resource/password + # def create + # super + # end - # GET /resource/password/edit?reset_password_token=abcdef - # def edit - # super - # end + # GET /resource/password/edit?reset_password_token=abcdef + # def edit + # super + # end - # PUT /resource/password - # def update - # super - # end + # PUT /resource/password + # def update + # super + # end - # protected + # protected - # def after_resetting_password_path_for(resource) - # super(resource) - # end + # def after_resetting_password_path_for(resource) + # super(resource) + # end - # The path used after sending reset password instructions - # def after_sending_reset_password_instructions_path_for(resource_name) - # super(resource_name) - # end + # The path used after sending reset password instructions + # def after_sending_reset_password_instructions_path_for(resource_name) + # super(resource_name) + # end + end end diff --git a/app/controllers/admin/sessions_controller.rb b/app/controllers/admin/sessions_controller.rb index d62697d..f9f7a9d 100644 --- a/app/controllers/admin/sessions_controller.rb +++ b/app/controllers/admin/sessions_controller.rb @@ -1,33 +1,35 @@ # frozen_string_literal: true -class Admin::SessionsController < Devise::SessionsController - # before_action :configure_sign_in_params, only: [:create] +module Admin + class SessionsController < Devise::SessionsController + # before_action :configure_sign_in_params, only: [:create] - # GET /resource/sign_in - # def new - # super - # end + # GET /resource/sign_in + # def new + # super + # end - # POST /resource/sign_in - def create - super - @current_person ||= PresentablePerson.build(resource, view_context) - after_sign_in_path_for(resource) - end + # POST /resource/sign_in + def create + super + @current_person ||= PresentablePerson.build(resource, view_context) + after_sign_in_path_for(resource) + end - # DELETE /resource/sign_out - # def destroy - # super - # end + # DELETE /resource/sign_out + # def destroy + # super + # end - protected + protected - def after_sign_in_path_for(resource) - people_path - end + def after_sign_in_path_for(_resource) + people_path + end - # If you have extra params to permit, append them to the sanitizer. - # def configure_sign_in_params - # devise_parameter_sanitizer.permit(:sign_in, keys: [:attribute]) - # end -end \ No newline at end of file + # If you have extra params to permit, append them to the sanitizer. + # def configure_sign_in_params + # devise_parameter_sanitizer.permit(:sign_in, keys: [:attribute]) + # end + end +end diff --git a/app/controllers/animal_applications_controller.rb b/app/controllers/animal_applications_controller.rb index 14f0160..2fb1775 100644 --- a/app/controllers/animal_applications_controller.rb +++ b/app/controllers/animal_applications_controller.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + class AnimalApplicationsController < ApplicationController - before_action :set_animal_application, only: %i[ show edit update destroy ] + before_action :set_animal_application, only: %i[show edit update destroy] # GET /animal_applications or /animal_applications.json def index @@ -7,8 +9,7 @@ def index end # GET /animal_applications/1 or /animal_applications/1.json - def show - end + def show; end # GET /animal_applications/new def new @@ -16,8 +17,7 @@ def new end # GET /animal_applications/1/edit - def edit - end + def edit; end # POST /animal_applications or /animal_applications.json def create @@ -25,7 +25,7 @@ def create respond_to do |format| if @animal_application.save - format.html { redirect_to @animal_application, notice: "Animal application was successfully created." } + format.html { redirect_to @animal_application, notice: 'Animal application was successfully created.' } format.json { render :show, status: :created, location: @animal_application } else format.html { render :new, status: :unprocessable_entity } @@ -38,7 +38,7 @@ def create def update respond_to do |format| if @animal_application.update(animal_application_params) - format.html { redirect_to @animal_application, notice: "Animal application was successfully updated." } + format.html { redirect_to @animal_application, notice: 'Animal application was successfully updated.' } format.json { render :show, status: :ok, location: @animal_application } else format.html { render :edit, status: :unprocessable_entity } @@ -51,19 +51,20 @@ def update def destroy @animal_application.destroy respond_to do |format| - format.html { redirect_to animal_applications_url, notice: "Animal application was successfully destroyed." } + format.html { redirect_to animal_applications_url, notice: 'Animal application was successfully destroyed.' } format.json { head :no_content } end end private - # Use callbacks to share common setup or constraints between actions. - def set_animal_application - @animal_application = AnimalApplication.find(params[:id]) - end - # Only allow a list of trusted parameters through. - def animal_application_params - params.fetch(:animal_application, {}).permit(:inspiration, :start_date) - end + # Use callbacks to share common setup or constraints between actions. + def set_animal_application + @animal_application = AnimalApplication.find(params[:id]) + end + + # Only allow a list of trusted parameters through. + def animal_application_params + params.fetch(:animal_application, {}).permit(:inspiration, :start_date) + end end diff --git a/app/controllers/animals_controller.rb b/app/controllers/animals_controller.rb index 28fa938..f405715 100644 --- a/app/controllers/animals_controller.rb +++ b/app/controllers/animals_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AnimalsController < ApplicationController def index animals = Animal.all @@ -7,17 +9,13 @@ def index end end - def create animal = Animal.new(animal_params) - unless animal.save - response_status = :bad_request - render :new - end + render :new unless animal.save render(json: { - errors: animal.errors, - path: animals_path - }) + errors: animal.errors, + path: animals_path + }) end def new @@ -44,4 +42,4 @@ def animal_params :birthdate ) end -end \ No newline at end of file +end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 3feea39..835850a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ApplicationController < ActionController::Base def current_person @current_person ||= PresentablePerson.build(nil, view_context) diff --git a/app/controllers/dogs_controller.rb b/app/controllers/dogs_controller.rb index 552ef37..237ef19 100644 --- a/app/controllers/dogs_controller.rb +++ b/app/controllers/dogs_controller.rb @@ -1,5 +1,6 @@ -class DogsController < ApplicationController +# frozen_string_literal: true +class DogsController < ApplicationController def index @dogs = fetch_mock_dog_data end @@ -10,13 +11,14 @@ def index # Returns an array of mock dog data # @return [Array] def fetch_mock_dog_data - names = [ "Bella", "Buddy", "Buster", "Cali", "Charlie", "Max", "Oliver", "Oscar", "Penny", "Riley", "Shadow", "Sophie", "Toby", "Tucker", "Winston" ] - ages = [ 'Puppy', 'Adult', 'Senior' ] - breeds = [ 'Labrador', 'Poodle', 'German Shepherd', 'Golden Retriever', 'Pug' ] - weights = [ 'Small', 'Medium', 'Large' ] - sexs = [ 'Male', 'Female' ] + names = %w[Bella Buddy Buster Cali Charlie Max Oliver Oscar Penny Riley Shadow + Sophie Toby Tucker Winston] + ages = %w[Puppy Adult Senior] + breeds = ['Labrador', 'Poodle', 'German Shepherd', 'Golden Retriever', 'Pug'] + weights = %w[Small Medium Large] + sexs = %w[Male Female] - 12.times.map do |i| + 12.times.map do |_i| name = names.sample age = ages.sample breed = breeds.sample @@ -27,5 +29,4 @@ def fetch_mock_dog_data OpenStruct.new(image_src: dog_photo, name: name, age: age, breed: breed, weight: weight, sex: sex) end end - -end +end diff --git a/app/controllers/home_page_controller.rb b/app/controllers/home_page_controller.rb index c5eb978..b042731 100644 --- a/app/controllers/home_page_controller.rb +++ b/app/controllers/home_page_controller.rb @@ -1,4 +1,5 @@ +# frozen_string_literal: true + class HomePageController < ApplicationController - def index - end -end \ No newline at end of file + def index; end +end diff --git a/app/controllers/homes_controller.rb b/app/controllers/homes_controller.rb index a3ec82c..88d40a7 100644 --- a/app/controllers/homes_controller.rb +++ b/app/controllers/homes_controller.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + class HomesController < ApplicationController - before_action :set_home, only: %i[ show edit update destroy ] + before_action :set_home, only: %i[show edit update destroy] # GET /homes or /homes.json def index @@ -7,8 +9,7 @@ def index end # GET /homes/1 or /homes/1.json - def show - end + def show; end # GET /homes/new def new @@ -16,14 +17,13 @@ def new end # GET /homes/1/edit - def edit - end + def edit; end # PATCH/PUT /homes/1 or /homes/1.json def update respond_to do |format| if @home.update(home_params) - format.html { redirect_to @home, notice: "Home was successfully updated." } + format.html { redirect_to @home, notice: 'Home was successfully updated.' } format.json { render :show, status: :ok, location: @home } else format.html { render :edit, status: :unprocessable_entity } @@ -38,21 +38,22 @@ def destroy PersonHome.where(home_id: params[:id]).destroy_all @home.destroy end - + respond_to do |format| - format.html { redirect_to homes_url, notice: "Home was successfully destroyed." } + format.html { redirect_to homes_url, notice: 'Home was successfully destroyed.' } format.json { head :no_content } end end private - # Use callbacks to share common setup or constraints between actions. - def set_home - @home = Home.find(params[:id]) - end - # Only allow a list of trusted parameters through. - def home_params - params.fetch(:home, {}).permit(:home_type) - end + # Use callbacks to share common setup or constraints between actions. + def set_home + @home = Home.find(params[:id]) + end + + # Only allow a list of trusted parameters through. + def home_params + params.fetch(:home, {}).permit(:home_type) + end end diff --git a/app/controllers/password_protected_controller.rb b/app/controllers/password_protected_controller.rb index 75ace20..50ad1ed 100644 --- a/app/controllers/password_protected_controller.rb +++ b/app/controllers/password_protected_controller.rb @@ -1,7 +1,9 @@ +# frozen_string_literal: true + class PasswordProtectedController < DeviseController before_action :authenticate_person! def current_person @current_person ||= warden.authenticate(scope: :person) end -end \ No newline at end of file +end diff --git a/app/controllers/passwordless_controller.rb b/app/controllers/passwordless_controller.rb index a180dd2..c71abad 100644 --- a/app/controllers/passwordless_controller.rb +++ b/app/controllers/passwordless_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class PasswordlessController < Passwordless::ApplicationController include Passwordless::ControllerHelpers helper_method :current_person @@ -10,6 +12,7 @@ def current_person def require_person! return if current_person + redirect_to root_path, flash: { error: 'Go to your crate!' } end end diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index b2bbd34..0cd379f 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + class PeopleController < PasswordProtectedController - before_action :set_person, only: %i[ show edit update destroy ] + before_action :set_person, only: %i[show edit update destroy] # GET /people or /people.json def index @@ -11,8 +13,7 @@ def index end # GET /people/1 or /people/1.json - def show - end + def show; end # GET /people/new def new @@ -20,15 +21,14 @@ def new end # GET /people/1/edit - def edit - end + def edit; end # POST /people or /people.json def create @person = Person.new(person_params) respond_to do |format| if @person.save - format.html { redirect_to @person, notice: "Person was successfully created." } + format.html { redirect_to @person, notice: 'Person was successfully created.' } format.json { render :show, status: :created, location: @person } else format.html { render :new, status: :unprocessable_entity } @@ -41,7 +41,7 @@ def create def update respond_to do |format| if @person.update(person_params) - format.html { redirect_to @person, notice: "Person was successfully updated." } + format.html { redirect_to @person, notice: 'Person was successfully updated.' } format.json { render :show, status: :ok, location: @person } else format.html { render :edit, status: :unprocessable_entity } @@ -58,30 +58,31 @@ def destroy end respond_to do |format| - format.html { redirect_to people_url, notice: "Person was successfully destroyed." } + format.html { redirect_to people_url, notice: 'Person was successfully destroyed.' } format.json { head :no_content } end end private - # Use callbacks to share common setup or constraints between actions. - def set_person - @person = Person.find(params[:id]) - end - # Only allow a list of trusted parameters through. - def person_params - params.fetch(:person, {}).permit( - :full_name, - :email, - :street, - :apt, - :phone, - :is_home_during_day, - :transportation, - :available_from, - :available_to, - :availability_notes, - ) - end + # Use callbacks to share common setup or constraints between actions. + def set_person + @person = Person.find(params[:id]) + end + + # Only allow a list of trusted parameters through. + def person_params + params.fetch(:person, {}).permit( + :full_name, + :email, + :street, + :apt, + :phone, + :is_home_during_day, + :transportation, + :available_from, + :available_to, + :availability_notes + ) + end end diff --git a/app/controllers/signups_controller.rb b/app/controllers/signups_controller.rb index 87cdb1d..2110836 100644 --- a/app/controllers/signups_controller.rb +++ b/app/controllers/signups_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class SignupsController < PasswordlessController prepend_before_action :require_no_person, only: [:new] @@ -8,18 +10,11 @@ def create format.html {} format.json do if person.save - session = build_passwordless_session(person) - session.token = Passwordless.token_generator.call(session) - session.save! - Passwordless::Mailer.magic_link(session).deliver_now - # redirect_to signup_path, notice: 'Check your email for a login link' # change to personal status page - render(json: { - path: confirmation_signup_path - }, status: 201) + confirm_signup(person) else render(json: { - errors: person.errors, - }, status: :bad_request) + errors: person.errors + }, status: :bad_request) end end end @@ -34,8 +29,7 @@ def new end end - def confirmation - end + def confirmation; end private @@ -56,19 +50,19 @@ def person_params animal_gender_preferences_attributes: [:animal_value], animal_age_preferences_attributes: [:animal_value], animal_size_preferences_attributes: [:animal_value], - homes_attributes: [ - :id, - :has_children, - :has_fenced_yard, - :has_other_adults, - :has_other_dog, - :has_other_cat, - :home_type, - :street, - :apt, - :state, - :city, - :zip_code, + homes_attributes: %i[ + id + has_children + has_fenced_yard + has_other_adults + has_other_dog + has_other_cat + home_type + street + apt + state + city + zip_code ] ) end @@ -76,4 +70,15 @@ def person_params def require_no_person redirect_to person_root_path if current_person.logged_in? end + + def confirm_signup(person) + session = build_passwordless_session(person) + session.token = Passwordless.token_generator.call(session) + session.save! + Passwordless::Mailer.magic_link(session).deliver_now + # redirect_to signup_path, notice: 'Check your email for a login link' # change to personal status page + render(json: { + path: confirmation_signup_path + }, status: :created) + end end diff --git a/app/controllers/status_controller.rb b/app/controllers/status_controller.rb index 1fd0ff8..df36a46 100644 --- a/app/controllers/status_controller.rb +++ b/app/controllers/status_controller.rb @@ -1,16 +1,20 @@ +# frozen_string_literal: true + class StatusController < PasswordlessController before_action :require_person! def show respond_to do |format| format.html {} - format.json { render json: { - person: current_person, - homes: current_person.homes, - animal_age_preferences: current_person.animal_age_preferences, - animal_gender_preferences: current_person.animal_gender_preferences, - animal_kind_preferences: current_person.animal_kind_preferences, - animal_size_preferences: current_person.animal_size_preferences, - } } + format.json do + render json: { + person: current_person, + homes: current_person.homes, + animal_age_preferences: current_person.animal_age_preferences, + animal_gender_preferences: current_person.animal_gender_preferences, + animal_kind_preferences: current_person.animal_kind_preferences, + animal_size_preferences: current_person.animal_size_preferences + } + end end end end diff --git a/app/helpers/animal_applications_helper.rb b/app/helpers/animal_applications_helper.rb index 51587b6..ffa05ed 100644 --- a/app/helpers/animal_applications_helper.rb +++ b/app/helpers/animal_applications_helper.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + module AnimalApplicationsHelper end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be79..15b06f0 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/helpers/homes_helper.rb b/app/helpers/homes_helper.rb index 2a8ce49..3cab01f 100644 --- a/app/helpers/homes_helper.rb +++ b/app/helpers/homes_helper.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + module HomesHelper end diff --git a/app/helpers/people_helper.rb b/app/helpers/people_helper.rb index b682fbf..6acafd3 100644 --- a/app/helpers/people_helper.rb +++ b/app/helpers/people_helper.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + module PeopleHelper end diff --git a/app/helpers/presentable_person.rb b/app/helpers/presentable_person.rb index 458ddaa..996ed49 100644 --- a/app/helpers/presentable_person.rb +++ b/app/helpers/presentable_person.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'delegate' class PresentablePerson < DelegateClass(Person) def self.build(person, view) @@ -10,9 +12,8 @@ def self.build(person, view) end alias person __getobj__ - def initialize(person, view) + def initialize(person, _view) super(person) - @view = view end def name @@ -25,6 +26,7 @@ def logged_in? class Visitor < self def name; end + def admin? false end diff --git a/app/helpers/rescues_helper.rb b/app/helpers/rescues_helper.rb index 30c4f9f..6724d5f 100644 --- a/app/helpers/rescues_helper.rb +++ b/app/helpers/rescues_helper.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + module RescuesHelper end diff --git a/app/helpers/signups_helper.rb b/app/helpers/signups_helper.rb index 1280d05..5c9bc54 100644 --- a/app/helpers/signups_helper.rb +++ b/app/helpers/signups_helper.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + module SignupsHelper end diff --git a/app/helpers/status_helper.rb b/app/helpers/status_helper.rb index fc2a6e1..bd60a5d 100644 --- a/app/helpers/status_helper.rb +++ b/app/helpers/status_helper.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + module StatusHelper end diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb index d394c3d..bef3959 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 3c34c81..d84cb6e 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,4 +1,6 @@ +# frozen_string_literal: true + class ApplicationMailer < ActionMailer::Base - default from: "from@example.com" - layout "mailer" + default from: 'from@example.com' + layout 'mailer' end diff --git a/app/models/animal.rb b/app/models/animal.rb index 1400d03..4405652 100644 --- a/app/models/animal.rb +++ b/app/models/animal.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Animal < ApplicationRecord has_many :person_animals has_many :people, through: :person_animals diff --git a/app/models/animal_age_preference.rb b/app/models/animal_age_preference.rb index 9f87d2a..c777bbf 100644 --- a/app/models/animal_age_preference.rb +++ b/app/models/animal_age_preference.rb @@ -1,10 +1,12 @@ +# frozen_string_literal: true + class AnimalAgePreference < ApplicationRecord belongs_to :person enum animal_value: { - "Newborn (up to 3 months)" => 1, - "Young (3 months - 2 years)" => 2, - "Adult (2 - 5 years)" => 3, - "Senior (5 years + )" => 4 + 'Newborn (up to 3 months)' => 1, + 'Young (3 months - 2 years)' => 2, + 'Adult (2 - 5 years)' => 3, + 'Senior (5 years + )' => 4 } end diff --git a/app/models/animal_application.rb b/app/models/animal_application.rb index a3ae057..a8eacb2 100644 --- a/app/models/animal_application.rb +++ b/app/models/animal_application.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + class AnimalApplication < ApplicationRecord end diff --git a/app/models/animal_gender_preference.rb b/app/models/animal_gender_preference.rb index 0c0b10b..d3941ad 100644 --- a/app/models/animal_gender_preference.rb +++ b/app/models/animal_gender_preference.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + class AnimalGenderPreference < ApplicationRecord belongs_to :person - enum animal_value: { "Male" => 1, "Female" => 2 } + enum animal_value: { 'Male' => 1, 'Female' => 2 } end diff --git a/app/models/animal_kind_preference.rb b/app/models/animal_kind_preference.rb index af64b4d..359761a 100644 --- a/app/models/animal_kind_preference.rb +++ b/app/models/animal_kind_preference.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + class AnimalKindPreference < ApplicationRecord belongs_to :person - enum animal_value: { "Dog" => 1, "Cat" => 2 } + enum animal_value: { 'Dog' => 1, 'Cat' => 2 } end diff --git a/app/models/animal_size_preference.rb b/app/models/animal_size_preference.rb index 48b4277..73cdf25 100644 --- a/app/models/animal_size_preference.rb +++ b/app/models/animal_size_preference.rb @@ -1,10 +1,12 @@ +# frozen_string_literal: true + class AnimalSizePreference < ApplicationRecord belongs_to :person enum animal_value: { - "less than 20 lbs" => 1, - "20 - 40 lbs" => 2, - "40 - 60 lbs" => 3, - "60 +" => 4 + 'less than 20 lbs' => 1, + '20 - 40 lbs' => 2, + '40 - 60 lbs' => 3, + '60 +' => 4 } end diff --git a/app/models/application_record.rb b/app/models/application_record.rb index b63caeb..08dc537 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ApplicationRecord < ActiveRecord::Base primary_abstract_class end diff --git a/app/models/dog.rb b/app/models/dog.rb index c6f51bc..e4fe319 100644 --- a/app/models/dog.rb +++ b/app/models/dog.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Dog < ApplicationRecord validates :name, presence: true end diff --git a/app/models/home.rb b/app/models/home.rb index 50c9cfb..a4b8dc3 100644 --- a/app/models/home.rb +++ b/app/models/home.rb @@ -1,11 +1,13 @@ +# frozen_string_literal: true + class Home < ApplicationRecord has_many :person_homes, inverse_of: :home has_many :people, through: :person_homes enum home_type: { - "Apartment/Condo" => 1, - "Townhouse" => 2, - "House" => 3, + 'Apartment/Condo' => 1, + 'Townhouse' => 2, + 'House' => 3 } validates :home_type, presence: true diff --git a/app/models/person.rb b/app/models/person.rb index aa887e1..9bf247e 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Person < ApplicationRecord rolify # Include default devise modules. Others available are: @@ -6,7 +8,7 @@ class Person < ApplicationRecord :recoverable, :rememberable, :validatable passwordless_with :email - enum transportation: [ :access_to_car, :car, :no_car ] + enum transportation: { access_to_car: 0, car: 1, no_car: 2 } has_many :animal_kind_preferences has_many :animal_gender_preferences @@ -16,10 +18,18 @@ class Person < ApplicationRecord has_many :person_animals has_many :animals, through: :person_animals - accepts_nested_attributes_for :animal_kind_preferences, reject_if: proc { |attributes| attributes["animal_value"].blank? } - accepts_nested_attributes_for :animal_gender_preferences, reject_if: proc { |attributes| attributes["animal_value"].blank? } - accepts_nested_attributes_for :animal_age_preferences, reject_if: proc { |attributes| attributes["animal_value"].blank? } - accepts_nested_attributes_for :animal_size_preferences, reject_if: proc { |attributes| attributes["animal_value"].blank? } + accepts_nested_attributes_for :animal_kind_preferences, reject_if: proc { |attributes| + attributes['animal_value'].blank? + } + accepts_nested_attributes_for :animal_gender_preferences, reject_if: proc { |attributes| + attributes['animal_value'].blank? + } + accepts_nested_attributes_for :animal_age_preferences, reject_if: proc { |attributes| + attributes['animal_value'].blank? + } + accepts_nested_attributes_for :animal_size_preferences, reject_if: proc { |attributes| + attributes['animal_value'].blank? + } has_many :person_homes, inverse_of: :person has_many :homes, through: :person_homes @@ -29,13 +39,13 @@ class Person < ApplicationRecord validates :is_home_during_day, presence: true validates :transportation, presence: true validates :available_from, presence: true - validates :phone, format: { with: /\A\d+\z/, message: "Numbers only, please." } + validates :phone, format: { with: /\A\d+\z/, message: 'Numbers only, please.' } before_validation :prep_phone after_create :assign_default_role def prep_phone - self.phone = self.phone.to_s.gsub(/[^0-9A-Za-z]/, '') + self.phone = phone.to_s.gsub(/[^0-9A-Za-z]/, '') end def self.fetch_resource_for_passwordless(email) @@ -50,9 +60,9 @@ def name nick_name.presence || full_name end -private + private def assign_default_role - self.add_role(:foster) if self.roles.blank? + add_role(:foster) if roles.blank? end end diff --git a/app/models/person_animal.rb b/app/models/person_animal.rb index c885579..42ba1d3 100644 --- a/app/models/person_animal.rb +++ b/app/models/person_animal.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class PersonAnimal < ApplicationRecord belongs_to :person belongs_to :animal diff --git a/app/models/person_home.rb b/app/models/person_home.rb index 8cd659d..f419d73 100644 --- a/app/models/person_home.rb +++ b/app/models/person_home.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class PersonHome < ApplicationRecord belongs_to :person belongs_to :home diff --git a/app/models/rescue.rb b/app/models/rescue.rb index fbb85ea..6786cec 100644 --- a/app/models/rescue.rb +++ b/app/models/rescue.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + class Rescue < ApplicationRecord end diff --git a/app/models/role.rb b/app/models/role.rb index d3b88aa..87749ab 100644 --- a/app/models/role.rb +++ b/app/models/role.rb @@ -1,14 +1,15 @@ +# frozen_string_literal: true + class Role < ApplicationRecord - has_and_belongs_to_many :people, :join_table => :people_roles - + has_and_belongs_to_many :people, join_table: :people_roles + belongs_to :resource, - :polymorphic => true, - :optional => true - + polymorphic: true, + optional: true validates :resource_type, - :inclusion => { :in => Rolify.resource_types }, - :allow_nil => true + inclusion: { in: Rolify.resource_types }, + allow_nil: true scopify end diff --git a/app/views/animal_applications/_animal_application.json.jbuilder b/app/views/animal_applications/_animal_application.json.jbuilder index c34f83f..5a29486 100644 --- a/app/views/animal_applications/_animal_application.json.jbuilder +++ b/app/views/animal_applications/_animal_application.json.jbuilder @@ -1,2 +1,4 @@ +# frozen_string_literal: true + json.extract! animal_application, :id, :created_at, :updated_at json.url animal_application_url(animal_application, format: :json) diff --git a/app/views/animal_applications/index.json.jbuilder b/app/views/animal_applications/index.json.jbuilder index fba442e..fb857f7 100644 --- a/app/views/animal_applications/index.json.jbuilder +++ b/app/views/animal_applications/index.json.jbuilder @@ -1 +1,3 @@ -json.array! @animal_applications, partial: "animal_applications/animal_application", as: :animal_application +# frozen_string_literal: true + +json.array! @animal_applications, partial: 'animal_applications/animal_application', as: :animal_application diff --git a/app/views/animal_applications/show.json.jbuilder b/app/views/animal_applications/show.json.jbuilder index a1da2a9..dedb9c2 100644 --- a/app/views/animal_applications/show.json.jbuilder +++ b/app/views/animal_applications/show.json.jbuilder @@ -1 +1,3 @@ -json.partial! "animal_applications/animal_application", animal_application: @animal_application +# frozen_string_literal: true + +json.partial! 'animal_applications/animal_application', animal_application: @animal_application diff --git a/app/views/homes/_home.json.jbuilder b/app/views/homes/_home.json.jbuilder index abc1fba..bec8f99 100644 --- a/app/views/homes/_home.json.jbuilder +++ b/app/views/homes/_home.json.jbuilder @@ -1,2 +1,4 @@ +# frozen_string_literal: true + json.extract! home, :id, :created_at, :updated_at json.url home_url(home, format: :json) diff --git a/app/views/homes/index.json.jbuilder b/app/views/homes/index.json.jbuilder index 54b7745..9fd4a6c 100644 --- a/app/views/homes/index.json.jbuilder +++ b/app/views/homes/index.json.jbuilder @@ -1 +1,3 @@ -json.array! @homes, partial: "homes/home", as: :home +# frozen_string_literal: true + +json.array! @homes, partial: 'homes/home', as: :home diff --git a/app/views/homes/show.json.jbuilder b/app/views/homes/show.json.jbuilder index 055c8e4..d1499f6 100644 --- a/app/views/homes/show.json.jbuilder +++ b/app/views/homes/show.json.jbuilder @@ -1 +1,3 @@ -json.partial! "homes/home", home: @home +# frozen_string_literal: true + +json.partial! 'homes/home', home: @home diff --git a/app/views/people/_person.json.jbuilder b/app/views/people/_person.json.jbuilder index a54deba..44740f4 100644 --- a/app/views/people/_person.json.jbuilder +++ b/app/views/people/_person.json.jbuilder @@ -1,2 +1,4 @@ +# frozen_string_literal: true + json.extract! person, :id, :created_at, :updated_at json.url person_url(person, format: :json) diff --git a/app/views/people/index.json.jbuilder b/app/views/people/index.json.jbuilder index 14d7899..57f83a7 100644 --- a/app/views/people/index.json.jbuilder +++ b/app/views/people/index.json.jbuilder @@ -1 +1,3 @@ -json.array! @people, partial: "people/person", as: :person +# frozen_string_literal: true + +json.array! @people, partial: 'people/person', as: :person diff --git a/app/views/people/show.json.jbuilder b/app/views/people/show.json.jbuilder index cf0f817..b0770af 100644 --- a/app/views/people/show.json.jbuilder +++ b/app/views/people/show.json.jbuilder @@ -1 +1,3 @@ -json.partial! "people/person", person: @person +# frozen_string_literal: true + +json.partial! 'people/person', person: @person diff --git a/config.ru b/config.ru index 4a3c09a..6dc8321 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_server diff --git a/config/application.rb b/config/application.rb index 6ecf3ba..7a26c74 100644 --- a/config/application.rb +++ b/config/application.rb @@ -1,6 +1,8 @@ -require_relative "boot" +# frozen_string_literal: true -require "rails/all" +require_relative 'boot' + +require 'rails/all' # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. diff --git a/config/boot.rb b/config/boot.rb index 988a5dd..c04863f 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,4 +1,6 @@ -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) +# frozen_string_literal: true -require "bundler/setup" # Set up gems listed in the Gemfile. -require "bootsnap/setup" # Speed up boot time by caching expensive operations. +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) + +require 'bundler/setup' # Set up gems listed in the Gemfile. +require 'bootsnap/setup' # Speed up boot time by caching expensive operations. diff --git a/config/environment.rb b/config/environment.rb index cac5315..d5abe55 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + # Load the Rails application. -require_relative "application" +require_relative 'application' # Initialize the Rails application. Rails.application.initialize! diff --git a/config/environments/development.rb b/config/environments/development.rb index a8fa87a..b2c4f3a 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,4 +1,6 @@ -require "active_support/core_ext/integer/time" +# frozen_string_literal: true + +require 'active_support/core_ext/integer/time' Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. @@ -16,13 +18,13 @@ # Enable/disable caching. By default caching is disabled. # Run rails dev:cache to toggle caching. - if Rails.root.join("tmp/caching-dev.txt").exist? + if Rails.root.join('tmp/caching-dev.txt').exist? config.action_controller.perform_caching = true config.action_controller.enable_fragment_cache_logging = true config.cache_store = :memory_store config.public_file_server.headers = { - "Cache-Control" => "public, max-age=#{2.days.to_i}" + 'Cache-Control' => "public, max-age=#{2.days.to_i}" } else config.action_controller.perform_caching = false @@ -38,7 +40,7 @@ config.action_mailer.perform_caching = false config.action_mailer.default_url_options = { host: 'localhost', port: 3000 } - config.action_mailer.smtp_settings = { :address => "localhost", :port => 1025 } + config.action_mailer.smtp_settings = { address: 'localhost', port: 1025 } # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log diff --git a/config/environments/production.rb b/config/environments/production.rb index 0e73ac0..3cc2660 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,4 +1,6 @@ -require "active_support/core_ext/integer/time" +# frozen_string_literal: true + +require 'active_support/core_ext/integer/time' Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. @@ -22,7 +24,7 @@ # Disable serving static files from the `/public` folder by default since # Apache or NGINX already handles this. - config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present? + config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? # Compress CSS using a preprocessor. # config.assets.css_compressor = :sass @@ -53,7 +55,7 @@ config.log_level = :info # 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 @@ -63,16 +65,16 @@ # config.active_job.queue_name_prefix = "shelter_assist_production" config.action_mailer.perform_caching = false - config.action_mailer.default_url_options = { host: ENV["SHELTERASSIST_HOSTNAME"] || "https://shelterassist.herokuapp.com" } + config.action_mailer.default_url_options = { host: ENV['SHELTERASSIST_HOSTNAME'] || 'https://shelterassist.herokuapp.com' } config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { - address: ENV["SHELTERASSIST_SMTP_SERVER"], - port: ENV["SHELTERASSIST_SMTP_PORT"], - user_name: ENV["SHELTERASSIST_SMTP_USER"], - password: ENV["SHELTERASSIST_SMTP_PASSWORD"], + address: ENV['SHELTERASSIST_SMTP_SERVER'], + port: ENV['SHELTERASSIST_SMTP_PORT'], + user_name: ENV['SHELTERASSIST_SMTP_USER'], + password: ENV['SHELTERASSIST_SMTP_PASSWORD'], authentication: :plain, enable_starttls_auto: true, - openssl_verify_mode: "none" + openssl_verify_mode: 'none' } # Ignore bad email addresses and do not raise email delivery errors. @@ -93,8 +95,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 fc5f2f3..de3283d 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -1,4 +1,6 @@ -require "active_support/core_ext/integer/time" +# frozen_string_literal: true + +require 'active_support/core_ext/integer/time' # The test environment is used exclusively to run your application's # test suite. You never need to work with it otherwise. Remember that @@ -19,7 +21,7 @@ # Configure public file server for tests with Cache-Control for performance. config.public_file_server.enabled = true config.public_file_server.headers = { - "Cache-Control" => "public, max-age=#{1.hour.to_i}" + 'Cache-Control' => "public, max-age=#{1.hour.to_i}" } # Show full error reports and disable caching. diff --git a/config/initializers/application_controller_renderer.rb b/config/initializers/application_controller_renderer.rb index 89d2efa..f4556db 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 2eeef96..bcafccd 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -1,7 +1,9 @@ +# 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. -Rails.application.config.assets.version = "1.0" +Rails.application.config.assets.version = '1.0' # Add additional assets to the asset load path. # Rails.application.config.assets.paths << Emoji.images_path diff --git a/config/initializers/backtrace_silencers.rb b/config/initializers/backtrace_silencers.rb index 33699c3..d43cc1d 100644 --- a/config/initializers/backtrace_silencers.rb +++ b/config/initializers/backtrace_silencers.rb @@ -1,3 +1,5 @@ +# 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. @@ -5,4 +7,4 @@ # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code # by setting BACKTRACE=1 before calling your invocation, like "BACKTRACE=1 ./bin/rails runner 'MyClass.perform'". -Rails.backtrace_cleaner.remove_silencers! if ENV["BACKTRACE"] +Rails.backtrace_cleaner.remove_silencers! if ENV['BACKTRACE'] diff --git a/config/initializers/content_security_policy.rb b/config/initializers/content_security_policy.rb index d988237..52f334c 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 5a6a32d..ee8dff9 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 4b34a03..3babc73 100644 --- a/config/initializers/filter_parameter_logging.rb +++ b/config/initializers/filter_parameter_logging.rb @@ -1,6 +1,8 @@ +# 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. -Rails.application.config.filter_parameters += [ - :passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn +Rails.application.config.filter_parameters += %i[ + passw secret token _key crypt salt certificate otp ssn ] diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index 3860f65..6c78420 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 dc18996..6e1d16f 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/passwordless.rb b/config/initializers/passwordless.rb index d1a7a5f..86d2316 100644 --- a/config/initializers/passwordless.rb +++ b/config/initializers/passwordless.rb @@ -1,11 +1,13 @@ -Passwordless.default_from_address = ENV["SHELTERASSIST_EMAIL_ADDRESS"] || "CHANGE_ME@example.com" -Passwordless.parent_mailer = "ActionMailer::Base" +# frozen_string_literal: true + +Passwordless.default_from_address = ENV['SHELTERASSIST_EMAIL_ADDRESS'] || 'CHANGE_ME@example.com' +Passwordless.parent_mailer = 'ActionMailer::Base' Passwordless.token_generator = Passwordless::UrlSafeBase64Generator.new # Used to generate magic link tokens. Passwordless.restrict_token_reuse = false # By default a magic link token can be used multiple times. Passwordless.redirect_back_after_sign_in = true # When enabled the user will be redirected to their previous page, or a page specified by the `destination_path` query parameter, if available. -Passwordless.expires_at = lambda { 1.year.from_now } # How long until a passwordless session expires. -Passwordless.timeout_at = lambda { 1.hour.from_now } # How long until a magic link expires. +Passwordless.expires_at = -> { 1.year.from_now } # How long until a passwordless session expires. +Passwordless.timeout_at = -> { 1.hour.from_now } # How long until a magic link expires. # Default redirection paths Passwordless.success_redirect_path = '/status' # When a user succeeds in logging in. diff --git a/config/initializers/permissions_policy.rb b/config/initializers/permissions_policy.rb index 00f64d7..50bcf4e 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/rolify.rb b/config/initializers/rolify.rb index bbf8fe2..ace6ec8 100644 --- a/config/initializers/rolify.rb +++ b/config/initializers/rolify.rb @@ -1,10 +1,12 @@ +# frozen_string_literal: true + Rolify.configure do |config| # By default ORM adapter is ActiveRecord. uncomment to use mongoid # config.use_mongoid # Dynamic shortcuts for User class (user.is_admin? like methods). Default is: false # config.use_dynamic_shortcuts - + # Configuration to remove roles from database once the last resource is removed. Default is: true # config.remove_role_if_empty = false end diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb index bbfc396..2f3c0db 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 daaf036..1713441 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -1,28 +1,30 @@ +# 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. # -max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } -min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count } +max_threads_count = ENV.fetch('RAILS_MAX_THREADS', 5) +min_threads_count = ENV.fetch('RAILS_MIN_THREADS') { max_threads_count } threads min_threads_count, max_threads_count # Specifies the `worker_timeout` threshold that Puma will use to wait before # terminating a worker in development environments. # -worker_timeout 3600 if ENV.fetch("RAILS_ENV", "development") == "development" +worker_timeout 3600 if ENV.fetch('RAILS_ENV', 'development') == 'development' # 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 web server processes. If using threads and workers together diff --git a/config/routes.rb b/config/routes.rb index 268b2d6..a0a6430 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Rails.application.routes.draw do resources :animal_applications resources :homes @@ -10,7 +12,7 @@ end # admin - devise_for :people, only: [:sessions, :passwords], module: :admin, path_prefix: :admin + devise_for :people, only: %i[sessions passwords], module: :admin, path_prefix: :admin # non-admin people passwordless_for :people, at: '/', as: :auth @@ -21,8 +23,8 @@ get '/status', to: 'status#show', as: :person_root authenticated :admin do - root "people#index", as: :admin_root + root 'people#index', as: :admin_root end - root to: "home_page#index" + root to: 'home_page#index' end diff --git a/config/spring.rb b/config/spring.rb index db5bf13..93cd0ff 100644 --- a/config/spring.rb +++ b/config/spring.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + Spring.watch( - ".ruby-version", - ".rbenv-vars", - "tmp/restart.txt", - "tmp/caching-dev.txt" + '.ruby-version', + '.rbenv-vars', + 'tmp/restart.txt', + 'tmp/caching-dev.txt' ) diff --git a/db/migrate/20210924175316_create_fosters.rb b/db/migrate/20210924175316_create_fosters.rb index b2b02d8..d6a8c6a 100644 --- a/db/migrate/20210924175316_create_fosters.rb +++ b/db/migrate/20210924175316_create_fosters.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + class CreateFosters < ActiveRecord::Migration[7.0] def change create_table :fosters do |t| t.string :full_name, null: false t.string :nick_name - t.string :email, null: false, default: "" + t.string :email, null: false, default: '' t.boolean :is_home_during_day, null: false t.integer :transportation, null: false t.string :street, null: false diff --git a/db/migrate/20210925130640_create_homes.rb b/db/migrate/20210925130640_create_homes.rb index 1bcb5f0..3441bb7 100644 --- a/db/migrate/20210925130640_create_homes.rb +++ b/db/migrate/20210925130640_create_homes.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateHomes < ActiveRecord::Migration[7.0] def change create_table :homes do |t| diff --git a/db/migrate/20210925140044_create_animal_applications.rb b/db/migrate/20210925140044_create_animal_applications.rb index c6eb774..a03aae3 100644 --- a/db/migrate/20210925140044_create_animal_applications.rb +++ b/db/migrate/20210925140044_create_animal_applications.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateAnimalApplications < ActiveRecord::Migration[7.0] def change create_table :animal_applications do |t| diff --git a/db/migrate/20210925143211_add_devise_to_fosters.rb b/db/migrate/20210925143211_add_devise_to_fosters.rb index 8a47107..8539b24 100644 --- a/db/migrate/20210925143211_add_devise_to_fosters.rb +++ b/db/migrate/20210925143211_add_devise_to_fosters.rb @@ -5,7 +5,7 @@ def self.up change_table :fosters do |t| ## Database authenticatable # t.string :email, null: false, default: "" - t.string :encrypted_password, null: false, default: "" + t.string :encrypted_password, null: false, default: '' ## Recoverable t.string :reset_password_token @@ -32,7 +32,6 @@ def self.up # t.string :unlock_token # Only if unlock strategy is :email or :both # t.datetime :locked_at - # Uncomment below if timestamps were not included in your original model. # t.timestamps null: false end diff --git a/db/migrate/20210925144518_create_passwordless_sessions.passwordless.rb b/db/migrate/20210925144518_create_passwordless_sessions.passwordless.rb index 8b1b8dd..362a443 100644 --- a/db/migrate/20210925144518_create_passwordless_sessions.passwordless.rb +++ b/db/migrate/20210925144518_create_passwordless_sessions.passwordless.rb @@ -7,7 +7,7 @@ def change t.belongs_to( :authenticatable, polymorphic: true, - index: {name: "authenticatable"} + index: { name: 'authenticatable' } ) t.datetime :timeout_at, null: false t.datetime :expires_at, null: false diff --git a/db/migrate/20210926130241_add_admin_to_fosters.rb b/db/migrate/20210926130241_add_admin_to_fosters.rb index 07de0d9..6abaa1f 100644 --- a/db/migrate/20210926130241_add_admin_to_fosters.rb +++ b/db/migrate/20210926130241_add_admin_to_fosters.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddAdminToFosters < ActiveRecord::Migration[7.0] def change add_column :fosters, :admin, :boolean, default: false, null: false diff --git a/db/migrate/20210927225655_add_home_to_fosters.rb b/db/migrate/20210927225655_add_home_to_fosters.rb index 2ced515..bbe9383 100644 --- a/db/migrate/20210927225655_add_home_to_fosters.rb +++ b/db/migrate/20210927225655_add_home_to_fosters.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + class AddHomeToFosters < ActiveRecord::Migration[7.0] def change - add_reference :homes, :foster, null: false, foreign_key: true + add_reference :homes, :foster, null: false, foreign_key: true, default: {} end end diff --git a/db/migrate/20211003204848_create_foster_homes.rb b/db/migrate/20211003204848_create_foster_homes.rb index 7654a04..3fcbe13 100644 --- a/db/migrate/20211003204848_create_foster_homes.rb +++ b/db/migrate/20211003204848_create_foster_homes.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateFosterHomes < ActiveRecord::Migration[7.0] def change create_table :foster_homes do |t| diff --git a/db/migrate/20211003205905_remove_foster_id_from_home.rb b/db/migrate/20211003205905_remove_foster_id_from_home.rb index f32564d..1865fce 100644 --- a/db/migrate/20211003205905_remove_foster_id_from_home.rb +++ b/db/migrate/20211003205905_remove_foster_id_from_home.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class RemoveFosterIdFromHome < ActiveRecord::Migration[7.0] def change remove_index :homes, :foster_id diff --git a/db/migrate/20211011194446_create_rescues.rb b/db/migrate/20211011194446_create_rescues.rb index 21c8826..93a7226 100644 --- a/db/migrate/20211011194446_create_rescues.rb +++ b/db/migrate/20211011194446_create_rescues.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateRescues < ActiveRecord::Migration[7.0] def change create_table :rescues do |t| diff --git a/db/migrate/20211012134202_rename_fosters_to_people.rb b/db/migrate/20211012134202_rename_fosters_to_people.rb index 9034a1b..ea4866e 100644 --- a/db/migrate/20211012134202_rename_fosters_to_people.rb +++ b/db/migrate/20211012134202_rename_fosters_to_people.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class RenameFostersToPeople < ActiveRecord::Migration[7.0] def change rename_table :fosters, :people diff --git a/db/migrate/20211012135622_add_address_fields_to_homes.rb b/db/migrate/20211012135622_add_address_fields_to_homes.rb index b63b992..9e424f8 100644 --- a/db/migrate/20211012135622_add_address_fields_to_homes.rb +++ b/db/migrate/20211012135622_add_address_fields_to_homes.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddAddressFieldsToHomes < ActiveRecord::Migration[7.0] def change add_column :homes, :street, :string diff --git a/db/migrate/20211012143507_rename_foster_id_to_person_id.rb b/db/migrate/20211012143507_rename_foster_id_to_person_id.rb index df81198..8456812 100644 --- a/db/migrate/20211012143507_rename_foster_id_to_person_id.rb +++ b/db/migrate/20211012143507_rename_foster_id_to_person_id.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class RenameFosterIdToPersonId < ActiveRecord::Migration[7.0] def change rename_column :person_homes, :foster_id, :person_id diff --git a/db/migrate/20211012145930_add_home_type_to_homes.rb b/db/migrate/20211012145930_add_home_type_to_homes.rb index 6e9c32d..50ea4d9 100644 --- a/db/migrate/20211012145930_add_home_type_to_homes.rb +++ b/db/migrate/20211012145930_add_home_type_to_homes.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddHomeTypeToHomes < ActiveRecord::Migration[7.0] def change add_column :homes, :home_type, :integer diff --git a/db/migrate/20211012174146_create_animals.rb b/db/migrate/20211012174146_create_animals.rb index c788268..d498e62 100644 --- a/db/migrate/20211012174146_create_animals.rb +++ b/db/migrate/20211012174146_create_animals.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateAnimals < ActiveRecord::Migration[7.0] def change create_table :animals do |t| diff --git a/db/migrate/20211012190621_rolify_create_roles.rb b/db/migrate/20211012190621_rolify_create_roles.rb index 550c2ee..092e936 100644 --- a/db/migrate/20211012190621_rolify_create_roles.rb +++ b/db/migrate/20211012190621_rolify_create_roles.rb @@ -1,18 +1,22 @@ +# frozen_string_literal: true + class RolifyCreateRoles < ActiveRecord::Migration[7.0] def change create_table(:roles) do |t| t.string :name - t.references :resource, :polymorphic => true + t.references :resource, polymorphic: true t.timestamps end - create_table(:people_roles, :id => false) do |t| + create_table(:people_roles, id: false) do |t| t.references :person t.references :role + + t.timestamps end - - add_index(:roles, [ :name, :resource_type, :resource_id ]) - add_index(:people_roles, [ :person_id, :role_id ]) + + add_index(:roles, %i[name resource_type resource_id]) + add_index(:people_roles, %i[person_id role_id]) end end diff --git a/db/migrate/20211012191129_remove_admin_from_people.rb b/db/migrate/20211012191129_remove_admin_from_people.rb index dca8c7b..fcb17b9 100644 --- a/db/migrate/20211012191129_remove_admin_from_people.rb +++ b/db/migrate/20211012191129_remove_admin_from_people.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class RemoveAdminFromPeople < ActiveRecord::Migration[7.0] def change remove_column :people, :admin, :boolean diff --git a/db/migrate/20211013151216_create_animal_kind_preferences.rb b/db/migrate/20211013151216_create_animal_kind_preferences.rb index 5d1a6d0..bf86c32 100644 --- a/db/migrate/20211013151216_create_animal_kind_preferences.rb +++ b/db/migrate/20211013151216_create_animal_kind_preferences.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateAnimalKindPreferences < ActiveRecord::Migration[7.0] def change create_table :animal_kind_preferences do |t| diff --git a/db/migrate/20211013151223_create_animal_gender_preferences.rb b/db/migrate/20211013151223_create_animal_gender_preferences.rb index 68503b5..1d87f6b 100644 --- a/db/migrate/20211013151223_create_animal_gender_preferences.rb +++ b/db/migrate/20211013151223_create_animal_gender_preferences.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateAnimalGenderPreferences < ActiveRecord::Migration[7.0] def change create_table :animal_gender_preferences do |t| diff --git a/db/migrate/20211013151243_create_animal_age_preferences.rb b/db/migrate/20211013151243_create_animal_age_preferences.rb index f8802d1..4c52019 100644 --- a/db/migrate/20211013151243_create_animal_age_preferences.rb +++ b/db/migrate/20211013151243_create_animal_age_preferences.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateAnimalAgePreferences < ActiveRecord::Migration[7.0] def change create_table :animal_age_preferences do |t| diff --git a/db/migrate/20211013151254_create_animal_size_preferences.rb b/db/migrate/20211013151254_create_animal_size_preferences.rb index aed266d..e4159c5 100644 --- a/db/migrate/20211013151254_create_animal_size_preferences.rb +++ b/db/migrate/20211013151254_create_animal_size_preferences.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateAnimalSizePreferences < ActiveRecord::Migration[7.0] def change create_table :animal_size_preferences do |t| diff --git a/db/migrate/20211014142021_add_missing_animal_fields.rb b/db/migrate/20211014142021_add_missing_animal_fields.rb index f3c3421..ca29098 100644 --- a/db/migrate/20211014142021_add_missing_animal_fields.rb +++ b/db/migrate/20211014142021_add_missing_animal_fields.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddMissingAnimalFields < ActiveRecord::Migration[7.0] def change add_column :animals, :breed, :string diff --git a/db/migrate/20211014185424_create_person_animals.rb b/db/migrate/20211014185424_create_person_animals.rb index cc3c823..8c10128 100644 --- a/db/migrate/20211014185424_create_person_animals.rb +++ b/db/migrate/20211014185424_create_person_animals.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreatePersonAnimals < ActiveRecord::Migration[7.0] def change create_table :person_animals do |t| diff --git a/db/migrate/20211015141513_remove_street_null_contraint_for_person.rb b/db/migrate/20211015141513_remove_street_null_contraint_for_person.rb index e205258..af06491 100644 --- a/db/migrate/20211015141513_remove_street_null_contraint_for_person.rb +++ b/db/migrate/20211015141513_remove_street_null_contraint_for_person.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class RemoveStreetNullContraintForPerson < ActiveRecord::Migration[7.0] def change change_column_null :people, :street, true diff --git a/db/migrate/20211015150227_update_animals_attributes.rb b/db/migrate/20211015150227_update_animals_attributes.rb index 2ae7e65..54978da 100644 --- a/db/migrate/20211015150227_update_animals_attributes.rb +++ b/db/migrate/20211015150227_update_animals_attributes.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class UpdateAnimalsAttributes < ActiveRecord::Migration[7.0] def up remove_column :animals, :size diff --git a/db/migrate/20220115204940_remove_homes_fields_from_people.rb b/db/migrate/20220115204940_remove_homes_fields_from_people.rb index 9fa3e28..c2a3495 100644 --- a/db/migrate/20220115204940_remove_homes_fields_from_people.rb +++ b/db/migrate/20220115204940_remove_homes_fields_from_people.rb @@ -1,11 +1,13 @@ +# frozen_string_literal: true + class RemoveHomesFieldsFromPeople < ActiveRecord::Migration[7.0] -def up + def up remove_column :people, :street remove_column :people, :apt end def down - add_column :people, :street, :string, null: false + add_column :people, :street, :string, null: false, default: 'Unkown' add_column :people, :apt, :string end end diff --git a/db/migrate/20220115205410_fix_types_in_person_animals_table.rb b/db/migrate/20220115205410_fix_types_in_person_animals_table.rb index f9f7456..e128233 100644 --- a/db/migrate/20220115205410_fix_types_in_person_animals_table.rb +++ b/db/migrate/20220115205410_fix_types_in_person_animals_table.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class FixTypesInPersonAnimalsTable < ActiveRecord::Migration[7.0] def up change_column :person_animals, :person_id, :bigint diff --git a/db/migrate/20220115211102_add_fk_constraints_on_people_roles.rb b/db/migrate/20220115211102_add_fk_constraints_on_people_roles.rb index ff0845f..6f273f3 100644 --- a/db/migrate/20220115211102_add_fk_constraints_on_people_roles.rb +++ b/db/migrate/20220115211102_add_fk_constraints_on_people_roles.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddFkConstraintsOnPeopleRoles < ActiveRecord::Migration[7.0] def up add_foreign_key :people_roles, :people diff --git a/db/migrate/20220505020054_add_availability_to_person.rb b/db/migrate/20220505020054_add_availability_to_person.rb index 0850543..2ea7a3a 100644 --- a/db/migrate/20220505020054_add_availability_to_person.rb +++ b/db/migrate/20220505020054_add_availability_to_person.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddAvailabilityToPerson < ActiveRecord::Migration[7.0] def change add_column :people, :available_from, :datetime diff --git a/db/migrate/20220613223104_add_availability_notes_to_person.rb b/db/migrate/20220613223104_add_availability_notes_to_person.rb index d6fdf37..7bd48e4 100644 --- a/db/migrate/20220613223104_add_availability_notes_to_person.rb +++ b/db/migrate/20220613223104_add_availability_notes_to_person.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddAvailabilityNotesToPerson < ActiveRecord::Migration[7.0] def change add_column :people, :availability_notes, :string, null: true diff --git a/db/migrate/20220913002300_create_dogs.rb b/db/migrate/20220913002300_create_dogs.rb index 50f409a..c1065f7 100644 --- a/db/migrate/20220913002300_create_dogs.rb +++ b/db/migrate/20220913002300_create_dogs.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateDogs < ActiveRecord::Migration[7.0] def change create_table :dogs do |t| diff --git a/db/seeds.rb b/db/seeds.rb index 682e535..7cc1eed 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,19 +1,21 @@ +# frozen_string_literal: true + admin = Person.create!( - full_name: "Ad Ministrator", - nick_name: "Admin", + full_name: 'Ad Ministrator', + nick_name: 'Admin', email: 'admin@test.com', password: 'password', is_home_during_day: true, phone: '123-555-1212', transportation: 'car', - available_from: 4.days.from_now, + available_from: 4.days.from_now ) admin.add_role(:admin) -person = Person.create!( - full_name: "Person", - email: "foster@test.com", +Person.create!( + full_name: 'Person', + email: 'foster@test.com', is_home_during_day: true, phone: '123-555-1212', transportation: 'car', @@ -25,11 +27,11 @@ has_other_adults: true, has_other_dog: false, has_other_cat: false, - street: "123 main st.", - city: "someplace", - state: "MD", - zip_code: "20782", - home_type: "House" + street: '123 main st.', + city: 'someplace', + state: 'MD', + zip_code: '20782', + home_type: 'House' } ] ) @@ -62,4 +64,4 @@ # gender: "male", # breed: "Burmese", # birthdate: Date.new(2018, 6, 2) -# ) \ No newline at end of file +# ) diff --git a/lib/devise_patches.rb b/lib/devise_patches.rb index 66709e4..0c72dff 100644 --- a/lib/devise_patches.rb +++ b/lib/devise_patches.rb @@ -1,9 +1,12 @@ +# frozen_string_literal: true + # Patches to support Devise on Rails 7+ module DevisePatches ActiveSupport::Dependencies.instance_eval do def constantize(name) name.constantize end + def reference(_); end end end diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb index 6caee50..757cf79 100644 --- a/test/application_system_test_case.rb +++ b/test/application_system_test_case.rb @@ -1,8 +1,10 @@ -require "test_helper" +# frozen_string_literal: true + +require 'test_helper' class ApplicationSystemTestCase < ActionDispatch::SystemTestCase driven_by :selenium, using: :headless_chrome, screen_size: [1400, 1400] do |option| - option.add_argument "--no-sandbox" + option.add_argument '--no-sandbox' end Capybara.app_host = 'http://127.0.0.1' diff --git a/test/channels/application_cable/connection_test.rb b/test/channels/application_cable/connection_test.rb index 800405f..4aee9b3 100644 --- a/test/channels/application_cable/connection_test.rb +++ b/test/channels/application_cable/connection_test.rb @@ -1,11 +1,15 @@ -require "test_helper" +# frozen_string_literal: true -class ApplicationCable::ConnectionTest < ActionCable::Connection::TestCase - # test "connects with cookies" do - # cookies.signed[:user_id] = 42 - # - # connect - # - # assert_equal connection.user_id, "42" - # end +require 'test_helper' + +module ApplicationCable + class ConnectionTest < ActionCable::Connection::TestCase + # test "connects with cookies" do + # cookies.signed[:user_id] = 42 + # + # connect + # + # assert_equal connection.user_id, "42" + # end + end end diff --git a/test/controllers/animal_applications_controller_test.rb b/test/controllers/animal_applications_controller_test.rb index 9cc53e9..de3ab9f 100644 --- a/test/controllers/animal_applications_controller_test.rb +++ b/test/controllers/animal_applications_controller_test.rb @@ -1,22 +1,24 @@ -require "test_helper" +# frozen_string_literal: true + +require 'test_helper' class AnimalApplicationsControllerTest < ActionDispatch::IntegrationTest setup do @animal_application = animal_applications(:one) end - test "should get index" do + test 'should get index' do get animal_applications_url assert_response :success end - test "should get new" do + test 'should get new' do get new_animal_application_url assert_response :success end - test "should create animal_application" do - assert_difference("AnimalApplication.count") do + test 'should create animal_application' do + assert_difference('AnimalApplication.count') do post animal_applications_url, params: { animal_application: { start_date: Date.new, @@ -28,23 +30,23 @@ class AnimalApplicationsControllerTest < ActionDispatch::IntegrationTest assert_redirected_to animal_application_url(AnimalApplication.last) end - test "should show animal_application" do + test 'should show animal_application' do get animal_application_url(@animal_application) assert_response :success end - test "should get edit" do + test 'should get edit' do get edit_animal_application_url(@animal_application) assert_response :success end - test "should update animal_application" do - patch animal_application_url(@animal_application), params: { animal_application: { } } + test 'should update animal_application' do + patch animal_application_url(@animal_application), params: { animal_application: {} } assert_redirected_to animal_application_url(@animal_application) end - test "should destroy animal_application" do - assert_difference("AnimalApplication.count", -1) do + test 'should destroy animal_application' do + assert_difference('AnimalApplication.count', -1) do delete animal_application_url(@animal_application) end diff --git a/test/controllers/dogs_controller_test.rb b/test/controllers/dogs_controller_test.rb index f8bee7a..3eeb64f 100644 --- a/test/controllers/dogs_controller_test.rb +++ b/test/controllers/dogs_controller_test.rb @@ -1,14 +1,15 @@ -require "test_helper" +# frozen_string_literal: true -class DogsControllerTest < ActionController::TestCase +require 'test_helper' - test "should get index with proper content" do +class DogsControllerTest < ActionController::TestCase + test 'should get index with proper content' do get :index assert_response :success assert_not_nil assigns(:dogs) - assert_includes @response.body, "Fosterable Dogs" - assert_includes @response.body, "Thinking about fostering? These adorable dogs from local rescues need someone to foster them while they await their furever home. Click on a dog below to see more information about each dog." + assert_includes @response.body, 'Fosterable Dogs' + assert_includes @response.body, + 'Thinking about fostering? These adorable dogs from local rescues need someone to foster them while they await their furever home. Click on a dog below to see more information about each dog.' end - end diff --git a/test/controllers/homes_controller_test.rb b/test/controllers/homes_controller_test.rb index 068f0d6..08ebfd8 100644 --- a/test/controllers/homes_controller_test.rb +++ b/test/controllers/homes_controller_test.rb @@ -1,37 +1,39 @@ -require "test_helper" +# frozen_string_literal: true + +require 'test_helper' class HomesControllerTest < ActionDispatch::IntegrationTest setup do @home = homes(:one) end - test "should get index" do + test 'should get index' do get homes_url assert_response :success end - test "should get new" do + test 'should get new' do get new_home_url assert_response :success end - test "should show home" do + test 'should show home' do get home_url(@home) assert_response :success end - test "should get edit" do + test 'should get edit' do get edit_home_url(@home) assert_response :success end - test "should update home" do - patch home_url(@home), params: { home: { home_type: "House" } } + test 'should update home' do + patch home_url(@home), params: { home: { home_type: 'House' } } assert_redirected_to home_url(@home) end - test "should destroy home and associated person_homes" do - assert_difference("Home.count", -1) do + test 'should destroy home and associated person_homes' do + assert_difference('Home.count', -1) do delete home_url(@home) end diff --git a/test/controllers/people_controller_test.rb b/test/controllers/people_controller_test.rb index 6a7e0d1..b162251 100644 --- a/test/controllers/people_controller_test.rb +++ b/test/controllers/people_controller_test.rb @@ -1,4 +1,6 @@ -require "test_helper" +# frozen_string_literal: true + +require 'test_helper' class PeopleControllerTest < ActionDispatch::IntegrationTest include Devise::Test::IntegrationHelpers @@ -7,63 +9,63 @@ class PeopleControllerTest < ActionDispatch::IntegrationTest sign_in(@person, scope: :admin) end - test "should get index" do + test 'should get index' do get people_url assert_response :success end - test "should get new" do + test 'should get new' do get new_person_url assert_response :success end - test "should create person" do - assert_difference("Person.count") do - post people_url, params: { - person: { + test 'should create person' do + assert_difference('Person.count') do + post people_url, params: { + person: { full_name: 'Chuck Norris', - email: "hi@hi.com", + email: 'hi@hi.com', phone: '5714128473', is_home_during_day: true, - transportation: "car", + transportation: 'car', available_from: 5.days.from_now, available_to: 7.days.from_now, - availability_notes: "I cannot do the first week of next month because I am on vacation." - } + availability_notes: 'I cannot do the first week of next month because I am on vacation.' + } } end assert_redirected_to person_url(Person.last) end - test "should show person" do + test 'should show person' do get person_url(@person) assert_response :success end - test "should get edit" do + test 'should get edit' do get edit_person_url(@person) assert_response :success end - test "should update person" do + test 'should update person' do patch person_url(@person), params: { - person: { + person: { full_name: 'Chuck Norris', - email: "hi@hi.com", + email: 'hi@hi.com', phone: '5714128473', - is_home_during_day: true, - transportation: Person.transportations(), + is_home_during_day: true, + transportation: Person.transportations, available_from: 5.days.from_now, available_to: 7.days.from_now, - availability_notes: "I cannot do the first week of next month because I am on vacation." + availability_notes: 'I cannot do the first week of next month because I am on vacation.' } } assert_redirected_to person_url(@person) end - test "should destroy person and associated person_homes" do - assert_difference("Person.count", -1) do + test 'should destroy person and associated person_homes' do + assert_difference('Person.count', -1) do delete person_url(@person) end diff --git a/test/controllers/signups_controller_test.rb b/test/controllers/signups_controller_test.rb index 2d20b6f..b1e6dbe 100644 --- a/test/controllers/signups_controller_test.rb +++ b/test/controllers/signups_controller_test.rb @@ -1,21 +1,23 @@ -require "test_helper" +# frozen_string_literal: true + +require 'test_helper' class SignupsControllerTest < ActionDispatch::IntegrationTest - test "should get create" do - post signup_url, params: { - person: { + test 'should get create' do + post signup_url, params: { + person: { full_name: 'Chuck Norris', - email: "hi@hi.com", - phone: '571-412-8473', - is_home_during_day: false, - transportation: "car" - } + email: 'hi@hi.com', + phone: '571-412-8473', + is_home_during_day: false, + transportation: 'car' + } } - + assert_response :success end - test "should get new" do + test 'should get new' do get new_signup_url assert_response :success end diff --git a/test/controllers/status_controller_test.rb b/test/controllers/status_controller_test.rb index 59e6c8c..b278850 100644 --- a/test/controllers/status_controller_test.rb +++ b/test/controllers/status_controller_test.rb @@ -1,10 +1,12 @@ -require "test_helper" -require "passwordless_test_helper" +# frozen_string_literal: true + +require 'test_helper' +require 'passwordless_test_helper' class StatusControllerTest < ActionDispatch::IntegrationTest include PasswordlessTestHelper - test "should get show" do + test 'should get show' do person = people(:one) sign_in(person, scope: :person) get person_root_url diff --git a/test/mailers/previews/passwordless_mailer_preview.rb b/test/mailers/previews/passwordless_mailer_preview.rb index 02ffa65..97a4da1 100644 --- a/test/mailers/previews/passwordless_mailer_preview.rb +++ b/test/mailers/previews/passwordless_mailer_preview.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class PasswordlessMailerPreview < ActionMailer::Preview def magic_link Passwordless::Mailer.magic_link( diff --git a/test/models/animal_application_test.rb b/test/models/animal_application_test.rb index fbc674c..dd6ceb6 100644 --- a/test/models/animal_application_test.rb +++ b/test/models/animal_application_test.rb @@ -1,4 +1,6 @@ -require "test_helper" +# frozen_string_literal: true + +require 'test_helper' class AnimalApplicationTest < ActiveSupport::TestCase test 'valid application' do diff --git a/test/models/dog_test.rb b/test/models/dog_test.rb index 7005f71..8870fc3 100644 --- a/test/models/dog_test.rb +++ b/test/models/dog_test.rb @@ -1,7 +1,9 @@ -require "test_helper" +# frozen_string_literal: true + +require 'test_helper' class DogTest < ActiveSupport::TestCase context 'validations' do should validate_presence_of(:name) - end + end end diff --git a/test/models/foster_home_test.rb b/test/models/foster_home_test.rb index 2c643c5..7b92915 100644 --- a/test/models/foster_home_test.rb +++ b/test/models/foster_home_test.rb @@ -1,4 +1,6 @@ -require "test_helper" +# frozen_string_literal: true + +require 'test_helper' class FosterHomeTest < ActiveSupport::TestCase # test "the truth" do diff --git a/test/models/home_test.rb b/test/models/home_test.rb index 476451e..206289a 100644 --- a/test/models/home_test.rb +++ b/test/models/home_test.rb @@ -1,4 +1,6 @@ -require "test_helper" +# frozen_string_literal: true + +require 'test_helper' class HomeTest < ActiveSupport::TestCase test 'valid home has person_id' do @@ -10,7 +12,7 @@ class HomeTest < ActiveSupport::TestCase end test 'defaults all attrs to false' do - home = Home.new({ home_type: "House" }) + home = Home.new({ home_type: 'House' }) assert home.valid? end @@ -21,7 +23,7 @@ def create_home_attributes(opts = {}) has_other_adults: opts[:has_other_adults] || false, has_other_dog: opts[:has_other_dog] || false, has_other_cat: opts[:has_other_cat] || false, - home_type: opts[:home_type] || "House", + home_type: opts[:home_type] || 'House' } end end diff --git a/test/models/person_home_test.rb b/test/models/person_home_test.rb index d56a01a..42a4afc 100644 --- a/test/models/person_home_test.rb +++ b/test/models/person_home_test.rb @@ -1,4 +1,6 @@ -require "test_helper" +# frozen_string_literal: true + +require 'test_helper' class PersonHomeTest < ActiveSupport::TestCase # test "the truth" do diff --git a/test/models/person_test.rb b/test/models/person_test.rb index c11bdf8..098a249 100644 --- a/test/models/person_test.rb +++ b/test/models/person_test.rb @@ -1,4 +1,6 @@ -require "test_helper" +# frozen_string_literal: true + +require 'test_helper' class PersonTest < ActiveSupport::TestCase def setup @@ -8,7 +10,7 @@ def setup phone: '4017825678', is_home_during_day: true, transportation: :access_to_car, - available_from: 5.days.from_now, + available_from: 5.days.from_now } end @@ -27,14 +29,14 @@ def setup assert_equal person.phone, '4017825678' end - test "a person can be rejected for bad entries" do + test 'a person can be rejected for bad entries' do bad_parameters = @valid_parameters bad_parameters['phone'] = '401-789-4567asdf' - bad_person_1 = Person.new(bad_parameters) + bad_person1 = Person.new(bad_parameters) bad_parameters['phone'] = 'ruby for bad' - bad_person_2 = Person.new(bad_parameters) + bad_person2 = Person.new(bad_parameters) - assert bad_person_1.invalid? - assert bad_person_2.invalid? + assert bad_person1.invalid? + assert bad_person2.invalid? end end diff --git a/test/models/role_test.rb b/test/models/role_test.rb index 5e1a9ae..d653142 100644 --- a/test/models/role_test.rb +++ b/test/models/role_test.rb @@ -1,4 +1,6 @@ -require "test_helper" +# frozen_string_literal: true + +require 'test_helper' class RoleTest < ActiveSupport::TestCase # test "the truth" do diff --git a/test/passwordless_test_helper.rb b/test/passwordless_test_helper.rb index bc6de15..f83ad5d 100644 --- a/test/passwordless_test_helper.rb +++ b/test/passwordless_test_helper.rb @@ -1,10 +1,12 @@ +# frozen_string_literal: true + module PasswordlessTestHelper - def sign_in(resource, scope: nil) + def sign_in(resource, _scope) session = Passwordless::Session.new({ - authenticatable: resource, - user_agent: 'Integration Test', - remote_addr: 'unknown', - }) + authenticatable: resource, + user_agent: 'Integration Test', + remote_addr: 'unknown' + }) session.save! end end diff --git a/test/system/animal_applications_test.rb b/test/system/animal_applications_test.rb index a45507a..9b67de3 100644 --- a/test/system/animal_applications_test.rb +++ b/test/system/animal_applications_test.rb @@ -1,24 +1,26 @@ -require "application_system_test_case" +# frozen_string_literal: true + +require 'application_system_test_case' class AnimalApplicationsTest < ApplicationSystemTestCase setup do @animal_application = animal_applications(:one) end - test "visiting the index" do + test 'visiting the index' do visit animal_applications_url - assert_selector "h1", text: "Animal application" + assert_selector 'h1', text: 'Animal application' end - test "should create Animal application" do + test 'should create Animal application' do visit animal_applications_url - click_on "New Animal application" + click_on 'New Animal application' - fill_in "inspiration", with: "pls approve me" - fill_in "start_date", with: "2021-09-20" - click_on "Create Animal application" + fill_in 'inspiration', with: 'pls approve me' + fill_in 'start_date', with: '2021-09-20' + click_on 'Create Animal application' - assert_text "Animal application was successfully created" - click_on "Back" + assert_text 'Animal application was successfully created' + click_on 'Back' end end diff --git a/test/system/homes_test.rb b/test/system/homes_test.rb index 6d2c320..8c21e7e 100644 --- a/test/system/homes_test.rb +++ b/test/system/homes_test.rb @@ -1,12 +1,14 @@ -require "application_system_test_case" +# frozen_string_literal: true + +require 'application_system_test_case' class HomesTest < ApplicationSystemTestCase setup do @home = homes(:one) end - test "visiting the index" do + test 'visiting the index' do visit homes_url - assert_selector "h1", text: "Home" + assert_selector 'h1', text: 'Home' end end diff --git a/test/system/people_test.rb b/test/system/people_test.rb index 6f71601..f1c0acc 100644 --- a/test/system/people_test.rb +++ b/test/system/people_test.rb @@ -1,22 +1,24 @@ -require "application_system_test_case" +# frozen_string_literal: true + +require 'application_system_test_case' class PeopleTest < ApplicationSystemTestCase - test "signing up" do + test 'signing up' do visit new_signup_url - assert_selector "h1", text: "Foster Application" - assert_selector "label", text: "Email" - assert_selector "label", text: "Phone" - assert_selector "div", text: "Are you or another adult home during the day?" + assert_selector 'h1', text: 'Foster Application' + assert_selector 'label', text: 'Email' + assert_selector 'label', text: 'Phone' + assert_selector 'div', text: 'Are you or another adult home during the day?' - fill_in "Name", with: "Cookie Monster" - fill_in "Email", with: "peter@github.com" - fill_in "Street", with: "123 Sesame Street" - fill_in "City", with: "Chicago" - fill_in "State", with: "Illinois" - fill_in "Zip", with: "12345" - fill_in "Apartment", with: "Unit A" - fill_in "Phone", with: "401-791-7482" + fill_in 'Name', with: 'Cookie Monster' + fill_in 'Email', with: 'peter@github.com' + fill_in 'Street', with: '123 Sesame Street' + fill_in 'City', with: 'Chicago' + fill_in 'State', with: 'Illinois' + fill_in 'Zip', with: '12345' + fill_in 'Apartment', with: 'Unit A' + fill_in 'Phone', with: '401-791-7482' # --- Capybara does not wait here! fenced_yard_checkbox = find("input[value='has_fenced_yard']", visible: false) @@ -26,8 +28,8 @@ class PeopleTest < ApplicationSystemTestCase children_checkbox.click assert children_checkbox.checked? - find("#person_home_type", visible: false) - select "House", from: "home_type" + find('#person_home_type', visible: false) + select 'House', from: 'home_type' find("#person_is_home_during_day input[value='1']", visible: false).click @@ -36,21 +38,21 @@ class PeopleTest < ApplicationSystemTestCase find("#person_animal_age_preferences_attributes input[value='1']", visible: false).click find("#person_animal_size_preferences_attributes input[value='1']", visible: false).click - find("#person_transportation", visible: false) - select("Car", from: "transportation") - - find("#person_available_from").click - find(".ant-picker-today-btn").click + find('#person_transportation', visible: false) + select('Car', from: 'transportation') + + find('#person_available_from').click + find('.ant-picker-today-btn').click - click_on "Submit" + click_on 'Submit' sleep 1 - assert_selector("div", text: "Successfully Submitted") + assert_selector('div', text: 'Successfully Submitted') mail = ActionMailer::Base.deliveries.last body = Nokogiri::HTML(mail.body.raw_source) - assert_equal "peter@github.com", mail.to.first - assert_match /your login link/, body.to_s + assert_equal 'peter@github.com', mail.to.first + assert_match(/your login link/, body.to_s) end end diff --git a/test/test_helper.rb b/test/test_helper.rb index dbed9c4..ad1e418 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,22 +1,26 @@ -ENV["RAILS_ENV"] ||= "test" -require_relative "../config/environment" -require "rails/test_help" -require "webdrivers" +# frozen_string_literal: true -class ActiveSupport::TestCase - # Run tests in parallel with specified workers - parallelize(workers: :number_of_processors) +ENV['RAILS_ENV'] ||= 'test' +require_relative '../config/environment' +require 'rails/test_help' +require 'webdrivers' - # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. - fixtures :all +module ActiveSupport + class TestCase + # Run tests in parallel with specified workers + parallelize(workers: :number_of_processors) - # Add more helper methods to be used by all tests here... + # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. + fixtures :all - # Configuration for shoulda-matcher gem - Shoulda::Matchers.configure do |config| - config.integrate do |with| - with.test_framework :minitest - with.library :rails + # Add more helper methods to be used by all tests here... + + # Configuration for shoulda-matcher gem + Shoulda::Matchers.configure do |config| + config.integrate do |with| + with.test_framework :minitest + with.library :rails + end end end end