Skip to content

Commit 9d18dc8

Browse files
committed
Remove all code to work with Ruby < 3.1
1 parent dc581c0 commit 9d18dc8

File tree

22 files changed

+144
-400
lines changed

22 files changed

+144
-400
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,6 @@ gem "wdm", ">= 0.1.0", platforms: [:windows]
193193
# The error_highlight gem only works on CRuby 3.1 or later.
194194
# Also, Rails depends on a new API available since error_highlight 0.4.0.
195195
# (Note that Ruby 3.1 bundles error_highlight 0.3.0.)
196-
if RUBY_VERSION >= "3.1" && RUBY_VERSION < "3.2"
196+
if RUBY_VERSION < "3.2"
197197
gem "error_highlight", ">= 0.4.0", platforms: [:ruby]
198198
end

actionpack/test/dispatch/system_testing/screenshot_helper_test.rb

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -152,18 +152,15 @@ def setup
152152
assert_match %r|url=artifact://.+?tmp/screenshots/1_x\.png|, display_image_actual
153153
end
154154

155-
# minitest doesn't support metadata in the version locked on Ruby 2.7
156-
if RUBY_VERSION > "3.0"
157-
test "take_failed_screenshot persists the image path in the test metadata" do
158-
Rails.stub :root, Pathname.getwd do
159-
@new_test.stub :passed?, false do
160-
Capybara::Session.stub :instance_created?, true do
161-
@new_test.stub :save_image, nil do
162-
@new_test.stub :show, -> (_) { } do
163-
@new_test.take_failed_screenshot
164-
165-
assert_equal @new_test.send(:relative_image_path), @new_test.metadata[:failure_screenshot_path]
166-
end
155+
test "take_failed_screenshot persists the image path in the test metadata" do
156+
Rails.stub :root, Pathname.getwd do
157+
@new_test.stub :passed?, false do
158+
Capybara::Session.stub :instance_created?, true do
159+
@new_test.stub :save_image, nil do
160+
@new_test.stub :show, -> (_) { } do
161+
@new_test.take_failed_screenshot
162+
163+
assert_equal @new_test.send(:relative_image_path), @new_test.metadata[:failure_screenshot_path]
167164
end
168165
end
169166
end

actionpack/test/dispatch/test_response_test.rb

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,43 @@ def assert_response_code_range(range, predicate)
4040
assert_equal("Content", response.parsed_body.at_xpath("/html/body/div").text)
4141
end
4242

43-
if RUBY_VERSION >= "3.1"
44-
require_relative "./test_response_test/pattern_matching_test_cases"
43+
test "JSON response Hash pattern matching" do
44+
response = ActionDispatch::TestResponse.create(200, { "Content-Type" => "application/json" }, '{ "foo": "fighters" }')
45+
46+
# rubocop:disable Lint/Syntax
47+
assert_pattern { response.parsed_body => { foo: /fighter/ } }
48+
# rubocop:enable Lint/Syntax
49+
end
50+
51+
test "JSON response Array pattern matching" do
52+
response = ActionDispatch::TestResponse.create(200, { "Content-Type" => "application/json" }, '[{ "foo": "fighters" }, { "nir": "vana" }]')
53+
# rubocop:disable Lint/Syntax
54+
assert_pattern { response.parsed_body => [{ foo: /fighter/ }, { nir: /vana/ }] }
55+
# rubocop:enable Lint/Syntax
56+
end
57+
58+
test "HTML response pattern matching" do
59+
response = ActionDispatch::TestResponse.create(200, { "Content-Type" => "text/html" }, <<~HTML)
60+
<html>
61+
<head></head>
62+
<body>
63+
<main><h1>Some main content</h1></main>
64+
</body>
65+
</html>
66+
HTML
67+
html = response.parsed_body
68+
69+
# rubocop:disable Lint/Syntax
70+
html.at("main") => {name:, content:}
71+
# rubocop:enable Lint/Syntax
72+
73+
assert_equal "main", name
74+
assert_equal "Some main content", content
4575

46-
include PatternMatchingTestCases
76+
# rubocop:disable Lint/Syntax
77+
assert_pattern { html.at("main") => { content: "Some main content" } }
78+
assert_pattern { html.at("main") => { content: /content/ } }
79+
assert_pattern { html.at("main") => { children: [{ name: "h1", content: /content/ }] } }
80+
# rubocop:enable Lint/Syntax
4781
end
4882
end

actionpack/test/dispatch/test_response_test/pattern_matching_test_cases.rb

Lines changed: 0 additions & 47 deletions
This file was deleted.

actiontext/test/unit/content_test.rb

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,20 @@ class ActionText::ContentTest < ActiveSupport::TestCase
194194
assert_equal expected_html.strip, replaced_fragment.to_html
195195
end
196196

