diff --git a/rails_root/.simplecov b/rails_root/.simplecov index e873109..d3fd032 100644 --- a/rails_root/.simplecov +++ b/rails_root/.simplecov @@ -1,3 +1,5 @@ +# frozen_string_literal: true + SimpleCov.start 'rails' do enable_coverage :branch # see https://github.com/colszowka/simplecov#branch-coverage-ruby--25 -end \ No newline at end of file +end diff --git a/rails_root/Gemfile b/rails_root/Gemfile index 134ec12..79bdf44 100644 --- a/rails_root/Gemfile +++ b/rails_root/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' ruby '3.3.0' diff --git a/rails_root/Rakefile b/rails_root/Rakefile index e85f913..488c551 100644 --- a/rails_root/Rakefile +++ b/rails_root/Rakefile @@ -1,3 +1,5 @@ +# 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. diff --git a/rails_root/app/channels/application_cable/channel.rb b/rails_root/app/channels/application_cable/channel.rb index d672697..9aec230 100644 --- a/rails_root/app/channels/application_cable/channel.rb +++ b/rails_root/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/rails_root/app/channels/application_cable/connection.rb b/rails_root/app/channels/application_cable/connection.rb index 0ff5442..8d6c2a1 100644 --- a/rails_root/app/channels/application_cable/connection.rb +++ b/rails_root/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/rails_root/app/controllers/application_controller.rb b/rails_root/app/controllers/application_controller.rb index 09705d1..7944f9f 100644 --- a/rails_root/app/controllers/application_controller.rb +++ b/rails_root/app/controllers/application_controller.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + class ApplicationController < ActionController::Base end diff --git a/rails_root/app/controllers/survey_profiles_controller.rb b/rails_root/app/controllers/survey_profiles_controller.rb index 93ef582..b30fb1e 100644 --- a/rails_root/app/controllers/survey_profiles_controller.rb +++ b/rails_root/app/controllers/survey_profiles_controller.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + class SurveyProfilesController < ApplicationController - before_action :set_survey_profile, only: %i[ show edit update destroy ] + before_action :set_survey_profile, only: %i[show edit update destroy] # GET /survey_profiles or /survey_profiles.json def index @@ -7,8 +9,7 @@ def index end # GET /survey_profiles/1 or /survey_profiles/1.json - def show - end + def show; end # GET /survey_profiles/new def new @@ -16,8 +17,7 @@ def new end # GET /survey_profiles/1/edit - def edit - end + def edit; end # POST /survey_profiles or /survey_profiles.json def create @@ -25,7 +25,9 @@ def create respond_to do |format| if @survey_profile.save - format.html { redirect_to survey_profile_url(@survey_profile), notice: "Survey profile was successfully created." } + format.html do + redirect_to survey_profile_url(@survey_profile), notice: 'Survey profile was successfully created.' + end format.json { render :show, status: :created, location: @survey_profile } else format.html { render :new, status: :unprocessable_entity } @@ -38,7 +40,9 @@ def create def update respond_to do |format| if @survey_profile.update(survey_profile_params) - format.html { redirect_to survey_profile_url(@survey_profile), notice: "Survey profile was successfully updated." } + format.html do + redirect_to survey_profile_url(@survey_profile), notice: 'Survey profile was successfully updated.' + end format.json { render :show, status: :ok, location: @survey_profile } else format.html { render :edit, status: :unprocessable_entity } @@ -52,19 +56,20 @@ def destroy @survey_profile.destroy! respond_to do |format| - format.html { redirect_to survey_profiles_url, notice: "Survey profile was successfully destroyed." } + format.html { redirect_to survey_profiles_url, notice: 'Survey profile was successfully destroyed.' } format.json { head :no_content } end end private - # Use callbacks to share common setup or constraints between actions. - def set_survey_profile - @survey_profile = SurveyProfile.find(params[:id]) - end - # Only allow a list of trusted parameters through. - def survey_profile_params - params.require(:survey_profile).permit(:user_id, :first_name, :last_name, :campus_name, :district_name) - end + # Use callbacks to share common setup or constraints between actions. + def set_survey_profile + @survey_profile = SurveyProfile.find(params[:id]) + end + + # Only allow a list of trusted parameters through. + def survey_profile_params + params.require(:survey_profile).permit(:user_id, :first_name, :last_name, :campus_name, :district_name) + end end diff --git a/rails_root/app/controllers/survey_responses_controller.rb b/rails_root/app/controllers/survey_responses_controller.rb index 2c1b1e9..3e83bc4 100644 --- a/rails_root/app/controllers/survey_responses_controller.rb +++ b/rails_root/app/controllers/survey_responses_controller.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + class SurveyResponsesController < ApplicationController - before_action :set_survey_response, only: %i[ show edit update destroy ] + before_action :set_survey_response, only: %i[show edit update destroy] # GET /survey_responses or /survey_responses.json def index @@ -7,8 +9,7 @@ def index end # GET /survey_responses/1 or /survey_responses/1.json - def show - end + def show; end # GET /survey_responses/new def new @@ -16,33 +17,50 @@ def new end # GET /survey_responses/1/edit - def edit - end + def edit; end # POST /survey_responses or /survey_responses.json def create - @survey_response = SurveyResponse.new(survey_response_params) + if survey_response_params.values.any?(&:nil?) + respond_to do |format| + format.html do + redirect_to new_survey_response_url, notice: 'invalid form', status: :unprocessable_entity + end + format.json { render json: { error: 'invalid form' }, status: :unprocessable_entity } + end + else + @survey_response = SurveyResponse.new(survey_response_params) - respond_to do |format| - if @survey_response.save - format.html { redirect_to survey_response_url(@survey_response), notice: "Survey response was successfully created." } - format.json { render :show, status: :created, location: @survey_response } - else - format.html { render :new, status: :unprocessable_entity } - format.json { render json: @survey_response.errors, status: :unprocessable_entity } + respond_to do |format| + if @survey_response.save + format.html do + redirect_to survey_response_url(@survey_response), notice: 'Survey response was successfully created.' + end + format.json { render :show, status: :created, location: @survey_response } + + end end end end # PATCH/PUT /survey_responses/1 or /survey_responses/1.json def update - respond_to do |format| - if @survey_response.update(survey_response_params) - format.html { redirect_to survey_response_url(@survey_response), notice: "Survey response was successfully updated." } - format.json { render :show, status: :ok, location: @survey_response } - else - format.html { render :edit, status: :unprocessable_entity } - format.json { render json: @survey_response.errors, status: :unprocessable_entity } + if survey_response_params.values.any?(&:nil?) + respond_to do |format| + format.html do + redirect_to edit_survey_response_url(@survey_response), notice: 'invalid form', status: :unprocessable_entity + end + format.json { render json: { error: 'invalid form' }, status: :unprocessable_entity } + end + else + respond_to do |format| + if @survey_response.update(survey_response_params) + format.html do + redirect_to survey_response_url(@survey_response), notice: 'Survey response was successfully updated.' + end + format.json { render :show, status: :ok, location: @survey_response } + + end end end end @@ -52,19 +70,21 @@ def destroy @survey_response.destroy! respond_to do |format| - format.html { redirect_to survey_responses_url, notice: "Survey response was successfully destroyed." } + format.html { redirect_to survey_responses_url, notice: 'Survey response was successfully destroyed.' } format.json { head :no_content } end end private - # Use callbacks to share common setup or constraints between actions. - def set_survey_response - @survey_response = SurveyResponse.find(params[:id]) - end - # Only allow a list of trusted parameters through. - def survey_response_params - params.require(:survey_response).permit(:user_id, :leads_by_example, :ability_to_juggle, :communicator, :lifelong_learner, :high_expectations, :cooperative, :empathetic, :people_oriented) - end + # Use callbacks to share common setup or constraints between actions. + def set_survey_response + @survey_response = SurveyResponse.find(params[:id]) + end + + # Only allow a list of trusted parameters through. + def survey_response_params + params.require(:survey_response).permit(:user_id, :leads_by_example, :ability_to_juggle, :communicator, + :lifelong_learner, :high_expectations, :cooperative, :empathetic, :people_oriented) + end end diff --git a/rails_root/app/helpers/application_helper.rb b/rails_root/app/helpers/application_helper.rb index de6be79..15b06f0 100644 --- a/rails_root/app/helpers/application_helper.rb +++ b/rails_root/app/helpers/application_helper.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + module ApplicationHelper end diff --git a/rails_root/app/helpers/survey_profiles_helper.rb b/rails_root/app/helpers/survey_profiles_helper.rb index 0e48fa9..22efde9 100644 --- a/rails_root/app/helpers/survey_profiles_helper.rb +++ b/rails_root/app/helpers/survey_profiles_helper.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + module SurveyProfilesHelper end diff --git a/rails_root/app/helpers/survey_responses_helper.rb b/rails_root/app/helpers/survey_responses_helper.rb index 6851b09..5d78163 100644 --- a/rails_root/app/helpers/survey_responses_helper.rb +++ b/rails_root/app/helpers/survey_responses_helper.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + module SurveyResponsesHelper end diff --git a/rails_root/app/jobs/application_job.rb b/rails_root/app/jobs/application_job.rb index d394c3d..bef3959 100644 --- a/rails_root/app/jobs/application_job.rb +++ b/rails_root/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/rails_root/app/mailers/application_mailer.rb b/rails_root/app/mailers/application_mailer.rb index 3c34c81..d84cb6e 100644 --- a/rails_root/app/mailers/application_mailer.rb +++ b/rails_root/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/rails_root/app/models/application_record.rb b/rails_root/app/models/application_record.rb index b63caeb..08dc537 100644 --- a/rails_root/app/models/application_record.rb +++ b/rails_root/app/models/application_record.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ApplicationRecord < ActiveRecord::Base primary_abstract_class end diff --git a/rails_root/app/models/survey_profile.rb b/rails_root/app/models/survey_profile.rb index 4294b02..6cfd0e0 100644 --- a/rails_root/app/models/survey_profile.rb +++ b/rails_root/app/models/survey_profile.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + class SurveyProfile < ApplicationRecord end diff --git a/rails_root/app/models/survey_response.rb b/rails_root/app/models/survey_response.rb index 2ecb50b..a8352b9 100644 --- a/rails_root/app/models/survey_response.rb +++ b/rails_root/app/models/survey_response.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + class SurveyResponse < ApplicationRecord end diff --git a/rails_root/app/views/survey_profiles/_survey_profile.json.jbuilder b/rails_root/app/views/survey_profiles/_survey_profile.json.jbuilder index d3f9ac6..3e74a32 100644 --- a/rails_root/app/views/survey_profiles/_survey_profile.json.jbuilder +++ b/rails_root/app/views/survey_profiles/_survey_profile.json.jbuilder @@ -1,2 +1,5 @@ -json.extract! survey_profile, :id, :user_id, :first_name, :last_name, :campus_name, :district_name, :created_at, :updated_at +# frozen_string_literal: true + +json.extract! survey_profile, :id, :user_id, :first_name, :last_name, :campus_name, :district_name, :created_at, + :updated_at json.url survey_profile_url(survey_profile, format: :json) diff --git a/rails_root/app/views/survey_profiles/index.json.jbuilder b/rails_root/app/views/survey_profiles/index.json.jbuilder index 89e553a..be7dbdb 100644 --- a/rails_root/app/views/survey_profiles/index.json.jbuilder +++ b/rails_root/app/views/survey_profiles/index.json.jbuilder @@ -1 +1,3 @@ -json.array! @survey_profiles, partial: "survey_profiles/survey_profile", as: :survey_profile +# frozen_string_literal: true + +json.array! @survey_profiles, partial: 'survey_profiles/survey_profile', as: :survey_profile diff --git a/rails_root/app/views/survey_profiles/show.json.jbuilder b/rails_root/app/views/survey_profiles/show.json.jbuilder index 0f7d56e..de51ac5 100644 --- a/rails_root/app/views/survey_profiles/show.json.jbuilder +++ b/rails_root/app/views/survey_profiles/show.json.jbuilder @@ -1 +1,3 @@ -json.partial! "survey_profiles/survey_profile", survey_profile: @survey_profile +# frozen_string_literal: true + +json.partial! 'survey_profiles/survey_profile', survey_profile: @survey_profile diff --git a/rails_root/app/views/survey_responses/_survey_response.json.jbuilder b/rails_root/app/views/survey_responses/_survey_response.json.jbuilder index 004497a..a69dba0 100644 --- a/rails_root/app/views/survey_responses/_survey_response.json.jbuilder +++ b/rails_root/app/views/survey_responses/_survey_response.json.jbuilder @@ -1,2 +1,5 @@ -json.extract! survey_response, :id, :user_id, :leads_by_example, :ability_to_juggle, :communicator, :lifelong_learner, :high_expectations, :cooperative, :empathetic, :people_oriented, :created_at, :updated_at +# frozen_string_literal: true + +json.extract! survey_response, :id, :user_id, :leads_by_example, :ability_to_juggle, :communicator, :lifelong_learner, + :high_expectations, :cooperative, :empathetic, :people_oriented, :created_at, :updated_at json.url survey_response_url(survey_response, format: :json) diff --git a/rails_root/app/views/survey_responses/index.json.jbuilder b/rails_root/app/views/survey_responses/index.json.jbuilder index 4d37b3f..af61667 100644 --- a/rails_root/app/views/survey_responses/index.json.jbuilder +++ b/rails_root/app/views/survey_responses/index.json.jbuilder @@ -1 +1,3 @@ -json.array! @survey_responses, partial: "survey_responses/survey_response", as: :survey_response +# frozen_string_literal: true + +json.array! @survey_responses, partial: 'survey_responses/survey_response', as: :survey_response diff --git a/rails_root/app/views/survey_responses/show.json.jbuilder b/rails_root/app/views/survey_responses/show.json.jbuilder index 97367ba..f151762 100644 --- a/rails_root/app/views/survey_responses/show.json.jbuilder +++ b/rails_root/app/views/survey_responses/show.json.jbuilder @@ -1 +1,3 @@ -json.partial! "survey_responses/survey_response", survey_response: @survey_response +# frozen_string_literal: true + +json.partial! 'survey_responses/survey_response', survey_response: @survey_response diff --git a/rails_root/bin/bundle b/rails_root/bin/bundle index 50da5fd..ef688ec 100755 --- a/rails_root/bin/bundle +++ b/rails_root/bin/bundle @@ -8,46 +8,46 @@ # this file is here to facilitate running it. # -require "rubygems" +require 'rubygems' m = Module.new do module_function def invoked_as_script? - File.expand_path($0) == File.expand_path(__FILE__) + File.expand_path($PROGRAM_NAME) == File.expand_path(__FILE__) end def env_var_version - ENV["BUNDLER_VERSION"] + ENV['BUNDLER_VERSION'] end def cli_arg_version return unless invoked_as_script? # don't want to hijack other binstubs - return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update` + return unless 'update'.start_with?(ARGV.first || ' ') # must be running `bundle update` + bundler_version = nil update_index = nil ARGV.each_with_index do |a, i| - if update_index && update_index.succ == i && a.match?(Gem::Version::ANCHORED_VERSION_PATTERN) - bundler_version = a - end + bundler_version = a if update_index && update_index.succ == i && a.match?(Gem::Version::ANCHORED_VERSION_PATTERN) next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/ - bundler_version = $1 + + bundler_version = Regexp.last_match(1) update_index = i end bundler_version end def gemfile - gemfile = ENV["BUNDLE_GEMFILE"] + gemfile = ENV['BUNDLE_GEMFILE'] return gemfile if gemfile && !gemfile.empty? - File.expand_path("../Gemfile", __dir__) + File.expand_path('../Gemfile', __dir__) end def lockfile lockfile = case File.basename(gemfile) - when "gems.rb" then gemfile.sub(/\.rb$/, ".locked") + when 'gems.rb' then gemfile.sub(/\.rb$/, '.locked') else "#{gemfile}.lock" end File.expand_path(lockfile) @@ -55,8 +55,10 @@ m = Module.new do def lockfile_version return unless File.file?(lockfile) + lockfile_contents = File.read(lockfile) return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/ + Regexp.last_match(1) end @@ -76,20 +78,24 @@ m = Module.new do end def load_bundler! - ENV["BUNDLE_GEMFILE"] ||= gemfile + ENV['BUNDLE_GEMFILE'] ||= gemfile activate_bundler end def activate_bundler gem_error = activation_error_handling do - gem "bundler", bundler_requirement + gem 'bundler', bundler_requirement end return if gem_error.nil? + require_error = activation_error_handling do - require "bundler/version" + require 'bundler/version' + end + if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION)) + return end - return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION)) + warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`" exit 42 end @@ -104,6 +110,4 @@ end m.load_bundler! -if m.invoked_as_script? - load Gem.bin_path("bundler", "bundle") -end +load Gem.bin_path('bundler', 'bundle') if m.invoked_as_script? diff --git a/rails_root/bin/importmap b/rails_root/bin/importmap index 36502ab..d423864 100755 --- a/rails_root/bin/importmap +++ b/rails_root/bin/importmap @@ -1,4 +1,5 @@ #!/usr/bin/env ruby +# frozen_string_literal: true -require_relative "../config/application" -require "importmap/commands" +require_relative '../config/application' +require 'importmap/commands' diff --git a/rails_root/bin/rails b/rails_root/bin/rails index efc0377..a31728a 100755 --- a/rails_root/bin/rails +++ b/rails_root/bin/rails @@ -1,4 +1,6 @@ #!/usr/bin/env ruby -APP_PATH = File.expand_path("../config/application", __dir__) -require_relative "../config/boot" -require "rails/commands" +# frozen_string_literal: true + +APP_PATH = File.expand_path('../config/application', __dir__) +require_relative '../config/boot' +require 'rails/commands' diff --git a/rails_root/bin/rake b/rails_root/bin/rake index 4fbf10b..c199955 100755 --- a/rails_root/bin/rake +++ b/rails_root/bin/rake @@ -1,4 +1,6 @@ #!/usr/bin/env ruby -require_relative "../config/boot" -require "rake" +# frozen_string_literal: true + +require_relative '../config/boot' +require 'rake' Rake.application.run diff --git a/rails_root/bin/setup b/rails_root/bin/setup index 3cd5a9d..3a74034 100755 --- a/rails_root/bin/setup +++ b/rails_root/bin/setup @@ -1,8 +1,10 @@ #!/usr/bin/env ruby -require "fileutils" +# frozen_string_literal: true + +require 'fileutils' # path to your application root. -APP_ROOT = File.expand_path("..", __dir__) +APP_ROOT = File.expand_path('..', __dir__) def system!(*args) system(*args, exception: true) @@ -13,9 +15,9 @@ FileUtils.chdir APP_ROOT do # This script is idempotent, so that you can run it at any time and get an expectable outcome. # Add necessary setup steps to this file. - puts "== Installing dependencies ==" - system! "gem install bundler --conservative" - system("bundle check") || system!("bundle install") + puts '== Installing dependencies ==' + system! 'gem install bundler --conservative' + system('bundle check') || system!('bundle install') # puts "\n== Copying sample files ==" # unless File.exist?("config/database.yml") @@ -23,11 +25,11 @@ FileUtils.chdir APP_ROOT do # end puts "\n== Preparing database ==" - system! "bin/rails db:prepare" + system! 'bin/rails db:prepare' puts "\n== Removing old logs and tempfiles ==" - system! "bin/rails log:clear tmp:clear" + system! 'bin/rails log:clear tmp:clear' puts "\n== Restarting application server ==" - system! "bin/rails restart" + system! 'bin/rails restart' end diff --git a/rails_root/config.ru b/rails_root/config.ru index 4a3c09a..6dc8321 100644 --- a/rails_root/config.ru +++ b/rails_root/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/rails_root/config/application.rb b/rails_root/config/application.rb index 876cdf6..c88afa4 100644 --- a/rails_root/config/application.rb +++ b/rails_root/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. @@ -14,7 +16,7 @@ class Application < Rails::Application # Please, add to the `ignore` list any other `lib` subdirectories that do # not contain `.rb` files, or that should not be reloaded or eager loaded. # Common ones are `templates`, `generators`, or `middleware`, for example. - config.autoload_lib(ignore: %w(assets tasks)) + config.autoload_lib(ignore: %w[assets tasks]) # Configuration for the application, engines, and railties goes here. # diff --git a/rails_root/config/boot.rb b/rails_root/config/boot.rb index 988a5dd..c04863f 100644 --- a/rails_root/config/boot.rb +++ b/rails_root/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/rails_root/config/environment.rb b/rails_root/config/environment.rb index cac5315..d5abe55 100644 --- a/rails_root/config/environment.rb +++ b/rails_root/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/rails_root/config/environments/development.rb b/rails_root/config/environments/development.rb index f4a7fc5..a4d83a5 100644 --- a/rails_root/config/environments/development.rb +++ b/rails_root/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 # Configure 'rails notes' to inspect Cucumber files @@ -23,13 +25,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 diff --git a/rails_root/config/environments/production.rb b/rails_root/config/environments/production.rb index 100a25c..f26af9e 100644 --- a/rails_root/config/environments/production.rb +++ b/rails_root/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. @@ -52,17 +54,17 @@ config.force_ssl = true # Log to STDOUT by default - config.logger = ActiveSupport::Logger.new(STDOUT) - .tap { |logger| logger.formatter = ::Logger::Formatter.new } - .then { |logger| ActiveSupport::TaggedLogging.new(logger) } + config.logger = ActiveSupport::Logger.new($stdout) + .tap { |logger| logger.formatter = ::Logger::Formatter.new } + .then { |logger| ActiveSupport::TaggedLogging.new(logger) } # Prepend all log lines with the following tags. - config.log_tags = [ :request_id ] + config.log_tags = [:request_id] # "info" includes generic and useful information about system operation, but avoids logging too much # information to avoid inadvertent exposure of personally identifiable information (PII). If you # want to log everything, set the level to "debug". - config.log_level = ENV.fetch("RAILS_LOG_LEVEL", "info") + config.log_level = ENV.fetch('RAILS_LOG_LEVEL', 'info') # Use a different cache store in production. # config.cache_store = :mem_cache_store diff --git a/rails_root/config/environments/test.rb b/rails_root/config/environments/test.rb index fdf88c0..8228920 100644 --- a/rails_root/config/environments/test.rb +++ b/rails_root/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,12 +21,12 @@ # this is usually not necessary, and can slow down your test suite. However, it's # recommended that you enable it in continuous integration systems to ensure eager # loading is working properly before deploying your code. - config.eager_load = ENV["CI"].present? + config.eager_load = ENV['CI'].present? # 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/rails_root/config/importmap.rb b/rails_root/config/importmap.rb index 909dfc5..15fd627 100644 --- a/rails_root/config/importmap.rb +++ b/rails_root/config/importmap.rb @@ -1,7 +1,9 @@ +# frozen_string_literal: true + # Pin npm packages by running ./bin/importmap -pin "application" -pin "@hotwired/turbo-rails", to: "turbo.min.js" -pin "@hotwired/stimulus", to: "stimulus.min.js" -pin "@hotwired/stimulus-loading", to: "stimulus-loading.js" -pin_all_from "app/javascript/controllers", under: "controllers" +pin 'application' +pin '@hotwired/turbo-rails', to: 'turbo.min.js' +pin '@hotwired/stimulus', to: 'stimulus.min.js' +pin '@hotwired/stimulus-loading', to: 'stimulus-loading.js' +pin_all_from 'app/javascript/controllers', under: 'controllers' diff --git a/rails_root/config/initializers/assets.rb b/rails_root/config/initializers/assets.rb index 2eeef96..bcafccd 100644 --- a/rails_root/config/initializers/assets.rb +++ b/rails_root/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/rails_root/config/initializers/content_security_policy.rb b/rails_root/config/initializers/content_security_policy.rb index b3076b3..af395e4 100644 --- a/rails_root/config/initializers/content_security_policy.rb +++ b/rails_root/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/rails_root/config/initializers/filter_parameter_logging.rb b/rails_root/config/initializers/filter_parameter_logging.rb index c2d89e2..c416e6a 100644 --- a/rails_root/config/initializers/filter_parameter_logging.rb +++ b/rails_root/config/initializers/filter_parameter_logging.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Configure parameters to be partially matched (e.g. passw matches password) and filtered from the log file. # Use this to limit dissemination of sensitive information. # See the ActiveSupport::ParameterFilter documentation for supported notations and behaviors. -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/rails_root/config/initializers/inflections.rb b/rails_root/config/initializers/inflections.rb index 3860f65..6c78420 100644 --- a/rails_root/config/initializers/inflections.rb +++ b/rails_root/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/rails_root/config/initializers/permissions_policy.rb b/rails_root/config/initializers/permissions_policy.rb index 7db3b95..b635b52 100644 --- a/rails_root/config/initializers/permissions_policy.rb +++ b/rails_root/config/initializers/permissions_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 HTTP permissions policy. For further diff --git a/rails_root/config/puma.rb b/rails_root/config/puma.rb index afa809b..7ed4157 100644 --- a/rails_root/config/puma.rb +++ b/rails_root/config/puma.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This configuration file will be evaluated by Puma. The top-level methods that # are invoked here are part of Puma's configuration DSL. For more information # about methods provided by the DSL, see https://puma.io/puma/Puma/DSL.html. @@ -7,29 +9,29 @@ # 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 that the worker count should equal the number of processors in production. -if ENV["RAILS_ENV"] == "production" - require "concurrent-ruby" - worker_count = Integer(ENV.fetch("WEB_CONCURRENCY") { Concurrent.physical_processor_count }) +if ENV['RAILS_ENV'] == 'production' + require 'concurrent-ruby' + worker_count = Integer(ENV.fetch('WEB_CONCURRENCY') { Concurrent.physical_processor_count }) workers worker_count if worker_count > 1 end # 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') # Allow puma to be restarted by `bin/rails restart` command. plugin :tmp_restart diff --git a/rails_root/config/routes.rb b/rails_root/config/routes.rb index 5fd11fc..e47955f 100644 --- a/rails_root/config/routes.rb +++ b/rails_root/config/routes.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Rails.application.routes.draw do resources :survey_responses resources :survey_profiles @@ -5,7 +7,7 @@ # Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500. # Can be used by load balancers and uptime monitors to verify that the app is live. - get "up" => "rails/health#show", as: :rails_health_check + get 'up' => 'rails/health#show', as: :rails_health_check # Defines the root path route ("/") # root "posts#index" diff --git a/rails_root/db/migrate/20240213011213_create_survey_profiles.rb b/rails_root/db/migrate/20240213011213_create_survey_profiles.rb index 72ab414..f15941f 100644 --- a/rails_root/db/migrate/20240213011213_create_survey_profiles.rb +++ b/rails_root/db/migrate/20240213011213_create_survey_profiles.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateSurveyProfiles < ActiveRecord::Migration[7.1] def change create_table :survey_profiles do |t| diff --git a/rails_root/db/migrate/20240213012651_create_survey_responses.rb b/rails_root/db/migrate/20240213012651_create_survey_responses.rb index ac51c39..0482af9 100644 --- a/rails_root/db/migrate/20240213012651_create_survey_responses.rb +++ b/rails_root/db/migrate/20240213012651_create_survey_responses.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateSurveyResponses < ActiveRecord::Migration[7.1] def change create_table :survey_responses do |t| diff --git a/rails_root/db/schema.rb b/rails_root/db/schema.rb index edc73f1..00608d6 100644 --- a/rails_root/db/schema.rb +++ b/rails_root/db/schema.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. @@ -10,38 +12,38 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_02_13_012651) do - create_table "posts", force: :cascade do |t| - t.string "title" - t.text "body" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false +ActiveRecord::Schema[7.1] + .define(version: 20_240_213_012_651) do + create_table 'posts', force: :cascade do |t| + t.string 'title' + t.text 'body' + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false end - create_table "survey_profiles", force: :cascade do |t| - t.integer "user_id" - t.string "first_name" - t.string "last_name" - t.string "campus_name" - t.string "district_name" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["user_id"], name: "index_survey_profiles_on_user_id", unique: true + create_table 'survey_profiles', force: :cascade do |t| + t.integer 'user_id' + t.string 'first_name' + t.string 'last_name' + t.string 'campus_name' + t.string 'district_name' + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false + t.index ['user_id'], name: 'index_survey_profiles_on_user_id', unique: true end - create_table "survey_responses", force: :cascade do |t| - t.integer "user_id" - t.integer "leads_by_example" - t.integer "ability_to_juggle" - t.integer "communicator" - t.integer "lifelong_learner" - t.integer "high_expectations" - t.integer "cooperative" - t.integer "empathetic" - t.integer "people_oriented" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["user_id"], name: "index_survey_responses_on_user_id", unique: true + create_table 'survey_responses', force: :cascade do |t| + t.integer 'user_id' + t.integer 'leads_by_example' + t.integer 'ability_to_juggle' + t.integer 'communicator' + t.integer 'lifelong_learner' + t.integer 'high_expectations' + t.integer 'cooperative' + t.integer 'empathetic' + t.integer 'people_oriented' + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false + t.index ['user_id'], name: 'index_survey_responses_on_user_id', unique: true end - end diff --git a/rails_root/db/seeds.rb b/rails_root/db/seeds.rb index 0b132ac..992fe6e 100644 --- a/rails_root/db/seeds.rb +++ b/rails_root/db/seeds.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This file should ensure the existence of records required to run the application in every environment (production, # development, test). The code here should be idempotent so that it can be executed at any point in every environment. # The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup). diff --git a/rails_root/features/support/env.rb b/rails_root/features/support/env.rb index d0f3f89..e23cc1d 100644 --- a/rails_root/features/support/env.rb +++ b/rails_root/features/support/env.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Run simplecov before any tests to capture all test coverage require 'simplecov' require 'simplecov_json_formatter' diff --git a/rails_root/lib/tasks/cucumber.rake b/rails_root/lib/tasks/cucumber.rake index 0caa4d2..2874d92 100644 --- a/rails_root/lib/tasks/cucumber.rake +++ b/rails_root/lib/tasks/cucumber.rake @@ -1,69 +1,68 @@ +# frozen_string_literal: true + # IMPORTANT: This file is generated by cucumber-rails - edit at your own peril. # It is recommended to regenerate this file in the future when you upgrade to a # newer version of cucumber-rails. Consider adding your own code to a new file # instead of editing this one. Cucumber will automatically load all features/**/*.rb # files. +unless ARGV.any? { |a| a =~ /^gems/ } # Don't load anything when running the gems:* tasks + + vendored_cucumber_bin = Dir["#{Rails.root}/vendor/{gems,plugins}/cucumber*/bin/cucumber"].first + $LOAD_PATH.unshift("#{File.dirname(vendored_cucumber_bin)}/../lib") unless vendored_cucumber_bin.nil? + + begin + require 'cucumber/rake/task' + + namespace :cucumber do + Cucumber::Rake::Task.new({ ok: 'test:prepare' }, 'Run features that should pass') do |t| + t.binary = vendored_cucumber_bin # If nil, the gem's binary is used. + t.fork = true # You may get faster startup if you set this to false + t.profile = 'default' + end + + Cucumber::Rake::Task.new({ wip: 'test:prepare' }, 'Run features that are being worked on') do |t| + t.binary = vendored_cucumber_bin + t.fork = true # You may get faster startup if you set this to false + t.profile = 'wip' + end + + Cucumber::Rake::Task.new({ rerun: 'test:prepare' }, + 'Record failing features and run only them if any exist') do |t| + t.binary = vendored_cucumber_bin + t.fork = true # You may get faster startup if you set this to false + t.profile = 'rerun' + end + + desc 'Run all features' + task all: %i[ok wip] + + task :statsetup do + require 'rails/code_statistics' + ::STATS_DIRECTORIES << ['Cucumber features', 'features'] if File.exist?('features') + ::CodeStatistics::TEST_TYPES << 'Cucumber features' if File.exist?('features') + end + end -unless ARGV.any? {|a| a =~ /^gems/} # Don't load anything when running the gems:* tasks - -vendored_cucumber_bin = Dir["#{Rails.root}/vendor/{gems,plugins}/cucumber*/bin/cucumber"].first -$LOAD_PATH.unshift(File.dirname(vendored_cucumber_bin) + '/../lib') unless vendored_cucumber_bin.nil? - -begin - require 'cucumber/rake/task' + desc 'Alias for cucumber:ok' + task cucumber: 'cucumber:ok' - namespace :cucumber do - Cucumber::Rake::Task.new({ok: 'test:prepare'}, 'Run features that should pass') do |t| - t.binary = vendored_cucumber_bin # If nil, the gem's binary is used. - t.fork = true # You may get faster startup if you set this to false - t.profile = 'default' - end + task default: :cucumber - Cucumber::Rake::Task.new({wip: 'test:prepare'}, 'Run features that are being worked on') do |t| - t.binary = vendored_cucumber_bin - t.fork = true # You may get faster startup if you set this to false - t.profile = 'wip' + task features: :cucumber do + warn "*** The 'features' task is deprecated. See rake -T cucumber ***" end - Cucumber::Rake::Task.new({rerun: 'test:prepare'}, 'Record failing features and run only them if any exist') do |t| - t.binary = vendored_cucumber_bin - t.fork = true # You may get faster startup if you set this to false - t.profile = 'rerun' + # In case we don't have the generic Rails test:prepare hook, append a no-op task that we can depend upon. + task 'test:prepare' do end - desc 'Run all features' - task all: [:ok, :wip] - - task :statsetup do - require 'rails/code_statistics' - ::STATS_DIRECTORIES << %w(Cucumber\ features features) if File.exist?('features') - ::CodeStatistics::TEST_TYPES << "Cucumber features" if File.exist?('features') + task stats: 'cucumber:statsetup' + rescue LoadError + desc 'cucumber rake task not available (cucumber not installed)' + task :cucumber do + abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin' end - - end - - desc 'Alias for cucumber:ok' - task cucumber: 'cucumber:ok' - - task default: :cucumber - - task features: :cucumber do - STDERR.puts "*** The 'features' task is deprecated. See rake -T cucumber ***" - end - - # In case we don't have the generic Rails test:prepare hook, append a no-op task that we can depend upon. - task 'test:prepare' do end - task stats: 'cucumber:statsetup' - - -rescue LoadError - desc 'cucumber rake task not available (cucumber not installed)' - task :cucumber do - abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin' - end -end - end diff --git a/rails_root/spec/helpers/survey_profiles_helper_spec.rb b/rails_root/spec/helpers/survey_profiles_helper_spec.rb index d07349c..2cc9d6b 100644 --- a/rails_root/spec/helpers/survey_profiles_helper_spec.rb +++ b/rails_root/spec/helpers/survey_profiles_helper_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' # Specs in this file have access to a helper object that includes diff --git a/rails_root/spec/helpers/survey_responses_helper_spec.rb b/rails_root/spec/helpers/survey_responses_helper_spec.rb index f65fad1..8883c93 100644 --- a/rails_root/spec/helpers/survey_responses_helper_spec.rb +++ b/rails_root/spec/helpers/survey_responses_helper_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' # Specs in this file have access to a helper object that includes diff --git a/rails_root/spec/models/survey_profile_spec.rb b/rails_root/spec/models/survey_profile_spec.rb index a511bda..158de05 100644 --- a/rails_root/spec/models/survey_profile_spec.rb +++ b/rails_root/spec/models/survey_profile_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe SurveyProfile, type: :model do diff --git a/rails_root/spec/models/survey_response_spec.rb b/rails_root/spec/models/survey_response_spec.rb index 60b0e86..3e3d457 100644 --- a/rails_root/spec/models/survey_response_spec.rb +++ b/rails_root/spec/models/survey_response_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe SurveyResponse, type: :model do diff --git a/rails_root/spec/rails_helper.rb b/rails_root/spec/rails_helper.rb index a15455f..254658c 100644 --- a/rails_root/spec/rails_helper.rb +++ b/rails_root/spec/rails_helper.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + # This file is copied to spec/ when you run 'rails generate rspec:install' require 'spec_helper' ENV['RAILS_ENV'] ||= 'test' require_relative '../config/environment' # Prevent database truncation if the environment is production -abort("The Rails environment is running in production mode!") if Rails.env.production? +abort('The Rails environment is running in production mode!') if Rails.env.production? require 'rspec/rails' # Add additional requires below this line. Rails is not loaded until this point! diff --git a/rails_root/spec/requests/survey_profiles_spec.rb b/rails_root/spec/requests/survey_profiles_spec.rb index 436e520..d932f5d 100644 --- a/rails_root/spec/requests/survey_profiles_spec.rb +++ b/rails_root/spec/requests/survey_profiles_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' # This spec was generated by rspec-rails when you ran the scaffold generator. @@ -12,94 +14,107 @@ # of tools you can use to make these specs even more expressive, but we're # sticking to rails and rspec-rails APIs to keep things simple and stable. -RSpec.describe "/survey_profiles", type: :request do - +RSpec.describe '/survey_profiles', type: :request do # This should return the minimal set of attributes required to create a valid # SurveyProfile. As you add validations to SurveyProfile, be sure to # adjust the attributes here as well. - let(:valid_attributes) { - skip("Add a hash of attributes valid for your model") - } + let(:valid_attributes) do + # skip('Add a hash of attributes valid for your model') + + { + user_id: 1, + first_name: 'John', + last_name: 'Doe', + campus_name: 'Campus', + district_name: 'District' + } + end - let(:invalid_attributes) { - skip("Add a hash of attributes invalid for your model") - } + let(:invalid_attributes) do + skip('Add a hash of attributes invalid for your model') - describe "GET /index" do - it "renders a successful response" do + # { + # user_id: 1, + # first_name: nil, + # last_name: nil, + # campus_name: nil, + # district_name: nil + # } + end + + describe 'GET /index' do + it 'renders a successful response' do SurveyProfile.create! valid_attributes get survey_profiles_url expect(response).to be_successful end end - describe "GET /show" do - it "renders a successful response" do + describe 'GET /show' do + it 'renders a successful response' do survey_profile = SurveyProfile.create! valid_attributes get survey_profile_url(survey_profile) expect(response).to be_successful end end - describe "GET /new" do - it "renders a successful response" do + describe 'GET /new' do + it 'renders a successful response' do get new_survey_profile_url expect(response).to be_successful end end - describe "GET /edit" do - it "renders a successful response" do + describe 'GET /edit' do + it 'renders a successful response' do survey_profile = SurveyProfile.create! valid_attributes get edit_survey_profile_url(survey_profile) expect(response).to be_successful end end - describe "POST /create" do - context "with valid parameters" do - it "creates a new SurveyProfile" do - expect { + describe 'POST /create' do + context 'with valid parameters' do + it 'creates a new SurveyProfile' do + expect do post survey_profiles_url, params: { survey_profile: valid_attributes } - }.to change(SurveyProfile, :count).by(1) + end.to change(SurveyProfile, :count).by(1) end - it "redirects to the created survey_profile" do + it 'redirects to the created survey_profile' do post survey_profiles_url, params: { survey_profile: valid_attributes } expect(response).to redirect_to(survey_profile_url(SurveyProfile.last)) end end - context "with invalid parameters" do - it "does not create a new SurveyProfile" do - expect { + context 'with invalid parameters' do + it 'does not create a new SurveyProfile' do + expect do post survey_profiles_url, params: { survey_profile: invalid_attributes } - }.to change(SurveyProfile, :count).by(0) + end.to change(SurveyProfile, :count).by(0) end - it "renders a response with 422 status (i.e. to display the 'new' template)" do post survey_profiles_url, params: { survey_profile: invalid_attributes } expect(response).to have_http_status(:unprocessable_entity) end - end end - describe "PATCH /update" do - context "with valid parameters" do - let(:new_attributes) { - skip("Add a hash of attributes valid for your model") - } + describe 'PATCH /update' do + context 'with valid parameters' do + let(:new_attributes) do + skip('Add a hash of attributes valid for your model') + end - it "updates the requested survey_profile" do + it 'updates the requested survey_profile' do survey_profile = SurveyProfile.create! valid_attributes patch survey_profile_url(survey_profile), params: { survey_profile: new_attributes } survey_profile.reload - skip("Add assertions for updated state") + skip('Add assertions for updated state') end - it "redirects to the survey_profile" do + it 'redirects to the survey_profile' do survey_profile = SurveyProfile.create! valid_attributes patch survey_profile_url(survey_profile), params: { survey_profile: new_attributes } survey_profile.reload @@ -107,26 +122,24 @@ end end - context "with invalid parameters" do - + context 'with invalid parameters' do it "renders a response with 422 status (i.e. to display the 'edit' template)" do survey_profile = SurveyProfile.create! valid_attributes patch survey_profile_url(survey_profile), params: { survey_profile: invalid_attributes } expect(response).to have_http_status(:unprocessable_entity) end - end end - describe "DELETE /destroy" do - it "destroys the requested survey_profile" do + describe 'DELETE /destroy' do + it 'destroys the requested survey_profile' do survey_profile = SurveyProfile.create! valid_attributes - expect { + expect do delete survey_profile_url(survey_profile) - }.to change(SurveyProfile, :count).by(-1) + end.to change(SurveyProfile, :count).by(-1) end - it "redirects to the survey_profiles list" do + it 'redirects to the survey_profiles list' do survey_profile = SurveyProfile.create! valid_attributes delete survey_profile_url(survey_profile) expect(response).to redirect_to(survey_profiles_url) diff --git a/rails_root/spec/requests/survey_responses_spec.rb b/rails_root/spec/requests/survey_responses_spec.rb index d5d4d0d..480f602 100644 --- a/rails_root/spec/requests/survey_responses_spec.rb +++ b/rails_root/spec/requests/survey_responses_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' # This spec was generated by rspec-rails when you ran the scaffold generator. @@ -12,94 +14,119 @@ # of tools you can use to make these specs even more expressive, but we're # sticking to rails and rspec-rails APIs to keep things simple and stable. -RSpec.describe "/survey_responses", type: :request do - +RSpec.describe '/survey_responses', type: :request do # This should return the minimal set of attributes required to create a valid # SurveyResponse. As you add validations to SurveyResponse, be sure to # adjust the attributes here as well. - let(:valid_attributes) { - skip("Add a hash of attributes valid for your model") - } + let(:valid_attributes) do + # skip('Add a hash of attributes valid for your model') + { + user_id: 1, + leads_by_example: 1, + ability_to_juggle: 1, + communicator: 1, + lifelong_learner: 1, + high_expectations: 1, + cooperative: 1, + empathetic: 1, + people_oriented: 1 + } + end - let(:invalid_attributes) { - skip("Add a hash of attributes invalid for your model") - } + let(:invalid_attributes) do + # skip('Add a hash of attributes invalid for your model') + # any value in form is null + { + user_id: 1, + leads_by_example: 1, + ability_to_juggle: nil, + communicator: 1, + lifelong_learner: 1, + high_expectations: 1, + cooperative: 1, + empathetic: 1, + people_oriented: nil + } + end - describe "GET /index" do - it "renders a successful response" do + describe 'GET /index' do + it 'renders a successful response' do SurveyResponse.create! valid_attributes get survey_responses_url expect(response).to be_successful end end - describe "GET /show" do - it "renders a successful response" do + describe 'GET /show' do + it 'renders a successful response' do survey_response = SurveyResponse.create! valid_attributes get survey_response_url(survey_response) expect(response).to be_successful end end - describe "GET /new" do - it "renders a successful response" do + describe 'GET /new' do + it 'renders a successful response' do get new_survey_response_url expect(response).to be_successful end end - describe "GET /edit" do - it "renders a successful response" do + describe 'GET /edit' do + it 'renders a successful response' do survey_response = SurveyResponse.create! valid_attributes get edit_survey_response_url(survey_response) expect(response).to be_successful end end - describe "POST /create" do - context "with valid parameters" do - it "creates a new SurveyResponse" do - expect { + describe 'POST /create' do + context 'with valid parameters' do + it 'creates a new SurveyResponse' do + expect do post survey_responses_url, params: { survey_response: valid_attributes } - }.to change(SurveyResponse, :count).by(1) + end.to change(SurveyResponse, :count).by(1) end - it "redirects to the created survey_response" do + it 'redirects to the created survey_response' do post survey_responses_url, params: { survey_response: valid_attributes } expect(response).to redirect_to(survey_response_url(SurveyResponse.last)) end end - context "with invalid parameters" do - it "does not create a new SurveyResponse" do - expect { + context 'with invalid parameters' do + it 'does not create a new SurveyResponse' do + expect do post survey_responses_url, params: { survey_response: invalid_attributes } - }.to change(SurveyResponse, :count).by(0) + end.to_not change(SurveyResponse, :count) end - - it "renders a response with 422 status (i.e. to display the 'new' template)" do + it 'returns a failure response (i.e., to display the "new" template)' do post survey_responses_url, params: { survey_response: invalid_attributes } expect(response).to have_http_status(:unprocessable_entity) end - end end - describe "PATCH /update" do - context "with valid parameters" do - let(:new_attributes) { - skip("Add a hash of attributes valid for your model") - } + describe 'PATCH /update' do + context 'with valid parameters' do + let(:new_attributes) do + # skip('Add a hash of attributes valid for your model') + + { + leads_by_example: 5 + } + end - it "updates the requested survey_response" do + it 'updates the requested survey_response' do survey_response = SurveyResponse.create! valid_attributes patch survey_response_url(survey_response), params: { survey_response: new_attributes } survey_response.reload - skip("Add assertions for updated state") + # skip('Add assertions for updated state') + expect(survey_response.leads_by_example).to eq(5) end - it "redirects to the survey_response" do + it 'redirects to the survey_response' do survey_response = SurveyResponse.create! valid_attributes patch survey_response_url(survey_response), params: { survey_response: new_attributes } survey_response.reload @@ -107,26 +134,24 @@ end end - context "with invalid parameters" do - + context 'with invalid parameters' do it "renders a response with 422 status (i.e. to display the 'edit' template)" do survey_response = SurveyResponse.create! valid_attributes patch survey_response_url(survey_response), params: { survey_response: invalid_attributes } expect(response).to have_http_status(:unprocessable_entity) end - end end - describe "DELETE /destroy" do - it "destroys the requested survey_response" do + describe 'DELETE /destroy' do + it 'destroys the requested survey_response' do survey_response = SurveyResponse.create! valid_attributes - expect { + expect do delete survey_response_url(survey_response) - }.to change(SurveyResponse, :count).by(-1) + end.to change(SurveyResponse, :count).by(-1) end - it "redirects to the survey_responses list" do + it 'redirects to the survey_responses list' do survey_response = SurveyResponse.create! valid_attributes delete survey_response_url(survey_response) expect(response).to redirect_to(survey_responses_url) diff --git a/rails_root/spec/routing/survey_profiles_routing_spec.rb b/rails_root/spec/routing/survey_profiles_routing_spec.rb index bb4c8ce..4e817ca 100644 --- a/rails_root/spec/routing/survey_profiles_routing_spec.rb +++ b/rails_root/spec/routing/survey_profiles_routing_spec.rb @@ -1,38 +1,39 @@ -require "rails_helper" +# frozen_string_literal: true + +require 'rails_helper' RSpec.describe SurveyProfilesController, type: :routing do - describe "routing" do - it "routes to #index" do - expect(get: "/survey_profiles").to route_to("survey_profiles#index") + describe 'routing' do + it 'routes to #index' do + expect(get: '/survey_profiles').to route_to('survey_profiles#index') end - it "routes to #new" do - expect(get: "/survey_profiles/new").to route_to("survey_profiles#new") + it 'routes to #new' do + expect(get: '/survey_profiles/new').to route_to('survey_profiles#new') end - it "routes to #show" do - expect(get: "/survey_profiles/1").to route_to("survey_profiles#show", id: "1") + it 'routes to #show' do + expect(get: '/survey_profiles/1').to route_to('survey_profiles#show', id: '1') end - it "routes to #edit" do - expect(get: "/survey_profiles/1/edit").to route_to("survey_profiles#edit", id: "1") + it 'routes to #edit' do + expect(get: '/survey_profiles/1/edit').to route_to('survey_profiles#edit', id: '1') end - - it "routes to #create" do - expect(post: "/survey_profiles").to route_to("survey_profiles#create") + it 'routes to #create' do + expect(post: '/survey_profiles').to route_to('survey_profiles#create') end - it "routes to #update via PUT" do - expect(put: "/survey_profiles/1").to route_to("survey_profiles#update", id: "1") + it 'routes to #update via PUT' do + expect(put: '/survey_profiles/1').to route_to('survey_profiles#update', id: '1') end - it "routes to #update via PATCH" do - expect(patch: "/survey_profiles/1").to route_to("survey_profiles#update", id: "1") + it 'routes to #update via PATCH' do + expect(patch: '/survey_profiles/1').to route_to('survey_profiles#update', id: '1') end - it "routes to #destroy" do - expect(delete: "/survey_profiles/1").to route_to("survey_profiles#destroy", id: "1") + it 'routes to #destroy' do + expect(delete: '/survey_profiles/1').to route_to('survey_profiles#destroy', id: '1') end end end diff --git a/rails_root/spec/routing/survey_responses_routing_spec.rb b/rails_root/spec/routing/survey_responses_routing_spec.rb index c60ac31..4918183 100644 --- a/rails_root/spec/routing/survey_responses_routing_spec.rb +++ b/rails_root/spec/routing/survey_responses_routing_spec.rb @@ -1,38 +1,39 @@ -require "rails_helper" +# frozen_string_literal: true + +require 'rails_helper' RSpec.describe SurveyResponsesController, type: :routing do - describe "routing" do - it "routes to #index" do - expect(get: "/survey_responses").to route_to("survey_responses#index") + describe 'routing' do + it 'routes to #index' do + expect(get: '/survey_responses').to route_to('survey_responses#index') end - it "routes to #new" do - expect(get: "/survey_responses/new").to route_to("survey_responses#new") + it 'routes to #new' do + expect(get: '/survey_responses/new').to route_to('survey_responses#new') end - it "routes to #show" do - expect(get: "/survey_responses/1").to route_to("survey_responses#show", id: "1") + it 'routes to #show' do + expect(get: '/survey_responses/1').to route_to('survey_responses#show', id: '1') end - it "routes to #edit" do - expect(get: "/survey_responses/1/edit").to route_to("survey_responses#edit", id: "1") + it 'routes to #edit' do + expect(get: '/survey_responses/1/edit').to route_to('survey_responses#edit', id: '1') end - - it "routes to #create" do - expect(post: "/survey_responses").to route_to("survey_responses#create") + it 'routes to #create' do + expect(post: '/survey_responses').to route_to('survey_responses#create') end - it "routes to #update via PUT" do - expect(put: "/survey_responses/1").to route_to("survey_responses#update", id: "1") + it 'routes to #update via PUT' do + expect(put: '/survey_responses/1').to route_to('survey_responses#update', id: '1') end - it "routes to #update via PATCH" do - expect(patch: "/survey_responses/1").to route_to("survey_responses#update", id: "1") + it 'routes to #update via PATCH' do + expect(patch: '/survey_responses/1').to route_to('survey_responses#update', id: '1') end - it "routes to #destroy" do - expect(delete: "/survey_responses/1").to route_to("survey_responses#destroy", id: "1") + it 'routes to #destroy' do + expect(delete: '/survey_responses/1').to route_to('survey_responses#destroy', id: '1') end end end diff --git a/rails_root/spec/spec_helper.rb b/rails_root/spec/spec_helper.rb index e999948..3c3fcb7 100644 --- a/rails_root/spec/spec_helper.rb +++ b/rails_root/spec/spec_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Run simplecov before any tests to capture all test coverage require 'simplecov' require 'simplecov_json_formatter' diff --git a/rails_root/test/application_system_test_case.rb b/rails_root/test/application_system_test_case.rb index d19212a..652febb 100644 --- a/rails_root/test/application_system_test_case.rb +++ b/rails_root/test/application_system_test_case.rb @@ -1,4 +1,6 @@ -require "test_helper" +# frozen_string_literal: true + +require 'test_helper' class ApplicationSystemTestCase < ActionDispatch::SystemTestCase driven_by :selenium, using: :chrome, screen_size: [1400, 1400] diff --git a/rails_root/test/channels/application_cable/connection_test.rb b/rails_root/test/channels/application_cable/connection_test.rb index 6340bf9..4aee9b3 100644 --- a/rails_root/test/channels/application_cable/connection_test.rb +++ b/rails_root/test/channels/application_cable/connection_test.rb @@ -1,4 +1,6 @@ -require "test_helper" +# frozen_string_literal: true + +require 'test_helper' module ApplicationCable class ConnectionTest < ActionCable::Connection::TestCase diff --git a/rails_root/test/controllers/posts_controller_test.rb b/rails_root/test/controllers/posts_controller_test.rb index 076625f..7ed8d3e 100644 --- a/rails_root/test/controllers/posts_controller_test.rb +++ b/rails_root/test/controllers/posts_controller_test.rb @@ -1,45 +1,47 @@ -require "test_helper" +# frozen_string_literal: true + +require 'test_helper' class PostsControllerTest < ActionDispatch::IntegrationTest setup do @post = posts(:one) end - test "should get index" do + test 'should get index' do get posts_url assert_response :success end - test "should get new" do + test 'should get new' do get new_post_url assert_response :success end - test "should create post" do - assert_difference("Post.count") do + test 'should create post' do + assert_difference('Post.count') do post posts_url, params: { post: { body: @post.body, title: @post.title } } end assert_redirected_to post_url(Post.last) end - test "should show post" do + test 'should show post' do get post_url(@post) assert_response :success end - test "should get edit" do + test 'should get edit' do get edit_post_url(@post) assert_response :success end - test "should update post" do + test 'should update post' do patch post_url(@post), params: { post: { body: @post.body, title: @post.title } } assert_redirected_to post_url(@post) end - test "should destroy post" do - assert_difference("Post.count", -1) do + test 'should destroy post' do + assert_difference('Post.count', -1) do delete post_url(@post) end diff --git a/rails_root/test/models/post_test.rb b/rails_root/test/models/post_test.rb index ff155c4..35f740f 100644 --- a/rails_root/test/models/post_test.rb +++ b/rails_root/test/models/post_test.rb @@ -1,4 +1,6 @@ -require "test_helper" +# frozen_string_literal: true + +require 'test_helper' class PostTest < ActiveSupport::TestCase # test "the truth" do diff --git a/rails_root/test/system/posts_test.rb b/rails_root/test/system/posts_test.rb index c3e6dae..7a005b4 100644 --- a/rails_root/test/system/posts_test.rb +++ b/rails_root/test/system/posts_test.rb @@ -1,43 +1,45 @@ -require "application_system_test_case" +# frozen_string_literal: true + +require 'application_system_test_case' class PostsTest < ApplicationSystemTestCase setup do @post = posts(:one) end - test "visiting the index" do + test 'visiting the index' do visit posts_url - assert_selector "h1", text: "Posts" + assert_selector 'h1', text: 'Posts' end - test "should create post" do + test 'should create post' do visit posts_url - click_on "New post" + click_on 'New post' - fill_in "Body", with: @post.body - fill_in "Title", with: @post.title - click_on "Create Post" + fill_in 'Body', with: @post.body + fill_in 'Title', with: @post.title + click_on 'Create Post' - assert_text "Post was successfully created" - click_on "Back" + assert_text 'Post was successfully created' + click_on 'Back' end - test "should update Post" do + test 'should update Post' do visit post_url(@post) - click_on "Edit this post", match: :first + click_on 'Edit this post', match: :first - fill_in "Body", with: @post.body - fill_in "Title", with: @post.title - click_on "Update Post" + fill_in 'Body', with: @post.body + fill_in 'Title', with: @post.title + click_on 'Update Post' - assert_text "Post was successfully updated" - click_on "Back" + assert_text 'Post was successfully updated' + click_on 'Back' end - test "should destroy Post" do + test 'should destroy Post' do visit post_url(@post) - click_on "Destroy this post", match: :first + click_on 'Destroy this post', match: :first - assert_text "Post was successfully destroyed" + assert_text 'Post was successfully destroyed' end end diff --git a/rails_root/test/test_helper.rb b/rails_root/test/test_helper.rb index 0c22470..0c92e8e 100644 --- a/rails_root/test/test_helper.rb +++ b/rails_root/test/test_helper.rb @@ -1,6 +1,8 @@ -ENV["RAILS_ENV"] ||= "test" -require_relative "../config/environment" -require "rails/test_help" +# frozen_string_literal: true + +ENV['RAILS_ENV'] ||= 'test' +require_relative '../config/environment' +require 'rails/test_help' module ActiveSupport class TestCase