diff --git a/app/controllers/admin/variant_overrides_controller.rb b/app/controllers/admin/variant_overrides_controller.rb index 66e8d97baf..9edf82a82a 100644 --- a/app/controllers/admin/variant_overrides_controller.rb +++ b/app/controllers/admin/variant_overrides_controller.rb @@ -14,7 +14,6 @@ module Admin def bulk_update collection_hash = Hash[params[:variant_overrides].each_with_index.map { |vo, i| [i, vo] }] vo_set = VariantOverrideSet.new @variant_overrides, collection_attributes: collection_hash - # Ensure we're authorised to update all variant overrides vo_set.collection.each { |vo| authorize! :update, vo } diff --git a/spec/controllers/admin/variant_overrides_spec.rb b/spec/controllers/admin/variant_overrides_spec.rb new file mode 100644 index 0000000000..f726bd8869 --- /dev/null +++ b/spec/controllers/admin/variant_overrides_spec.rb @@ -0,0 +1,51 @@ +require 'spec_helper' + +module Admin + describe VariantOverridesController, type: :controller do + include AuthenticationWorkflow + let!(:hub_owner) { create :admin_user, enterprise_limit: 2 } + + before do + controller.stub spree_current_user: hub_owner + end + + describe "bulk_update" do + context "as an enterprise user I update the variant overrides" do + let!(:hub) { create(:distributor_enterprise, owner: hub_owner) } + it "updates the overrides correctly" do + v1 = create(:variant) + v2 = create(:variant) + vo1 = create(:variant_override, hub: hub, variant: v1, price: "6.0", count_on_hand: 5, default_stock: 7) + vo2 = create(:variant_override, hub: hub, variant: v2, price: "6.0", count_on_hand: 5, default_stock: 7) + vo1.price = "10.0" + vo2.default_stock = 12 + # Have to use .attributes as otherwise passes just the ID + spree_put :bulk_update, {variant_overrides: [vo1.attributes, vo2.attributes]} + # Retrieve from database + VariantOverride.find(vo1.id).price.should eq 10 + VariantOverride.find(vo2.id).default_stock.should eq 12 + end + end + end + describe "bulk_reset" do + let!(:hub) { create(:distributor_enterprise, owner: hub_owner) } + before do + controller.stub spree_current_user: hub.owner + end + context "when a reset request is received" do + it "updates stock to default values" do + v1 = create(:variant) + v2 = create(:variant) + vo1 = create(:variant_override, hub: hub, variant: v1, price: "6.0", count_on_hand: 5, default_stock: 7) + vo2 = create(:variant_override, hub: hub, variant: v2, price: "6.0", count_on_hand: 2, default_stock: 1) + params = {"variant_overrides" => [vo1.attributes, vo2.attributes]} + spree_put :bulk_reset, params + vo1.reload + expect(vo1.count_on_hand).to eq 7 + vo2.reload + expect(vo2.count_on_hand).to eq 1 + end + end + end + end +end