forked from solidusio/solidus
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request solidusio#5813 from SuperGoodSoft/raise-error-with…
…-spree-deprecator Raise on deprecation when `SOLIDUS_RAISE_DEPRECATIONS` set
- Loading branch information
Showing
2 changed files
with
54 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe "Spree.deprecator" do | ||
Dummy = Class.new do | ||
def deprecated_method | ||
"foo" | ||
end | ||
deprecate :deprecated_method, deprecator: Spree.deprecator | ||
end | ||
|
||
context "by default" do | ||
it "returns a valid deprecator" do | ||
expect(Spree.deprecator).to have_attributes( | ||
deprecation_horizon: "5.0", | ||
gem_name: "Solidus" | ||
) | ||
end | ||
|
||
it "does not raise an error unless overridden by environment" do | ||
if ENV["SOLIDUS_RAISE_DEPRECATIONS"] | ||
expect { Dummy.new.deprecated_method }.to raise_error(ActiveSupport::DeprecationException) | ||
else | ||
expect { Dummy.new.deprecated_method }.not_to raise_error | ||
end | ||
end | ||
end | ||
|
||
context "when the behavior has been changed to :raise" do | ||
around do |example| | ||
behavior_name = ActiveSupport::Deprecation::DEFAULT_BEHAVIORS.detect { |_behavior_name, behavior_proc| | ||
behavior_proc == Spree.deprecator.behavior.first | ||
}.first | ||
|
||
Spree.deprecator.behavior = :raise | ||
|
||
example.run | ||
|
||
Spree.deprecator.behavior = behavior_name | ||
end | ||
|
||
it "raises an error when a deprecated method is called" do | ||
expect { Dummy.new.deprecated_method } | ||
.to raise_error(ActiveSupport::DeprecationException) | ||
end | ||
end | ||
end |