From caa0f17468babae222abc1abfdb16d844b6924dd Mon Sep 17 00:00:00 2001 From: Bilal Hankins Date: Mon, 22 Jul 2024 08:48:35 -0700 Subject: [PATCH 1/9] create/annotate Challenge model --- app/models/challenge.rb | 86 +++++++++++++++++++++++++++++++++ spec/models/challenge_spec.rb | 89 +++++++++++++++++++++++++++++++++++ 2 files changed, 175 insertions(+) create mode 100644 app/models/challenge.rb create mode 100644 spec/models/challenge_spec.rb diff --git a/app/models/challenge.rb b/app/models/challenge.rb new file mode 100644 index 00000000..e79a31ce --- /dev/null +++ b/app/models/challenge.rb @@ -0,0 +1,86 @@ +# == Schema Information +# +# Table name: challenges +# +# id :bigint not null, primary key +# user_id :bigint not null +# description :text +# inserted_at :datetime not null +# updated_at :datetime not null +# status :string(255) default("pending"), not null +# captured_on :date +# published_on :date +# title :string(255) +# tagline :text +# poc_email :string(255) +# agency_name :string(255) +# how_to_enter :text +# rules :text +# external_url :string(255) +# custom_url :string(255) +# start_date :datetime +# end_date :datetime +# fiscal_year :string(255) +# type :string(255) +# prize_total :bigint not null +# prize_description :text +# judging_criteria :text +# challenge_manager :string(255) +# legal_authority :string(255) +# terms_and_conditions :text +# non_monetary_prizes :text +# federal_partners :text +# faq :text +# winner_information :text +# number_of_phases :text +# phase_descriptions :text +# phase_dates :text +# brief_description :text +# multi_phase :boolean +# eligibility_requirements :text +# challenge_manager_email :string(255) +# agency_id :bigint +# logo_key :uuid +# logo_extension :string(255) +# winner_image_key :uuid +# winner_image_extension :string(255) +# last_section :string(255) +# types :jsonb +# auto_publish_date :datetime +# deleted_at :datetime +# rejection_message :text +# phases :jsonb +# upload_logo :boolean +# is_multi_phase :boolean +# timeline_events :jsonb +# prize_type :string(255) +# terms_equal_rules :boolean +# how_to_enter_link :string(255) +# resource_banner_key :uuid +# resource_banner_extension :string(255) +# imported :boolean default(FALSE), not null +# description_delta :text +# prize_description_delta :text +# faq_delta :text +# eligibility_requirements_delta :text +# rules_delta :text +# terms_and_conditions_delta :text +# uuid :uuid +# sub_agency_id :bigint +# primary_type :string(255) +# other_type :string(255) +# announcement :text +# announcement_datetime :datetime +# sub_status :string(255) +# gov_delivery_topic :string(255) +# archive_date :datetime +# gov_delivery_subscribers :integer default(0), not null +# brief_description_delta :text +# logo_alt_text :string(255) +# short_url :string(255) +# submission_collection_method :string(255) +# file_upload_required :boolean default(FALSE) +# upload_instruction_note :string(255) +# +class Challenge < ApplicationRecord +end diff --git a/spec/models/challenge_spec.rb b/spec/models/challenge_spec.rb new file mode 100644 index 00000000..bea04154 --- /dev/null +++ b/spec/models/challenge_spec.rb @@ -0,0 +1,89 @@ +# == Schema Information +# +# Table name: challenges +# +# id :bigint not null, primary key +# user_id :bigint not null +# description :text +# inserted_at :datetime not null +# updated_at :datetime not null +# status :string(255) default("pending"), not null +# captured_on :date +# published_on :date +# title :string(255) +# tagline :text +# poc_email :string(255) +# agency_name :string(255) +# how_to_enter :text +# rules :text +# external_url :string(255) +# custom_url :string(255) +# start_date :datetime +# end_date :datetime +# fiscal_year :string(255) +# type :string(255) +# prize_total :bigint not null +# prize_description :text +# judging_criteria :text +# challenge_manager :string(255) +# legal_authority :string(255) +# terms_and_conditions :text +# non_monetary_prizes :text +# federal_partners :text +# faq :text +# winner_information :text +# number_of_phases :text +# phase_descriptions :text +# phase_dates :text +# brief_description :text +# multi_phase :boolean +# eligibility_requirements :text +# challenge_manager_email :string(255) +# agency_id :bigint +# logo_key :uuid +# logo_extension :string(255) +# winner_image_key :uuid +# winner_image_extension :string(255) +# last_section :string(255) +# types :jsonb +# auto_publish_date :datetime +# deleted_at :datetime +# rejection_message :text +# phases :jsonb +# upload_logo :boolean +# is_multi_phase :boolean +# timeline_events :jsonb +# prize_type :string(255) +# terms_equal_rules :boolean +# how_to_enter_link :string(255) +# resource_banner_key :uuid +# resource_banner_extension :string(255) +# imported :boolean default(FALSE), not null +# description_delta :text +# prize_description_delta :text +# faq_delta :text +# eligibility_requirements_delta :text +# rules_delta :text +# terms_and_conditions_delta :text +# uuid :uuid +# sub_agency_id :bigint +# primary_type :string(255) +# other_type :string(255) +# announcement :text +# announcement_datetime :datetime +# sub_status :string(255) +# gov_delivery_topic :string(255) +# archive_date :datetime +# gov_delivery_subscribers :integer default(0), not null +# brief_description_delta :text +# logo_alt_text :string(255) +# short_url :string(255) +# submission_collection_method :string(255) +# file_upload_required :boolean default(FALSE) +# upload_instruction_note :string(255) +# +require 'rails_helper' + +RSpec.describe Challenge, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end From 82719b40fd44f50349ea33665a384c35eb700f46 Mon Sep 17 00:00:00 2001 From: Bilal Hankins Date: Thu, 25 Jul 2024 12:14:37 -0500 Subject: [PATCH 2/9] created challenge and agency models --- app/models/agency.rb | 29 +++++++++++++++++++++++++++++ app/models/challenge.rb | 19 +++++++++++++++++++ spec/models/agency_spec.rb | 35 +++++++++++++++++++++++++++++++++++ spec/models/challenge_spec.rb | 25 +++++++++++++++++++++++-- 4 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 app/models/agency.rb create mode 100644 spec/models/agency_spec.rb diff --git a/app/models/agency.rb b/app/models/agency.rb new file mode 100644 index 00000000..ad458064 --- /dev/null +++ b/app/models/agency.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +# == Schema Information +# +# Table name: agencies +# +# id :bigint not null, primary key +# name :string(255) not null +# description :text +# avatar_key :uuid +# avatar_extension :string(255) +# deleted_at :datetime +# inserted_at :datetime not null +# updated_at :datetime not null +# created_on_import :boolean default(FALSE), not null +# acronym :string(255) +# parent_id :bigint +# +class Agency < ApplicationRecord + belongs_to :parent, class_name: 'Agency', optional: true + has_many :sub_agencies, class_name: 'Agency', foreign_key: :parent_id + has_many :federal_partners, dependent: :destroy + has_many :federal_partner_challenges, through: :federal_partners, source: :challenge + has_many :members, dependent: :destroy + has_many :challenges, dependent: :destroy + + validates :name, presence: true + validates :acronym, presence: true +end diff --git a/app/models/challenge.rb b/app/models/challenge.rb index e79a31ce..1071d846 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # == Schema Information # # Table name: challenges @@ -83,4 +85,21 @@ # upload_instruction_note :string(255) # class Challenge < ApplicationRecord + belongs_to :user + belongs_to :agency + belongs_to :sub_agency, class_name: 'Agency', optional: true + + has_many :events, dependent: :delete_all + has_many :supporting_documents, class_name: 'Document', dependent: :delete_all + has_many :challenge_managers, dependent: :delete_all + has_many :challenge_manager_users, through: :challenge_managers, source: :user + has_many :federal_partners, dependent: :delete_all + has_many :federal_partner_agencies, through: :federal_partners, source: :agency + has_many :non_federal_partners, dependent: :delete_all + has_many :phases + has_many :submissions + has_many :submission_exports + + validates :title, presence: true + validates :status, presence: true end diff --git a/spec/models/agency_spec.rb b/spec/models/agency_spec.rb new file mode 100644 index 00000000..90ca4249 --- /dev/null +++ b/spec/models/agency_spec.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +# == Schema Information +# +# Table name: agencies +# +# id :bigint not null, primary key +# name :string(255) not null +# description :text +# avatar_key :uuid +# avatar_extension :string(255) +# deleted_at :datetime +# inserted_at :datetime not null +# updated_at :datetime not null +# created_on_import :boolean default(FALSE), not null +# acronym :string(255) +# parent_id :bigint +# +require 'rails_helper' + +RSpec.describe Agency, type: :model do + describe 'validations' do + it 'validates presence of name' do + agency = described_class.new(name: nil, acronym: 'TEST') + expect(agency).not_to be_valid + expect(agency.errors[:name]).to include("can't be blank") + end + + it 'validates presence of acronym' do + agency = described_class.new(name: 'Test Agency', acronym: nil) + expect(agency).not_to be_valid + expect(agency.errors[:acronym]).to include("can't be blank") + end + end +end diff --git a/spec/models/challenge_spec.rb b/spec/models/challenge_spec.rb index bea04154..0b58b1ea 100644 --- a/spec/models/challenge_spec.rb +++ b/spec/models/challenge_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # == Schema Information # # Table name: challenges @@ -84,6 +86,25 @@ # require 'rails_helper' -RSpec.describe Challenge, type: :model do - pending "add some examples to (or delete) #{__FILE__}" +RSpec.describe Challenge do + describe 'validations' do + it 'validates presence of title' do + challenge = described_class.new(title: nil) + expect(challenge).not_to be_valid + expect(challenge.errors[:title]).to include("can't be blank") + end + + it 'validates presence of status' do + challenge = described_class.new(status: nil) + expect(challenge).not_to be_valid + expect(challenge.errors[:status]).to include("can't be blank") + end + end + + describe 'default values' do + it 'sets status to pending by default' do + challenge = described_class.new + expect(challenge.status).to eq('pending') + end + end end From e39ee67c957546b69698ff8a9ce956a8418edc56 Mon Sep 17 00:00:00 2001 From: Bilal Hankins Date: Thu, 25 Jul 2024 12:15:06 -0500 Subject: [PATCH 3/9] linting --- .rspec | 1 + Gemfile | 38 ++++---- Rakefile | 4 +- app/channels/application_cable/channel.rb | 2 + app/channels/application_cable/connection.rb | 2 + app/controllers/application_controller.rb | 2 + app/helpers/application_helper.rb | 2 + app/helpers/users_helper.rb | 2 + app/jobs/application_job.rb | 2 + app/mailers/application_mailer.rb | 6 +- app/models/application_record.rb | 2 + app/models/user.rb | 2 + bin/bundle | 40 ++++---- bin/rails | 8 +- bin/rake | 6 +- bin/setup | 18 ++-- config.ru | 4 +- config/application.rb | 8 +- config/boot.rb | 8 +- config/environment.rb | 4 +- config/environments/development.rb | 8 +- config/environments/production.rb | 14 +-- config/environments/test.rb | 8 +- config/initializers/assets.rb | 4 +- .../initializers/content_security_policy.rb | 1 + .../initializers/filter_parameter_logging.rb | 6 +- config/initializers/inflections.rb | 1 + config/initializers/permissions_policy.rb | 1 + config/puma.rb | 20 ++-- config/routes.rb | 4 +- db/seeds.rb | 1 + spec/helpers/users_helper_spec.rb | 2 + spec/models/user_spec.rb | 2 + spec/rails_helper.rb | 67 +++++++++++++ spec/spec_helper.rb | 94 +++++++++++++++++++ test/application_system_test_case.rb | 4 +- .../application_cable/connection_test.rb | 4 +- test/test_helper.rb | 8 +- 38 files changed, 320 insertions(+), 90 deletions(-) create mode 100644 .rspec create mode 100644 spec/rails_helper.rb create mode 100644 spec/spec_helper.rb diff --git a/.rspec b/.rspec new file mode 100644 index 00000000..c99d2e73 --- /dev/null +++ b/.rspec @@ -0,0 +1 @@ +--require spec_helper diff --git a/Gemfile b/Gemfile index 90e7c7ee..85b719dc 100644 --- a/Gemfile +++ b/Gemfile @@ -1,30 +1,32 @@ -source "https://rubygems.org" +# frozen_string_literal: true -ruby "3.2.2" +source 'https://rubygems.org' + +ruby '3.2.2' # Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main" -gem "rails", "~> 7.1.3", ">= 7.1.3.4" +gem 'rails', '~> 7.1.3', '>= 7.1.3.4' # The original asset pipeline for Rails [https://github.com/rails/sprockets-rails] -gem "sprockets-rails" +gem 'sprockets-rails' # Use postgresql as the database for Active Record -gem "pg" +gem 'pg' # Use the Puma web server [https://github.com/puma/puma] -gem "puma", ">= 5.0" +gem 'puma', '>= 5.0' # Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails] -gem "importmap-rails" +gem 'importmap-rails' # Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev] -gem "turbo-rails" +gem 'turbo-rails' # Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev] -gem "stimulus-rails" +gem 'stimulus-rails' # Build JSON APIs with ease [https://github.com/rails/jbuilder] -gem "jbuilder" +gem 'jbuilder' # Use Redis adapter to run Action Cable in production # gem "redis", ">= 4.0.1" @@ -36,26 +38,26 @@ gem "jbuilder" # gem "bcrypt", "~> 3.1.7" # Windows does not include zoneinfo files, so bundle the tzinfo-data gem -gem "tzinfo-data", platforms: %i[ windows jruby ] +gem 'tzinfo-data', platforms: %i[windows jruby] # Reduces boot times through caching; required in config/boot.rb -gem "bootsnap", require: false +gem 'bootsnap', require: false # Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images] # gem "image_processing", "~> 1.2" group :development, :test do # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem - gem "debug", platforms: %i[ mri windows ] + gem 'debug', platforms: %i[mri windows] - gem "rspec-rails" + gem 'rspec-rails' end group :development do # Use console on exceptions pages [https://github.com/rails/web-console] - gem "web-console" + gem 'web-console' - gem "annotate" + gem 'annotate' # Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler] # gem "rack-mini-profiler" @@ -65,6 +67,6 @@ end group :test do # Use system testing [https://guides.rubyonrails.org/testing.html#system-testing] - gem "capybara" - gem "selenium-webdriver" + gem 'capybara' + gem 'selenium-webdriver' end diff --git a/Rakefile b/Rakefile index 9a5ea738..488c551f 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 d6726972..9aec2305 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 0ff5442f..8d6c2a1b 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/application_controller.rb b/app/controllers/application_controller.rb index 09705d12..7944f9f9 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + class ApplicationController < ActionController::Base end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be794..15b06f0f 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/users_helper.rb b/app/helpers/users_helper.rb index 2310a240..4dc909ed 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + module UsersHelper end diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb index d394c3d1..bef39599 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 3c34c814..d84cb6e7 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/application_record.rb b/app/models/application_record.rb index b63caeb8..08dc5379 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/user.rb b/app/models/user.rb index 148b15f2..ca0a1244 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # == Schema Information # # Table name: users diff --git a/bin/bundle b/bin/bundle index 42c7fd7c..8012441d 100755 --- a/bin/bundle +++ b/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 =~ Gem::Version::ANCHORED_VERSION_PATTERN - bundler_version = a - end + bundler_version = a if update_index && update_index.succ == i && a =~ 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/bin/rails b/bin/rails index efc03774..a31728ab 100755 --- a/bin/rails +++ b/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/bin/rake b/bin/rake index 4fbf10b9..c1999550 100755 --- a/bin/rake +++ b/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/bin/setup b/bin/setup index 3cd5a9d7..3a74034f 100755 --- a/bin/setup +++ b/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/config.ru b/config.ru index 4a3c09a6..6dc83218 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 bbd5579a..c2bdd337 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. @@ -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/config/boot.rb b/config/boot.rb index 988a5ddc..c04863fa 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 cac53157..d5abe558 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 2e7fb486..80e0587b 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. @@ -19,13 +21,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/config/environments/production.rb b/config/environments/production.rb index 13ffe7d8..36c4606f 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. @@ -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/config/environments/test.rb b/config/environments/test.rb index adbb4a6f..f1d2fb50 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 @@ -15,12 +17,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/config/initializers/assets.rb b/config/initializers/assets.rb index 2eeef966..bcafccdd 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/content_security_policy.rb b/config/initializers/content_security_policy.rb index b3076b38..af395e46 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/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb index c2d89e28..c416e6a6 100644 --- a/config/initializers/filter_parameter_logging.rb +++ b/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/config/initializers/inflections.rb b/config/initializers/inflections.rb index 3860f659..6c78420e 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/permissions_policy.rb b/config/initializers/permissions_policy.rb index 7db3b957..b635b527 100644 --- a/config/initializers/permissions_policy.rb +++ b/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/config/puma.rb b/config/puma.rb index afa809b4..7ed41574 100644 --- a/config/puma.rb +++ b/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/config/routes.rb b/config/routes.rb index a125ef08..7c16bc70 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + Rails.application.routes.draw do # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html # 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/db/seeds.rb b/db/seeds.rb index 4fbd6ed9..07b11e82 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,3 +1,4 @@ +# 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/spec/helpers/users_helper_spec.rb b/spec/helpers/users_helper_spec.rb index b2e34440..15ca021b 100644 --- a/spec/helpers/users_helper_spec.rb +++ b/spec/helpers/users_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/spec/models/user_spec.rb b/spec/models/user_spec.rb index fed2b67e..75771356 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # == Schema Information # # Table name: users diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb new file mode 100644 index 00000000..254658cb --- /dev/null +++ b/spec/rails_helper.rb @@ -0,0 +1,67 @@ +# 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? +require 'rspec/rails' +# Add additional requires below this line. Rails is not loaded until this point! + +# Requires supporting ruby files with custom matchers and macros, etc, in +# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are +# run as spec files by default. This means that files in spec/support that end +# in _spec.rb will both be required and run as specs, causing the specs to be +# run twice. It is recommended that you do not name files matching this glob to +# end with _spec.rb. You can configure this pattern with the --pattern +# option on the command line or in ~/.rspec, .rspec or `.rspec-local`. +# +# The following line is provided for convenience purposes. It has the downside +# of increasing the boot-up time by auto-requiring all files in the support +# directory. Alternatively, in the individual `*_spec.rb` files, manually +# require only the support files necessary. +# +# Rails.root.glob('spec/support/**/*.rb').sort.each { |f| require f } + +# Checks for pending migrations and applies them before tests are run. +# If you are not using ActiveRecord, you can remove these lines. +begin + ActiveRecord::Migration.maintain_test_schema! +rescue ActiveRecord::PendingMigrationError => e + abort e.to_s.strip +end +RSpec.configure do |config| + # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures + config.fixture_paths = [ + Rails.root.join('spec/fixtures') + ] + + # If you're not using ActiveRecord, or you'd prefer not to run each of your + # examples within a transaction, remove the following line or assign false + # instead of true. + config.use_transactional_fixtures = true + + # You can uncomment this line to turn off ActiveRecord support entirely. + # config.use_active_record = false + + # RSpec Rails can automatically mix in different behaviours to your tests + # based on their file location, for example enabling you to call `get` and + # `post` in specs under `spec/controllers`. + # + # You can disable this behaviour by removing the line below, and instead + # explicitly tag your specs with their type, e.g.: + # + # RSpec.describe UsersController, type: :controller do + # # ... + # end + # + # The different available types are documented in the features, such as in + # https://rspec.info/features/6-0/rspec-rails + config.infer_spec_type_from_file_location! + + # Filter lines from Rails gems in backtraces. + config.filter_rails_from_backtrace! + # arbitrary gems may also be filtered via: + # config.filter_gems_from_backtrace("gem name") +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 00000000..409c64b6 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,94 @@ +# frozen_string_literal: true + +# This file was generated by the `rails generate rspec:install` command. Conventionally, all +# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. +# The generated `.rspec` file contains `--require spec_helper` which will cause +# this file to always be loaded, without a need to explicitly require it in any +# files. +# +# Given that it is always loaded, you are encouraged to keep this file as +# light-weight as possible. Requiring heavyweight dependencies from this file +# will add to the boot time of your test suite on EVERY test run, even for an +# individual file that may not need all of that loaded. Instead, consider making +# a separate helper file that requires the additional dependencies and performs +# the additional setup, and require it from the spec files that actually need +# it. +# +# See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration +RSpec.configure do |config| + # rspec-expectations config goes here. You can use an alternate + # assertion/expectation library such as wrong or the stdlib/minitest + # assertions if you prefer. + config.expect_with :rspec do |expectations| + # This option will default to `true` in RSpec 4. It makes the `description` + # and `failure_message` of custom matchers include text for helper methods + # defined using `chain`, e.g.: + # be_bigger_than(2).and_smaller_than(4).description + # # => "be bigger than 2 and smaller than 4" + # ...rather than: + # # => "be bigger than 2" + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + end + + # rspec-mocks config goes here. You can use an alternate test double + # library (such as bogus or mocha) by changing the `mock_with` option here. + config.mock_with :rspec do |mocks| + # Prevents you from mocking or stubbing a method that does not exist on + # a real object. This is generally recommended, and will default to + # `true` in RSpec 4. + mocks.verify_partial_doubles = true + end + + # This option will default to `:apply_to_host_groups` in RSpec 4 (and will + # have no way to turn it off -- the option exists only for backwards + # compatibility in RSpec 3). It causes shared context metadata to be + # inherited by the metadata hash of host groups and examples, rather than + # triggering implicit auto-inclusion in groups with matching metadata. + config.shared_context_metadata_behavior = :apply_to_host_groups + + # The settings below are suggested to provide a good initial experience + # with RSpec, but feel free to customize to your heart's content. + # # This allows you to limit a spec run to individual examples or groups + # # you care about by tagging them with `:focus` metadata. When nothing + # # is tagged with `:focus`, all examples get run. RSpec also provides + # # aliases for `it`, `describe`, and `context` that include `:focus` + # # metadata: `fit`, `fdescribe` and `fcontext`, respectively. + # config.filter_run_when_matching :focus + # + # # Allows RSpec to persist some state between runs in order to support + # # the `--only-failures` and `--next-failure` CLI options. We recommend + # # you configure your source control system to ignore this file. + # config.example_status_persistence_file_path = "spec/examples.txt" + # + # # Limits the available syntax to the non-monkey patched syntax that is + # # recommended. For more details, see: + # # https://rspec.info/features/3-12/rspec-core/configuration/zero-monkey-patching-mode/ + # config.disable_monkey_patching! + # + # # Many RSpec users commonly either run the entire suite or an individual + # # file, and it's useful to allow more verbose output when running an + # # individual spec file. + # if config.files_to_run.one? + # # Use the documentation formatter for detailed output, + # # unless a formatter has already been configured + # # (e.g. via a command-line flag). + # config.default_formatter = "doc" + # end + # + # # Print the 10 slowest examples and example groups at the + # # end of the spec run, to help surface which specs are running + # # particularly slow. + # config.profile_examples = 10 + # + # # Run specs in random order to surface order dependencies. If you find an + # # order dependency and want to debug it, you can fix the order by providing + # # the seed, which is printed after each run. + # # --seed 1234 + # config.order = :random + # + # # Seed global randomization in this process using the `--seed` CLI option. + # # Setting this allows you to use `--seed` to deterministically reproduce + # # test failures related to randomization by passing the same `--seed` value + # # as the one that triggered the failure. + # Kernel.srand config.seed +end diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb index d19212ab..652febbd 100644 --- a/test/application_system_test_case.rb +++ b/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/test/channels/application_cable/connection_test.rb b/test/channels/application_cable/connection_test.rb index 6340bf9c..4aee9b33 100644 --- a/test/channels/application_cable/connection_test.rb +++ b/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/test/test_helper.rb b/test/test_helper.rb index 0c22470e..0c92e8e8 100644 --- a/test/test_helper.rb +++ b/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 From f429060a6dfdc31bbbec91184c98c3a62f3ae61f Mon Sep 17 00:00:00 2001 From: Stephen Chudleigh Date: Fri, 26 Jul 2024 14:20:56 -0700 Subject: [PATCH 4/9] revert Gemfile to dev version --- Gemfile | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/Gemfile b/Gemfile index 47ab2454..e3968f1b 100644 --- a/Gemfile +++ b/Gemfile @@ -2,33 +2,31 @@ source "https://rubygems.org" -source 'https://rubygems.org' - -ruby '3.2.2' +ruby "3.2.2" # Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main" -gem 'rails', '~> 7.1.3', '>= 7.1.3.4' +gem "rails", "~> 7.1.3", ">= 7.1.3.4" # The original asset pipeline for Rails [https://github.com/rails/sprockets-rails] -gem 'sprockets-rails' +gem "sprockets-rails" # Use postgresql as the database for Active Record -gem 'pg' +gem "pg" # Use the Puma web server [https://github.com/puma/puma] -gem 'puma', '>= 5.0' +gem "puma", ">= 5.0" # Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails] -gem 'importmap-rails' +gem "importmap-rails" # Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev] -gem 'turbo-rails' +gem "turbo-rails" # Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev] -gem 'stimulus-rails' +gem "stimulus-rails" # Build JSON APIs with ease [https://github.com/rails/jbuilder] -gem 'jbuilder' +gem "jbuilder" # Use Redis adapter to run Action Cable in production # gem "redis", ">= 4.0.1" @@ -43,7 +41,7 @@ gem 'jbuilder' gem "tzinfo-data", platforms: %i[windows jruby] # Reduces boot times through caching; required in config/boot.rb -gem 'bootsnap', require: false +gem "bootsnap", require: false # Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images] # gem "image_processing", "~> 1.2" @@ -59,9 +57,9 @@ end group :development do # Use console on exceptions pages [https://github.com/rails/web-console] - gem 'web-console' + gem "web-console" - gem 'annotate' + gem "annotate" # Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler] # gem "rack-mini-profiler" From 2599bbf61c21a7a44d9d8e8ad80551a9769b1a36 Mon Sep 17 00:00:00 2001 From: Bilal Hankins Date: Mon, 29 Jul 2024 12:00:13 -0500 Subject: [PATCH 5/9] Added missing attributes --- Gemfile.lock | 3 ++ app/models/agency.rb | 10 ++++- app/models/challenge.rb | 79 ++++++++++++++++++++++++++++++++++++-- spec/models/agency_spec.rb | 2 +- 4 files changed, 89 insertions(+), 5 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index aa5f2646..aadaabbc 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -77,6 +77,9 @@ GEM tzinfo (~> 2.0) addressable (2.8.7) public_suffix (>= 2.0.2, < 7.0) + annotate (3.2.0) + activerecord (>= 3.2, < 8.0) + rake (>= 10.4, < 14.0) ast (2.4.2) base64 (0.2.0) bigdecimal (3.1.8) diff --git a/app/models/agency.rb b/app/models/agency.rb index ad458064..17a6644b 100644 --- a/app/models/agency.rb +++ b/app/models/agency.rb @@ -18,12 +18,20 @@ # class Agency < ApplicationRecord belongs_to :parent, class_name: 'Agency', optional: true - has_many :sub_agencies, class_name: 'Agency', foreign_key: :parent_id + has_many :sub_agencies, class_name: 'Agency', foreign_key: :parent_id, dependent: :destroy, inverse_of: :parent has_many :federal_partners, dependent: :destroy has_many :federal_partner_challenges, through: :federal_partners, source: :challenge has_many :members, dependent: :destroy has_many :challenges, dependent: :destroy + attribute :acronym, :string + attribute :created_on_import, :boolean, default: false + attribute :description, :string + attribute :deleted_at, :datetime + attribute :name, :string + attribute :avatar_key, :uuid + attribute :avatar_extension, :string + validates :name, presence: true validates :acronym, presence: true end diff --git a/app/models/challenge.rb b/app/models/challenge.rb index 1071d846..35217d32 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -96,9 +96,82 @@ class Challenge < ApplicationRecord has_many :federal_partners, dependent: :delete_all has_many :federal_partner_agencies, through: :federal_partners, source: :agency has_many :non_federal_partners, dependent: :delete_all - has_many :phases - has_many :submissions - has_many :submission_exports + has_many :phases, dependent: :destroy + has_many :submissions, dependent: :destroy + has_many :submission_exports, dependent: :destroy + + # JSON fields + attribute :types, :jsonb, default: [] + attribute :timeline_events, :jsonb, default: [] + attribute :phases, :jsonb, default: [] + + attribute :status, :string, default: "draft" + attribute :prize_total, :integer, default: 0 + attribute :gov_delivery_subscribers, :integer, default: 0 + attribute :imported, :boolean, default: false + attribute :uuid, :uuid + + # other fields + attribute :sub_status, :string + attribute :last_section, :string + attribute :challenge_manager, :string + attribute :challenge_manager_email, :string + attribute :poc_email, :string + attribute :agency_name, :string + attribute :title, :string + attribute :custom_url, :string + attribute :external_url, :string + attribute :tagline, :string + attribute :type, :string + attribute :description, :string + attribute :description_delta, :string + attribute :description_length, :integer + attribute :brief_description, :string + attribute :brief_description_delta, :string + attribute :brief_description_length, :integer + attribute :how_to_enter, :string + attribute :fiscal_year, :string + attribute :start_date, :datetime + attribute :end_date, :datetime + attribute :archive_date, :datetime + attribute :multi_phase, :boolean + attribute :number_of_phases, :string + attribute :phase_descriptions, :string + attribute :phase_dates, :string + attribute :judging_criteria, :string + attribute :prize_type, :string + attribute :non_monetary_prizes, :string + attribute :prize_description, :string + attribute :prize_description_delta, :string + attribute :prize_description_length, :integer + attribute :eligibility_requirements, :string + attribute :eligibility_requirements_delta, :string + attribute :rules, :string + attribute :rules_delta, :string + attribute :terms_and_conditions, :string + attribute :terms_and_conditions_delta, :string + attribute :legal_authority, :string + attribute :faq, :string + attribute :faq_delta, :string + attribute :faq_length, :integer + attribute :winner_information, :string + attribute :captured_on, :date + attribute :auto_publish_date, :datetime + attribute :published_on, :date + attribute :rejection_message, :string + attribute :how_to_enter_link, :string + attribute :announcement, :string + attribute :announcement_datetime, :datetime + attribute :gov_delivery_topic, :string + attribute :short_url, :string + attribute :upload_logo, :boolean + attribute :is_multi_phase, :boolean + attribute :terms_equal_rules, :boolean + attribute :file_upload_required, :boolean + attribute :upload_instruction_note, :string + attribute :submission_collection_method, :string + + attribute :deleted_at, :datetime validates :title, presence: true validates :status, presence: true diff --git a/spec/models/agency_spec.rb b/spec/models/agency_spec.rb index 90ca4249..1d981271 100644 --- a/spec/models/agency_spec.rb +++ b/spec/models/agency_spec.rb @@ -18,7 +18,7 @@ # require 'rails_helper' -RSpec.describe Agency, type: :model do +RSpec.describe Agency do describe 'validations' do it 'validates presence of name' do agency = described_class.new(name: nil, acronym: 'TEST') From 86ea0959bcf68a22936dcc957162032e6a64ea20 Mon Sep 17 00:00:00 2001 From: Bilal Hankins Date: Tue, 30 Jul 2024 09:40:38 -0500 Subject: [PATCH 6/9] updated spec default --- spec/models/challenge_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/models/challenge_spec.rb b/spec/models/challenge_spec.rb index 0b58b1ea..14a2437b 100644 --- a/spec/models/challenge_spec.rb +++ b/spec/models/challenge_spec.rb @@ -102,9 +102,9 @@ end describe 'default values' do - it 'sets status to pending by default' do + it 'sets status to draft by default' do challenge = described_class.new - expect(challenge.status).to eq('pending') + expect(challenge.status).to eq('draft') end end end From 84fa9a747ca4214022439e0f5f997dbb481eb302 Mon Sep 17 00:00:00 2001 From: Bilal Hankins Date: Tue, 30 Jul 2024 09:45:41 -0500 Subject: [PATCH 7/9] linting --- app/models/challenge.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/challenge.rb b/app/models/challenge.rb index 35217d32..0e0a139f 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -100,10 +100,10 @@ class Challenge < ApplicationRecord has_many :submissions, dependent: :destroy has_many :submission_exports, dependent: :destroy - # JSON fields - attribute :types, :jsonb, default: [] - attribute :timeline_events, :jsonb, default: [] - attribute :phases, :jsonb, default: [] + # JSON fields + attribute :types, :jsonb + attribute :timeline_events, :jsonb + attribute :phases, :jsonb attribute :status, :string, default: "draft" attribute :prize_total, :integer, default: 0 From b3fd155319355d8c25da2e77496df1d0ed903fdd Mon Sep 17 00:00:00 2001 From: Stephen Chudleigh Date: Tue, 30 Jul 2024 20:49:13 -0700 Subject: [PATCH 8/9] Revert "linting" This reverts commit e39ee67c957546b69698ff8a9ce956a8418edc56. --- .rspec | 1 - Gemfile | 10 ++--- Rakefile | 4 +- app/channels/application_cable/channel.rb | 2 - app/channels/application_cable/connection.rb | 2 - app/controllers/application_controller.rb | 2 - app/helpers/application_helper.rb | 2 - app/helpers/users_helper.rb | 2 - app/jobs/application_job.rb | 2 - app/mailers/application_mailer.rb | 6 +-- app/models/application_record.rb | 2 - app/models/user.rb | 2 - bin/bundle | 40 +++++++++---------- bin/rails | 8 ++-- bin/rake | 6 +-- bin/setup | 18 ++++----- config.ru | 4 +- config/application.rb | 8 ++-- config/boot.rb | 8 ++-- config/environment.rb | 4 +- config/environments/development.rb | 8 ++-- config/environments/production.rb | 14 +++---- config/environments/test.rb | 8 ++-- config/initializers/assets.rb | 4 +- .../initializers/content_security_policy.rb | 1 - .../initializers/filter_parameter_logging.rb | 6 +-- config/initializers/inflections.rb | 1 - config/initializers/permissions_policy.rb | 1 - config/puma.rb | 20 +++++----- config/routes.rb | 4 +- db/seeds.rb | 1 - spec/helpers/users_helper_spec.rb | 2 - spec/models/user_spec.rb | 2 - 33 files changed, 71 insertions(+), 134 deletions(-) delete mode 100644 .rspec diff --git a/.rspec b/.rspec deleted file mode 100644 index c99d2e73..00000000 --- a/.rspec +++ /dev/null @@ -1 +0,0 @@ ---require spec_helper diff --git a/Gemfile b/Gemfile index f14c25f0..6a42bbf6 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,3 @@ -# frozen_string_literal: true - source "https://rubygems.org" ruby "3.2.4" @@ -52,7 +50,7 @@ group :development, :test do gem "rubocop" gem "rspec-rails" - gem 'codeclimate-test-reporter' + gem "codeclimate-test-reporter" end group :development do @@ -66,15 +64,15 @@ group :development do # Speed up commands on slow machines / big apps [https://github.com/rails/spring] # gem "spring" - gem 'foreman' + gem "foreman" end group :test do # Use system testing [https://guides.rubyonrails.org/testing.html#system-testing] gem "capybara" gem "selenium-webdriver" - gem 'rspec_junit_formatter' - gem 'simplecov' + gem "rspec_junit_formatter" + gem "simplecov" end gem "cssbundling-rails", "~> 1.4" diff --git a/Rakefile b/Rakefile index c691746c..18f21e17 100644 --- a/Rakefile +++ b/Rakefile @@ -1,9 +1,7 @@ -# 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 9aec2305..d6726972 100644 --- a/app/channels/application_cable/channel.rb +++ b/app/channels/application_cable/channel.rb @@ -1,5 +1,3 @@ -# 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 8d6c2a1b..0ff5442f 100644 --- a/app/channels/application_cable/connection.rb +++ b/app/channels/application_cable/connection.rb @@ -1,5 +1,3 @@ -# frozen_string_literal: true - module ApplicationCable class Connection < ActionCable::Connection::Base end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 7944f9f9..09705d12 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,4 +1,2 @@ -# frozen_string_literal: true - class ApplicationController < ActionController::Base end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 15b06f0f..de6be794 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,4 +1,2 @@ -# frozen_string_literal: true - module ApplicationHelper end diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 4dc909ed..2310a240 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -1,4 +1,2 @@ -# frozen_string_literal: true - module UsersHelper end diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb index bef39599..d394c3d1 100644 --- a/app/jobs/application_job.rb +++ b/app/jobs/application_job.rb @@ -1,5 +1,3 @@ -# 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 d84cb6e7..3c34c814 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,6 +1,4 @@ -# 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/application_record.rb b/app/models/application_record.rb index 08dc5379..b63caeb8 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -1,5 +1,3 @@ -# frozen_string_literal: true - class ApplicationRecord < ActiveRecord::Base primary_abstract_class end diff --git a/app/models/user.rb b/app/models/user.rb index 7bd1bd84..07ca350e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,5 +1,3 @@ -# frozen_string_literal: true - # == Schema Information # # Table name: users diff --git a/bin/bundle b/bin/bundle index 8012441d..42c7fd7c 100755 --- a/bin/bundle +++ b/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($PROGRAM_NAME) == File.expand_path(__FILE__) + File.expand_path($0) == 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| - bundler_version = a if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN + if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN + bundler_version = a + end next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/ - - bundler_version = Regexp.last_match(1) + bundler_version = $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,10 +55,8 @@ 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 @@ -78,24 +76,20 @@ 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' - end - if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION)) - return + require "bundler/version" 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 @@ -110,4 +104,6 @@ end m.load_bundler! -load Gem.bin_path('bundler', 'bundle') if m.invoked_as_script? +if m.invoked_as_script? + load Gem.bin_path("bundler", "bundle") +end diff --git a/bin/rails b/bin/rails index a31728ab..efc03774 100755 --- a/bin/rails +++ b/bin/rails @@ -1,6 +1,4 @@ #!/usr/bin/env ruby -# frozen_string_literal: true - -APP_PATH = File.expand_path('../config/application', __dir__) -require_relative '../config/boot' -require 'rails/commands' +APP_PATH = File.expand_path("../config/application", __dir__) +require_relative "../config/boot" +require "rails/commands" diff --git a/bin/rake b/bin/rake index c1999550..4fbf10b9 100755 --- a/bin/rake +++ b/bin/rake @@ -1,6 +1,4 @@ #!/usr/bin/env ruby -# frozen_string_literal: true - -require_relative '../config/boot' -require 'rake' +require_relative "../config/boot" +require "rake" Rake.application.run diff --git a/bin/setup b/bin/setup index 3a74034f..3cd5a9d7 100755 --- a/bin/setup +++ b/bin/setup @@ -1,10 +1,8 @@ #!/usr/bin/env ruby -# frozen_string_literal: true - -require 'fileutils' +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) @@ -15,9 +13,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") @@ -25,11 +23,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/config.ru b/config.ru index 6dc83218..4a3c09a6 100644 --- a/config.ru +++ b/config.ru @@ -1,8 +1,6 @@ -# 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 c2bdd337..bbd5579a 100644 --- a/config/application.rb +++ b/config/application.rb @@ -1,8 +1,6 @@ -# frozen_string_literal: true +require_relative "boot" -require_relative 'boot' - -require 'rails/all' +require "rails/all" # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. @@ -16,7 +14,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/config/boot.rb b/config/boot.rb index c04863fa..988a5ddc 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,6 +1,4 @@ -# frozen_string_literal: true +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) -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. +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 d5abe558..cac53157 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,7 +1,5 @@ -# 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 80e0587b..2e7fb486 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,6 +1,4 @@ -# frozen_string_literal: true - -require 'active_support/core_ext/integer/time' +require "active_support/core_ext/integer/time" Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. @@ -21,13 +19,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/config/environments/production.rb b/config/environments/production.rb index 36c4606f..13ffe7d8 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,6 +1,4 @@ -# frozen_string_literal: true - -require 'active_support/core_ext/integer/time' +require "active_support/core_ext/integer/time" Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. @@ -54,17 +52,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/config/environments/test.rb b/config/environments/test.rb index f1d2fb50..adbb4a6f 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -1,6 +1,4 @@ -# frozen_string_literal: true - -require 'active_support/core_ext/integer/time' +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 @@ -17,12 +15,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/config/initializers/assets.rb b/config/initializers/assets.rb index 860dce1a..925f18ef 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -1,9 +1,7 @@ -# 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 << './uswds' diff --git a/config/initializers/content_security_policy.rb b/config/initializers/content_security_policy.rb index af395e46..b3076b38 100644 --- a/config/initializers/content_security_policy.rb +++ b/config/initializers/content_security_policy.rb @@ -1,4 +1,3 @@ -# 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/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb index c416e6a6..c2d89e28 100644 --- a/config/initializers/filter_parameter_logging.rb +++ b/config/initializers/filter_parameter_logging.rb @@ -1,10 +1,8 @@ -# 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 += %i[ - passw secret token _key crypt salt certificate otp ssn +Rails.application.config.filter_parameters += [ + :passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn ] diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index 6c78420e..3860f659 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -1,4 +1,3 @@ -# 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/permissions_policy.rb b/config/initializers/permissions_policy.rb index b635b527..7db3b957 100644 --- a/config/initializers/permissions_policy.rb +++ b/config/initializers/permissions_policy.rb @@ -1,4 +1,3 @@ -# 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/config/puma.rb b/config/puma.rb index 7ed41574..afa809b4 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -1,5 +1,3 @@ -# 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. @@ -9,29 +7,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/config/routes.rb b/config/routes.rb index f386b5d0..e93c1a31 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,11 +1,9 @@ -# frozen_string_literal: true - Rails.application.routes.draw do # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html # 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/db/seeds.rb b/db/seeds.rb index 07b11e82..4fbd6ed9 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,4 +1,3 @@ -# 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/spec/helpers/users_helper_spec.rb b/spec/helpers/users_helper_spec.rb index 1365c7fe..48d28dd6 100644 --- a/spec/helpers/users_helper_spec.rb +++ b/spec/helpers/users_helper_spec.rb @@ -1,5 +1,3 @@ -# frozen_string_literal: true - require 'rails_helper' # Specs in this file have access to a helper object that includes diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index e1550e7a..81f6e0e9 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1,5 +1,3 @@ -# frozen_string_literal: true - # == Schema Information # # Table name: users From 09d9af76cc9c2b1edfeab77db4f844db5faa2834 Mon Sep 17 00:00:00 2001 From: Stephen Chudleigh Date: Tue, 30 Jul 2024 21:16:01 -0700 Subject: [PATCH 9/9] add frozen_string_literal back --- Gemfile | 2 ++ Rakefile | 2 ++ app/channels/application_cable/channel.rb | 2 ++ app/channels/application_cable/connection.rb | 2 ++ app/controllers/application_controller.rb | 2 ++ app/helpers/application_helper.rb | 2 ++ app/helpers/users_helper.rb | 2 ++ app/jobs/application_job.rb | 2 ++ app/mailers/application_mailer.rb | 2 ++ app/models/application_record.rb | 2 ++ app/models/user.rb | 2 ++ bin/rails | 2 ++ bin/rake | 2 ++ bin/setup | 2 ++ config.ru | 2 ++ config/application.rb | 2 ++ config/boot.rb | 2 ++ config/environment.rb | 2 ++ config/environments/dev.rb | 2 ++ config/environments/development.rb | 2 ++ config/environments/production.rb | 2 ++ config/environments/staging.rb | 2 ++ config/environments/test.rb | 2 ++ config/initializers/assets.rb | 2 ++ config/initializers/content_security_policy.rb | 2 ++ config/initializers/filter_parameter_logging.rb | 2 ++ config/initializers/inflections.rb | 2 ++ config/initializers/permissions_policy.rb | 2 ++ config/puma.rb | 2 ++ config/routes.rb | 2 ++ db/seeds.rb | 2 ++ spec/helpers/users_helper_spec.rb | 2 ++ spec/models/user_spec.rb | 2 ++ 33 files changed, 66 insertions(+) diff --git a/Gemfile b/Gemfile index 6a42bbf6..fbba23aa 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source "https://rubygems.org" ruby "3.2.4" diff --git a/Rakefile b/Rakefile index 18f21e17..84b021d0 100644 --- a/Rakefile +++ b/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/app/channels/application_cable/channel.rb b/app/channels/application_cable/channel.rb index d6726972..9aec2305 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 0ff5442f..8d6c2a1b 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/application_controller.rb b/app/controllers/application_controller.rb index 09705d12..7944f9f9 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + class ApplicationController < ActionController::Base end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be794..15b06f0f 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/users_helper.rb b/app/helpers/users_helper.rb index 2310a240..4dc909ed 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + module UsersHelper end diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb index d394c3d1..bef39599 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 3c34c814..5cc63a0c 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ApplicationMailer < ActionMailer::Base default from: "from@example.com" layout "mailer" diff --git a/app/models/application_record.rb b/app/models/application_record.rb index b63caeb8..08dc5379 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/user.rb b/app/models/user.rb index 07ca350e..7bd1bd84 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # == Schema Information # # Table name: users diff --git a/bin/rails b/bin/rails index efc03774..22f2d8de 100755 --- a/bin/rails +++ b/bin/rails @@ -1,4 +1,6 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + APP_PATH = File.expand_path("../config/application", __dir__) require_relative "../config/boot" require "rails/commands" diff --git a/bin/rake b/bin/rake index 4fbf10b9..e436ea54 100755 --- a/bin/rake +++ b/bin/rake @@ -1,4 +1,6 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + require_relative "../config/boot" require "rake" Rake.application.run diff --git a/bin/setup b/bin/setup index 3cd5a9d7..461ab94e 100755 --- a/bin/setup +++ b/bin/setup @@ -1,4 +1,6 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + require "fileutils" # path to your application root. diff --git a/config.ru b/config.ru index 4a3c09a6..536a9d2a 100644 --- a/config.ru +++ b/config.ru @@ -1,3 +1,5 @@ +# frozen_string_literal: true +# # This file is used by Rack-based servers to start the application. require_relative "config/environment" diff --git a/config/application.rb b/config/application.rb index bbd5579a..0f48164e 100644 --- a/config/application.rb +++ b/config/application.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative "boot" require "rails/all" diff --git a/config/boot.rb b/config/boot.rb index 988a5ddc..aef6d031 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) require "bundler/setup" # Set up gems listed in the Gemfile. diff --git a/config/environment.rb b/config/environment.rb index cac53157..6319a6ad 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true +# # Load the Rails application. require_relative "application" diff --git a/config/environments/dev.rb b/config/environments/dev.rb index 13ffe7d8..59363bd6 100644 --- a/config/environments/dev.rb +++ b/config/environments/dev.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "active_support/core_ext/integer/time" Rails.application.configure do diff --git a/config/environments/development.rb b/config/environments/development.rb index 2e7fb486..a10ac8b1 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "active_support/core_ext/integer/time" Rails.application.configure do diff --git a/config/environments/production.rb b/config/environments/production.rb index 13ffe7d8..59363bd6 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "active_support/core_ext/integer/time" Rails.application.configure do diff --git a/config/environments/staging.rb b/config/environments/staging.rb index 13ffe7d8..59363bd6 100644 --- a/config/environments/staging.rb +++ b/config/environments/staging.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "active_support/core_ext/integer/time" Rails.application.configure do diff --git a/config/environments/test.rb b/config/environments/test.rb index adbb4a6f..8a33329b 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "active_support/core_ext/integer/time" # The test environment is used exclusively to run your application's diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index 925f18ef..6db2f3a2 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Version of your assets, change this if you want to expire all your assets. diff --git a/config/initializers/content_security_policy.rb b/config/initializers/content_security_policy.rb index b3076b38..35ab3fd6 100644 --- a/config/initializers/content_security_policy.rb +++ b/config/initializers/content_security_policy.rb @@ -1,3 +1,5 @@ +# 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/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb index c2d89e28..a119afa1 100644 --- a/config/initializers/filter_parameter_logging.rb +++ b/config/initializers/filter_parameter_logging.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Configure parameters to be partially matched (e.g. passw matches password) and filtered from the log file. diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index 3860f659..9e049dcc 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -1,3 +1,5 @@ +# 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/permissions_policy.rb b/config/initializers/permissions_policy.rb index 7db3b957..e8d0b2ae 100644 --- a/config/initializers/permissions_policy.rb +++ b/config/initializers/permissions_policy.rb @@ -1,3 +1,5 @@ +# 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/config/puma.rb b/config/puma.rb index afa809b4..40efb189 100644 --- a/config/puma.rb +++ b/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. diff --git a/config/routes.rb b/config/routes.rb index e93c1a31..7e495288 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Rails.application.routes.draw do # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html diff --git a/db/seeds.rb b/db/seeds.rb index 4fbd6ed9..0f162112 100644 --- a/db/seeds.rb +++ b/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/spec/helpers/users_helper_spec.rb b/spec/helpers/users_helper_spec.rb index 48d28dd6..1365c7fe 100644 --- a/spec/helpers/users_helper_spec.rb +++ b/spec/helpers/users_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/spec/models/user_spec.rb b/spec/models/user_spec.rb index 81f6e0e9..e1550e7a 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # == Schema Information # # Table name: users