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.
Properly delegate Spree::ApiConfiguration#promotion_attributes
Initializing the app with the code prior to this commit would instantiate the promotions configuration, which is not good because instantiating it via `Spree::Config.promotions` leads to the object being instacached and very, very hard to change. Also, we currently have to spots in the app where we can configure the promotion api attributes, and this reduces it to just one by deprecating the preference :promotion_attributes on `Spree::ApiConfiguration`.
- Loading branch information
Showing
2 changed files
with
52 additions
and
1 deletion.
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,41 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
RSpec.describe Spree::ApiConfiguration do | ||
subject(:config) { Spree::ApiConfiguration.new } | ||
|
||
describe "#promotion_attributes" do | ||
subject(:promotion_attributes) { config.promotion_attributes } | ||
|
||
it { is_expected.to eq(Spree::Config.promotions.promotion_api_attributes) } | ||
|
||
it "can be changed" do | ||
config.promotion_attributes << :foo | ||
expect(promotion_attributes).to include(:foo) | ||
end | ||
|
||
it "can delete attributes" do | ||
expect(promotion_attributes).to include(:name) | ||
config.promotion_attributes.delete(:name) | ||
expect(promotion_attributes).not_to include(:name) | ||
end | ||
end | ||
|
||
describe "#promotion_attributes=" do | ||
subject(:promotion_attributes_setter) { config.promotion_attributes = [:name] } | ||
|
||
around do |example| | ||
original_attributes = Spree::Config.promotions.promotion_api_attributes | ||
Spree.deprecator.silence do | ||
example.run | ||
end | ||
Spree::Config.promotions.promotion_api_attributes = original_attributes | ||
end | ||
|
||
it "sets the promotion_attributes" do | ||
promotion_attributes_setter | ||
expect(config.promotion_attributes).to eq([:name]) | ||
end | ||
end | ||
end |