diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index ed4b1e520b..b7fe63572b 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -12,7 +12,7 @@ "version": "latest" }, "ghcr.io/devcontainers/features/ruby:1": { - "version": "3.3.6" + "version": "3.1.4" }, "ghcr.io/devcontainers/features/node:1": { "version": "18.16" diff --git a/.ruby-version b/.ruby-version index 9c25013dbb..0aec50e6ed 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -3.3.6 +3.1.4 diff --git a/.tool-versions b/.tool-versions index 3a396fea2d..7fef5f5899 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,2 +1,2 @@ terraform 1.5.4 -ruby 3.3.6 +ruby 3.1.4 diff --git a/Dockerfile b/Dockerfile index 4e6051a1f5..122eb1601f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # To use or update to a ruby version, change BASE_RUBY_IMAGE -ARG BASE_RUBY_IMAGE=ruby:3.3.6-alpine3.20 +ARG BASE_RUBY_IMAGE=ruby:3.1.4-alpine3.18 FROM ${BASE_RUBY_IMAGE} AS base diff --git a/Gemfile b/Gemfile index 9968bd758c..2602de4c44 100644 --- a/Gemfile +++ b/Gemfile @@ -134,12 +134,13 @@ group :development, :test do # Testing framework gem "knapsack" - gem "rspec-rails", "~> 7.1.0" + gem "rspec-rails", "~> 6.0.3" # Adds support for Capybara system testing and selenium driver gem "capybara", "~> 3.40.0" gem "factory_bot_rails", ">= 6.2.0" - gem "rspec-sonarqube-formatter", "~> 1.6.1", require: false + # See: https://github.com/otherguy/rspec-sonarqube-formatter/pull/63 + gem "rspec-sonarqube-formatter", github: "otherguy/rspec-sonarqube-formatter", ref: "13fe436", require: false gem "simplecov" # Linting diff --git a/Gemfile.lock b/Gemfile.lock index 12431de7d4..6ca8f91823 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -68,6 +68,15 @@ GIT activemodel (>= 6.0.0, < 7.1) timeliness (>= 0.3.10, < 1) +GIT + remote: https://github.com/otherguy/rspec-sonarqube-formatter.git + revision: 13fe436921e1442a09c23d9e46055773d1511638 + ref: 13fe436 + specs: + rspec-sonarqube-formatter (1.0.0.pre.local) + htmlentities (~> 4.3.3) + rspec (~> 3.0) + GIT remote: https://github.com/pkorenev/rack-page_caching.git revision: 9ca404f7f7e4773030e75799da7ab02e27cbe9a3 @@ -196,7 +205,7 @@ GEM csv (3.3.0) declarative (0.0.20) delegate (0.3.1) - diff-lcs (1.5.1) + diff-lcs (1.5.0) docile (1.4.0) dotenv (3.1.2) dotenv-rails (3.1.2) @@ -391,10 +400,10 @@ GEM net-smtp (0.5.0) net-protocol nio4r (2.7.3) - nokogiri (1.16.7) + nokogiri (1.16.5) mini_portile2 (~> 2.8.2) racc (~> 1.4) - nokogiri (1.16.7-x86_64-linux) + nokogiri (1.16.5-x86_64-linux) racc (~> 1.4) observer (0.1.1) os (1.1.4) @@ -488,32 +497,29 @@ GEM rexml (3.3.3) strscan rinku (2.0.6) - rspec (3.13.0) - rspec-core (~> 3.13.0) - rspec-expectations (~> 3.13.0) - rspec-mocks (~> 3.13.0) - rspec-core (3.13.2) - rspec-support (~> 3.13.0) - rspec-expectations (3.13.3) + rspec (3.12.0) + rspec-core (~> 3.12.0) + rspec-expectations (~> 3.12.0) + rspec-mocks (~> 3.12.0) + rspec-core (3.12.0) + rspec-support (~> 3.12.0) + rspec-expectations (3.12.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.13.0) - rspec-mocks (3.13.2) + rspec-support (~> 3.12.0) + rspec-mocks (3.12.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.13.0) - 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.12.0) + rspec-rails (6.0.3) + actionpack (>= 6.1) + activesupport (>= 6.1) + railties (>= 6.1) + rspec-core (~> 3.12) + rspec-expectations (~> 3.12) + rspec-mocks (~> 3.12) + rspec-support (~> 3.12) rspec-retry (0.6.2) rspec-core (> 3.3) - rspec-sonarqube-formatter (1.6.1) - htmlentities (~> 4.3) - rspec (~> 3.0) - rspec-support (3.13.1) + rspec-support (3.12.0) rubocop (1.64.1) json (~> 2.3) language_server-protocol (>= 3.17.0) @@ -632,7 +638,7 @@ GEM websocket-extensions (0.1.5) xpath (3.2.0) nokogiri (~> 1.8) - zeitwerk (2.7.1) + zeitwerk (2.6.18) PLATFORMS ruby @@ -700,9 +706,9 @@ DEPENDENCIES redis-session-store (>= 0.11.4) rexml (>= 3.2.5) rinku - rspec-rails (~> 7.1.0) + rspec-rails (~> 6.0.3) rspec-retry - rspec-sonarqube-formatter (~> 1.6.1) + rspec-sonarqube-formatter! rubocop-govuk (~> 5.0.2) secure_headers selenium-webdriver (~> 4.21.1) @@ -726,7 +732,7 @@ DEPENDENCIES webmock (>= 3.14.0) RUBY VERSION - ruby 3.3.6 + ruby 3.1.4p223 BUNDLED WITH 2.3.4 diff --git a/config/application.rb b/config/application.rb index 3e3754335b..32186bad84 100644 --- a/config/application.rb +++ b/config/application.rb @@ -19,9 +19,6 @@ # you've limited to :test, :development, or :production. Bundler.require(*Rails.groups) -# Patch to Rack::PageCaching::Utils to substitute Fixnum --> Integer -require_relative "../lib/patch_rack_page_caching" - module GetIntoTeachingWebsite class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. diff --git a/config/environments/development.rb b/config/environments/development.rb index 02ac88d6d8..49f741adf6 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -72,5 +72,5 @@ config.x.dfe_analytics = true # Allow access from Codespaces - config.hosts << /[a-z0-9-]+\.((preview\.)?app\.github|githubpreview)\.dev/ + config.hosts << /[a-z0-9-]+\.(preview\.app\.github|githubpreview)\.dev/ end diff --git a/lib/patch_rack_page_caching.rb b/lib/patch_rack_page_caching.rb deleted file mode 100644 index aca69ea86d..0000000000 --- a/lib/patch_rack_page_caching.rb +++ /dev/null @@ -1,19 +0,0 @@ -# NB: we are using a very old gem (https://github.com/pkorenev/rack-page_caching) -# which requires the deprecated Fixnum class - this is a patch to switch Fixnum --> Integer - -module Rack - class PageCaching - module Utils - def self.gzip_level(gzip) - case gzip - when Symbol - Zlib.const_get(gzip.to_s.upcase) - when Integer - gzip - else - false - end - end - end - end -end diff --git a/spec/capybara_driver_helper.rb b/spec/capybara_driver_helper.rb index 05769f81e0..ac3817a117 100644 --- a/spec/capybara_driver_helper.rb +++ b/spec/capybara_driver_helper.rb @@ -23,10 +23,6 @@ Capybara.default_max_wait_time = 2 RSpec.configure do |config| config.before do |example| - if example.metadata[:js] - raise NotImplementedError, "The Capybara driver #{JS_DRIVER} is not currently supported in Alpine 3.20. Please use the default :rack_test driver instead and test javascript behaviour in js-spec tests" - end - Capybara.current_driver = JS_DRIVER if example.metadata[:js] Capybara.current_driver = :selenium if example.metadata[:selenium] Capybara.current_driver = :selenium_chrome if example.metadata[:selenium_chrome] diff --git a/spec/features/chat_spec.rb b/spec/features/chat_spec.rb index 5dd270a70a..024d92bb6c 100644 --- a/spec/features/chat_spec.rb +++ b/spec/features/chat_spec.rb @@ -6,39 +6,57 @@ before do allow(ENV).to receive(:fetch).and_call_original allow(ENV).to receive(:fetch).with("CHAT_AVAILABILITY_API", nil).and_return("http://api.example/") + stub_request(:get, "http://api.example/") + .to_return(status: 200, body: "{\"skillid\": 123456, \"available\": false, \"status_age\": 123 }") end - context "when agents are available" do - before do - stub_request(:get, "http://api.example/") - .to_return(status: 200, body: "{\"skillid\": 123456, \"available\": true, \"status_age\": 123 }") - end + context "when javascript is enabled", :js do + context "when agents are available" do + before do + stub_request(:get, "http://api.example/") + .to_return(status: 200, body: "{\"skillid\": 123456, \"available\": true, \"status_age\": 123 }") + end - scenario "viewing the chat section of the talk to us component" do - visit root_path - dismiss_cookies + scenario "viewing the chat section of the talk to us component" do + visit root_path + dismiss_cookies - within(".talk-to-us") do - click_link("Open chat in new tab") - end + within(".talk-to-us") do + click_link("Open chat in new tab") + end - expect(page.driver.current_url).to end_with("/chat#root") - expect(page).to have_css("#root", visible: false) + popup_window_handle = (page.driver.browser.window_handles - [page.driver.current_window_handle]).first + page.driver.switch_to_window(popup_window_handle) + expect(page.driver.current_url).to end_with("/chat") + expect(page).to have_css("#root", visible: false) + page.driver.close_window(popup_window_handle) + end end - end - context "when agents are not available" do - before do - stub_request(:get, "http://api.example/") - .to_return(status: 200, body: "{\"skillid\": 123456, \"available\": false, \"status_age\": 123 }") + context "when agents are not available" do + before do + stub_request(:get, "http://api.example/") + .to_return(status: 200, body: "{\"skillid\": 123456, \"available\": false, \"status_age\": 123 }") + end + + scenario "viewing the chat section of the talk to us component" do + visit root_path + dismiss_cookies + + within(".talk-to-us") do + expect(page).to have_text("Chat is closed") + end + end end + end + context "when javascript is not enabled", js: false do scenario "viewing the chat section of the talk to us component" do visit root_path dismiss_cookies within(".talk-to-us") do - expect(page).to have_text("Chat is closed") + expect(page).to have_text("Chat not available") end end end @@ -46,4 +64,8 @@ def dismiss_cookies click_link "Accept all cookies" end + + def visit_on_date(path) + visit "#{path}?fake_browser_time=#{date.to_i * 1000}" + end end diff --git a/spec/javascript/controllers/chat_controller_spec.js b/spec/javascript/controllers/chat_controller_spec.js index 6017ae0a53..f0953fbd52 100644 --- a/spec/javascript/controllers/chat_controller_spec.js +++ b/spec/javascript/controllers/chat_controller_spec.js @@ -78,4 +78,5 @@ describe('ChatController', () => { }) }); }); + });