197+
test "delegates pattern matching to Nokogiri" do
198+
content = ActionText::Content.new <<~HTML
199+
<h1 id="hello-world">Hello, world</h1>
200+
201+
<div>The body</div>
202+
HTML
203+
204+
content => [h1, div]
205+
206+
assert_pattern { h1 => { name: "h1", content: "Hello, world", attributes: [{ name: "id", value: "hello-world" }] } }
207+
refute_pattern { h1 => { name: "h1", content: "Goodbye, world" } }
208+
assert_pattern { div => { content: "The body" } }
209+
end
210+
197211
private
198212
def content_from_html(html)
199213
ActionText::Content.new(html).tap do |content|
@@ -210,7 +224,3 @@ def with_attachment_tag_name(tag_name)
210224
ActionText::Attachment.tag_name = previous_tag_name
211225
end
212226
end
213-
214-
if RUBY_VERSION >= "3.1"
215-
require_relative "./content_test/pattern_matching_test_cases"
216-
end

actiontext/test/unit/content_test/pattern_matching_test_cases.rb

Lines changed: 0 additions & 19 deletions
This file was deleted.

actionview/lib/action_view/helpers/url_helper.rb

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -574,19 +574,6 @@ def current_page?(options = nil, check_parameters: false, **options_as_kwargs)
574574
url_string == request_uri
575575
end
576576

577-
if RUBY_VERSION.start_with?("2.7")
578-
using Module.new {
579-
refine UrlHelper do
580-
alias :_current_page? :current_page?
581-
end
582-
}
583-
584-
def current_page?(*args) # :nodoc:
585-
options = args.pop
586-
options.is_a?(Hash) ? _current_page?(*args, **options) : _current_page?(*args, options)
587-
end
588-
end
589-
590577
# Creates an SMS anchor link tag to the specified +phone_number+. When the
591578
# link is clicked, the default SMS messaging app is opened ready to send a
592579
# message to the linked phone number. If the +body+ option is specified,

actionview/test/template/test_case_test.rb

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,38 @@ class AHelperWithInitializeTest < ActionView::TestCase
453453
assert @called_initialize
454454
end
455455
end
456-
end
457456

458-
if RUBY_VERSION >= "3.1"
459-
require_relative "./test_case_test/pattern_matching_test_cases"
457+
class PatternMatchingTestCases < ActionView::TestCase
458+
test "document_root_element integrates with pattern matching" do
459+
developer = DeveloperStruct.new("Eloy")
460+
461+
render "developers/developer_with_h1", developer: developer
462+
463+
# rubocop:disable Lint/Syntax
464+
assert_pattern { document_root_element.at("h1") => { content: "Eloy", attributes: [{ name: "id", value: "name" }] } }
465+
refute_pattern { document_root_element.at("h1") => { content: "Not Eloy" } }
466+
end
467+
468+
test "rendered.html integrates with pattern matching" do
469+
developer = DeveloperStruct.new("Eloy")
470+
471+
render "developers/developer", developer: developer
472+
473+
# rubocop:disable Lint/Syntax
474+
assert_pattern { rendered.html => { content: "Eloy" } }
475+
refute_pattern { rendered.html => { content: "Not Eloy" } }
476+
# rubocop:enable Lint/Syntax
477+
end
478+
479+
test "rendered.json integrates with pattern matching" do
480+
developer = DeveloperStruct.new("Eloy")
481+
482+
render formats: :json, partial: "developers/developer", locals: { developer: developer }
483+
484+
# rubocop:disable Lint/Syntax
485+
assert_pattern { rendered.json => { name: "Eloy" } }
486+
refute_pattern { rendered.json => { name: "Not Eloy" } }
487+
# rubocop:enable Lint/Syntax
488+
end
489+
end
460490
end

actionview/test/template/test_case_test/pattern_matching_test_cases.rb

Lines changed: 0 additions & 36 deletions
This file was deleted.

activerecord/test/cases/migration/command_recorder_test.rb

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,10 @@ def test_invert_change_table
9999
end
100100
end
101101

102-
if RUBY_VERSION >= "2.8"
103-
assert_equal [
104-
[:rename_column, [:fruits, :cultivar, :kind]],
105-
[:remove_column, [:fruits, :name, :string], nil],
106-
], @recorder.commands
107-
else
108-
assert_equal [
109-
[:rename_column, [:fruits, :cultivar, :kind]],
110-
[:remove_column, [:fruits, :name, :string, {}], nil],
111-
], @recorder.commands
112-
end
102+
assert_equal [
103+
[:rename_column, [:fruits, :cultivar, :kind]],
104+
[:remove_column, [:fruits, :name, :string], nil],
105+
], @recorder.commands
113106

114107
assert_raises(ActiveRecord::IrreversibleMigration) do
115108
@recorder.revert do

0 commit comments

Comments
 (0)