Skip to content

Commit

Permalink
Don't raise when including CableReadyHelper (#256)
Browse files Browse the repository at this point in the history
* Don't raise when including `CableReadyHelper`

Instead print a warning and include the module anyway, so we are not breaking any exisiting code

* use `base.include(...)` over `include`
  • Loading branch information
marcoroth authored Feb 14, 2023
1 parent d12f2e7 commit 1c28d83
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/cable_ready.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

require "open-uri"
require "active_support/message_verifier"
require "cable_ready_helper"
require "cable_ready/identifiable"
require "cable_ready/operation_builder"
require "cable_ready/config"
Expand All @@ -15,6 +14,7 @@
require "cable_ready/cable_car"
require "cable_ready/stream_identifier"
require "cable_ready/version"
require "cable_ready_helper"

module CableReady
class << self
Expand Down
6 changes: 5 additions & 1 deletion lib/cable_ready_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

# TODO: remove me once CableReady 5.0 was released

require_relative "../app/helpers/cable_ready/view_helper"

module CableReadyHelper
def self.included(base)
raise "`CableReadyHelper` was renamed to `CableReady::ViewHelper`"
warn "NOTICE: `CableReadyHelper` was renamed to `CableReady::ViewHelper`. Please update your include accordingly."

base.include(::CableReady::ViewHelper)
end
end
13 changes: 7 additions & 6 deletions test/lib/cable_ready/view_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,18 @@ class CableReady::ViewHelperTest < ActionView::TestCase
assert_equal "div", element.name
end

test "raises when including CableReadyHelper" do
expection = assert_raises do
class RaiseHelperTest # standard:disable Lint/ConstantDefinitionInBlock
# standard:disable Lint/ConstantDefinitionInBlock
test "prints warning when including CableReadyHelper" do
assert_output(nil, %(NOTICE: `CableReadyHelper` was renamed to `CableReady::ViewHelper`. Please update your include accordingly.\n)) do
class CableReadyHelperTest
include ::CableReadyHelper
end

RaiseHelperTest.new
assert_includes CableReadyHelperTest, ::CableReadyHelper
assert_includes CableReadyHelperTest, ::CableReady::ViewHelper
end

assert_equal "`CableReadyHelper` was renamed to `CableReady::ViewHelper`", expection.message
end
# standard:enable Lint/ConstantDefinitionInBlock

# deprecation warnings

Expand Down

0 comments on commit 1c28d83

Please sign in to comment.