diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fd35420e..dc359006 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,10 +50,13 @@ jobs: - name: Run unit tests run: | bundle exec rspec - sed -i 's/\/home\/runner\/work\/pafs_core\/pafs_core\//\/github\/workspace\//g' coverage/coverage.json + + - name: Update coverage output + run: | + sed -i "s@/home/runner/work/DEFRA/pafs_core@/github/workspace@g" coverage/coverage.json - name: Analyze with SonarCloud - uses: sonarsource/sonarcloud-github-action@master + uses: sonarsource/sonarqube-scan-action@master env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This is provided automatically by GitHub SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} # This needs to be set in your repo; settings -> secrets diff --git a/Gemfile b/Gemfile index c576d05f..1e63e98e 100644 --- a/Gemfile +++ b/Gemfile @@ -52,4 +52,5 @@ group :test do gem "database_cleaner" gem "faker" gem "memory_profiler" + gem "rspec-retry" end diff --git a/Gemfile.lock b/Gemfile.lock index 3a3226a3..24592d13 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -9,7 +9,7 @@ PATH remote: . specs: pafs_core (0.0.2) - aws-sdk-s3 (~> 1.67) + aws-sdk-s3 bstard clamav-client defra_ruby_alert (~> 2.2) @@ -21,7 +21,7 @@ PATH net-smtp nokogiri rack-cors - rails (~> 7.0) + rails (~> 7.2) roo rubyXL secure_headers @@ -29,110 +29,107 @@ PATH GEM remote: https://rubygems.org/ specs: - actioncable (7.1.4.1) - actionpack (= 7.1.4.1) - activesupport (= 7.1.4.1) + actioncable (7.2.2.1) + actionpack (= 7.2.2.1) + activesupport (= 7.2.2.1) nio4r (~> 2.0) websocket-driver (>= 0.6.1) zeitwerk (~> 2.6) - actionmailbox (7.1.4.1) - actionpack (= 7.1.4.1) - activejob (= 7.1.4.1) - activerecord (= 7.1.4.1) - activestorage (= 7.1.4.1) - activesupport (= 7.1.4.1) - mail (>= 2.7.1) - net-imap - net-pop - net-smtp - actionmailer (7.1.4.1) - actionpack (= 7.1.4.1) - actionview (= 7.1.4.1) - activejob (= 7.1.4.1) - activesupport (= 7.1.4.1) - mail (~> 2.5, >= 2.5.4) - net-imap - net-pop - net-smtp + actionmailbox (7.2.2.1) + actionpack (= 7.2.2.1) + activejob (= 7.2.2.1) + activerecord (= 7.2.2.1) + activestorage (= 7.2.2.1) + activesupport (= 7.2.2.1) + mail (>= 2.8.0) + actionmailer (7.2.2.1) + actionpack (= 7.2.2.1) + actionview (= 7.2.2.1) + activejob (= 7.2.2.1) + activesupport (= 7.2.2.1) + mail (>= 2.8.0) rails-dom-testing (~> 2.2) - actionpack (7.1.4.1) - actionview (= 7.1.4.1) - activesupport (= 7.1.4.1) + actionpack (7.2.2.1) + actionview (= 7.2.2.1) + activesupport (= 7.2.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.4.1) - actionpack (= 7.1.4.1) - activerecord (= 7.1.4.1) - activestorage (= 7.1.4.1) - activesupport (= 7.1.4.1) + useragent (~> 0.16) + actiontext (7.2.2.1) + actionpack (= 7.2.2.1) + activerecord (= 7.2.2.1) + activestorage (= 7.2.2.1) + activesupport (= 7.2.2.1) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (7.1.4.1) - activesupport (= 7.1.4.1) + actionview (7.2.2.1) + activesupport (= 7.2.2.1) builder (~> 3.1) erubi (~> 1.11) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) - activejob (7.1.4.1) - activesupport (= 7.1.4.1) + activejob (7.2.2.1) + activesupport (= 7.2.2.1) globalid (>= 0.3.6) - activemodel (7.1.4.1) - activesupport (= 7.1.4.1) - activerecord (7.1.4.1) - activemodel (= 7.1.4.1) - activesupport (= 7.1.4.1) + activemodel (7.2.2.1) + activesupport (= 7.2.2.1) + activerecord (7.2.2.1) + activemodel (= 7.2.2.1) + activesupport (= 7.2.2.1) timeout (>= 0.4.0) - activestorage (7.1.4.1) - actionpack (= 7.1.4.1) - activejob (= 7.1.4.1) - activerecord (= 7.1.4.1) - activesupport (= 7.1.4.1) + activestorage (7.2.2.1) + actionpack (= 7.2.2.1) + activejob (= 7.2.2.1) + activerecord (= 7.2.2.1) + activesupport (= 7.2.2.1) marcel (~> 1.0) - activesupport (7.1.4.1) + activesupport (7.2.2.1) base64 + benchmark (>= 0.3) 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) - airbrake (13.0.4) + airbrake (13.0.5) airbrake-ruby (~> 6.0) airbrake-ruby (6.2.2) rbtree3 (~> 0.6) ast (2.4.2) - async (2.10.2) - console (~> 1.10) + async (2.21.1) + console (~> 1.29) fiber-annotation - io-event (~> 1.5, >= 1.5.1) - timers (~> 4.1) - async-http (0.64.1) - async (>= 1.25) - async-io (>= 1.28) - async-pool (>= 0.2) - protocol-http (~> 0.26.0) - protocol-http1 (~> 0.19.0) - protocol-http2 (~> 0.16.0) - traces (>= 0.10.0) - async-http-faraday (0.13.1) + io-event (~> 1.6, >= 1.6.5) + async-http (0.86.0) + async (>= 2.10.2) + async-pool (~> 0.9) + io-endpoint (~> 0.14) + io-stream (~> 0.6) + metrics (~> 0.12) + protocol-http (~> 0.43) + protocol-http1 (>= 0.28.1) + protocol-http2 (~> 0.22) + traces (~> 0.10) + async-http-faraday (0.19.0) async-http (~> 0.42) faraday - async-io (1.42.1) - async - async-pool (0.4.0) + async-pool (0.10.2) async (>= 1.25) + traces aws-eventstream (1.3.0) - aws-partitions (1.1009.0) - aws-sdk-core (3.213.0) + aws-partitions (1.1027.0) + aws-sdk-core (3.214.0) aws-eventstream (~> 1, >= 1.3.0) aws-partitions (~> 1, >= 1.992.0) aws-sigv4 (~> 1.9) @@ -140,13 +137,14 @@ GEM aws-sdk-kms (1.96.0) aws-sdk-core (~> 3, >= 3.210.0) aws-sigv4 (~> 1.5) - aws-sdk-s3 (1.172.0) + aws-sdk-s3 (1.176.1) aws-sdk-core (~> 3, >= 3.210.0) aws-sdk-kms (~> 1) aws-sigv4 (~> 1.5) aws-sigv4 (1.10.1) aws-eventstream (~> 1, >= 1.0.2) base64 (0.2.0) + benchmark (0.4.0) bigdecimal (3.1.8) bstard (0.2.4) builder (3.3.0) @@ -165,21 +163,21 @@ GEM coderay (1.1.3) concurrent-ruby (1.3.4) connection_pool (2.4.1) - console (1.23.6) + console (1.29.2) fiber-annotation - fiber-local + fiber-local (~> 1.1) json crack (1.0.0) bigdecimal rexml crass (1.0.6) - database_cleaner (2.0.2) + database_cleaner (2.1.0) 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) - date (3.3.4) + date (3.4.1) defra_ruby_alert (2.2.1) airbrake defra_ruby_style (0.4.0) @@ -189,10 +187,10 @@ GEM rubocop-rspec defra_ruby_template (5.4.1) diff-lcs (1.5.1) - docile (1.4.0) - dotenv (3.1.4) + docile (1.4.1) + dotenv (3.1.7) drb (2.2.1) - erubi (1.13.0) + erubi (1.13.1) factory_bot (6.5.0) activesupport (>= 5.0.0) factory_bot_rails (6.4.4) @@ -200,7 +198,7 @@ GEM railties (>= 5.0.0) faker (3.5.1) i18n (>= 1.8.11, < 2) - faraday (2.12.1) + faraday (2.12.2) faraday-net_http (>= 2.0, < 3.5) json logger @@ -211,7 +209,9 @@ GEM faraday-retry (2.2.1) faraday (~> 2.0) fiber-annotation (0.2.0) - fiber-local (1.0.0) + fiber-local (1.1.0) + fiber-storage + fiber-storage (1.0.0) github_changelog_generator (1.16.4) activesupport async (>= 1.25.0) @@ -234,13 +234,15 @@ GEM activesupport (>= 6.1.4.4) i18n (1.14.6) concurrent-ruby (~> 1.0) - io-console (0.7.2) - io-event (1.5.1) - irb (1.14.1) + io-console (0.8.0) + io-endpoint (0.14.0) + io-event (1.7.5) + io-stream (0.6.1) + irb (1.14.3) rdoc (>= 4.0.0) reline (>= 0.4.2) jmespath (1.6.2) - json (2.7.4) + json (2.9.1) json_schemer (2.3.0) bigdecimal hana (~> 1.3) @@ -259,7 +261,7 @@ GEM kaminari-core (= 1.2.2) kaminari-core (1.2.2) language_server-protocol (3.17.0.3) - logger (1.6.1) + logger (1.6.4) loofah (2.23.1) crass (~> 1.0.2) nokogiri (>= 1.12.0) @@ -272,14 +274,14 @@ GEM matrix (0.4.2) memory_profiler (1.1.0) method_source (1.1.0) + metrics (0.12.1) mini_mime (1.1.5) mini_portile2 (2.8.8) - minitest (5.25.1) + minitest (5.25.4) multi_json (1.15.0) - mutex_m (0.2.0) - net-http (0.5.0) + net-http (0.6.0) uri - net-imap (0.4.14) + net-imap (0.5.4) date net-protocol net-pop (0.1.2) @@ -288,31 +290,32 @@ GEM timeout net-smtp (0.5.0) net-protocol - nio4r (2.7.3) - nokogiri (1.16.7) + nio4r (2.7.4) + nokogiri (1.17.2) mini_portile2 (~> 2.8.2) racc (~> 1.4) octokit (4.25.1) faraday (>= 1, < 3) sawyer (~> 0.9) parallel (1.26.3) - parser (3.3.5.0) + parser (3.3.6.0) ast (~> 2.4.1) racc pg (1.5.9) - protocol-hpack (1.4.3) - protocol-http (0.26.4) - protocol-http1 (0.19.0) + protocol-hpack (1.5.1) + protocol-http (0.47.1) + protocol-http1 (0.28.1) protocol-http (~> 0.22) - protocol-http2 (0.16.0) + protocol-http2 (0.22.0) protocol-hpack (~> 1.4) protocol-http (~> 0.18) - pry (0.14.2) + pry (0.15.0) coderay (~> 1.1) method_source (~> 1.0) pry-rails (0.3.11) pry (>= 0.13.0) - psych (5.2.0) + psych (5.2.2) + date stringio public_suffix (6.0.1) racc (1.8.1) @@ -326,20 +329,20 @@ GEM rackup (1.0.1) rack (< 3) webrick - rails (7.1.4.1) - actioncable (= 7.1.4.1) - actionmailbox (= 7.1.4.1) - actionmailer (= 7.1.4.1) - actionpack (= 7.1.4.1) - actiontext (= 7.1.4.1) - actionview (= 7.1.4.1) - activejob (= 7.1.4.1) - activemodel (= 7.1.4.1) - activerecord (= 7.1.4.1) - activestorage (= 7.1.4.1) - activesupport (= 7.1.4.1) + rails (7.2.2.1) + actioncable (= 7.2.2.1) + actionmailbox (= 7.2.2.1) + actionmailer (= 7.2.2.1) + actionpack (= 7.2.2.1) + actiontext (= 7.2.2.1) + actionview (= 7.2.2.1) + activejob (= 7.2.2.1) + activemodel (= 7.2.2.1) + activerecord (= 7.2.2.1) + activestorage (= 7.2.2.1) + activesupport (= 7.2.2.1) bundler (>= 1.15.0) - railties (= 7.1.4.1) + railties (= 7.2.2.1) rails-controller-testing (1.0.5) actionpack (>= 5.0.1.rc1) actionview (>= 5.0.1.rc1) @@ -348,13 +351,13 @@ GEM activesupport (>= 5.0.0) minitest nokogiri (>= 1.6) - rails-html-sanitizer (1.6.0) + rails-html-sanitizer (1.6.2) loofah (~> 2.21) - nokogiri (~> 1.14) - railties (7.1.4.1) - actionpack (= 7.1.4.1) - activesupport (= 7.1.4.1) - irb + nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0) + railties (7.2.2.1) + actionpack (= 7.2.2.1) + activesupport (= 7.2.2.1) + irb (~> 1.13) rackup (>= 1.0.0) rake (>= 12.2) thor (~> 1.0, >= 1.2.2) @@ -362,44 +365,45 @@ GEM rainbow (3.1.1) rake (13.2.1) rbtree3 (0.7.1) - rdoc (6.8.1) + rdoc (6.10.0) psych (>= 4.0.0) - regexp_parser (2.9.2) - reline (0.5.11) + regexp_parser (2.9.3) + reline (0.6.0) io-console (~> 0.5) - rexml (3.3.9) + rexml (3.4.0) roo (2.10.1) nokogiri (~> 1) rubyzip (>= 1.3.0, < 3.0.0) - rspec-core (3.13.0) + rspec-core (3.13.2) rspec-support (~> 3.13.0) - rspec-expectations (3.13.1) + rspec-expectations (3.13.3) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.13.0) - rspec-mocks (3.13.1) + rspec-mocks (3.13.2) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.13.0) - rspec-rails (6.1.4) - actionpack (>= 6.1) - activesupport (>= 6.1) - railties (>= 6.1) + rspec-rails (7.1.0) + actionpack (>= 7.0) + activesupport (>= 7.0) + railties (>= 7.0) rspec-core (~> 3.13) rspec-expectations (~> 3.13) rspec-mocks (~> 3.13) rspec-support (~> 3.13) - rspec-support (3.13.1) - rubocop (1.65.1) + rspec-retry (0.6.2) + rspec-core (> 3.3) + rspec-support (3.13.2) + rubocop (1.69.2) json (~> 2.3) language_server-protocol (>= 3.17.0) parallel (~> 1.10) parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) - regexp_parser (>= 2.4, < 3.0) - rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.31.1, < 2.0) + regexp_parser (>= 2.9.3, < 3.0) + rubocop-ast (>= 1.36.2, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.32.3) + unicode-display_width (>= 2.4.0, < 4.0) + rubocop-ast (1.37.0) parser (>= 3.3.1.0) rubocop-capybara (2.21.0) rubocop (~> 1.41) @@ -412,27 +416,28 @@ GEM rubocop-ast (>= 1.31.1, < 2.0) rubocop-rake (0.6.0) rubocop (~> 1.0) - rubocop-rspec (3.2.0) + rubocop-rspec (3.3.0) rubocop (~> 1.61) rubocop-rspec_rails (2.30.0) rubocop (~> 1.61) rubocop-rspec (~> 3, >= 3.0.1) ruby-progressbar (1.13.0) - rubyXL (3.4.27) + rubyXL (3.4.32) nokogiri (>= 1.10.8) rubyzip (>= 1.3.0) rubyzip (2.3.2) sawyer (0.9.2) addressable (>= 2.3.5) faraday (>= 0.17.3, < 3) - secure_headers (7.0.0) + secure_headers (7.1.0) + securerandom (0.4.1) shoulda-matchers (6.4.0) activesupport (>= 5.2.0) simplecov (0.22.0) docile (~> 1.1) simplecov-html (~> 0.11) simplecov_json_formatter (~> 0.1) - simplecov-html (0.12.3) + simplecov-html (0.13.1) simplecov_json_formatter (0.1.4) simpleidn (0.2.3) sprockets (3.7.5) @@ -446,20 +451,22 @@ GEM stringio (3.1.2) thor (1.3.2) timecop (0.9.10) - timeout (0.4.1) - timers (4.3.5) - traces (0.11.1) + timeout (0.4.3) + traces (0.14.1) tzinfo (2.0.6) concurrent-ruby (~> 1.0) - unicode-display_width (2.6.0) + unicode-display_width (3.1.2) + unicode-emoji (~> 4.0, >= 4.0.4) + unicode-emoji (4.0.4) uri (1.0.2) + useragent (0.16.11) vcr (6.3.1) base64 webmock (3.24.0) addressable (>= 2.8.0) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) - webrick (1.9.0) + webrick (1.9.1) websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) @@ -490,6 +497,7 @@ DEPENDENCIES pry-rails rails-controller-testing rspec-rails + rspec-retry rubocop rubocop-capybara rubocop-rails diff --git a/app/presenters/pafs_core/spreadsheet_presenter.rb b/app/presenters/pafs_core/spreadsheet_presenter.rb index 370d6cc5..b0598d52 100644 --- a/app/presenters/pafs_core/spreadsheet_presenter.rb +++ b/app/presenters/pafs_core/spreadsheet_presenter.rb @@ -41,7 +41,9 @@ def rma_type end def pso_name - pso? ? creator&.primary_area&.name : creator&.primary_area&.parent&.name + return nil if creator&.primary_area.blank? + + pso? ? creator.primary_area.name : creator.primary_area.parent&.name end def coastal_group @@ -129,7 +131,7 @@ def strategic_approach # pv_whole_life_benefits def benefit_cost_ratio - return unless pv_whole_life_benefits && pv_whole_life_costs && pv_whole_life_costs.positive? + return unless pv_whole_life_benefits && pv_whole_life_costs&.positive? (pv_whole_life_benefits / pv_whole_life_costs).round(1) end diff --git a/app/steps/pafs_core/coastal_erosion_protection_outcomes_step.rb b/app/steps/pafs_core/coastal_erosion_protection_outcomes_step.rb index ebeafd5f..1f3c1424 100644 --- a/app/steps/pafs_core/coastal_erosion_protection_outcomes_step.rb +++ b/app/steps/pafs_core/coastal_erosion_protection_outcomes_step.rb @@ -30,8 +30,8 @@ def values? if outcome.send(attr).to_i.positive? return errors.add( :base, - "In the applicable year(s), tell us how many households moved to a lower flood risk category \ - (column A), OR if this does not apply select the checkbox." + "In the applicable year(s), tell us how many households moved to a lower flood risk category " \ + "(column A), OR if this does not apply select the checkbox." ) end end @@ -52,8 +52,8 @@ def values_make_sense unless b_too_big.empty? errors.add( :base, - "The number of households protected from loss within the next 20 years (column B) must be lower \ - than or equal to the number of households at a reduced risk of coastal erosion (column A)." + "The number of households protected from loss within the next 20 years (column B) must be lower " \ + "than or equal to the number of households at a reduced risk of coastal erosion (column A)." ) end @@ -61,8 +61,8 @@ def values_make_sense errors.add( :base, - "The number of households in the 20% most deprived areas (column C) must be lower than or \ - equal to the number of households protected from loss within the next 20 years (column B)." + "The number of households in the 20% most deprived areas (column C) must be lower than or " \ + "equal to the number of households protected from loss within the next 20 years (column B)." ) end @@ -111,8 +111,8 @@ def sensible_number_of_houses unless c_insensible.empty? errors.add( :base, - "The number of households protected from loss in the 20 percent most deprived areas must \ - be less than or equal to 1 million." + "The number of households protected from loss in the 20 percent most deprived areas must " \ + "be less than or equal to 1 million." ) end @@ -120,8 +120,7 @@ def sensible_number_of_houses errors.add( :base, - "The number of non-residential properties must \ - be less than or equal to 1 million." + "The number of non-residential properties must be less than or equal to 1 million." ) end diff --git a/app/steps/pafs_core/flood_protection_outcomes2040_step.rb b/app/steps/pafs_core/flood_protection_outcomes2040_step.rb index fc7e0ce6..628914f1 100644 --- a/app/steps/pafs_core/flood_protection_outcomes2040_step.rb +++ b/app/steps/pafs_core/flood_protection_outcomes2040_step.rb @@ -56,9 +56,9 @@ def values_make_sense unless b_too_big.empty? errors.add( :base, - "The number of households moved from very significant or significant to\ - the moderate or low flood risk category (column B) must be lower than or equal\ - to the number of households moved to a lower flood risk category (column A)." + "The number of households moved from very significant or significant to " \ + "the moderate or low flood risk category (column B) must be lower than or equal " \ + "to the number of households moved to a lower flood risk category (column A)." ) end @@ -66,9 +66,9 @@ def values_make_sense errors.add( :base, - "The number of households in the 20% most deprived areas (column C) must be lower than or equal \ - to the number of households moved from very significant \ - or significant to the moderate or low flood risk category (column B)." + "The number of households in the 20% most deprived areas (column C) must be lower than or equal " \ + "to the number of households moved from very significant " \ + "or significant to the moderate or low flood risk category (column B)." ) end @@ -78,8 +78,8 @@ def at_least_one_value errors.add( :base, - "In the applicable year(s), tell us how many households moved to a lower flood risk category (column A), \ - OR if this does not apply select the checkbox." + "In the applicable year(s), tell us how many households moved to a lower flood risk category (column A), " \ + "OR if this does not apply select the checkbox." ) end @@ -112,16 +112,16 @@ def sensible_number_of_houses unless b_insensible.empty? errors.add( :base, - "The number of households moved from very significant and significant to moderate or low must be \ - less than or equal to 1 million." + "The number of households moved from very significant and significant to moderate or low must be " \ + "less than or equal to 1 million." ) end unless c_insensible.empty? errors.add( :base, - "The number of households protected from loss in the 20 percent most deprived must be \ - less than or equal to 1 million." + "The number of households protected from loss in the 20 percent most deprived must be " \ + "less than or equal to 1 million." ) end @@ -129,8 +129,8 @@ def sensible_number_of_houses errors.add( :base, - "The number of non-residential properties must be \ - less than or equal to 1 million." + "The number of non-residential properties must be " \ + "less than or equal to 1 million." ) end diff --git a/app/steps/pafs_core/flood_protection_outcomes_step.rb b/app/steps/pafs_core/flood_protection_outcomes_step.rb index d03e3600..1897574b 100644 --- a/app/steps/pafs_core/flood_protection_outcomes_step.rb +++ b/app/steps/pafs_core/flood_protection_outcomes_step.rb @@ -58,18 +58,18 @@ def values_make_sense unless b_too_big.empty? errors.add( :base, - "The number of households moved from very significant or significant to \ - the moderate or low flood risk category (column B) must be lower than or equal \ - to the number of households moved to a lower flood risk category (column A)." + "The number of households moved from very significant or significant to " \ + "moderate or low flood risk category (column B) must be lower than or equal " \ + "to the number of households moved to a lower flood risk category (column A)." ) end unless c_too_big.empty? errors.add( :base, - "The number of households in the 20% most deprived areas (column C) must be lower than or equal \ - to the number of households moved from very significant \ - or significant to the moderate or low flood risk category (column B)." + "The number of households in the 20% most deprived areas (column C) must be lower than or equal " \ + "to the number of households moved from very significant " \ + "or significant to the moderate or low flood risk category (column B)." ) end @@ -77,10 +77,10 @@ def values_make_sense errors.add( :base, - "The number of households that are protected through Property Level Protection (PLP) \ - measures (column D) must be lower than or equal to \ - to the number of households moved from very significant \ - or significant to the moderate or low flood risk category (column B)." + "The number of households that are protected through Property Level Protection (PLP) " \ + "measures (column D) must be lower than or equal to " \ + "the number of households moved from very significant " \ + "or significant to the moderate or low flood risk category (column B)." ) end @@ -89,8 +89,8 @@ def at_least_one_value errors.add( :base, - "In the applicable year(s), tell us how many households moved to a lower flood risk category (column A), \ - OR if this does not apply select the checkbox." + "In the applicable year(s), tell us how many households moved to a lower flood risk category (column A), " \ + "OR if this does not apply select the checkbox." ) end @@ -125,24 +125,24 @@ def sensible_number_of_houses unless b_insensible.empty? errors.add( :base, - "The number of households moved from very significant and significant to moderate or low must be \ - less than or equal to 1 million." + "The number of households moved from very significant and significant to moderate or low must be " \ + "less than or equal to 1 million." ) end unless c_insensible.empty? errors.add( :base, - "The number of households protected from loss in the 20 percent most deprived must be \ - less than or equal to 1 million." + "The number of households protected from loss in the 20 percent most deprived must be " \ + "less than or equal to 1 million." ) end unless d_insensible.empty? errors.add( :base, - "The number of households protected through Property Level Protection (PLP) measures must be \ - less than or equal to 1 million." + "The number of households protected through Property Level Protection (PLP) measures must be " \ + "less than or equal to 1 million." ) end @@ -150,8 +150,7 @@ def sensible_number_of_houses errors.add( :base, - "The number of non-residential properties must be \ - less than or equal to 1 million." + "The number of non-residential properties must be less than or equal to 1 million." ) end diff --git a/app/steps/pafs_core/standard_of_protection_after_step.rb b/app/steps/pafs_core/standard_of_protection_after_step.rb index 62703c17..cb212bc5 100644 --- a/app/steps/pafs_core/standard_of_protection_after_step.rb +++ b/app/steps/pafs_core/standard_of_protection_after_step.rb @@ -6,8 +6,8 @@ class StandardOfProtectionAfterStep < BasicStep include PafsCore::Risks validates :flood_protection_after, presence: { - message: "Select the option that shows the potential risk of flooding \ - to the area after the project is complete." + message: "Select the option that shows the potential risk of flooding " \ + "to the area after the project is complete." } validates :flood_protection_after, numericality: { diff --git a/app/steps/pafs_core/standard_of_protection_coastal_after_step.rb b/app/steps/pafs_core/standard_of_protection_coastal_after_step.rb index 121b2695..98419eb9 100644 --- a/app/steps/pafs_core/standard_of_protection_coastal_after_step.rb +++ b/app/steps/pafs_core/standard_of_protection_coastal_after_step.rb @@ -5,8 +5,8 @@ class StandardOfProtectionCoastalAfterStep < BasicStep include PafsCore::StandardOfProtection validates :coastal_protection_after, presence: { - message: "Select the option that shows the length of time before coastal \ - erosion affects the area likely to benefit after the project is complete." + message: "Select the option that shows the length of time before coastal " \ + "erosion affects the area likely to benefit after the project is complete." } validates :coastal_protection_after, numericality: { diff --git a/app/steps/pafs_core/standard_of_protection_coastal_step.rb b/app/steps/pafs_core/standard_of_protection_coastal_step.rb index 1dd9b9c4..2f53f93f 100644 --- a/app/steps/pafs_core/standard_of_protection_coastal_step.rb +++ b/app/steps/pafs_core/standard_of_protection_coastal_step.rb @@ -5,8 +5,8 @@ class StandardOfProtectionCoastalStep < BasicStep include PafsCore::StandardOfProtection validates :coastal_protection_before, presence: { - message: "Select the option that shows the length of time before coastal \ - erosion affects the area likely to benefit from the project." + message: "Select the option that shows the length of time before coastal " \ + "erosion affects the area likely to benefit from the project." } validates :coastal_protection_before, numericality: { diff --git a/app/steps/pafs_core/standard_of_protection_step.rb b/app/steps/pafs_core/standard_of_protection_step.rb index 6394f569..9567e5f3 100644 --- a/app/steps/pafs_core/standard_of_protection_step.rb +++ b/app/steps/pafs_core/standard_of_protection_step.rb @@ -7,8 +7,8 @@ class StandardOfProtectionStep < BasicStep validates :flood_protection_before, presence: { message: - "Select the option that shows the current risk of flooding to the area \ - likely to benefit from the project." + "Select the option that shows the current risk of flooding to the area " \ + "likely to benefit from the project." } validates :flood_protection_before, numericality: { diff --git a/lib/pafs_core/data_migration/update_areas.rb b/lib/pafs_core/data_migration/update_areas.rb index df6ba6e4..e4f1ec90 100644 --- a/lib/pafs_core/data_migration/update_areas.rb +++ b/lib/pafs_core/data_migration/update_areas.rb @@ -23,7 +23,7 @@ def perform area = PafsCore::Area.find_by(name: row["PAFS_LRMA_NAME"]) destination_area = PafsCore::Area.where.not( - id: (area ? area.id : nil) + id: area&.id ).find_by(name: row["POL_LRMA_NAME"]) next if destination_area && area.nil? diff --git a/pafs_core.gemspec b/pafs_core.gemspec index 021114c2..0fba3b0e 100644 --- a/pafs_core.gemspec +++ b/pafs_core.gemspec @@ -26,7 +26,7 @@ Gem::Specification.new do |s| "README.md"] s.metadata["rubygems_mfa_required"] = "true" - s.add_dependency "aws-sdk-s3", "~> 1.67" + s.add_dependency "aws-sdk-s3" s.add_dependency "bstard" s.add_dependency "clamav-client" s.add_dependency "faraday" @@ -35,7 +35,7 @@ Gem::Specification.new do |s| s.add_dependency "net-smtp" s.add_dependency "nokogiri" s.add_dependency "rack-cors" - s.add_dependency "rails", "~> 7.0" + s.add_dependency "rails", "~> 7.2" s.add_dependency "roo" s.add_dependency "rubyXL" s.add_dependency "secure_headers" diff --git a/spec/factories/coastal_erosion_protection_outcomes.rb b/spec/factories/coastal_erosion_protection_outcomes.rb index bc2f271f..b79330c8 100644 --- a/spec/factories/coastal_erosion_protection_outcomes.rb +++ b/spec/factories/coastal_erosion_protection_outcomes.rb @@ -2,7 +2,6 @@ FactoryBot.define do factory :coastal_erosion_protection_outcomes, class: "PafsCore::CoastalErosionProtectionOutcome" do - project_id { 1 } financial_year { 2020 } households_at_reduced_risk { 100 } households_protected_from_loss_in_next_20_years { 50 } diff --git a/spec/factories/flood_proctection2040_outcomes.rb b/spec/factories/flood_protection2040_outcomes.rb similarity index 95% rename from spec/factories/flood_proctection2040_outcomes.rb rename to spec/factories/flood_protection2040_outcomes.rb index e660104d..76e142b2 100644 --- a/spec/factories/flood_proctection2040_outcomes.rb +++ b/spec/factories/flood_protection2040_outcomes.rb @@ -2,7 +2,6 @@ FactoryBot.define do factory :flood_protection2040_outcomes, class: "PafsCore::FloodProtection2040Outcome" do - project_id { 1 } financial_year { 2022 } households_at_reduced_risk { 100 } moved_from_very_significant_and_significant_to_moderate_or_low { 50 } diff --git a/spec/factories/flood_protection_outcomes.rb b/spec/factories/flood_protection_outcomes.rb index 5e269759..007210b4 100644 --- a/spec/factories/flood_protection_outcomes.rb +++ b/spec/factories/flood_protection_outcomes.rb @@ -2,7 +2,6 @@ FactoryBot.define do factory :flood_protection_outcomes, class: "PafsCore::FloodProtectionOutcome" do - project_id { 1 } financial_year { 2020 } households_at_reduced_risk { 100 } moved_from_very_significant_and_significant_to_moderate_or_low { 50 } diff --git a/spec/lib/pafs_core/custom_headers_spec.rb b/spec/lib/pafs_core/custom_headers_spec.rb index ea5b82c7..02c225f0 100644 --- a/spec/lib/pafs_core/custom_headers_spec.rb +++ b/spec/lib/pafs_core/custom_headers_spec.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require "rails_helper" +require "ostruct" RSpec.describe PafsCore::CustomHeaders do describe "#cache_busting" do diff --git a/spec/lib/pafs_core/mapper/funding_sources_spec.rb b/spec/lib/pafs_core/mapper/funding_sources_spec.rb index 2f5a4c5e..29db382b 100644 --- a/spec/lib/pafs_core/mapper/funding_sources_spec.rb +++ b/spec/lib/pafs_core/mapper/funding_sources_spec.rb @@ -5,8 +5,8 @@ RSpec.describe PafsCore::Mapper::FundingSources do subject { described_class.new(project: project) } - let(:funding_values) { create_list(:funding_value, 1) } - let(:project) { create(:full_project, funding_values: funding_values) } + let(:project) { create(:full_project) } + let(:funding_values) { create_list(:funding_value, 1, project:) } describe "#attributes" do let(:expected_funding_values) do diff --git a/spec/models/pafs_core/funding_value_spec.rb b/spec/models/pafs_core/funding_value_spec.rb index 683b74da..4eb63c50 100644 --- a/spec/models/pafs_core/funding_value_spec.rb +++ b/spec/models/pafs_core/funding_value_spec.rb @@ -14,7 +14,7 @@ end describe "attributes" do - subject { create(:funding_value) } + subject { create(:funding_value, project:) } it { is_expected.to validate_numericality_of(:fcerm_gia).allow_nil } it { is_expected.to validate_numericality_of(:local_levy).allow_nil } diff --git a/spec/presenters/pafs_core/validation_presenter_spec.rb b/spec/presenters/pafs_core/validation_presenter_spec.rb index 41d73505..2365c70b 100644 --- a/spec/presenters/pafs_core/validation_presenter_spec.rb +++ b/spec/presenters/pafs_core/validation_presenter_spec.rb @@ -139,16 +139,18 @@ end describe "#key_dates_complete?" do + let(:future_start_date) { 1.month.from_now } + before do - subject.start_outline_business_case_month = 12 - subject.start_outline_business_case_year = Time.zone.today.year - subject.award_contract_month = 12 - subject.award_contract_year = Time.zone.today.year + 1 - subject.start_construction_month = 12 - subject.start_construction_year = Time.zone.today.year + 2 - subject.ready_for_service_month = 12 - subject.ready_for_service_year = Time.zone.today.year + 3 - subject.project_end_financial_year = Time.zone.today.year + 4 + subject.start_outline_business_case_month = future_start_date.month + subject.start_outline_business_case_year = future_start_date.year + subject.award_contract_month = future_start_date.month + subject.award_contract_year = future_start_date.year + 1 + subject.start_construction_month = future_start_date.month + subject.start_construction_year = future_start_date.year + 2 + subject.ready_for_service_month = future_start_date.month + subject.ready_for_service_year = future_start_date.year + 3 + subject.project_end_financial_year = future_start_date.year + 4 end context "when the key dates are all present and in future" do diff --git a/spec/services/pafs_core/remove_previous_years_service_spec.rb b/spec/services/pafs_core/remove_previous_years_service_spec.rb index b214953e..58371ff6 100644 --- a/spec/services/pafs_core/remove_previous_years_service_spec.rb +++ b/spec/services/pafs_core/remove_previous_years_service_spec.rb @@ -17,14 +17,10 @@ project.state.update(state: state) (data_start_year..data_end_year).each do |year| - project.funding_values << - create(:funding_value, financial_year: year) - project.flood_protection_outcomes << - create(:flood_protection_outcomes, financial_year: year) - project.flood_protection2040_outcomes << - create(:flood_protection2040_outcomes, financial_year: year) - project.coastal_erosion_protection_outcomes << - create(:coastal_erosion_protection_outcomes, financial_year: year) + create(:funding_value, project:, financial_year: year) + create(:flood_protection_outcomes, project:, financial_year: year) + create(:flood_protection2040_outcomes, project:, financial_year: year) + create(:coastal_erosion_protection_outcomes, project:, financial_year: year) end described_class.new(project).run diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 560aac0a..a898c935 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -3,6 +3,7 @@ # Require and run our simplecov initializer as the very first thing we do. # This is as per its docs https://github.com/colszowka/simplecov#getting-started require "./spec/support/simplecov" +require "rspec/retry" # 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`. @@ -105,4 +106,13 @@ # describe ThingsController, :type => :controller do # # Equivalent to being in spec/controllers # end + + # show retry status in spec process + config.verbose_retry = true + # show exception that triggers a retry if verbose_retry is set to true + config.display_try_failure_messages = true + + config.around do |ex| + ex.run_with_retry retry: 3 + end end diff --git a/spec/steps/pafs_core/approach_step_spec.rb b/spec/steps/pafs_core/approach_step_spec.rb index 5b80266a..e1627b97 100644 --- a/spec/steps/pafs_core/approach_step_spec.rb +++ b/spec/steps/pafs_core/approach_step_spec.rb @@ -11,8 +11,9 @@ it "validates that :approach is present" do subject.approach = nil expect(subject.valid?).to be false - expect(subject.errors.messages[:approach]).to include - "Tell us the work the project plans to do to achieve its outcomes." + expect(subject.errors.messages[:approach]).to include( + "Tell us about the work the project plans to do to achieve its benefits." + ) end end diff --git a/spec/steps/pafs_core/coastal_erosion_protection_outcomes_step_spec.rb b/spec/steps/pafs_core/coastal_erosion_protection_outcomes_step_spec.rb index 36edc385..235620ee 100644 --- a/spec/steps/pafs_core/coastal_erosion_protection_outcomes_step_spec.rb +++ b/spec/steps/pafs_core/coastal_erosion_protection_outcomes_step_spec.rb @@ -32,9 +32,10 @@ households_protected_from_loss_in_next_20_years: 50, households_protected_from_loss_in_20_percent_most_deprived: 100) expect(subject.valid?).to be false - expect(subject.errors.messages[:base]).to include - "The number of households in the 20% most deprived areas (column C) must be lower than or equal to the number of \ - households protected from loss within the next 20 years (column B)." + expect(subject.errors.messages[:base]).to include( + "The number of households in the 20% most deprived areas (column C) must be lower than or equal to the number of " \ + "households protected from loss within the next 20 years (column B)." + ) end it "validates that value B is smaller than A" do @@ -42,9 +43,10 @@ households_at_reduced_risk: 100, households_protected_from_loss_in_next_20_years: 200) expect(subject.valid?).to be false - expect(subject.errors.messages[:base]).to include - "The number of households protected from loss within the next 20 years (column B) must be lower than or equal \ - to the number of households at a reduced risk of coastal erosion (column A)." + expect(subject.errors.messages[:base]).to include( + "The number of households protected from loss within the next 20 years (column B) must be lower than or equal " \ + "to the number of households at a reduced risk of coastal erosion (column A)." + ) end it "validates that there is at least one A value" do @@ -54,30 +56,37 @@ households_at_reduced_risk: 0) expect(subject.valid?).to be false - expect(subject.errors.messages[:base]).to include - "In the applicable year(s), tell us how many households are at a reduced risk of coastal erosion." + expect(subject.errors.messages[:base]).to include( + "In the applicable year(s), tell us how many households are at a reduced risk of coastal erosion " \ + "(column A), OR if this does not apply select the checkbox." + ) end - # rubocop:disable Lint/Void + # rubocop:disable RSpec/ExampleLength it "validates that number of properties is less than or equal to 1 million" do subject.coastal_erosion_protection_outcomes.build(financial_year: 2020, households_at_reduced_risk: 1_000_001, households_protected_from_loss_in_next_20_years: 1_000_001, households_protected_from_loss_in_20_percent_most_deprived: 1_000_001, non_residential_properties: 1_000_001) - expect(subject.valid?).to be false - expect(subject.errors.messages[:base]).to include - "The number of properties at reduced risk must be less than or equal to 1 million." - expect(subject.errors.messages[:base]).to include - "The number of properties protected from loss in the next 20 years must be less than or equal to 1 million." - expect(subject.errors.messages[:base]).to include - "The number of properties protected from loss in the 20 percent most deprived must be \ - less than or equal to 1 million." - expect(subject.errors.messages[:base]).to include - "The number of non-residential properties protected from loss must be \ - less than or equal to 1 million." + aggregate_failures do + expect(subject.valid?).to be false + expect(subject.errors.messages[:base]).to include( + "The number of households at reduced risk must be less than or equal to 1 million." + ) + expect(subject.errors.messages[:base]).to include( + "The number of households protected from loss in the next 20 years must be less than or equal to 1 million." + ) + expect(subject.errors.messages[:base]).to include( + "The number of households protected from loss in the 20 percent most deprived areas must be " \ + "less than or equal to 1 million." + ) + expect(subject.errors.messages[:base]).to include( + "The number of non-residential properties must be less than or equal to 1 million." + ) + end end - # rubocop:enable Lint/Void + # rubocop:enable RSpec/ExampleLength end describe "#update" do diff --git a/spec/steps/pafs_core/financial_year_alternative_step_spec.rb b/spec/steps/pafs_core/financial_year_alternative_step_spec.rb index 71edca19..e76daa44 100644 --- a/spec/steps/pafs_core/financial_year_alternative_step_spec.rb +++ b/spec/steps/pafs_core/financial_year_alternative_step_spec.rb @@ -11,8 +11,9 @@ it "validates :project_end_financial_year can't be empty/falsey" do subject.project_end_financial_year = nil expect(subject.valid?).to be false - expect(subject.errors[:project_end_financial_year]).to include - "Tell us the financial year when the project will stop spending funds" + expect(subject.errors[:project_end_financial_year]).to include( + "Tell us the financial year when the project will stop spending funds." + ) end # validates_numericality_of doesn't seem to work with multiple qualifiers @@ -27,14 +28,15 @@ it "validates that :project_end_financial_year is current financial year or later" do subject.project_end_financial_year = 2015 expect(subject.valid?).to be false - expect(subject.errors[:project_end_financial_year]).to include - "The financial year must be in the future" + expect(subject.errors[:project_end_financial_year]).to include( + "The financial year must be in the future" + ) end it "validates that :project_end_financial_year is earlier than 2100" do subject.project_end_financial_year = 2101 expect(subject.valid?).to be false - expect(subject.errors[:project_end_financial_year]).to include "must be 2100 or earlier" + expect(subject.errors[:project_end_financial_year]).to include("must be 2100 or earlier") end end diff --git a/spec/steps/pafs_core/flood_protection_outcomes2040_step_spec.rb b/spec/steps/pafs_core/flood_protection_outcomes2040_step_spec.rb index ec330eb3..74cddf44 100644 --- a/spec/steps/pafs_core/flood_protection_outcomes2040_step_spec.rb +++ b/spec/steps/pafs_core/flood_protection_outcomes2040_step_spec.rb @@ -32,10 +32,11 @@ moved_from_very_significant_and_significant_to_moderate_or_low: 50, households_protected_from_loss_in_20_percent_most_deprived: 100) expect(subject.valid?).to be false - expect(subject.errors.messages[:base]).to include - "The number of households in the 20% most deprived areas (column C) must be lower than \ - or equal to the number of households moved from very significant \ - or significant to the moderate or low flood risk category (column B)." + expect(subject.errors.messages[:base]).to include( + "The number of households in the 20% most deprived areas (column C) must be lower than " \ + "or equal to the number of households moved from very significant or significant " \ + "to the moderate or low flood risk category (column B)." + ) end it "validates that value B is smaller than A" do @@ -43,10 +44,11 @@ households_at_reduced_risk: 100, moved_from_very_significant_and_significant_to_moderate_or_low: 200) expect(subject.valid?).to be false - expect(subject.errors.messages[:base]).to include - "The number of households moved from very significant or significant to \ - the moderate or low flood risk category (column B) must be lower than or equal \ - to the number of households moved to a lower flood risk category (column A)." + expect(subject.errors.messages[:base]).to include( + "The number of households moved from very significant or significant to " \ + "the moderate or low flood risk category (column B) must be lower than or equal " \ + "to the number of households moved to a lower flood risk category (column A)." + ) end it "validates that there is at least one A value" do @@ -56,28 +58,30 @@ households_at_reduced_risk: 0) expect(subject.valid?).to be false - expect(subject.errors.messages[:base]).to include - "In the applicable year(s), tell us how many households moved to a lower flood \ - risk category (column A)." + expect(subject.errors.messages[:base]).to include( + "In the applicable year(s), tell us how many households moved to a lower flood " \ + "risk category (column A), OR if this does not apply select the checkbox." + ) end - # rubocop:disable Lint/Void it "validates that number of households is less than or equal to 1 million" do subject.flood_protection2040_outcomes.build(financial_year: 2024, households_at_reduced_risk: 1_000_001, moved_from_very_significant_and_significant_to_moderate_or_low: 1_000_001, households_protected_from_loss_in_20_percent_most_deprived: 1_000_001) expect(subject.valid?).to be false - expect(subject.errors.messages[:base]).to include - "The number of households at reduced risk must be less than or equal to 1 million." - expect(subject.errors.messages[:base]).to include - "The number of households moved from very significant and significant to moderate or low must be \ - less than or equal to 1 million." - expect(subject.errors.messages[:base]).to include - "The number of households protected from loss in the 20 percent most deprived must be \ - less than or equal to 1 million." + expect(subject.errors.messages[:base]).to include( + "The number of households at reduced risk must be less than or equal to 1 million." + ) + expect(subject.errors.messages[:base]).to include( + "The number of households moved from very significant and significant to moderate or low must be " \ + "less than or equal to 1 million." + ) + expect(subject.errors.messages[:base]).to include( + "The number of households protected from loss in the 20 percent most deprived must be " \ + "less than or equal to 1 million." + ) end - # rubocop:enable Lint/Void end describe "#update" do diff --git a/spec/steps/pafs_core/flood_protection_outcomes_step_spec.rb b/spec/steps/pafs_core/flood_protection_outcomes_step_spec.rb index 9dc24a81..360615ea 100644 --- a/spec/steps/pafs_core/flood_protection_outcomes_step_spec.rb +++ b/spec/steps/pafs_core/flood_protection_outcomes_step_spec.rb @@ -32,10 +32,11 @@ moved_from_very_significant_and_significant_to_moderate_or_low: 50, households_protected_from_loss_in_20_percent_most_deprived: 100) expect(subject.valid?).to be false - expect(subject.errors.messages[:base]).to include - "The number of households in the 20% most deprived areas (column C) must be lower than \ - or equal to the number of households moved from very significant \ - or significant to the moderate or low flood risk category (column B)." + expect(subject.errors.messages[:base]).to include( + "The number of households in the 20% most deprived areas (column C) must be lower than " \ + "or equal to the number of households moved from very significant " \ + "or significant to the moderate or low flood risk category (column B)." + ) end it "validates that value D is smaller than B" do @@ -44,10 +45,12 @@ moved_from_very_significant_and_significant_to_moderate_or_low: 50, households_protected_through_plp_measures: 100) expect(subject.valid?).to be false - expect(subject.errors.messages[:base]).to include - "The number of households that are protected through Property Level Protection (PLP) measures (column D) must be lower than or equal to \ - to the number of households moved from very significant \ - or significant to the moderate or low flood risk category (column B)." + expect(subject.errors.messages[:base]).to include( + "The number of households that are protected through Property Level Protection " \ + "(PLP) measures (column D) must be lower than or equal to " \ + "the number of households moved from very significant " \ + "or significant to the moderate or low flood risk category (column B)." + ) end it "validates that value B is smaller than A" do @@ -55,10 +58,11 @@ households_at_reduced_risk: 100, moved_from_very_significant_and_significant_to_moderate_or_low: 200) expect(subject.valid?).to be false - expect(subject.errors.messages[:base]).to include - "The number of households moved from very significant or significant to \ - the moderate or low flood risk category (column B) must be lower than or equal \ - to the number of households moved to a lower flood risk category (column A)." + expect(subject.errors.messages[:base]).to include( + "The number of households moved from very significant or significant to " \ + "moderate or low flood risk category (column B) must be lower than or equal " \ + "to the number of households moved to a lower flood risk category (column A)." + ) end it "validates that there is at least one A value" do @@ -68,28 +72,30 @@ households_at_reduced_risk: 0) expect(subject.valid?).to be false - expect(subject.errors.messages[:base]).to include - "In the applicable year(s), tell us how many households moved to a lower flood \ - risk category (column A)." + expect(subject.errors.messages[:base]).to include( + "In the applicable year(s), tell us how many households moved to a lower flood " \ + "risk category (column A), OR if this does not apply select the checkbox." + ) end - # rubocop:disable Lint/Void it "validates that number of households is less than or equal to 1 million" do subject.flood_protection_outcomes.build(financial_year: 2020, households_at_reduced_risk: 1_000_001, moved_from_very_significant_and_significant_to_moderate_or_low: 1_000_001, households_protected_from_loss_in_20_percent_most_deprived: 1_000_001) expect(subject.valid?).to be false - expect(subject.errors.messages[:base]).to include - "The number of households at reduced risk must be less than or equal to 1 million." - expect(subject.errors.messages[:base]).to include - "The number of households moved from very significant and significant to moderate or low must be \ - less than or equal to 1 million." - expect(subject.errors.messages[:base]).to include - "The number of households protected from loss in the 20 percent most deprived must be \ - less than or equal to 1 million." + expect(subject.errors.messages[:base]).to include( + "The number of households at reduced risk must be less than or equal to 1 million." + ) + expect(subject.errors.messages[:base]).to include( + "The number of households moved from very significant and significant to moderate or low must be " \ + "less than or equal to 1 million." + ) + expect(subject.errors.messages[:base]).to include( + "The number of households protected from loss in the 20 percent most deprived must be " \ + "less than or equal to 1 million." + ) end - # rubocop:enable Lint/Void end describe "#update" do diff --git a/spec/steps/pafs_core/standard_of_protection_after_step_spec.rb b/spec/steps/pafs_core/standard_of_protection_after_step_spec.rb index f99d7141..0d371509 100644 --- a/spec/steps/pafs_core/standard_of_protection_after_step_spec.rb +++ b/spec/steps/pafs_core/standard_of_protection_after_step_spec.rb @@ -11,16 +11,18 @@ it "validates that :flood_protection_before is present" do subject.flood_protection_after = nil expect(subject.valid?).to be false - expect(subject.errors.messages[:flood_protection_after]).to include - "Select the option that shows the potential risk of flooding to the area after the project is complete." + expect(subject.errors.messages[:flood_protection_after]).to include( + "Select the option that shows the potential risk of flooding to the area after the project is complete." + ) end it "validates that :flood_protection_before is not greater than :flood_protection_after" do subject.project.flood_protection_before = 3 subject.flood_protection_after = 1 expect(subject.valid?).to be false - expect(subject.errors.messages[:flood_protection_after]).to include - "Once the project is complete the flood risk must be less than it is now" + expect(subject.errors.messages[:flood_protection_after]).to include( + "Once the project is complete, the flood risk must not be greater than it is now" + ) end end diff --git a/spec/steps/pafs_core/standard_of_protection_coastal_after_step_spec.rb b/spec/steps/pafs_core/standard_of_protection_coastal_after_step_spec.rb index 622e54c9..dff2e237 100644 --- a/spec/steps/pafs_core/standard_of_protection_coastal_after_step_spec.rb +++ b/spec/steps/pafs_core/standard_of_protection_coastal_after_step_spec.rb @@ -11,19 +11,20 @@ it "validates that :coastal_protection_after is present" do subject.coastal_protection_after = nil expect(subject.valid?).to be false - expect(subject.errors.messages[:coastal_protection_after]).to include - "Select the option that shows the length of time before coastal \ - erosion affects the area likely to benefit from the project." + expect(subject.errors.messages[:coastal_protection_after]).to include( + "Select the option that shows the length of time before coastal " \ + "erosion affects the area likely to benefit after the project is complete." + ) end it "validates that :coastal_protection_before is not greater than :coastal_protection_after" do subject.coastal_protection_before = 3 subject.coastal_protection_after = 0 expect(subject.valid?).to be false - expect(subject.errors.messages[:coastal_protection_after]).to include - "Once the project is complete the length of time before " \ - "coastal erosion affects the area must be greater than it " \ - "is now" + expect(subject.errors.messages[:coastal_protection_after]).to include( + "Once the project is complete, the length of time before " \ + "coastal erosion affects the area must not be less than it is now" + ) end end diff --git a/spec/steps/pafs_core/standard_of_protection_coastal_step_spec.rb b/spec/steps/pafs_core/standard_of_protection_coastal_step_spec.rb index afe3854a..90ca48b6 100644 --- a/spec/steps/pafs_core/standard_of_protection_coastal_step_spec.rb +++ b/spec/steps/pafs_core/standard_of_protection_coastal_step_spec.rb @@ -11,19 +11,20 @@ it "validates that :coastal_protection_before is present" do subject.coastal_protection_before = nil expect(subject.valid?).to be false - expect(subject.errors.messages[:coastal_protection_before]).to include - "Select the option that shows the length of time before coastal \ - erosion affects the area likely to benefit from the project." + expect(subject.errors.messages[:coastal_protection_before]).to include( + "Select the option that shows the length of time before coastal " \ + "erosion affects the area likely to benefit from the project." + ) end it "validates that :coastal_protection_before is not greater than :coastal_protection_after" do subject.project.coastal_protection_before = 3 subject.coastal_protection_after = 0 expect(subject.valid?).to be false - expect(subject.errors.messages[:coastal_protection_before]).to include - "Once the project is complete the length of time before " \ - "coastal erosion affects the area must be greater than it " \ - "is now" + expect(subject.errors.messages[:coastal_protection_before]).to include( + "Once the project is complete, the length of time before " \ + "coastal erosion affects the area must not be less than it is now" + ) end end diff --git a/spec/steps/pafs_core/standard_of_protection_step_spec.rb b/spec/steps/pafs_core/standard_of_protection_step_spec.rb index 89135062..b390ddf2 100644 --- a/spec/steps/pafs_core/standard_of_protection_step_spec.rb +++ b/spec/steps/pafs_core/standard_of_protection_step_spec.rb @@ -11,16 +11,18 @@ it "validates that :flood_protection_before is present" do subject.flood_protection_before = nil expect(subject.valid?).to be false - expect(subject.errors.messages[:flood_protection_before]).to include - "Select the option that shows the current risk of flooding to the area likely to benefit from the project." + expect(subject.errors.messages[:flood_protection_before]).to include( + "Select the option that shows the current risk of flooding to the area likely to benefit from the project." + ) end it "validates that :flood_protection_before is not greater than :flood_protection_after" do subject.flood_protection_before = 3 subject.project.flood_protection_after = 1 expect(subject.valid?).to be false - expect(subject.errors.messages[:flood_protection_before]).to include - "Once the project is complete the flood risk must be less than it is now" + expect(subject.errors.messages[:flood_protection_before]).to include( + "Once the project is complete, the flood risk must not be greater than it is now" + ) end end diff --git a/spec/steps/pafs_core/urgency_details_step_spec.rb b/spec/steps/pafs_core/urgency_details_step_spec.rb index fcbd368e..1f05cb3a 100644 --- a/spec/steps/pafs_core/urgency_details_step_spec.rb +++ b/spec/steps/pafs_core/urgency_details_step_spec.rb @@ -18,8 +18,9 @@ it "validates that :urgency_details is present" do subject.urgency_details = nil expect(subject.valid?).to be false - expect(subject.errors.messages[:urgency_details]).to include - "You told us the project is urgent due to a health and safety issue. Tell us more information about this." + expect(subject.errors.messages[:urgency_details]).to include( + "You told us the project is urgent due to a health and safety issue. Tell us more information about this." + ) end end diff --git a/spec/steps/pafs_core/urgency_step_spec.rb b/spec/steps/pafs_core/urgency_step_spec.rb index 91aae986..1d67ddf4 100644 --- a/spec/steps/pafs_core/urgency_step_spec.rb +++ b/spec/steps/pafs_core/urgency_step_spec.rb @@ -11,8 +11,9 @@ it "validates that :urgency_reason is present" do subject.urgency_reason = nil expect(subject.valid?).to be false - expect(subject.errors.messages[:urgency_reason]).to include - "If your project is urgent, select a reason. If it isn't urgent, select the first option." + expect(subject.errors.messages[:urgency_reason]).to include( + "If your project is urgent, select a reason. If it isn't urgent, select the first option." + ) end it "validates that the selected :urgency_reason is valid" do @@ -22,8 +23,9 @@ end subject.urgency_reason = "wigwam_peanut" expect(subject.valid?).to be false - expect(subject.errors.messages[:urgency_reason]).to include - "If your project is urgent, select a reason. If it isn't urgent, select the first option." + expect(subject.errors.messages[:urgency_reason]).to include( + "If your project is urgent, select a reason. If it isn't urgent, select the first option." + ) end end