From 29e49b67cce20b0d8c6b1dcfa5861679b34ae2a0 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 3 Sep 2014 13:22:50 +1000 Subject: [PATCH] In BPE, rename producer and category JSON attrs to producer_id and category_id Conflicts: spec/features/admin/bulk_product_update_spec.rb --- .../admin/bulk_product_update.js.coffee | 8 +++---- .../admin/filters/category_filter.js.coffee | 2 +- .../admin/filters/producer_filter.js.coffee | 2 +- .../spree/api/product_serializer.rb | 16 ++++++------- .../bulk_edit/_products_product.html.haml | 4 ++-- .../admin/bulk_product_update_spec.rb | 24 +++++++++---------- .../unit/bulk_product_update_spec.js.coffee | 10 ++++---- 7 files changed, 33 insertions(+), 33 deletions(-) diff --git a/app/assets/javascripts/admin/bulk_product_update.js.coffee b/app/assets/javascripts/admin/bulk_product_update.js.coffee index c95f27932e..417ace3d6b 100644 --- a/app/assets/javascripts/admin/bulk_product_update.js.coffee +++ b/app/assets/javascripts/admin/bulk_product_update.js.coffee @@ -386,8 +386,8 @@ filterSubmitProducts = (productsToFilter) -> if product.hasOwnProperty("name") filteredProduct.name = product.name hasUpdatableProperty = true - if product.hasOwnProperty("producer") - filteredProduct.supplier_id = product.producer + if product.hasOwnProperty("producer_id") + filteredProduct.supplier_id = product.producer_id hasUpdatableProperty = true if product.hasOwnProperty("price") filteredProduct.price = product.price @@ -402,8 +402,8 @@ filterSubmitProducts = (productsToFilter) -> if product.hasOwnProperty("on_hand") and filteredVariants.length == 0 #only update if no variants present filteredProduct.on_hand = product.on_hand hasUpdatableProperty = true - if product.hasOwnProperty("category") - filteredProduct.primary_taxon_id = product.category + if product.hasOwnProperty("category_id") + filteredProduct.primary_taxon_id = product.category_id hasUpdatableProperty = true if product.hasOwnProperty("available_on") filteredProduct.available_on = product.available_on diff --git a/app/assets/javascripts/admin/filters/category_filter.js.coffee b/app/assets/javascripts/admin/filters/category_filter.js.coffee index b89e706815..8472a0f7dc 100644 --- a/app/assets/javascripts/admin/filters/category_filter.js.coffee +++ b/app/assets/javascripts/admin/filters/category_filter.js.coffee @@ -1,4 +1,4 @@ angular.module("ofn.admin").filter "category", ($filter) -> return (products, taxonID) -> return products if taxonID == "0" - return $filter('filter')( products, { category: taxonID }, true ) \ No newline at end of file + return $filter('filter')( products, { category_id: taxonID }, true ) \ No newline at end of file diff --git a/app/assets/javascripts/admin/filters/producer_filter.js.coffee b/app/assets/javascripts/admin/filters/producer_filter.js.coffee index 7325b2200d..bda3a9c751 100644 --- a/app/assets/javascripts/admin/filters/producer_filter.js.coffee +++ b/app/assets/javascripts/admin/filters/producer_filter.js.coffee @@ -1,4 +1,4 @@ angular.module("ofn.admin").filter "producer", ($filter) -> return (products, producerID) -> return products if producerID == "0" - $filter('filter')( products, { producer: producerID }, true ) \ No newline at end of file + $filter('filter')( products, { producer_id: producerID }, true ) \ No newline at end of file diff --git a/app/serializers/spree/api/product_serializer.rb b/app/serializers/spree/api/product_serializer.rb index aa8919f8d6..8c1a331936 100644 --- a/app/serializers/spree/api/product_serializer.rb +++ b/app/serializers/spree/api/product_serializer.rb @@ -2,25 +2,25 @@ class Spree::Api::ProductSerializer < ActiveModel::Serializer attributes :id, :name, :variant_unit, :variant_unit_scale, :variant_unit_name, :on_demand attributes :on_hand, :price, :available_on, :permalink_live - - has_one :supplier, key: :producer, embed: :id - has_one :primary_taxon, key: :category, embed: :id + + has_one :supplier, key: :producer_id, embed: :id + has_one :primary_taxon, key: :category_id, embed: :id has_many :variants, key: :variants, serializer: Spree::Api::VariantSerializer # embed: ids has_one :master, serializer: Spree::Api::VariantSerializer - + def on_hand object.on_hand.nil? ? 0 : object.on_hand.to_f.finite? ? object.on_hand : "On demand" end - + def price object.price.nil? ? '0.0' : object.price end - + def available_on object.available_on.blank? ? "" : object.available_on.strftime("%F %T") end - + def permalink_live object.permalink end -end \ No newline at end of file +end diff --git a/app/views/spree/admin/products/bulk_edit/_products_product.html.haml b/app/views/spree/admin/products/bulk_edit/_products_product.html.haml index ee2c1dc136..ed41532a11 100644 --- a/app/views/spree/admin/products/bulk_edit/_products_product.html.haml +++ b/app/views/spree/admin/products/bulk_edit/_products_product.html.haml @@ -3,7 +3,7 @@ %a{ 'ofn-toggle-variants' => 'true', :class => "view-variants icon-chevron-right", 'ng-show' => 'hasVariants(product)' } %a{ :class => "add-variant icon-plus-sign", 'ng-click' => "addVariant(product)", 'ng-show' => "!hasVariants(product) && hasUnit(product)" } %td.producer{ 'ng-show' => 'columns.producer.visible' } - %select.select2.fullwidth{ 'ng-model' => 'product.producer', :name => 'producer', 'ofn-track-product' => 'producer', 'ng-options' => 'producer.id as producer.name for producer in producers' } + %select.select2.fullwidth{ 'ng-model' => 'product.producer_id', :name => 'producer_id', 'ofn-track-product' => 'producer_id', 'ng-options' => 'producer.id as producer.name for producer in producers' } %td.name{ 'ng-show' => 'columns.name.visible' } %input{ 'ng-model' => "product.name", :name => 'product_name', 'ofn-track-product' => 'name', :type => 'text' } %td.unit{ 'ng-show' => 'columns.unit.visible' } @@ -19,7 +19,7 @@ %span{ 'ng-bind' => 'product.on_hand', :name => 'on_hand', 'ng-show' => '!hasOnDemandVariants(product) && (hasVariants(product) || product.on_demand)' } %input.field{ 'ng-model' => 'product.on_hand', :name => 'on_hand', 'ofn-track-product' => 'on_hand', 'ng-hide' => 'hasVariants(product) || product.on_demand', :type => 'number' } %td.category{ 'ng-if' => 'columns.category.visible' } - %input.fullwidth{ :type => 'text', id: "p{{product.id}}_category", 'ng-model' => 'product.category', 'ofn-taxon-autocomplete' => '', 'ofn-track-product' => 'category' } + %input.fullwidth{ :type => 'text', id: "p{{product.id}}_category_id", 'ng-model' => 'product.category_id', 'ofn-taxon-autocomplete' => '', 'ofn-track-product' => 'category_id' } %td.available_on{ 'ng-show' => 'columns.available_on.visible' } %input{ 'ng-model' => 'product.available_on', :name => 'available_on', 'ofn-track-product' => 'available_on', 'datetimepicker' => 'product.available_on', type: "text" } %td.actions diff --git a/spec/features/admin/bulk_product_update_spec.rb b/spec/features/admin/bulk_product_update_spec.rb index 03a90137d9..65776c4845 100644 --- a/spec/features/admin/bulk_product_update_spec.rb +++ b/spec/features/admin/bulk_product_update_spec.rb @@ -37,8 +37,8 @@ feature %q{ visit '/admin/products/bulk_edit' - expect(page).to have_select "producer", with_options: [s1.name,s2.name,s3.name], selected: s2.name - expect(page).to have_select "producer", with_options: [s1.name,s2.name,s3.name], selected: s3.name + expect(page).to have_select "producer_id", with_options: [s1.name,s2.name,s3.name], selected: s2.name + expect(page).to have_select "producer_id", with_options: [s1.name,s2.name,s3.name], selected: s3.name end it "displays a date input for available_on for each product, formatted to yyyy-mm-dd hh:mm:ss" do @@ -302,19 +302,19 @@ feature %q{ within "tr#p_#{p.id}" do expect(page).to have_field "product_name", with: p.name - expect(page).to have_select "producer", selected: s1.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_field "price", with: "10.0" - expect(page).to have_selector "div#s2id_p#{p.id}_category a.select2-choice" + expect(page).to have_selector "div#s2id_p#{p.id}_category_id a.select2-choice" expect(page).to have_select "variant_unit_with_scale", selected: "Volume (L)" expect(page).to have_field "on_hand", with: "6" fill_in "product_name", with: "Big Bag Of Potatoes" - select s2.name, :from => 'producer' + select s2.name, :from => 'producer_id' fill_in "available_on", with: (3.days.ago.beginning_of_day).strftime("%F %T") fill_in "price", with: "20" select "Weight (kg)", from: "variant_unit_with_scale" - select2_select t1.name, from: "p#{p.id}_category" + select2_select t1.name, from: "p#{p.id}_category_id" fill_in "on_hand", with: "18" fill_in "display_as", with: "Big Bag" end @@ -654,13 +654,13 @@ feature %q{ end expect(page).to have_selector "a.clone-product", :count => 4 expect(page).to have_field "product_name", with: "COPY OF #{p1.name}" - expect(page).to have_select "producer", selected: "#{p1.supplier.name}" + expect(page).to have_select "producer_id", selected: "#{p1.supplier.name}" visit '/admin/products/bulk_edit' expect(page).to have_selector "a.clone-product", :count => 4 expect(page).to have_field "product_name", with: "COPY OF #{p1.name}" - expect(page).to have_select "producer", selected: "#{p1.supplier.name}" + expect(page).to have_select "producer_id", selected: "#{p1.supplier.name}" end end end @@ -764,8 +764,8 @@ feature %q{ it "shows only suppliers that I manage or have permission to" do visit '/admin/products/bulk_edit' - expect(page).to have_select 'producer', with_options: [supplier_managed1.name, supplier_managed2.name, supplier_permitted.name], selected: supplier_managed1.name - expect(page).to have_no_select 'producer', with_options: [supplier_unmanaged.name] + expect(page).to have_select 'producer_id', with_options: [supplier_managed1.name, supplier_managed2.name, supplier_permitted.name], selected: supplier_managed1.name + expect(page).to have_no_select 'producer_id', with_options: [supplier_unmanaged.name] end it "shows inactive products that I supply" do @@ -807,13 +807,13 @@ feature %q{ within "tr#p_#{p.id}" do expect(page).to have_field "product_name", with: p.name - expect(page).to have_select "producer", selected: supplier_permitted.name + expect(page).to have_select "producer_id", selected: supplier_permitted.name expect(page).to have_field "available_on", with: p.available_on.strftime("%F %T") expect(page).to have_field "price", with: "10.0" expect(page).to have_field "on_hand", with: "6" fill_in "product_name", with: "Big Bag Of Potatoes" - select(supplier_managed2.name, :from => 'producer') + select supplier_managed2.name, :from => 'producer_id' fill_in "available_on", with: (3.days.ago.beginning_of_day).strftime("%F %T") fill_in "price", with: "20" select "Weight (kg)", from: "variant_unit_with_scale" diff --git a/spec/javascripts/unit/bulk_product_update_spec.js.coffee b/spec/javascripts/unit/bulk_product_update_spec.js.coffee index 649ab99f52..fa7ebdd82d 100644 --- a/spec/javascripts/unit/bulk_product_update_spec.js.coffee +++ b/spec/javascripts/unit/bulk_product_update_spec.js.coffee @@ -184,7 +184,7 @@ describe "filtering products for submission to database", -> created_at: null updated_at: null count_on_hand: 0 - producer: 5 + producer_id: 5 group_buy: null group_buy_unit_size: null @@ -1051,7 +1051,7 @@ describe "AdminProductEditCtrl", -> product: id: 17 name: "new_product" - producer: 6 + producer_id: 6 variants: [ id: 3 @@ -1061,7 +1061,7 @@ describe "AdminProductEditCtrl", -> $httpBackend.expectGET("/api/products/17?template=bulk_show").respond 200, id: 17 name: "new_product" - producer: 6 + producer_id: 6 variants: [ id: 3 @@ -1074,7 +1074,7 @@ describe "AdminProductEditCtrl", -> id: 17 name: "new_product" variant_unit_with_scale: null - producer: 6 + producer_id: 6 variants: [ id: 3 @@ -1091,7 +1091,7 @@ describe "AdminProductEditCtrl", -> id: 17 name: "new_product" variant_unit_with_scale: null - producer: 6 + producer_id: 6 variants: [ id: 3