Skip to content

Commit 2e0ca29

Browse files
petergoldsteinpirj
authored andcommitted
Add Ruby 3.1 and Rails 7 to CI
The bulk of the changes in this PR are test changes. These include: 1. Updating the example app configuration for Rails 7, including disabling eager class loading on CI 2. Updating specs to filter out additional lines that may be generated when running commands 3. Removing ".html.erb" and ".xml.erb" suffixes in render calls 4. Updating specs to accomodate differences in Rails view scaffolding before and after Rails 7 Material code changes include: 1. Adding additional logic to the ActionMailer argument parsing to accomodate for differences under Ruby 3.1/Rails 6.1 2. Symbolizing the handler argument parsed from the spec description for view specs with an empty render
1 parent 3e6db41 commit 2e0ca29

File tree

7 files changed

+56
-7
lines changed

7 files changed

+56
-7
lines changed

.github/workflows/ci.yml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,33 @@ jobs:
2929
fail-fast: false
3030
matrix:
3131
include:
32+
# Edge Rails (7.1) builds >= 2.7
33+
- ruby: 3.1
34+
allow_failure: true
35+
env:
36+
RAILS_VERSION: 'main'
37+
- ruby: '3.0'
38+
allow_failure: true
39+
env:
40+
RAILS_VERSION: 'main'
41+
- ruby: 2.7
42+
allow_failure: true
43+
env:
44+
RAILS_VERSION: 'main'
45+
46+
# Rails 7.0 builds >= 2.7
47+
- ruby: 3.1
48+
env:
49+
RAILS_VERSION: '~> 7.0.0'
50+
- ruby: '3.0'
51+
env:
52+
RAILS_VERSION: '~> 7.0.0'
53+
- ruby: 2.7
54+
env:
55+
RAILS_VERSION: '~> 7.0.0'
56+
3257
# Rails 6.1 builds >= 2.5
33-
- ruby: '3.1'
58+
- ruby: 3.1
3459
env:
3560
RAILS_VERSION: '~> 6.1.0'
3661
- ruby: '3.0'

example_app_generator/generate_stuff.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,10 @@ def using_source_path(path)
167167
gsub_file 'spec/controllers/uploads_controller_spec.rb',
168168
'skip("Add a hash of attributes valid for your model")',
169169
'{}'
170+
171+
if Rails.version >= '7.0.0'
172+
# Some gems (ActionMailBox, ActionCable, etc.) are not used when running `example_app_generator/spec/verify_mailer_preview_path_spec.rb`, so `eager_load` must be false.
173+
gsub_file "config/environments/test.rb", 'ENV["CI"].present?', "false"
174+
end
175+
170176
final_tasks

example_app_generator/spec/support/default_preview_path

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ require_file_stub 'config/environment' do
2626
require "action_controller/railtie"
2727
require "action_mailer/railtie" unless ENV['NO_ACTION_MAILER']
2828
require "action_view/railtie"
29+
if Rails::VERSION::STRING >= '6'
30+
require "action_cable/engine"
31+
require "action_mailbox/engine"
32+
end
2933

3034
# Require the gems listed in Gemfile, including any gems
3135
# you've limited to :test, :development, or :production.
@@ -44,6 +48,8 @@ require_file_stub 'config/environment' do
4448
if ENV['SHOW_PREVIEWS']
4549
config.action_mailer.show_previews = (ENV['SHOW_PREVIEWS'] == 'true')
4650
end
51+
52+
config.active_record.legacy_connection_handling = false if Rails::VERSION::STRING >= '7'
4753
end
4854
end
4955

example_app_generator/spec/verify_mailer_preview_path_spec.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ def capture_exec(*ops)
2222
out = io.readlines
2323
.reject { |line| line =~ /warning: circular argument reference/ }
2424
.reject { |line| line =~ /Gem::Specification#rubyforge_project=/ }
25+
.reject { |line| line =~ /DEPRECATION WARNING/ }
26+
.reject { |line| line =~ /warning: previous/ }
27+
.reject { |line| line =~ /warning: already/ }
2528
.join
2629
.chomp
2730
CaptureExec.new(out, $?.exitstatus)

lib/generators/rspec/scaffold/templates/index_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
1919
it "renders a list of <%= ns_table_name %>" do
2020
render
21+
cell_selector = Rails::VERSION::STRING >= '7' ? 'div>p' : 'tr>td'
2122
<% for attribute in output_attributes -%>
22-
assert_select "tr>td", text: <%= value_for(attribute) %>.to_s, count: 2
23+
assert_select cell_selector, text: Regexp.new(<%= value_for(attribute) %>.to_s), count: 2
2324
<% end -%>
2425
end
2526
end

lib/rspec/rails/matchers/have_enqueued_mail.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,19 @@ def process_arguments(job, given_mail_args)
102102

103103
def use_given_mail_args?(job)
104104
return true if FeatureCheck.has_action_mailer_parameterized? && job[:job] <= ActionMailer::Parameterized::DeliveryJob
105-
return false if FeatureCheck.ruby_3_1?
105+
return false if rails_6_1_and_ruby_3_1?
106106

107107
!(FeatureCheck.has_action_mailer_unified_delivery? && job[:job] <= ActionMailer::MailDeliveryJob)
108108
end
109109

110+
# TODO: move to FeatureCheck
111+
def rails_6_1_and_ruby_3_1?
112+
return false unless RUBY_VERSION >= "3.1"
113+
return false unless ::Rails::VERSION::STRING >= '6.1'
114+
115+
::Rails::VERSION::STRING < '7'
116+
end
117+
110118
def base_mailer_args
111119
[mailer_class_name, @method_name.to_s, MAILER_JOB_METHOD]
112120
end

spec/generators/rspec/scaffold/scaffold_generator_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,16 +208,16 @@
208208
before { run_generator %w[posts upvotes:integer downvotes:integer] }
209209
subject { file("spec/views/posts/index.html.erb_spec.rb") }
210210
it { is_expected.to exist }
211-
it { is_expected.to contain('assert_select "tr>td", text: 2.to_s, count: 2') }
212-
it { is_expected.to contain('assert_select "tr>td", text: 3.to_s, count: 2') }
211+
it { is_expected.to contain('assert_select cell_selector, text: Regexp.new(2.to_s), count: 2') }
212+
it { is_expected.to contain('assert_select cell_selector, text: Regexp.new(3.to_s), count: 2') }
213213
end
214214

215215
describe 'with multiple float attributes index' do
216216
before { run_generator %w[posts upvotes:float downvotes:float] }
217217
subject { file("spec/views/posts/index.html.erb_spec.rb") }
218218
it { is_expected.to exist }
219-
it { is_expected.to contain('assert_select "tr>td", text: 2.5.to_s, count: 2') }
220-
it { is_expected.to contain('assert_select "tr>td", text: 3.5.to_s, count: 2') }
219+
it { is_expected.to contain('assert_select cell_selector, text: Regexp.new(2.5.to_s), count: 2') }
220+
it { is_expected.to contain('assert_select cell_selector, text: Regexp.new(3.5.to_s), count: 2') }
221221
end
222222

223223
describe 'with reference attribute' do

0 commit comments

Comments
 (0)