Skip to content

Commit b11feaf

Browse files
authored
Merge pull request #2586 from rspec/petergoldstein-rails-7-ci
Add Ruby 3.1 to CI and fix Rails 7 (rebased)
2 parents 3818055 + 196e53c commit b11feaf

File tree

9 files changed

+30
-9
lines changed

9 files changed

+30
-9
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'

Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ namespace :no_active_record do
160160
sh "rm -f #{bindir}/rails"
161161
sh "bundle exec rails new #{example_app_dir} --no-rc --skip-active-record --skip-javascript --skip-bootsnap " \
162162
"--skip-sprockets --skip-git --skip-test-unit --skip-listen --skip-bundle --skip-spring " \
163-
"--template=example_app_generator/generate_app.rb"
163+
"--skip-action-text --template=example_app_generator/generate_app.rb"
164164

165165
in_example_app(app_dir: example_app_dir) do
166166
sh "./ci_retry_bundle_install.sh 2>&1"

example_app_generator/generate_action_mailer_specs.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
if skip_active_record?
3232
comment_lines 'spec/support/default_preview_path', /active_record/
3333
comment_lines 'spec/support/default_preview_path', /active_storage/
34+
comment_lines 'spec/support/default_preview_path', /action_mailbox/
3435
end
3536
copy_file 'spec/verify_mailer_preview_path_spec.rb'
3637
end

example_app_generator/generate_stuff.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,5 @@ 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+
170171
final_tasks

example_app_generator/no_active_record/app/models/in_memory/model.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
raise "ActiveRecord is defined but should not be!" if defined?(::ActiveRecord)
22

3+
require 'active_model'
4+
35
module InMemory
46
module Persistence
57
def all

example_app_generator/spec/support/default_preview_path

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ 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 "active_job/railtie"
32+
require "action_mailbox/engine"
33+
end
2934

3035
# Require the gems listed in Gemfile, including any gems
3136
# you've limited to :test, :development, or :production.
@@ -44,6 +49,8 @@ require_file_stub 'config/environment' do
4449
if ENV['SHOW_PREVIEWS']
4550
config.action_mailer.show_previews = (ENV['SHOW_PREVIEWS'] == 'true')
4651
end
52+
53+
config.active_record.legacy_connection_handling = false if Rails::VERSION::STRING >= '7'
4754
end
4855
end
4956

example_app_generator/spec/verify_mailer_preview_path_spec.rb

Lines changed: 5 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)
@@ -108,6 +111,8 @@ def have_no_preview
108111
end
109112

110113
it 'handles action mailer not being available' do
114+
skip "Rails 7 forces eager loading on CI, loads app/mailers and fails" if Rails::VERSION::STRING.to_f >= 7.0
115+
111116
expect(
112117
capture_exec(
113118
custom_env.merge('NO_ACTION_MAILER' => 'true'),

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)