Skip to content

Commit eba26c0

Browse files
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 fac29a1 commit eba26c0

File tree

10 files changed

+58
-17
lines changed

10 files changed

+58
-17
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ jobs:
3030
matrix:
3131
include:
3232
# Edge Rails (7.1) builds >= 2.7
33+
- ruby: 3.1
34+
allow_failure: true
35+
env:
36+
RAILS_VERSION: 'main'
3337
- ruby: '3.0'
3438
allow_failure: true
3539
env:
@@ -41,19 +45,19 @@ jobs:
4145

4246
# Rails 7.0 builds >= 2.7
4347
- ruby: 3.1
44-
allow_failure: true
4548
env:
4649
RAILS_VERSION: '~> 7.0.0'
4750
- ruby: '3.0'
48-
allow_failure: true
4951
env:
5052
RAILS_VERSION: '~> 7.0.0'
5153
- ruby: 2.7
52-
allow_failure: true
5354
env:
5455
RAILS_VERSION: '~> 7.0.0'
5556

5657
# Rails 6.1 builds >= 2.5
58+
- ruby: 3.1
59+
env:
60+
RAILS_VERSION: '~> 6.1.0'
5761
- ruby: '3.0'
5862
env:
5963
RAILS_VERSION: '~> 6.1.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)

features/view_specs/view_spec.feature

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ Feature: view spec
8080
it "displays the widget" do
8181
assign(:widget, Widget.create!(:name => "slicer"))
8282
83-
render :template => "widgets/widget.html.erb"
83+
render :template => "widgets/widget"
8484
8585
expect(rendered).to match /slicer/
8686
end
@@ -103,7 +103,7 @@ Feature: view spec
103103
it "displays the widget" do
104104
assign(:widget, Widget.create!(:name => "slicer"))
105105
106-
render :template => "widgets/widget.html.erb", :layout => "layouts/inventory"
106+
render :template => "widgets/widget", :layout => "layouts/inventory"
107107
108108
expect(rendered).to match /slicer/
109109
end
@@ -162,7 +162,7 @@ Feature: view spec
162162
it "displays the widget" do
163163
widget = Widget.create!(:name => "slicer")
164164
165-
render :partial => "widgets/widget.html.erb", :locals => {:widget => widget}
165+
render :partial => "widgets/widget", :locals => {:widget => widget}
166166
167167
expect(rendered).to match /slicer/
168168
end

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/example/view_example_group.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def _default_render_options
150150
match = path_regex.match(_default_file_to_render)
151151

152152
render_options = {template: match[:template]}
153-
render_options[:handlers] = [match[:handler]] if match[:handler]
153+
render_options[:handlers] = [match[:handler].to_sym] if match[:handler]
154154
render_options[:formats] = [match[:format].to_sym] if match[:format]
155155
render_options[:locales] = [match[:locale]] if match[:locale]
156156
render_options[:variants] = [match[:variant]] if match[:variant]

lib/rspec/rails/matchers/have_enqueued_mail.rb

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def arguments_match?(job)
9191

9292
def process_arguments(job, given_mail_args)
9393
# Old matcher behavior working with all builtin classes but ActionMailer::MailDeliveryJob
94-
return given_mail_args unless defined?(ActionMailer::MailDeliveryJob) && job[:job] <= ActionMailer::MailDeliveryJob
94+
return given_mail_args if use_given_mail_args?(job)
9595

9696
# If matching args starts with a hash and job instance has params match with them
9797
if given_mail_args.first.is_a?(Hash) && job[:args][3]['params'].present?
@@ -101,6 +101,20 @@ def process_arguments(job, given_mail_args)
101101
end
102102
end
103103

104+
def use_given_mail_args?(job)
105+
return true if defined?(ActionMailer::Parameterized::DeliveryJob) && job[:job] <= ActionMailer::Parameterized::DeliveryJob
106+
return false if rails_6_1_and_ruby_3_1?
107+
108+
!(defined?(ActionMailer::MailDeliveryJob) && job[:job] <= ActionMailer::MailDeliveryJob)
109+
end
110+
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+
104118
def base_mailer_args
105119
[mailer_class_name, @method_name.to_s, MAILER_JOB_METHOD]
106120
end
@@ -143,13 +157,20 @@ def mail_job_message(job)
143157
mailer_args = deserialize_arguments(job)[3..-1]
144158
mailer_args = mailer_args.first[:args] if unified_mail?(job)
145159
msg_parts = []
146-
msg_parts << "with #{mailer_args}" if mailer_args.any?
160+
display_args = display_mailer_args(mailer_args)
161+
msg_parts << "with #{display_args}" if display_args.any?
147162
msg_parts << "on queue #{job[:queue]}" if job[:queue] && job[:queue] != 'mailers'
148163
msg_parts << "at #{Time.at(job[:at])}" if job[:at]
149164

150165
"#{mailer_method} #{msg_parts.join(', ')}".strip
151166
end
152167

168+
def display_mailer_args(mailer_args)
169+
return mailer_args unless mailer_args.first.is_a?(Hash) && mailer_args.first.key?(:args)
170+
171+
mailer_args.first[:args]
172+
end
173+
153174
def legacy_mail?(job)
154175
RSpec::Rails::FeatureCheck.has_action_mailer_legacy_delivery_job? && job[:job] <= ActionMailer::DeliveryJob
155176
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

spec/rspec/rails/example/view_example_group_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,19 +151,19 @@ def _default_file_to_render; end # Stub method
151151
it "converts the filename components into render options" do
152152
allow(view_spec).to receive(:_default_file_to_render) { "widgets/new.en.html.erb" }
153153
view_spec.render
154-
expect(view_spec.received.first).to eq([{template: "widgets/new", locales: ['en'], formats: [:html], handlers: ['erb']}, {}, nil])
154+
expect(view_spec.received.first).to eq([{template: "widgets/new", locales: ['en'], formats: [:html], handlers: [:erb]}, {}, nil])
155155
end
156156

157157
it "converts the filename with variant into render options" do
158158
allow(view_spec).to receive(:_default_file_to_render) { "widgets/new.en.html+fancy.erb" }
159159
view_spec.render
160-
expect(view_spec.received.first).to eq([{template: "widgets/new", locales: ['en'], formats: [:html], handlers: ['erb'], variants: ['fancy']}, {}, nil])
160+
expect(view_spec.received.first).to eq([{template: "widgets/new", locales: ['en'], formats: [:html], handlers: [:erb], variants: ['fancy']}, {}, nil])
161161
end
162162

163163
it "converts the filename without format into render options" do
164164
allow(view_spec).to receive(:_default_file_to_render) { "widgets/new.en.erb" }
165165
view_spec.render
166-
expect(view_spec.received.first).to eq([{template: "widgets/new", locales: ['en'], handlers: ['erb']}, {}, nil])
166+
expect(view_spec.received.first).to eq([{template: "widgets/new", locales: ['en'], handlers: [:erb]}, {}, nil])
167167
end
168168
end
169169

0 commit comments

Comments
 (0)