From 54ace2f0a88458363f94a244b8d844ec6123ddcb Mon Sep 17 00:00:00 2001 From: Will Clarke Date: Tue, 15 Oct 2024 22:15:27 +0100 Subject: [PATCH 1/2] update rails and add new db cleaner gem and config --- Gemfile | 4 +- Gemfile.lock | 139 +++++++++++++++++++++---------------------- spec/rails_helper.rb | 29 +++++++-- 3 files changed, 93 insertions(+), 79 deletions(-) diff --git a/Gemfile b/Gemfile index cce7ff100..ec85900e5 100644 --- a/Gemfile +++ b/Gemfile @@ -4,7 +4,7 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" } ruby "3.3.4" # Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main" -gem "rails", "~> 7.1.3" +gem "rails", "~> 7.2.1" # The modern asset pipeline for Rails [https://github.com/rails/propshaft] gem "propshaft", ">= 0.9.0" @@ -102,7 +102,7 @@ group :test do gem "webmock", require: false gem "axe-core-rspec" gem "rack_session_access" - gem "database_cleaner" + gem "database_cleaner-active_record" gem "vcr", require: false end diff --git a/Gemfile.lock b/Gemfile.lock index 50429bf3a..5a68fc308 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,84 +1,80 @@ GEM remote: https://rubygems.org/ specs: - actioncable (7.1.3.4) - actionpack (= 7.1.3.4) - activesupport (= 7.1.3.4) + actioncable (7.2.1) + actionpack (= 7.2.1) + activesupport (= 7.2.1) nio4r (~> 2.0) websocket-driver (>= 0.6.1) zeitwerk (~> 2.6) - actionmailbox (7.1.3.4) - actionpack (= 7.1.3.4) - activejob (= 7.1.3.4) - activerecord (= 7.1.3.4) - activestorage (= 7.1.3.4) - activesupport (= 7.1.3.4) - mail (>= 2.7.1) - net-imap - net-pop - net-smtp - actionmailer (7.1.3.4) - actionpack (= 7.1.3.4) - actionview (= 7.1.3.4) - activejob (= 7.1.3.4) - activesupport (= 7.1.3.4) - mail (~> 2.5, >= 2.5.4) - net-imap - net-pop - net-smtp + actionmailbox (7.2.1) + actionpack (= 7.2.1) + activejob (= 7.2.1) + activerecord (= 7.2.1) + activestorage (= 7.2.1) + activesupport (= 7.2.1) + mail (>= 2.8.0) + actionmailer (7.2.1) + actionpack (= 7.2.1) + actionview (= 7.2.1) + activejob (= 7.2.1) + activesupport (= 7.2.1) + mail (>= 2.8.0) rails-dom-testing (~> 2.2) - actionpack (7.1.3.4) - actionview (= 7.1.3.4) - activesupport (= 7.1.3.4) + actionpack (7.2.1) + actionview (= 7.2.1) + activesupport (= 7.2.1) nokogiri (>= 1.8.5) racc - rack (>= 2.2.4) + rack (>= 2.2.4, < 3.2) rack-session (>= 1.0.1) rack-test (>= 0.6.3) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) - actiontext (7.1.3.4) - actionpack (= 7.1.3.4) - activerecord (= 7.1.3.4) - activestorage (= 7.1.3.4) - activesupport (= 7.1.3.4) + useragent (~> 0.16) + actiontext (7.2.1) + actionpack (= 7.2.1) + activerecord (= 7.2.1) + activestorage (= 7.2.1) + activesupport (= 7.2.1) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (7.1.3.4) - activesupport (= 7.1.3.4) + actionview (7.2.1) + activesupport (= 7.2.1) builder (~> 3.1) erubi (~> 1.11) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) - activejob (7.1.3.4) - activesupport (= 7.1.3.4) + activejob (7.2.1) + activesupport (= 7.2.1) globalid (>= 0.3.6) - activemodel (7.1.3.4) - activesupport (= 7.1.3.4) + activemodel (7.2.1) + activesupport (= 7.2.1) activemodel-serializers-xml (1.0.2) activemodel (> 5.x) activesupport (> 5.x) builder (~> 3.1) - activerecord (7.1.3.4) - activemodel (= 7.1.3.4) - activesupport (= 7.1.3.4) + activerecord (7.2.1) + activemodel (= 7.2.1) + activesupport (= 7.2.1) timeout (>= 0.4.0) - activestorage (7.1.3.4) - actionpack (= 7.1.3.4) - activejob (= 7.1.3.4) - activerecord (= 7.1.3.4) - activesupport (= 7.1.3.4) + activestorage (7.2.1) + actionpack (= 7.2.1) + activejob (= 7.2.1) + activerecord (= 7.2.1) + activesupport (= 7.2.1) marcel (~> 1.0) - activesupport (7.1.3.4) + activesupport (7.2.1) base64 bigdecimal - concurrent-ruby (~> 1.0, >= 1.0.2) + concurrent-ruby (~> 1.0, >= 1.3.1) connection_pool (>= 2.2.5) drb i18n (>= 1.6, < 2) + logger (>= 1.4.2) minitest (>= 5.1) - mutex_m - tzinfo (~> 2.0) + securerandom (>= 0.3) + tzinfo (~> 2.0, >= 2.0.5) addressable (2.8.7) public_suffix (>= 2.0.2, < 7.0) annotate_models (1.0.1) @@ -138,9 +134,7 @@ GEM cssbundling-rails (1.4.1) railties (>= 6.0.0) csv (3.3.0) - database_cleaner (2.0.2) - database_cleaner-active_record (>= 2, < 3) - database_cleaner-active_record (2.1.0) + database_cleaner-active_record (2.2.0) activerecord (>= 5.a) database_cleaner-core (~> 2.0.0) database_cleaner-core (2.0.1) @@ -259,7 +253,6 @@ GEM msgpack (1.7.2) multi_xml (0.7.1) bigdecimal (~> 3.1) - mutex_m (0.2.0) nested_form (0.3.2) net-http (0.4.1) uri @@ -357,20 +350,20 @@ GEM rackup (1.0.0) rack (< 3) webrick - rails (7.1.3.4) - actioncable (= 7.1.3.4) - actionmailbox (= 7.1.3.4) - actionmailer (= 7.1.3.4) - actionpack (= 7.1.3.4) - actiontext (= 7.1.3.4) - actionview (= 7.1.3.4) - activejob (= 7.1.3.4) - activemodel (= 7.1.3.4) - activerecord (= 7.1.3.4) - activestorage (= 7.1.3.4) - activesupport (= 7.1.3.4) + rails (7.2.1) + actioncable (= 7.2.1) + actionmailbox (= 7.2.1) + actionmailer (= 7.2.1) + actionpack (= 7.2.1) + actiontext (= 7.2.1) + actionview (= 7.2.1) + activejob (= 7.2.1) + activemodel (= 7.2.1) + activerecord (= 7.2.1) + activestorage (= 7.2.1) + activesupport (= 7.2.1) bundler (>= 1.15.0) - railties (= 7.1.3.4) + railties (= 7.2.1) rails-dom-testing (2.2.0) activesupport (>= 5.0.0) minitest @@ -385,10 +378,10 @@ GEM nested_form (~> 0.3) rails (>= 6.0, < 8) turbo-rails (>= 1.0, < 3) - railties (7.1.3.4) - actionpack (= 7.1.3.4) - activesupport (= 7.1.3.4) - irb + railties (7.2.1) + actionpack (= 7.2.1) + activesupport (= 7.2.1) + irb (~> 1.13) rackup (>= 1.0.0) rake (>= 12.2) thor (~> 1.0, >= 1.2.2) @@ -485,6 +478,7 @@ GEM rexml rubyzip (2.3.2) safe_shell (1.1.0) + securerandom (0.3.1) selenium-webdriver (4.25.0) base64 (~> 0.2) logger (~> 1.4) @@ -532,6 +526,7 @@ GEM concurrent-ruby (~> 1.0) unicode-display_width (2.6.0) uri (0.13.1) + useragent (0.16.10) vcr (6.3.1) base64 version_gem (1.1.4) @@ -580,7 +575,7 @@ DEPENDENCIES capybara capybara-selenium cssbundling-rails - database_cleaner + database_cleaner-active_record debug devise dotenv-rails (>= 3.1.1) @@ -609,7 +604,7 @@ DEPENDENCIES pry-stack_explorer puma (~> 6.4) rack_session_access - rails (~> 7.1.3) + rails (~> 7.2.1) rails_admin redis-rails rexml (>= 3.3.4) diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 07b574fae..7d031dadf 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -10,6 +10,8 @@ require "rspec/rails" require "axe-rspec" require "pry-rescue/rspec" if Rails.env.development? +require "database_cleaner/active_record" + Capybara.register_driver :headless_chrome do |app| options = Selenium::WebDriver::Chrome::Options.new @@ -168,11 +170,28 @@ expect(ErrorService).not_to receive(:call) unless test.metadata.key?(:throws_cfe_error) end - config.before(:suite) do - DatabaseCleaner.clean_with :truncation - end - config.after(:suite) do - DatabaseCleaner.clean_with :truncation + RSpec.configure do |config| + config.use_transactional_fixtures = false + + config.before(:suite) do + DatabaseCleaner[:active_record].clean_with(:truncation) + end + + config.before(:each) do + DatabaseCleaner[:active_record].strategy = :transaction + end + + config.before(:each, js: true) do + DatabaseCleaner[:active_record].strategy = :truncation + end + + config.before(:each) do + DatabaseCleaner[:active_record].start + end + + config.after(:each) do + DatabaseCleaner[:active_record].clean + end end config.after(:suite) do From e5851582c06c4a0ae2b920e3fa5d625fec892e18 Mon Sep 17 00:00:00 2001 From: Will Clarke Date: Tue, 15 Oct 2024 23:58:15 +0100 Subject: [PATCH 2/2] update alias_attribute which has been deprecated and use alias_method --- app/forms/additional_property_details_form.rb | 3 +- app/forms/benefit_details_form.rb | 3 +- app/forms/client_assets_form.rb | 3 +- app/forms/dependant_income_details_form.rb | 3 +- app/forms/income_form.rb | 3 +- app/forms/partner_assets_form.rb | 3 +- app/forms/vehicles_details_form.rb | 3 +- spec/rails_helper.rb | 29 ++++++++----------- 8 files changed, 26 insertions(+), 24 deletions(-) diff --git a/app/forms/additional_property_details_form.rb b/app/forms/additional_property_details_form.rb index 547e6e88c..94e933416 100644 --- a/app/forms/additional_property_details_form.rb +++ b/app/forms/additional_property_details_form.rb @@ -7,7 +7,8 @@ class AdditionalPropertyDetailsForm ITEMS_SESSION_KEY = "additional_properties".freeze ITEM_MODEL = AdditionalPropertyModel ATTRIBUTES = %i[additional_properties].freeze - alias_attribute :additional_properties, :items + alias_method :additional_properties, :items + alias_method :additional_properties=, :items= class << self def add_extra_attributes_to_model_from_session(model, session_data, index) diff --git a/app/forms/benefit_details_form.rb b/app/forms/benefit_details_form.rb index 2f28042cd..be764ef7d 100644 --- a/app/forms/benefit_details_form.rb +++ b/app/forms/benefit_details_form.rb @@ -7,7 +7,8 @@ class BenefitDetailsForm ITEMS_SESSION_KEY = "benefits".freeze ITEM_MODEL = BenefitModel ATTRIBUTES = %i[benefits].freeze - alias_attribute :benefits, :items + alias_method :benefits, :items + alias_method :benefits=, :items= def benefit_list @benefit_list ||= begin diff --git a/app/forms/client_assets_form.rb b/app/forms/client_assets_form.rb index 27b54937f..6bf21cbd8 100644 --- a/app/forms/client_assets_form.rb +++ b/app/forms/client_assets_form.rb @@ -13,7 +13,8 @@ class ClientAssetsForm < AssetsForm ITEMS_SESSION_KEY = "bank_accounts".freeze ITEM_MODEL = BankAccountModel - alias_attribute :bank_accounts, :items + alias_method :bank_accounts, :items + alias_method :bank_accounts=, :items= class << self def add_extra_attributes_to_model_from_session(bank_account_model, session_data, _) diff --git a/app/forms/dependant_income_details_form.rb b/app/forms/dependant_income_details_form.rb index 28136e910..ab9656a02 100644 --- a/app/forms/dependant_income_details_form.rb +++ b/app/forms/dependant_income_details_form.rb @@ -7,7 +7,8 @@ class DependantIncomeDetailsForm ITEMS_SESSION_KEY = "dependant_incomes".freeze ITEM_MODEL = DependantIncomeModel ATTRIBUTES = %i[dependant_incomes].freeze - alias_attribute :dependant_incomes, :items + alias_method :dependant_incomes, :items + alias_method :dependant_incomes=, :items= def max_items (check.adult_dependants ? check.adult_dependants_count : 0) + (check.child_dependants ? check.child_dependants_count : 0) diff --git a/app/forms/income_form.rb b/app/forms/income_form.rb index 37b7043f8..851d9be49 100644 --- a/app/forms/income_form.rb +++ b/app/forms/income_form.rb @@ -7,7 +7,8 @@ class IncomeForm ITEMS_SESSION_KEY = "incomes".freeze ITEM_MODEL = IncomeModel ATTRIBUTES = %i[incomes].freeze - alias_attribute :incomes, :items + alias_method :incomes, :items + alias_method :incomes=, :items= def self.add_extra_attributes_to_model_from_session(model, session_data, _) model.controlled = Steps::Logic.controlled?(session_data) diff --git a/app/forms/partner_assets_form.rb b/app/forms/partner_assets_form.rb index 13d789f93..148b20902 100644 --- a/app/forms/partner_assets_form.rb +++ b/app/forms/partner_assets_form.rb @@ -6,5 +6,6 @@ class PartnerAssetsForm < AssetsForm ITEMS_SESSION_KEY = "partner_bank_accounts".freeze ITEM_MODEL = BankAccountModel - alias_attribute :bank_accounts, :items + alias_method :bank_accounts, :items + alias_method :bank_accounts=, :items= end diff --git a/app/forms/vehicles_details_form.rb b/app/forms/vehicles_details_form.rb index edd9e3448..e51608168 100644 --- a/app/forms/vehicles_details_form.rb +++ b/app/forms/vehicles_details_form.rb @@ -7,7 +7,8 @@ class VehiclesDetailsForm ITEMS_SESSION_KEY = "vehicles".freeze ITEM_MODEL = VehicleModel ATTRIBUTES = %i[vehicles].freeze - alias_attribute :vehicles, :items + alias_method :vehicles, :items + alias_method :vehicles=, :items= class << self def add_extra_attributes_to_model_from_session(vehicle_model, session_data, _) diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 7d031dadf..cdad37439 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -12,7 +12,6 @@ require "pry-rescue/rspec" if Rails.env.development? require "database_cleaner/active_record" - Capybara.register_driver :headless_chrome do |app| options = Selenium::WebDriver::Chrome::Options.new options.add_argument("--headless=new") @@ -170,27 +169,23 @@ expect(ErrorService).not_to receive(:call) unless test.metadata.key?(:throws_cfe_error) end - RSpec.configure do |config| - config.use_transactional_fixtures = false - - config.before(:suite) do - DatabaseCleaner[:active_record].clean_with(:truncation) - end - - config.before(:each) do - DatabaseCleaner[:active_record].strategy = :transaction - end + RSpec.configure do |test| + test.use_transactional_fixtures = false - config.before(:each, js: true) do - DatabaseCleaner[:active_record].strategy = :truncation + # Clean the database before the suite runs + test.before(:suite) do + DatabaseCleaner.clean_with(:truncation) end - config.before(:each) do - DatabaseCleaner[:active_record].start + # Use truncation before each test runs + test.before do + DatabaseCleaner.strategy = :truncation + DatabaseCleaner.start end - config.after(:each) do - DatabaseCleaner[:active_record].clean + # Clean the database after each test + test.after do + DatabaseCleaner.clean end end