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 #368 from richardnuno/variant-property-rules
Introduce variant level properties
- Loading branch information
Showing
30 changed files
with
735 additions
and
59 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
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
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
7 changes: 7 additions & 0 deletions
7
backend/app/controllers/spree/admin/variant_property_rule_values_controller.rb
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,7 @@ | ||
module Spree | ||
module Admin | ||
class VariantPropertyRuleValuesController < ResourceController | ||
belongs_to 'spree/product', find_by: :slug | ||
end | ||
end | ||
end |
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
69 changes: 69 additions & 0 deletions
69
backend/spec/controllers/spree/admin/product_properties_controller_spec.rb
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,69 @@ | ||
require 'spec_helper' | ||
|
||
module Spree | ||
module Admin | ||
describe ProductPropertiesController, type: :controller do | ||
stub_authorization! | ||
|
||
describe "#index" do | ||
subject { spree_get :index, parameters } | ||
|
||
context "no option values are provided" do | ||
let(:product) { create(:product) } | ||
let(:parameters) do | ||
{ product_id: product.to_param } | ||
end | ||
|
||
before { subject } | ||
|
||
it "instantiates a new variant property rule" do | ||
expect(assigns(:variant_property_rule)).to_not be_persisted | ||
end | ||
|
||
it "instantiates a new variant property rule value" do | ||
expect(assigns(:variant_property_rule).values.size).to eq 1 | ||
expect(assigns(:variant_property_rule).values.first).to_not be_persisted | ||
end | ||
end | ||
|
||
context "option values are provided" do | ||
let(:size) { create(:option_type, name: 'size') } | ||
let(:product) { create(:product, option_types: [size]) } | ||
let(:size_small) { create(:option_value, name: 'small', option_type: size) } | ||
let(:size_large) { create(:option_value, name: 'large', option_type: size) } | ||
let!(:first_rule) { create(:variant_property_rule, product: product, option_value: size_small) } | ||
|
||
context "no rules match the option values" do | ||
let(:parameters) do | ||
{ | ||
product_id: product.to_param, | ||
ovi: [size_large.id] | ||
} | ||
end | ||
|
||
before { subject } | ||
|
||
it "instantiates a new variant property rule" do | ||
expect(assigns(:variant_property_rule)).to_not be_persisted | ||
end | ||
end | ||
|
||
context "a rule matches the option values" do | ||
let(:parameters) do | ||
{ | ||
product_id: product.to_param, | ||
ovi: [size_small.id] | ||
} | ||
end | ||
|
||
before { subject } | ||
|
||
it "assigns the property rule to the only property rule that matches the option values" do | ||
expect(assigns(:variant_property_rule)).to eq first_rule | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.