Skip to content

Commit

Permalink
Ruby v3.3 upgrade (third go) (#4397)
Browse files Browse the repository at this point in the history
* Reapply "Upgrade ruby v3 3 (#4357)" (#4367)

This reverts commit ae63a28.

* update chat specs to not use js selenium
  • Loading branch information
martyn-w authored Dec 3, 2024
1 parent 7a0ec8b commit 1fb8518
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 86 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"version": "latest"
},
"ghcr.io/devcontainers/features/ruby:1": {
"version": "3.1.4"
"version": "3.3.6"
},
"ghcr.io/devcontainers/features/node:1": {
"version": "18.16"
Expand Down
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1.4
3.3.6
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
terraform 1.5.4
ruby 3.1.4
ruby 3.3.6
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# To use or update to a ruby version, change BASE_RUBY_IMAGE
ARG BASE_RUBY_IMAGE=ruby:3.1.4-alpine3.18
ARG BASE_RUBY_IMAGE=ruby:3.3.6-alpine3.20

FROM ${BASE_RUBY_IMAGE} AS base

Expand Down
5 changes: 2 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,12 @@ group :development, :test do

# Testing framework
gem "knapsack"
gem "rspec-rails", "~> 6.0.3"
gem "rspec-rails", "~> 7.1.0"

# Adds support for Capybara system testing and selenium driver
gem "capybara", "~> 3.40.0"
gem "factory_bot_rails", ">= 6.2.0"
# See: https://github.com/otherguy/rspec-sonarqube-formatter/pull/63
gem "rspec-sonarqube-formatter", github: "otherguy/rspec-sonarqube-formatter", ref: "13fe436", require: false
gem "rspec-sonarqube-formatter", "~> 1.6.1", require: false
gem "simplecov"

# Linting
Expand Down
66 changes: 30 additions & 36 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,6 @@ 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
Expand Down Expand Up @@ -205,7 +196,7 @@ GEM
csv (3.3.0)
declarative (0.0.20)
delegate (0.3.1)
diff-lcs (1.5.0)
diff-lcs (1.5.1)
docile (1.4.0)
dotenv (3.1.2)
dotenv-rails (3.1.2)
Expand Down Expand Up @@ -380,7 +371,7 @@ GEM
mixlib-shellout
method_source (1.1.0)
mini_mime (1.1.5)
mini_portile2 (2.8.7)
mini_portile2 (2.8.8)
minitest (5.25.1)
mixlib-cli (2.1.8)
mixlib-config (3.0.27)
Expand All @@ -400,10 +391,10 @@ GEM
net-smtp (0.5.0)
net-protocol
nio4r (2.7.3)
nokogiri (1.16.5)
nokogiri (1.16.7)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
nokogiri (1.16.5-x86_64-linux)
nokogiri (1.16.7-x86_64-linux)
racc (~> 1.4)
observer (0.1.1)
os (1.1.4)
Expand Down Expand Up @@ -497,29 +488,32 @@ GEM
rexml (3.3.3)
strscan
rinku (2.0.6)
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)
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)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-mocks (3.12.0)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.2)
diff-lcs (>= 1.2.0, < 2.0)
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-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-retry (0.6.2)
rspec-core (> 3.3)
rspec-support (3.12.0)
rspec-sonarqube-formatter (1.6.1)
htmlentities (~> 4.3)
rspec (~> 3.0)
rspec-support (3.13.1)
rubocop (1.64.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
Expand Down Expand Up @@ -638,7 +632,7 @@ GEM
websocket-extensions (0.1.5)
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.6.18)
zeitwerk (2.7.1)

PLATFORMS
ruby
Expand Down Expand Up @@ -706,9 +700,9 @@ DEPENDENCIES
redis-session-store (>= 0.11.4)
rexml (>= 3.2.5)
rinku
rspec-rails (~> 6.0.3)
rspec-rails (~> 7.1.0)
rspec-retry
rspec-sonarqube-formatter!
rspec-sonarqube-formatter (~> 1.6.1)
rubocop-govuk (~> 5.0.2)
secure_headers
selenium-webdriver (~> 4.21.1)
Expand All @@ -732,7 +726,7 @@ DEPENDENCIES
webmock (>= 3.14.0)

RUBY VERSION
ruby 3.1.4p223
ruby 3.3.6

BUNDLED WITH
2.3.4
3 changes: 3 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
# 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.
Expand Down
2 changes: 1 addition & 1 deletion config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
19 changes: 19 additions & 0 deletions lib/patch_rack_page_caching.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 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
4 changes: 4 additions & 0 deletions spec/capybara_driver_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
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]
Expand Down
60 changes: 19 additions & 41 deletions spec/features/chat_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,66 +6,44 @@
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 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

within(".talk-to-us") do
click_link("Open chat in new tab")
end

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
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 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
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
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)
end
end

context "when javascript is not enabled", js: false do
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 not available")
expect(page).to have_text("Chat is closed")
end
end
end

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
1 change: 0 additions & 1 deletion spec/javascript/controllers/chat_controller_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,4 @@ describe('ChatController', () => {
})
});
});

});

0 comments on commit 1fb8518

Please sign in to comment.