diff --git a/app/assets/javascripts/admin/bulk_product_update.js.coffee b/app/assets/javascripts/admin/bulk_product_update.js.coffee index bb1bc4e99c..0f3d698d7e 100644 --- a/app/assets/javascripts/admin/bulk_product_update.js.coffee +++ b/app/assets/javascripts/admin/bulk_product_update.js.coffee @@ -259,7 +259,7 @@ productsApp.controller "AdminBulkProductsCtrl", [ url: "/admin/products/bulk_update" data: productsToSubmit ).success((data) -> - if angular.toJson($scope.productsWithoutDerivedAttributes()) == angular.toJson(data) + if angular.toJson($scope.productsWithoutDerivedAttributes($scope.products)) == angular.toJson($scope.productsWithoutDerivedAttributes(data)) $scope.resetProducts data $scope.displaySuccess() else @@ -302,16 +302,17 @@ productsApp.controller "AdminBulkProductsCtrl", [ variant.unit_description = match[3] - $scope.productsWithoutDerivedAttributes = -> - products = [] - if $scope.products - products.push angular.extend {}, product for product in $scope.products - for product in products + $scope.productsWithoutDerivedAttributes = (products) -> + products_filtered = [] + if products + products_filtered.push angular.extend {}, product for product in products + for product in products_filtered delete product.variant_unit_with_scale if product.variants for variant in product.variants delete variant.unit_value_with_description - products + delete variant.options_text + products_filtered $scope.setMessage = (model, text, style, timeout) -> model.text = text diff --git a/app/models/spree/product_set.rb b/app/models/spree/product_set.rb index 2abd05ef73..db3095187e 100644 --- a/app/models/spree/product_set.rb +++ b/app/models/spree/product_set.rb @@ -17,7 +17,7 @@ class Spree::ProductSet < ModelSet end end - def update_variants_attributes(product,variants_attributes) + def update_variants_attributes(product, variants_attributes) variants_attributes.each do |attributes| e = product.variants.detect { |e| e.id.to_s == attributes[:id].to_s && !e.id.nil? } e.update_attributes(attributes.except(:id)) if e.present? diff --git a/db/migrate/20140110040238_make_unit_description_default_blank.rb b/db/migrate/20140110040238_make_unit_description_default_blank.rb new file mode 100644 index 0000000000..58254259ab --- /dev/null +++ b/db/migrate/20140110040238_make_unit_description_default_blank.rb @@ -0,0 +1,10 @@ +class MakeUnitDescriptionDefaultBlank < ActiveRecord::Migration + def up + execute "UPDATE spree_variants SET unit_description='' WHERE unit_description IS NULL" + change_column :spree_variants, :unit_description, :string, default: '' + end + + def down + change_column :spree_variants, :unit_description, :string, default: nil + end +end diff --git a/db/schema.rb b/db/schema.rb index 5265be891e..4cf6c6dbd8 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20131128034556) do +ActiveRecord::Schema.define(:version => 20140110040238) do create_table "adjustment_metadata", :force => true do |t| t.integer "adjustment_id" @@ -890,7 +890,7 @@ ActiveRecord::Schema.define(:version => 20131128034556) do t.boolean "on_demand", :default => false t.string "cost_currency" t.float "unit_value" - t.string "unit_description" + t.string "unit_description", :default => "" end add_index "spree_variants", ["product_id"], :name => "index_variants_on_product_id" diff --git a/spec/features/admin/reports_spec.rb b/spec/features/admin/reports_spec.rb index 8f59e40d00..05ec22ef41 100644 --- a/spec/features/admin/reports_spec.rb +++ b/spec/features/admin/reports_spec.rb @@ -122,10 +122,10 @@ feature %q{ describe "products and inventory report" do it "shows products and inventory report" do - product_1 = create(:simple_product, name: "Product Name") - variant_1 = create(:variant, product: product_1, price: 100.0) - variant_2 = create(:variant, product: product_1, price: 80.0) - product_2 = create(:simple_product, name: "Product 2", price: 99.0) + product_1 = create(:simple_product, name: "Product Name", variant_unit: nil) + variant_1 = create(:variant, product: product_1, price: 100.0) + variant_2 = create(:variant, product: product_1, price: 80.0) + product_2 = create(:simple_product, name: "Product 2", price: 99.0, variant_unit: nil) variant_1.update_column(:count_on_hand, 10) variant_2.update_column(:count_on_hand, 20) product_2.master.update_column(:count_on_hand, 9) diff --git a/spec/javascripts/unit/bulk_product_update_spec.js.coffee b/spec/javascripts/unit/bulk_product_update_spec.js.coffee index bed0687231..5d2c26b83b 100644 --- a/spec/javascripts/unit/bulk_product_update_spec.js.coffee +++ b/spec/javascripts/unit/bulk_product_update_spec.js.coffee @@ -661,10 +661,10 @@ describe "AdminBulkProductsCtrl", -> describe "fetching products without derived attributes", -> it "returns products without the variant_unit_with_scale field", -> scope.products = [{id: 123, variant_unit_with_scale: 'weight_1000'}] - expect(scope.productsWithoutDerivedAttributes()).toEqual([{id: 123}]) + expect(scope.productsWithoutDerivedAttributes(scope.products)).toEqual([{id: 123}]) it "returns an empty array when products are undefined", -> - expect(scope.productsWithoutDerivedAttributes()).toEqual([]) + expect(scope.productsWithoutDerivedAttributes(scope.products)).toEqual([]) it "does not alter original products", -> scope.products = [{id: 123, variant_unit_with_scale: 'weight_1000'}] @@ -674,7 +674,7 @@ describe "AdminBulkProductsCtrl", -> describe "updating variants", -> it "returns variants without the unit_value_with_description field", -> scope.products = [{id: 123, variants: [{id: 234, unit_value_with_description: 'foo'}]}] - expect(scope.productsWithoutDerivedAttributes()).toEqual [ + expect(scope.productsWithoutDerivedAttributes(scope.products)).toEqual [ { id: 123 variants: [{id: 234}]