Skip to content

Commit

Permalink
Remove ActiveSupport::Concern#prepended usage for Rails 6 (#662)
Browse files Browse the repository at this point in the history
`ActiveSupport::Concern#prepended` is only available in Rails 6.1+.
Since we support `>= 5.2` we can't rely on the `prepended` callback in
`lib/stimulus_reflex/cable_readiness.rb`.

Since we can easily support Rails 5.2 and Rails 6.0 with this fix.
Otherwise we would need to make StimulusReflex depend on Rails 6.1+,
which seems rather dramatic.

Fixes #656
  • Loading branch information
marcoroth authored May 25, 2023
1 parent 3fca175 commit b079be2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
8 changes: 1 addition & 7 deletions lib/stimulus_reflex/cable_readiness.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
# frozen_string_literal: true

require "active_support/concern"

module StimulusReflex
module CableReadiness
extend ActiveSupport::Concern

prepended do
attr_reader :cable_ready
end
attr_reader :cable_ready

def initialize(*args, **kwargs)
super(*args, **kwargs)
Expand Down
22 changes: 22 additions & 0 deletions test/cable_readiness_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

require_relative "test_helper"

class MyReflexPrepended
prepend StimulusReflex::CableReadiness

def id
"123"
end

def stream_name
"123"
end
end

class StimulusReflex::CableReadinessTest < ActiveSupport::TestCase
test "can be prepended" do
reflex = MyReflexPrepended.new
assert_includes reflex.methods, :cable_ready
end
end

0 comments on commit b079be2

Please sign in to comment.