Merging master branch into require_standard_variant

This commit is contained in:
Rob Harrington
2015-04-29 14:30:49 +10:00
33 changed files with 280 additions and 119 deletions

View File

@@ -231,6 +231,55 @@ feature %q{
expect(page).to have_selector "a.edit-variant", visible: true
end
scenario "updating product attributes" do
s1 = FactoryGirl.create(:supplier_enterprise)
s2 = FactoryGirl.create(:supplier_enterprise)
t1 = FactoryGirl.create(:taxon)
t2 = FactoryGirl.create(:taxon)
p = FactoryGirl.create(:product, supplier: s1, available_on: Date.today, variant_unit: 'volume', variant_unit_scale: 1, primary_taxon: t2, sku: "OLD SKU")
login_to_admin_section
visit '/admin/products/bulk_edit'
first("div#columns_dropdown", :text => "COLUMNS").click
first("div#columns_dropdown div.menu div.menu_item", text: "Available On").click
first("div#columns_dropdown div.menu div.menu_item", text: "Category").click
first("div#columns_dropdown div.menu div.menu_item", text: "Inherits Properties?").click
first("div#columns_dropdown div.menu div.menu_item", text: "SKU").click
within "tr#p_#{p.id}" do
expect(page).to have_field "product_name", with: p.name
expect(page).to have_select "producer_id", selected: s1.name
expect(page).to have_field "available_on", with: p.available_on.strftime("%F %T")
expect(page).to have_select2 "p#{p.id}_category_id", selected: t2.name
expect(page).to have_select "variant_unit_with_scale", selected: "Volume (L)"
expect(page).to have_checked_field "inherits_properties"
expect(page).to have_field "product_sku", with: p.sku
fill_in "product_name", with: "Big Bag Of Potatoes"
select s2.name, :from => 'producer_id'
fill_in "available_on", with: (3.days.ago.beginning_of_day).strftime("%F %T")
select "Weight (kg)", from: "variant_unit_with_scale"
select2_select t1.name, from: "p#{p.id}_category_id"
uncheck "inherits_properties"
fill_in "product_sku", with: "NEW SKU"
end
click_button 'Save Changes'
expect(page.find("#status-message")).to have_content "Changes saved."
p.reload
expect(p.name).to eq "Big Bag Of Potatoes"
expect(p.supplier).to eq s2
expect(p.variant_unit).to eq "weight"
expect(p.variant_unit_scale).to eq 1000 # Kg
expect(p.available_on).to eq 3.days.ago.beginning_of_day
expect(p.primary_taxon).to eq t1
expect(p.inherits_properties).to be false
expect(p.sku).to eq "NEW SKU"
end
scenario "updating a product with a variant unit of 'items'" do
p = FactoryGirl.create(:product, variant_unit: 'weight', variant_unit_scale: 1000)

View File

@@ -69,7 +69,7 @@ describe 'Products service', ->
expect(Products.products[0].taxons[1]).toBe taxons[0]
it "dereferences properties", ->
product.properties = [1]
product.properties_with_values = [1]
$httpBackend.expectGET("/shop/products").respond([product])
$httpBackend.flush()
expect(Products.products[0].properties[1]).toBe properties[0]

View File

@@ -353,8 +353,9 @@ module Spree
it "returns product properties as a hash" do
product = create(:simple_product)
product.set_property 'Organic Certified', 'NASAA 12345'
property = product.properties.last
product.properties_h.should == [{presentation: 'Organic Certified', value: 'NASAA 12345'}]
product.properties_including_inherited.should == [{id: property.id, name: "Organic Certified", value: 'NASAA 12345'}]
end
it "returns producer properties as a hash" do
@@ -362,8 +363,9 @@ module Spree
product = create(:simple_product, supplier: supplier)
supplier.set_producer_property 'Organic Certified', 'NASAA 54321'
property = supplier.properties.last
product.properties_h.should == [{presentation: 'Organic Certified', value: 'NASAA 54321'}]
product.properties_including_inherited.should == [{id: property.id, name: "Organic Certified", value: 'NASAA 54321'}]
end
it "overrides producer properties with product properties" do
@@ -372,8 +374,32 @@ module Spree
product.set_property 'Organic Certified', 'NASAA 12345'
supplier.set_producer_property 'Organic Certified', 'NASAA 54321'
property = product.properties.last
product.properties_h.should == [{presentation: 'Organic Certified', value: 'NASAA 12345'}]
product.properties_including_inherited.should == [{id: property.id, name: "Organic Certified", value: 'NASAA 12345'}]
end
context "when product has an inherit_properties value set to true" do
let(:supplier) { create(:supplier_enterprise) }
let(:product) { create(:simple_product, supplier: supplier, inherits_properties: true) }
it "inherits producer properties" do
supplier.set_producer_property 'Organic Certified', 'NASAA 54321'
property = supplier.properties.last
product.properties_including_inherited.should == [{id: property.id, name: "Organic Certified", value: 'NASAA 54321'}]
end
end
context "when product has an inherit_properties value set to true" do
let(:supplier) { create(:supplier_enterprise) }
let(:product) { create(:simple_product, supplier: supplier, inherits_properties: false) }
it "does not inherit producer properties" do
supplier.set_producer_property 'Organic Certified', 'NASAA 54321'
product.properties_including_inherited.should == []
end
end
it "sorts by position" do
@@ -388,10 +414,10 @@ module Spree
product.product_properties.create!({property_id: pc.id, value: '3', position: 3}, {without_protection: true})
supplier.producer_properties.create!({property_id: pb.id, value: '2', position: 2}, {without_protection: true})
product.properties_h.should ==
[{presentation: 'A', value: '1'},
{presentation: 'B', value: '2'},
{presentation: 'C', value: '3'}]
product.properties_including_inherited.should ==
[{id: pa.id, name: "A", value: '1'},
{id: pb.id, name: "B", value: '2'},
{id: pc.id, name: "C", value: '3'}]
end
end

View File

@@ -1,7 +1,7 @@
describe Spree::Api::ProductSerializer do
describe Api::Admin::ProductSerializer do
let(:product) { create(:simple_product) }
it "serializes a product" do
serializer = Spree::Api::ProductSerializer.new product
serializer = Api::Admin::ProductSerializer.new product
serializer.to_json.should match product.name
end
end
end

View File

@@ -1,7 +1,7 @@
describe Spree::Api::VariantSerializer do
describe Api::Admin::VariantSerializer do
let(:variant) { create(:variant) }
it "serializes a variant" do
serializer = Spree::Api::VariantSerializer.new variant
serializer = Api::Admin::VariantSerializer.new variant
serializer.to_json.should match variant.options_text
end
end
end