From 0ca0abd0b28de7c1ed2a07653f8af78a96af01c8 Mon Sep 17 00:00:00 2001 From: Rob H Date: Sat, 1 Jun 2013 21:13:40 +0530 Subject: [PATCH] Can alter on_hand and price of individual variants --- .../spree/admin/products/bulk_index.html.haml | 11 ++- app/views/spree/admin/products/bulk_index.rep | 2 + spec/controllers/product_controller_spec.rb | 8 +- .../admin/bulk_product_update_spec.rb | 77 ++++++++++++++++++- .../unit/bulk_product_update_spec.js | 2 +- 5 files changed, 91 insertions(+), 9 deletions(-) diff --git a/app/views/spree/admin/products/bulk_index.html.haml b/app/views/spree/admin/products/bulk_index.html.haml index 0f2de43fe3..cc8a163cf8 100644 --- a/app/views/spree/admin/products/bulk_index.html.haml +++ b/app/views/spree/admin/products/bulk_index.html.haml @@ -29,10 +29,19 @@ %td %input{ 'ng-model' => 'product.master.price', 'ng-decimal' => :true, :name => 'master_price', :type => 'text' } %td - %span{ 'ng-bind' => 'onHand(product)', :name => 'master_on_hand', 'ng-show' => 'product.variants.length > 0' } + %span{ 'ng-bind' => 'onHand(product)', :name => 'on_hand', 'ng-show' => 'product.variants.length > 0' } %input.field{ 'ng-model' => 'product.master.on_hand', :name => 'master_on_hand', 'ng-show' => 'product.variants.length == 0', :type => 'number' } %td %input{ 'ng-model' => 'product.available_on', :name => 'available_on', :type => 'text' } + %tr{ 'ng-repeat' => 'variant in product.variants' } + %td + {{ variant.options_text }} + %td + %td + %input{ 'ng-model' => 'variant.price', 'ng-decimal' => :true, :name => 'variant_price', :type => 'text' } + %td + %input.field{ 'ng-model' => 'variant.on_hand', :name => 'variant_on_hand', :type => 'number' } + %td %input{:type => 'button', :value => 'Update', 'ng-click' => 'prepareProductsForSubmit()'} %span{ id: "update-status-message", 'ng-style' => 'updateStatusMessage.style' } {{ updateStatusMessage.text }} \ No newline at end of file diff --git a/app/views/spree/admin/products/bulk_index.rep b/app/views/spree/admin/products/bulk_index.rep index b7cd059876..4ad7766301 100644 --- a/app/views/spree/admin/products/bulk_index.rep +++ b/app/views/spree/admin/products/bulk_index.rep @@ -10,6 +10,8 @@ r.list_of :products, @collection do end r.list_of :variants, Proc.new{ |product| product.variants.sort { |a,b| a.id <=> b.id } } do r.element :id + r.element :options_text + r.element :price r.element :on_hand end end \ No newline at end of file diff --git a/spec/controllers/product_controller_spec.rb b/spec/controllers/product_controller_spec.rb index ea84c2ce5c..ac3c442466 100644 --- a/spec/controllers/product_controller_spec.rb +++ b/spec/controllers/product_controller_spec.rb @@ -39,9 +39,9 @@ describe Spree::Admin::ProductsController do "on_hand" => p1.master.on_hand }, "variants" => [ #ordered by id - { "id" => v11.id, "on_hand" => v11.on_hand }, - { "id" => v12.id, "on_hand" => v12.on_hand }, - { "id" => v13.id, "on_hand" => v13.on_hand } + { "id" => v11.id, "options_text" => v11.options_text, "price" => v11.price.to_s, "on_hand" => v11.on_hand }, + { "id" => v12.id, "options_text" => v12.options_text, "price" => v12.price.to_s, "on_hand" => v12.on_hand }, + { "id" => v13.id, "options_text" => v13.options_text, "price" => v13.price.to_s, "on_hand" => v13.on_hand } ] } p2r = { @@ -55,7 +55,7 @@ describe Spree::Admin::ProductsController do "on_hand" => p2.master.on_hand }, "variants" => [ #ordered by id - { "id" => v21.id, "on_hand" => v21.on_hand } + { "id" => v21.id, "options_text" => v21.options_text, "price" => v21.price.to_s, "on_hand" => v21.on_hand } ] } json_response = JSON.parse(response.body) diff --git a/spec/features/admin/bulk_product_update_spec.rb b/spec/features/admin/bulk_product_update_spec.rb index b08299a45e..123b6233d5 100644 --- a/spec/features/admin/bulk_product_update_spec.rb +++ b/spec/features/admin/bulk_product_update_spec.rb @@ -31,7 +31,7 @@ feature %q{ page.should have_field "product_name", with: p2.name end - it "displays a select box for suppliers, with the appropriate supplier selected" do + it "displays a select box for suppliers, with the appropriate supplier selected" do s1 = FactoryGirl.create(:supplier_enterprise) s2 = FactoryGirl.create(:supplier_enterprise) s3 = FactoryGirl.create(:supplier_enterprise) @@ -78,7 +78,7 @@ feature %q{ visit '/admin/products/bulk_index' - page.should_not have_selector "span[name='master_on_hand']", text: "0" + page.should_not have_selector "span[name='on_hand']", text: "0" page.should have_field "master_on_hand", with: "15" page.should have_field "master_on_hand", with: "12" end @@ -95,10 +95,53 @@ feature %q{ visit '/admin/products/bulk_index' page.should_not have_field "master_on_hand", with: "15" - page.should have_selector "span[name='master_on_hand']", text: "4" + page.should have_selector "span[name='on_hand']", text: "4" page.should have_field "master_on_hand", with: "12" end end + + describe "listing variants" do + before :each do + login_to_admin_section + end + + it "displays a list of variants for each product" do + v1 = FactoryGirl.create(:variant) + v2 = FactoryGirl.create(:variant) + + visit '/admin/products/bulk_index' + + page.should have_field "product_name", with: v1.product.name + page.should have_field "product_name", with: v2.product.name + page.should have_selector "td", text: v1.options_text + page.should have_selector "td", text: v2.options_text + end + + it "displays an on_hand input (for each variant) for each product" do + p1 = FactoryGirl.create(:product) + v1 = FactoryGirl.create(:variant, product: p1, is_master: false, on_hand: 15) + v2 = FactoryGirl.create(:variant, product: p1, is_master: false, on_hand: 6) + + visit '/admin/products/bulk_index' + + page.should have_selector "span[name='on_hand']", text: "21" + page.should have_field "variant_on_hand", with: "15" + page.should have_field "variant_on_hand", with: "6" + end + + + it "displays a price input (for each variant) for each product" do + p1 = FactoryGirl.create(:product, price: 2.0) + v1 = FactoryGirl.create(:variant, product: p1, is_master: false, price: 12.75) + v2 = FactoryGirl.create(:variant, product: p1, is_master: false, price: 2.50) + + visit '/admin/products/bulk_index' + + page.should have_field "master_price", with: "2.0" + page.should have_field "variant_price", with: "12.75" + page.should have_field "variant_price", with: "2.5" + end + end scenario "create a new product" do s = FactoryGirl.create(:supplier_enterprise) @@ -161,6 +204,34 @@ feature %q{ page.should have_field "master_on_hand", with: "18" end + scenario "updating a product with variants" do + s1 = FactoryGirl.create(:supplier_enterprise) + s2 = FactoryGirl.create(:supplier_enterprise) + p = FactoryGirl.create(:product, supplier: s1, available_on: Date.today) + v = FactoryGirl.create(:variant, product: p, price: 3.0, on_hand: 9) + + login_to_admin_section + + visit '/admin/products/bulk_index' + + page.should have_field "variant_price", with: "3.0" + page.should have_field "variant_on_hand", with: "9" + page.should have_selector "span[name='on_hand']", text: "9" + + fill_in "variant_price", with: "4.0" + fill_in "variant_on_hand", with: "10" + + page.should have_selector "span[name='on_hand']", text: "10" + + click_button 'Update' + page.find("span#update-status-message").should have_content "Update complete" + + visit '/admin/products/bulk_index' + + page.should have_field "variant_price", with: "4.0" + page.should have_field "variant_on_hand", with: "10" + end + scenario "updating a product mutiple times without refresh" do p = FactoryGirl.create(:product, name: 'original name') login_to_admin_section diff --git a/spec/javascripts/unit/bulk_product_update_spec.js b/spec/javascripts/unit/bulk_product_update_spec.js index b21be8d777..47b623236e 100644 --- a/spec/javascripts/unit/bulk_product_update_spec.js +++ b/spec/javascripts/unit/bulk_product_update_spec.js @@ -321,7 +321,7 @@ describe("AdminBulkProductsCtrl", function(){ }); it("sums variant on_hand properties", function(){ - expect(onHand(p1)).toEqual(6);r + expect(onHand(p1)).toEqual(6); }); it("ignores items in variants without an on_hand property (adds 0)", function(){