Skip to content

Commit b274e34

Browse files
petergoldsteinJonRowe
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 3818055 commit b274e34

File tree

6 files changed

+28
-8
lines changed

6 files changed

+28
-8
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)

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

spec/generators/rspec/scaffold/scaffold_generator_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,16 +224,16 @@
224224
before { run_generator %w[posts upvotes:integer downvotes:integer] }
225225
subject { file("spec/views/posts/index.html.erb_spec.rb") }
226226
it { is_expected.to exist }
227-
it { is_expected.to contain('assert_select "tr>td", text: 2.to_s, count: 2') }
228-
it { is_expected.to contain('assert_select "tr>td", text: 3.to_s, count: 2') }
227+
it { is_expected.to contain('assert_select cell_selector, text: Regexp.new(2.to_s), count: 2') }
228+
it { is_expected.to contain('assert_select cell_selector, text: Regexp.new(3.to_s), count: 2') }
229229
end
230230

231231
describe 'with multiple float attributes index' do
232232
before { run_generator %w[posts upvotes:float downvotes:float] }
233233
subject { file("spec/views/posts/index.html.erb_spec.rb") }
234234
it { is_expected.to exist }
235-
it { is_expected.to contain('assert_select "tr>td", text: 2.5.to_s, count: 2') }
236-
it { is_expected.to contain('assert_select "tr>td", text: 3.5.to_s, count: 2') }
235+
it { is_expected.to contain('assert_select cell_selector, text: Regexp.new(2.5.to_s), count: 2') }
236+
it { is_expected.to contain('assert_select cell_selector, text: Regexp.new(3.5.to_s), count: 2') }
237237
end
238238

239239
describe 'with reference attribute' do

0 commit comments

Comments
 (0)