From 3aedbb6c48adbdacc595ea43710e58f52875e8e1 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Thu, 27 Nov 2014 11:45:49 +1100 Subject: [PATCH] Display variant overrides --- .../override_variants_controller.js.coffee | 3 +- .../_products_variants.html.haml | 4 +- spec/factories.rb | 5 +++ spec/features/admin/override_variants_spec.rb | 42 +++++++++++++------ ...verride_variants_controller_spec.js.coffee | 3 +- 5 files changed, 40 insertions(+), 17 deletions(-) diff --git a/app/assets/javascripts/admin/controllers/override_variants_controller.js.coffee b/app/assets/javascripts/admin/controllers/override_variants_controller.js.coffee index d4bd2d73ba..2d4c55e356 100644 --- a/app/assets/javascripts/admin/controllers/override_variants_controller.js.coffee +++ b/app/assets/javascripts/admin/controllers/override_variants_controller.js.coffee @@ -1,9 +1,10 @@ -angular.module("ofn.admin").controller "AdminOverrideVariantsCtrl", ($scope, Indexer, SpreeApiAuth, PagedFetcher, hubs, producers, hubPermissions) -> +angular.module("ofn.admin").controller "AdminOverrideVariantsCtrl", ($scope, Indexer, SpreeApiAuth, PagedFetcher, hubs, producers, hubPermissions, variantOverrides) -> $scope.hubs = hubs $scope.hub = null $scope.products = [] $scope.producers = Indexer.index producers $scope.hubPermissions = hubPermissions + $scope.variantOverrides = Indexer.index variantOverrides, 'variant_id' $scope.initialise = -> SpreeApiAuth.authorise() diff --git a/app/views/spree/admin/products/override_variants/_products_variants.html.haml b/app/views/spree/admin/products/override_variants/_products_variants.html.haml index b15127677a..73dca63650 100644 --- a/app/views/spree/admin/products/override_variants/_products_variants.html.haml +++ b/app/views/spree/admin/products/override_variants/_products_variants.html.haml @@ -1,5 +1,5 @@ %tr.variant{ng: {repeat: 'variant in product.variants'}} %td %td {{ variant.options_text }} - %td {{ variant.price }} - %td {{ variant.on_hand }} + %td {{ variant.price }} - {{ variantOverrides[variant.id].price }} + %td {{ variant.on_hand }} - {{ variantOverrides[variant.id].count_on_hand }} diff --git a/spec/factories.rb b/spec/factories.rb index 0112ea8b51..214c61962d 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -89,6 +89,11 @@ FactoryGirl.define do incoming false end + factory :variant_override, :class => VariantOverride do + price 77.77 + count_on_hand 11111 + end + factory :enterprise, :class => Enterprise do owner { FactoryGirl.create :user } sequence(:name) { |n| "Enterprise #{n}" } diff --git a/spec/features/admin/override_variants_spec.rb b/spec/features/admin/override_variants_spec.rb index 1a37e90a84..a62c6fbc33 100644 --- a/spec/features/admin/override_variants_spec.rb +++ b/spec/features/admin/override_variants_spec.rb @@ -47,24 +47,40 @@ feature %q{ before do # Remove 'S' option value variant.option_values.first.destroy - - visit '/admin/products/override_variants' - select2_select hub.name, from: 'hub_id' - click_button 'Go' end - it "displays the list of products with variants" do - page.should have_table_row ['PRODUCER', 'PRODUCT', 'PRICE', 'ON HAND'] - page.should have_table_row [producer.name, product.name, '', ''] - page.should have_table_row ['', '1g', '1.23', '12'] + context "with no overrides" do + before do + visit '/admin/products/override_variants' + select2_select hub.name, from: 'hub_id' + click_button 'Go' + end + + it "displays the list of products with variants" do + page.should have_table_row ['PRODUCER', 'PRODUCT', 'PRICE', 'ON HAND'] + page.should have_table_row [producer.name, product.name, '', ''] + page.should have_table_row ['', '1g', '1.23 -', '12 -'] + end + + it "filters the products to those the hub can add to an order cycle" do + page.should_not have_content producer2.name + page.should_not have_content product2.name + end end - it "filters the products to those the hub can add to an order cycle" do - page.should_not have_content producer2.name - page.should_not have_content product2.name - end + context "with overrides" do + let!(:override) { create(:variant_override, variant: variant, hub: hub, price: 77.77, count_on_hand: 11111) } - it "products values are affected by overrides" + before do + visit '/admin/products/override_variants' + select2_select hub.name, from: 'hub_id' + click_button 'Go' + end + + it "product values are affected by overrides" do + page.should have_table_row ['', '1g', '1.23 - 77.77', '12 - 11111'] + end + end end end end diff --git a/spec/javascripts/unit/admin/controllers/override_variants_controller_spec.js.coffee b/spec/javascripts/unit/admin/controllers/override_variants_controller_spec.js.coffee index a34fa61816..093ccc3cb2 100644 --- a/spec/javascripts/unit/admin/controllers/override_variants_controller_spec.js.coffee +++ b/spec/javascripts/unit/admin/controllers/override_variants_controller_spec.js.coffee @@ -5,6 +5,7 @@ describe "OverrideVariantsCtrl", -> producers = [{id: 2, name: 'Producer'}] products = [{id: 1, name: 'Product'}] hubPermissions = {} + variantOverrides = {} beforeEach -> module 'ofn.admin' @@ -14,7 +15,7 @@ describe "OverrideVariantsCtrl", -> scope = {} inject ($controller, Indexer) -> - ctrl = $controller 'AdminOverrideVariantsCtrl', {$scope: scope, Indexer: Indexer, hubs: hubs, producers: producers, products: products, hubPermissions: hubPermissions} + ctrl = $controller 'AdminOverrideVariantsCtrl', {$scope: scope, Indexer: Indexer, hubs: hubs, producers: producers, products: products, hubPermissions: hubPermissions, variantOverrides: variantOverrides} it "initialises the hub list and the chosen hub", -> expect(scope.hubs).toEqual hubs