From 1035891cb329430fe80d60efae4a159e3b2fcf91 Mon Sep 17 00:00:00 2001 From: Sean Doyle Date: Wed, 30 Oct 2024 14:56:38 -0400 Subject: [PATCH] Drop Support for `ruby@2.x.x` Commit to requiring `ruby@3.1` Remove `ruby@2.6`, `ruby@2.7`, `ruby@3.0`, `rails@6.1`, and `rails@7.0` from the CI matrix, along with any `RUBY_VERSION < "3"` conditionals. The implementation changes include replace older syntaxes with newer variants. For example, utilize `...` in place of `*args, &block`, rely on `**`-ing attribute `Hash` arguments, etc. --- .github/workflows/ci.yml | 9 ++------- Gemfile | 18 ++++-------------- app/channels/turbo/streams/broadcasts.rb | 2 -- app/helpers/turbo/streams/action_helper.rb | 9 ++------- app/models/concerns/turbo/broadcastable.rb | 2 +- app/models/turbo/streams/tag_builder.rb | 4 ++-- lib/turbo/engine.rb | 2 +- lib/turbo/system_test_helper.rb | 8 ++++---- test/test_helper.rb | 4 +--- turbo-rails.gemspec | 6 +++--- 10 files changed, 20 insertions(+), 44 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 07c76acc..c54d48d4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,17 +5,13 @@ jobs: strategy: fail-fast: false matrix: - rails: [ "6.1", "7.0", "7.1", "7.2" ] - ruby: [ "2.7", "3.0", "3.1", "3.2", "3.3" ] + rails: [ "7.1", "7.2" ] + ruby: [ "3.1", "3.2", "3.3" ] allow-fail: [ false ] include: - - { ruby: "2.6", rails: "6.1" } - { ruby: "3.3", rails: "main", allow-fail: true } - { ruby: "3.2", rails: "main", allow-fail: true } - { ruby: "head", rails: "main", allow-fail: true } - exclude: - - { ruby: "2.7", rails: "7.2" } - - { ruby: "3.0", rails: "7.2" } env: FERRUM_PROCESS_TIMEOUT: 25 @@ -37,7 +33,6 @@ jobs: - name: Run Bug Template Tests run: ruby bug_report_template.rb || ruby bug_report_template.rb - continue-on-error: ${{ startsWith(matrix.ruby, "2") || false }} - name: Run tests id: test diff --git a/Gemfile b/Gemfile index fd01cf08..cf4a565b 100644 --- a/Gemfile +++ b/Gemfile @@ -15,26 +15,16 @@ gem "sprockets-rails" gem 'rake' gem 'byebug' - -if RUBY_VERSION < "3" - gem "rack", "< 3" - gem "puma", "< 6" -else - gem "rack" - gem "puma" -end +gem 'puma' +gem 'rack' group :development, :test do - if rails_version == "6.1" - gem "importmap-rails", "0.6.1" - else - gem "importmap-rails" - end + gem 'importmap-rails' end group :test do gem 'capybara' gem 'rexml' gem 'cuprite', '~> 0.9', require: 'capybara/cuprite' - gem 'sqlite3', '1.5' + gem 'sqlite3', '~> 1.5' end diff --git a/app/channels/turbo/streams/broadcasts.rb b/app/channels/turbo/streams/broadcasts.rb index 3d80a2bc..ea63df01 100644 --- a/app/channels/turbo/streams/broadcasts.rb +++ b/app/channels/turbo/streams/broadcasts.rb @@ -38,8 +38,6 @@ def broadcast_refresh_to(*streamables, **opts) end def broadcast_action_to(*streamables, action:, target: nil, targets: nil, attributes: {}, **rendering) - attributes.deep_symbolize_keys! if RUBY_VERSION < "3" - broadcast_stream_to(*streamables, content: turbo_stream_action_tag( action, target: target, targets: targets, template: render_broadcast_action(rendering), **attributes) ) diff --git a/app/helpers/turbo/streams/action_helper.rb b/app/helpers/turbo/streams/action_helper.rb index 7cb40263..16fdeb02 100644 --- a/app/helpers/turbo/streams/action_helper.rb +++ b/app/helpers/turbo/streams/action_helper.rb @@ -22,12 +22,7 @@ module Turbo::Streams::ActionHelper # message = Message.find(1) # turbo_stream_action_tag "remove", target: [message, :special] # # => - def turbo_stream_action_tag(action, attributes = {}) - attributes.deep_symbolize_keys! if RUBY_VERSION < "3" - - target = attributes.delete(:target) - targets = attributes.delete(:targets) - template = attributes.delete(:template) + def turbo_stream_action_tag(action, target: nil, targets: nil, template: nil, **attributes) template = action.to_sym.in?(%i[ remove refresh ]) ? "" : tag.template(template.to_s.html_safe) if target = convert_to_turbo_stream_dom_id(target) @@ -44,7 +39,7 @@ def turbo_stream_action_tag(action, attributes = {}) # turbo_stream_refresh_tag # # => def turbo_stream_refresh_tag(request_id: Turbo.current_request_id, **attributes) - turbo_stream_action_tag(:refresh, attributes.with_defaults({ "request-id": request_id }.compact)) + turbo_stream_action_tag(:refresh, "request-id": request_id.presence, **attributes) end private diff --git a/app/models/concerns/turbo/broadcastable.rb b/app/models/concerns/turbo/broadcastable.rb index 462d647d..b39c186e 100644 --- a/app/models/concerns/turbo/broadcastable.rb +++ b/app/models/concerns/turbo/broadcastable.rb @@ -508,7 +508,7 @@ def broadcast_target_default self.class.broadcast_target_default end - def extract_options_and_add_target(rendering, target: broadcast_target_default) + def extract_options_and_add_target(rendering = {}, target: broadcast_target_default) broadcast_rendering_with_defaults(rendering).tap do |options| options[:target] = target if !options.key?(:target) && !options.key?(:targets) end diff --git a/app/models/turbo/streams/tag_builder.rb b/app/models/turbo/streams/tag_builder.rb index 8b6eed84..93cf2e76 100644 --- a/app/models/turbo/streams/tag_builder.rb +++ b/app/models/turbo/streams/tag_builder.rb @@ -240,8 +240,8 @@ def prepend_all(targets, content = nil, **rendering, &block) # # turbo_stream.refresh request_id: "abc123" # # => - def refresh(**options) - turbo_stream_refresh_tag(**options) + def refresh(...) + turbo_stream_refresh_tag(...) end # Send an action of the type name to target. Options described in the concrete methods. diff --git a/lib/turbo/engine.rb b/lib/turbo/engine.rb index 8fb9933f..ecfd82e0 100644 --- a/lib/turbo/engine.rb +++ b/lib/turbo/engine.rb @@ -164,7 +164,7 @@ class TurboStreamEncoder < IdentityEncoder ActiveSupport.on_load(:action_dispatch_system_test_case) do app.config.turbo.test_connect_after_actions.map do |method| class_eval <<~RUBY, __FILE__, __LINE__ + 1 - def #{method}(*args, &block) # def visit(*args, &block) + def #{method}(...) # def visit(...) super.tap { connect_turbo_cable_stream_sources } # super.tap { connect_turbo_cable_stream_sources } end # end RUBY diff --git a/lib/turbo/system_test_helper.rb b/lib/turbo/system_test_helper.rb index c7b52101..4e81a1e1 100644 --- a/lib/turbo/system_test_helper.rb +++ b/lib/turbo/system_test_helper.rb @@ -51,8 +51,8 @@ def connect_turbo_cable_stream_sources(**options, &block) # # In addition to the filters listed above, accepts any valid Capybara global # filter option. - def assert_turbo_cable_stream_source(*args, &block) - assert_selector(:turbo_cable_stream_source, *args, &block) + def assert_turbo_cable_stream_source(...) + assert_selector(:turbo_cable_stream_source, ...) end # Asserts that a `` element is absent from the @@ -75,8 +75,8 @@ def assert_turbo_cable_stream_source(*args, &block) # # In addition to the filters listed above, accepts any valid Capybara global # filter option. - def assert_no_turbo_cable_stream_source(*args, &block) - assert_no_selector(:turbo_cable_stream_source, *args, &block) + def assert_no_turbo_cable_stream_source(...) + assert_no_selector(:turbo_cable_stream_source, ...) end Capybara.add_selector :turbo_cable_stream_source do diff --git a/test/test_helper.rb b/test/test_helper.rb index 1c54616f..00d2f13e 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -8,9 +8,7 @@ ActionCable.server.config.logger = Logger.new(STDOUT) if ENV["VERBOSE"] module ActionViewTestCaseExtensions - def render(*args, &block) - ApplicationController.renderer.render(*args, &block) - end + delegate :render, to: ApplicationController end class ActiveSupport::TestCase diff --git a/turbo-rails.gemspec b/turbo-rails.gemspec index 87e2092a..b6d14097 100644 --- a/turbo-rails.gemspec +++ b/turbo-rails.gemspec @@ -9,10 +9,10 @@ Gem::Specification.new do |s| s.homepage = "https://github.com/hotwired/turbo-rails" s.license = "MIT" - s.required_ruby_version = ">= 2.6.0" + s.required_ruby_version = ">= 3.1" - s.add_dependency "actionpack", ">= 6.0.0" - s.add_dependency "railties", ">= 6.0.0" + s.add_dependency "actionpack", ">= 7.1.0" + s.add_dependency "railties", ">= 7.1.0" s.files = Dir["{app,config,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"]