Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

add missing specs

Łukasz Adamczyk0960c88c4353
diff --git a/core/app/presenters/spree/filters/property.rb b/core/app/presenters/spree/filters/property.rb
index 04d3218ba0..2565a4524b 100644
--- a/core/app/presenters/spree/filters/property.rb
+++ b/core/app/presenters/spree/filters/property.rb
@@ -6,6 +6,8 @@ module Spree
@product_properties = product_properties
end
+ attr_reader :product_properties
+
delegate_missing_to :property
def uniq_values
@@ -14,7 +16,7 @@ module Spree
private
- attr_reader :property, :product_properties
+ attr_reader :property
end
end
end
diff --git a/core/spec/finders/spree/product_properties/find_available_spec.rb b/core/spec/finders/spree/product_properties/find_available_spec.rb
index 26ef0bbbee..5ada92f4a8 100644
--- a/core/spec/finders/spree/product_properties/find_available_spec.rb
+++ b/core/spec/finders/spree/product_properties/find_available_spec.rb
@@ -4,12 +4,12 @@ module Spree
RSpec.describe ProductProperties::FindAvailable do
let(:finder) { described_class.new }
- let(:brand) { create(:property, :brand, :filterable,) }
+ let(:brand) { create(:property, :brand, :filterable) }
let(:alpha_brand) { create(:product_property, property: brand, value: 'Alpha') }
let(:beta_brand) { create(:product_property, property: brand, value: 'Beta') }
let(:gamma_brand) { create(:product_property, property: brand, value: 'Gamma') }
- let(:manufacturer) { create(:property, :manufacturer, :filterable,) }
+ let(:manufacturer) { create(:property, :manufacturer, :filterable) }
let(:wilson_manufacturer) { create(:product_property, property: manufacturer, value: 'Wilson') }
let(:jerseys_manufacturer) { create(:product_property, property: manufacturer, value: 'Jerseys') }
diff --git a/core/spec/presenters/spree/filters/properties_spec.rb b/core/spec/presenters/spree/filters/properties_spec.rb
new file mode 100644
index 0000000000..d3c07a3cdd
--- /dev/null
+++ b/core/spec/presenters/spree/filters/properties_spec.rb
@@ -0,0 +1,34 @@
+require 'spec_helper'
+
+module Spree
+ RSpec.describe Filters::Properties do
+ let(:properties) { described_class.new(product_properties_scope: ProductProperty.where(id: product_properties)) }
+ let(:product_properties) { [alpha_brand, beta_brand, wilson_manufacturer] }
+
+ let(:brand) { create(:property, :brand, :filterable) }
+ let(:alpha_brand) { create(:product_property, property: brand, value: 'Alpha') }
+ let(:beta_brand) { create(:product_property, property: brand, value: 'Beta') }
+
+ let(:manufacturer) { create(:property, :manufacturer, :filterable) }
+ let(:wilson_manufacturer) { create(:product_property, property: manufacturer, value: 'Wilson') }
+
+ before do
+ create(:product_property, property: brand, value: 'Gamma')
+ create(:product_property, property: manufacturer, value: 'Jerseys')
+ end
+
+ describe '#to_a' do
+ subject(:filterable_properties) { properties.to_a }
+
+ it 'returns filterable Product Properties' do
+ aggregate_failures 'filterable product properties' do
+ brand_property = filterable_properties.find { |property| property.name == brand.name }
+ expect(brand_property.product_properties).to contain_exactly(alpha_brand, beta_brand)
+
+ manufacturer_property = filterable_properties.find { |property| property.name == manufacturer.name }
+ expect(manufacturer_property.product_properties).to contain_exactly(wilson_manufacturer)
+ end
+ end
+ end
+ end
+end
diff --git a/core/spec/presenters/spree/filters/property_spec.rb b/core/spec/presenters/spree/filters/property_spec.rb
new file mode 100644
index 0000000000..6c5746196f
--- /dev/null
+++ b/core/spec/presenters/spree/filters/property_spec.rb
@@ -0,0 +1,24 @@
+require 'spec_helper'
+
+module Spree
+ RSpec.describe Filters::Property do
+ let(:property) { described_class.new(property: brand, product_properties: product_properties) }
+ let(:product_properties) { [alpha_brand, beta_brand] }
+
+ let(:brand) { create(:property, :brand, :filterable) }
+ let(:alpha_brand) { create(:product_property, property: brand, value: 'Alpha') }
+ let(:beta_brand) { create(:product_property, property: brand, value: 'Beta') }
+
+ before do
+ create(:product_property, property: brand, value: 'Gamma')
+ end
+
+ describe '#uniq_values' do
+ subject(:uniq_values) { property.uniq_values }
+
+ it 'returns unique Product Properties values for a given list of Product Properties' do
+ expect(uniq_values).to eq([['alpha', 'Alpha'], ['beta', 'Beta']])
+ end
+ end
+ end
+end