Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecated Configurable Class: Allow class methods #5762

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 25 additions & 14 deletions core/app/models/spree/deprecated_configurable_class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,39 @@

module Spree
class DeprecatedConfigurableClass
def initialize(*_args, &_block)
issue_deprecation_warning
def self.new(*_args, &_block)
@deprecation_proxy ||= DeprecationProxy.new
end

def method_missing(_method_name, *_args, &_block)
issue_deprecation_warning
self
def self.method_missing(method_name, *args, &block)
@deprecation_proxy ||= DeprecationProxy.new
@deprecation_proxy.send(method_name, args, block)
end

def respond_to_missing?(_method_name, _include_private = false)
def self.respond_to_missing?(_method_name, _include_private = false)
true
end

private
class DeprecationProxy
def method_missing(_method_name, *_args, &_block)
issue_deprecation_warning
self
end

def issue_deprecation_warning
Spree.deprecator.warn(
<<-WARNING
It appears you are using Solidus' Legacy promotion system. This system has been extracted into the
`solidus_legacy_promotions` gem. Please add the gem to your Gemfile and follow in the instructions in the README.
WARNING
)
def respond_to_missing?(_method_name, _include_private = false)
true
end

private

def issue_deprecation_warning
Spree.deprecator.warn(
<<-WARNING
It appears you are using Solidus' Legacy promotion system. This system has been extracted into the
`solidus_legacy_promotions` gem. Please add the gem to your Gemfile and follow in the instructions in the README.
WARNING
)
end
end
end
end
14 changes: 14 additions & 0 deletions core/spec/models/spree/deprecated_configurable_class_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,18 @@
it "responds to anything" do
expect(described_class.new).to respond_to(:anything)
end

context "when calling a class method" do
it "warns when a method is called" do
described_class.some_method

expect(deprecator).to have_received(:warn).with(/It appears you are using Solidus' Legacy promotion system/).at_least(:once)
end

it "can take method chains" do
described_class.foo.bar.baz

expect(deprecator).to have_received(:warn).with(/It appears you are using Solidus' Legacy promotion system/).at_least(:once)
end
end
end
Loading