Skip to content

Commit b079be2

Browse files
authored
Remove ActiveSupport::Concern#prepended usage for Rails 6 (#662)
`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
1 parent 3fca175 commit b079be2

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

Diff for: lib/stimulus_reflex/cable_readiness.rb

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
# frozen_string_literal: true
22

3-
require "active_support/concern"
4-
53
module StimulusReflex
64
module CableReadiness
7-
extend ActiveSupport::Concern
8-
9-
prepended do
10-
attr_reader :cable_ready
11-
end
5+
attr_reader :cable_ready
126

137
def initialize(*args, **kwargs)
148
super(*args, **kwargs)

Diff for: test/cable_readiness_test.rb

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# frozen_string_literal: true
2+
3+
require_relative "test_helper"
4+
5+
class MyReflexPrepended
6+
prepend StimulusReflex::CableReadiness
7+
8+
def id
9+
"123"
10+
end
11+
12+
def stream_name
13+
"123"
14+
end
15+
end
16+
17+
class StimulusReflex::CableReadinessTest < ActiveSupport::TestCase
18+
test "can be prepended" do
19+
reflex = MyReflexPrepended.new
20+
assert_includes reflex.methods, :cable_ready
21+
end
22+
end

0 commit comments

Comments
 (0)