From 4b3198a2b4dd4c72f89409f1ceda0c8e7163fb3d Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Wed, 21 Nov 2018 23:28:34 +0800 Subject: [PATCH 01/60] Allow reset of "on demand" for variant overrides Change the UI control for "on demand" in the Inventory page from a checkbox to a SELECT field with three options: nil, true, and false. This resolves the following issues: * There is no way to tell between nil and false - both are represented by an unticked checkbox. * There is no way to go back to nil. --- .../variant_overrides_controller.js.coffee | 4 +++ .../_products_variants.html.haml | 5 ++-- config/locales/en.yml | 5 ++++ spec/features/admin/variant_overrides_spec.rb | 30 +++++++++++++++++-- 4 files changed, 39 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/admin/variant_overrides/controllers/variant_overrides_controller.js.coffee b/app/assets/javascripts/admin/variant_overrides/controllers/variant_overrides_controller.js.coffee index 0fe051f496..1bf77e160b 100644 --- a/app/assets/javascripts/admin/variant_overrides/controllers/variant_overrides_controller.js.coffee +++ b/app/assets/javascripts/admin/variant_overrides/controllers/variant_overrides_controller.js.coffee @@ -13,6 +13,10 @@ angular.module("admin.variantOverrides").controller "AdminVariantOverridesCtrl", $scope.RequestMonitor = RequestMonitor $scope.selectView = Views.selectView $scope.currentView = -> Views.currentView + $scope.onDemandOptions = [ + { description: t('js.yes'), value: true }, + { description: t('js.no'), value: false } + ] $scope.views = Views.setViews inventory: { name: t('js.variant_overrides.inventory_products'), visible: true } diff --git a/app/views/admin/variant_overrides/_products_variants.html.haml b/app/views/admin/variant_overrides/_products_variants.html.haml index 7c530a1cb2..5a3f3b2b39 100644 --- a/app/views/admin/variant_overrides/_products_variants.html.haml +++ b/app/views/admin/variant_overrides/_products_variants.html.haml @@ -10,7 +10,8 @@ %td.on_hand{ ng: { show: 'columns.on_hand.visible' } } %input{name: 'variant-overrides-{{ variant.id }}-count_on_hand', type: 'text', ng: {model: 'variantOverrides[hub_id][variant.id].count_on_hand'}, placeholder: '{{ variant.on_hand }}', 'ofn-track-variant-override' => 'count_on_hand'} %td.on_demand{ ng: { show: 'columns.on_demand.visible' } } - %input.field{ :type => 'checkbox', name: 'variant-overrides-{{ variant.id }}-on_demand', ng: { model: 'variantOverrides[hub_id][variant.id].on_demand' }, 'ofn-track-variant-override' => 'on_demand' } + %select{ name: 'variant-overrides-{{ variant.id }}-on_demand', ng: { model: 'variantOverrides[hub_id][variant.id].on_demand', options: 'option.value as option.description for option in onDemandOptions' }, 'ofn-track-variant-override' => 'on_demand' } + %option{ value: '' }= t(".on_demand.use_producer_settings") %td.reset{ ng: { show: 'columns.reset.visible' } } %input{name: 'variant-overrides-{{ variant.id }}-resettable', type: 'checkbox', ng: {model: 'variantOverrides[hub_id][variant.id].resettable'}, placeholder: '{{ variant.resettable }}', 'ofn-track-variant-override' => 'resettable'} %td.reset{ ng: { show: 'columns.reset.visible' } } @@ -24,4 +25,4 @@ %button.icon-remove.hide.fullwidth{ :type => 'button', ng: { click: "setVisibility(hub_id,variant.id,false)" } } = t('admin.variant_overrides.index.hide') %td.import_date{ ng: { show: 'columns.import_date.visible' } } - %span {{variantOverrides[hub_id][variant.id].import_date | date:"MMMM dd, yyyy HH:mm"}} \ No newline at end of file + %span {{variantOverrides[hub_id][variant.id].import_date | date:"MMMM dd, yyyy HH:mm"}} diff --git a/config/locales/en.yml b/config/locales/en.yml index de1222902e..25a5fcc179 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -623,6 +623,9 @@ en: new_powertip: These products are available to be added to your inventory. Click 'Add' to add a product to your inventory, or 'Hide' to hide it from view. You can always change your mind later! controls: back_to_my_inventory: Back to my inventory + products_variants: + on_demand: + use_producer_settings: "Use producer settings" orders: invoice_email_sent: 'Invoice email has been sent' order_email_resent: 'Order email has been resent' @@ -2445,6 +2448,8 @@ See the %{link} to find out more about %{sitename}'s features and to start using pending: Pending shipped: Shipped js: + "yes": "Yes" + "no": "No" saving: 'Saving...' changes_saved: 'Changes saved.' save_changes_first: Save changes first. diff --git a/spec/features/admin/variant_overrides_spec.rb b/spec/features/admin/variant_overrides_spec.rb index 60130ddc6d..1421cb496c 100644 --- a/spec/features/admin/variant_overrides_spec.rb +++ b/spec/features/admin/variant_overrides_spec.rb @@ -141,7 +141,7 @@ feature %q{ fill_in "variant-overrides-#{variant.id}-sku", with: 'NEWSKU' fill_in "variant-overrides-#{variant.id}-price", with: '777.77' fill_in "variant-overrides-#{variant.id}-count_on_hand", with: '123' - check "variant-overrides-#{variant.id}-on_demand" + select I18n.t("js.yes"), from: "variant-overrides-#{variant.id}-on_demand" page.should have_content "Changes to one override remain unsaved." expect do @@ -218,7 +218,7 @@ feature %q{ end context "with overrides" do - let!(:vo) { create(:variant_override, variant: variant, hub: hub, price: 77.77, count_on_hand: 11111, default_stock: 1000, resettable: true, tag_list: ["tag1","tag2","tag3"]) } + let!(:vo) { create(:variant_override, variant: variant, hub: hub, price: 77.77, on_demand: true, count_on_hand: 11111, default_stock: 1000, resettable: true, tag_list: ["tag1","tag2","tag3"]) } let!(:vo_no_auth) { create(:variant_override, variant: variant, hub: hub2, price: 1, count_on_hand: 2) } let!(:product2) { create(:simple_product, supplier: producer, variant_unit: 'weight', variant_unit_scale: 1) } let!(:variant2) { create(:variant, product: product2, unit_value: 8, price: 1.00, on_hand: 12) } @@ -236,6 +236,7 @@ feature %q{ it "product values are affected by overrides" do page.should have_input "variant-overrides-#{variant.id}-price", with: '77.77', placeholder: '1.23' page.should have_input "variant-overrides-#{variant.id}-count_on_hand", with: '11111', placeholder: '12' + expect(page).to have_select "variant-overrides-#{variant.id}-on_demand", selected: I18n.t("js.yes") end it "updates existing overrides" do @@ -255,10 +256,32 @@ feature %q{ vo.count_on_hand.should == 8888 end + it "updates on_demand settings" do + select I18n.t("js.no"), from: "variant-overrides-#{variant.id}-on_demand" + click_button I18n.t("save_changes") + expect(page).to have_content I18n.t("js.changes_saved") + + vo.reload + expect(vo.on_demand).to eq(false) + + select I18n.t("js.yes"), from: "variant-overrides-#{variant.id}-on_demand" + click_button I18n.t("save_changes") + expect(page).to have_content I18n.t("js.changes_saved") + + vo.reload + expect(vo.on_demand).to eq(true) + + select I18n.t("admin.variant_overrides.products_variants.on_demand.use_producer_settings"), from: "variant-overrides-#{variant.id}-on_demand" + click_button I18n.t("save_changes") + expect(page).to have_content I18n.t("js.changes_saved") + + vo.reload + expect(vo.on_demand).to be_nil + end + # Any new fields added to the VO model need to be added to this test it "deletes overrides when values are cleared" do first("div#columns-dropdown", :text => "COLUMNS").click - first("div#columns-dropdown div.menu div.menu_item", text: "On Demand").click first("div#columns-dropdown div.menu div.menu_item", text: "Enable Stock Reset?").click first("div#columns-dropdown div.menu div.menu_item", text: "Tags").click first("div#columns-dropdown", :text => "COLUMNS").click @@ -272,6 +295,7 @@ feature %q{ # Clearing values manually fill_in "variant-overrides-#{variant.id}-price", with: '' fill_in "variant-overrides-#{variant.id}-count_on_hand", with: '' + select I18n.t("admin.variant_overrides.products_variants.on_demand.use_producer_settings"), from: "variant-overrides-#{variant.id}-on_demand" fill_in "variant-overrides-#{variant.id}-default_stock", with: '' within "tr#v_#{variant.id}" do vo.tag_list.each do |tag| From 7ae555cd9ce0c5f11333a3e3962b45792de289b5 Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Mon, 26 Nov 2018 13:41:32 +0800 Subject: [PATCH 02/60] Translate variant override on_demand yes and no --- .../controllers/variant_overrides_controller.js.coffee | 4 ++-- config/locales/en.yml | 3 +++ spec/features/admin/variant_overrides_spec.rb | 8 ++++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/admin/variant_overrides/controllers/variant_overrides_controller.js.coffee b/app/assets/javascripts/admin/variant_overrides/controllers/variant_overrides_controller.js.coffee index 1bf77e160b..4598ad817d 100644 --- a/app/assets/javascripts/admin/variant_overrides/controllers/variant_overrides_controller.js.coffee +++ b/app/assets/javascripts/admin/variant_overrides/controllers/variant_overrides_controller.js.coffee @@ -14,8 +14,8 @@ angular.module("admin.variantOverrides").controller "AdminVariantOverridesCtrl", $scope.selectView = Views.selectView $scope.currentView = -> Views.currentView $scope.onDemandOptions = [ - { description: t('js.yes'), value: true }, - { description: t('js.no'), value: false } + { description: t('js.variant_overrides.on_demand.yes'), value: true }, + { description: t('js.variant_overrides.on_demand.no'), value: false } ] $scope.views = Views.setViews diff --git a/config/locales/en.yml b/config/locales/en.yml index 25a5fcc179..9bb981c7f3 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2596,6 +2596,9 @@ See the %{link} to find out more about %{sitename}'s features and to start using now_out_of_stock: is now out of stock. only_n_remainging: "now only has %{num} remaining." variant_overrides: + on_demand: + "yes": "Yes" + "no": "No" inventory_products: "Inventory Products" hidden_products: "Hidden Products" new_products: "New Products" diff --git a/spec/features/admin/variant_overrides_spec.rb b/spec/features/admin/variant_overrides_spec.rb index 1421cb496c..07273dfc19 100644 --- a/spec/features/admin/variant_overrides_spec.rb +++ b/spec/features/admin/variant_overrides_spec.rb @@ -141,7 +141,7 @@ feature %q{ fill_in "variant-overrides-#{variant.id}-sku", with: 'NEWSKU' fill_in "variant-overrides-#{variant.id}-price", with: '777.77' fill_in "variant-overrides-#{variant.id}-count_on_hand", with: '123' - select I18n.t("js.yes"), from: "variant-overrides-#{variant.id}-on_demand" + select I18n.t("js.variant_overrides.on_demand.yes"), from: "variant-overrides-#{variant.id}-on_demand" page.should have_content "Changes to one override remain unsaved." expect do @@ -236,7 +236,7 @@ feature %q{ it "product values are affected by overrides" do page.should have_input "variant-overrides-#{variant.id}-price", with: '77.77', placeholder: '1.23' page.should have_input "variant-overrides-#{variant.id}-count_on_hand", with: '11111', placeholder: '12' - expect(page).to have_select "variant-overrides-#{variant.id}-on_demand", selected: I18n.t("js.yes") + expect(page).to have_select "variant-overrides-#{variant.id}-on_demand", selected: I18n.t("js.variant_overrides.on_demand.yes") end it "updates existing overrides" do @@ -257,14 +257,14 @@ feature %q{ end it "updates on_demand settings" do - select I18n.t("js.no"), from: "variant-overrides-#{variant.id}-on_demand" + select I18n.t("js.variant_overrides.on_demand.no"), from: "variant-overrides-#{variant.id}-on_demand" click_button I18n.t("save_changes") expect(page).to have_content I18n.t("js.changes_saved") vo.reload expect(vo.on_demand).to eq(false) - select I18n.t("js.yes"), from: "variant-overrides-#{variant.id}-on_demand" + select I18n.t("js.variant_overrides.on_demand.yes"), from: "variant-overrides-#{variant.id}-on_demand" click_button I18n.t("save_changes") expect(page).to have_content I18n.t("js.changes_saved") From a32bb0445fd33f35c41191c5bd720d59406b0e0a Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Wed, 28 Nov 2018 18:12:35 +0800 Subject: [PATCH 03/60] Change translation for variant override use_producer_settings --- config/locales/en.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index 9bb981c7f3..7738fed822 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -625,7 +625,7 @@ en: back_to_my_inventory: Back to my inventory products_variants: on_demand: - use_producer_settings: "Use producer settings" + use_producer_settings: "Use producer stock settings" orders: invoice_email_sent: 'Invoice email has been sent' order_email_resent: 'Order email has been resent' From cc003c99d54ed1b0508d4bc6a0c46322bf81a8bc Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Wed, 28 Nov 2018 19:31:39 +0800 Subject: [PATCH 04/60] Ensure in UI compatible VO count and on demand --- .../variant_overrides_controller.js.coffee | 12 ++++ .../_products_variants.html.haml | 4 +- spec/features/admin/variant_overrides_spec.rb | 36 ++++++++++- ...ariant_overrides_controller_spec.js.coffee | 63 +++++++++++++++++++ 4 files changed, 112 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/admin/variant_overrides/controllers/variant_overrides_controller.js.coffee b/app/assets/javascripts/admin/variant_overrides/controllers/variant_overrides_controller.js.coffee index 4598ad817d..c0c6144f49 100644 --- a/app/assets/javascripts/admin/variant_overrides/controllers/variant_overrides_controller.js.coffee +++ b/app/assets/javascripts/admin/variant_overrides/controllers/variant_overrides_controller.js.coffee @@ -109,3 +109,15 @@ angular.module("admin.variantOverrides").controller "AdminVariantOverridesCtrl", StatusMessage.display 'success', t('js.variant_overrides.stock_reset') .error (data, status) -> $timeout -> StatusMessage.display 'failure', $scope.updateError(data, status) + + $scope.selectLimitedStockIfCountOnHandSet = (hubId, variantId) -> + variantOverride = $scope.variantOverrides[hubId][variantId] + if variantOverride.count_on_hand? && variantOverride.count_on_hand != '' && variantOverride.on_demand != false + variantOverride.on_demand = false + DirtyVariantOverrides.set hubId, variantId, variantOverride.id, 'on_demand', false + + $scope.clearCountOnHandUnlessLimitedStock = (hubId, variantId) -> + variantOverride = $scope.variantOverrides[hubId][variantId] + unless variantOverride.on_demand == false && variantOverride.count_on_hand? + variantOverride.count_on_hand = null + DirtyVariantOverrides.set hubId, variantId, variantOverride.id, 'count_on_hand', null diff --git a/app/views/admin/variant_overrides/_products_variants.html.haml b/app/views/admin/variant_overrides/_products_variants.html.haml index 5a3f3b2b39..38614ad2ba 100644 --- a/app/views/admin/variant_overrides/_products_variants.html.haml +++ b/app/views/admin/variant_overrides/_products_variants.html.haml @@ -8,9 +8,9 @@ %td.price{ ng: { show: 'columns.price.visible' } } %input{name: 'variant-overrides-{{ variant.id }}-price', type: 'text', ng: {model: 'variantOverrides[hub_id][variant.id].price'}, placeholder: '{{ variant.price }}', 'ofn-track-variant-override' => 'price'} %td.on_hand{ ng: { show: 'columns.on_hand.visible' } } - %input{name: 'variant-overrides-{{ variant.id }}-count_on_hand', type: 'text', ng: {model: 'variantOverrides[hub_id][variant.id].count_on_hand'}, placeholder: '{{ variant.on_hand }}', 'ofn-track-variant-override' => 'count_on_hand'} + %input{name: 'variant-overrides-{{ variant.id }}-count_on_hand', type: 'text', ng: { model: 'variantOverrides[hub_id][variant.id].count_on_hand', change: 'selectLimitedStockIfCountOnHandSet(hub_id, variant.id)' }, placeholder: '{{ variant.on_hand }}', 'ofn-track-variant-override' => 'count_on_hand'} %td.on_demand{ ng: { show: 'columns.on_demand.visible' } } - %select{ name: 'variant-overrides-{{ variant.id }}-on_demand', ng: { model: 'variantOverrides[hub_id][variant.id].on_demand', options: 'option.value as option.description for option in onDemandOptions' }, 'ofn-track-variant-override' => 'on_demand' } + %select{ name: 'variant-overrides-{{ variant.id }}-on_demand', ng: { model: 'variantOverrides[hub_id][variant.id].on_demand', change: 'clearCountOnHandUnlessLimitedStock(hub_id, variant.id)', options: 'option.value as option.description for option in onDemandOptions' }, 'ofn-track-variant-override' => 'on_demand' } %option{ value: '' }= t(".on_demand.use_producer_settings") %td.reset{ ng: { show: 'columns.reset.visible' } } %input{name: 'variant-overrides-{{ variant.id }}-resettable', type: 'checkbox', ng: {model: 'variantOverrides[hub_id][variant.id].resettable'}, placeholder: '{{ variant.resettable }}', 'ofn-track-variant-override' => 'resettable'} diff --git a/spec/features/admin/variant_overrides_spec.rb b/spec/features/admin/variant_overrides_spec.rb index 07273dfc19..9be249de4d 100644 --- a/spec/features/admin/variant_overrides_spec.rb +++ b/spec/features/admin/variant_overrides_spec.rb @@ -339,9 +339,43 @@ feature %q{ first("div#bulk-actions-dropdown div.menu div.menu_item", text: "Reset Stock Levels To Defaults").click page.should have_content "Save changes first" end + + describe "ensuring that on demand and count on hand settings are compatible" do + it "changes to limited stock when count on hand is set" do + # It sets on_demand to false when count_on_hand is filled. + fill_in "variant-overrides-#{variant.id}-count_on_hand", with: "200" + expect(page).to have_select "variant-overrides-#{variant.id}-on_demand", selected: I18n.t("js.variant_overrides.on_demand.no") + + # It saves the changes. + click_button I18n.t("save_changes") + expect(page).to have_content I18n.t("js.changes_saved") + + vo.reload + expect(vo.count_on_hand).to eq(200) + expect(vo.on_demand).to eq(false) + end + + it "clears count on hand when not limited stock" do + # It clears count_on_hand when selecting true on_demand. + fill_in "variant-overrides-#{variant.id}-count_on_hand", with: "200" + select I18n.t("js.variant_overrides.on_demand.yes"), from: "variant-overrides-#{variant.id}-on_demand" + expect(page).to have_input "variant-overrides-#{variant.id}-count_on_hand", with: "" + + # It clears count_on_hand when selecting nil on_demand. + fill_in "variant-overrides-#{variant.id}-count_on_hand", with: "200" + select I18n.t("admin.variant_overrides.products_variants.on_demand.use_producer_settings"), from: "variant-overrides-#{variant.id}-on_demand" + expect(page).to have_input "variant-overrides-#{variant.id}-count_on_hand", with: "" + + # It saves the changes. + click_button I18n.t("save_changes") + expect(page).to have_content I18n.t("js.changes_saved") + vo.reload + expect(vo.count_on_hand).to be_nil + expect(vo.on_demand).to be_nil + end + end end end - end describe "when manually placing an order" do diff --git a/spec/javascripts/unit/admin/controllers/variant_overrides_controller_spec.js.coffee b/spec/javascripts/unit/admin/controllers/variant_overrides_controller_spec.js.coffee index 450041a417..1ac20b4318 100644 --- a/spec/javascripts/unit/admin/controllers/variant_overrides_controller_spec.js.coffee +++ b/spec/javascripts/unit/admin/controllers/variant_overrides_controller_spec.js.coffee @@ -87,3 +87,66 @@ describe "VariantOverridesCtrl", -> $httpBackend.flush() expect(VariantOverrides.updateData).toHaveBeenCalledWith variant_overrides_mock expect(StatusMessage.display).toHaveBeenCalledWith 'success', 'Stocks reset to defaults.' + + describe "ensuring that on demand and count on hand settings are compatible", -> + describe "changing to limited stock when count on hand is set", -> + beforeEach -> + scope.variantOverrides = {123: {2: {id: 5, on_demand: true}}} + + describe "when count on hand is set", -> + beforeEach -> + scope.variantOverrides[123][2].count_on_hand = 1 + + it "changes to limited stock and registers dirty attribute", -> + scope.selectLimitedStockIfCountOnHandSet(123, 2) + expect(scope.variantOverrides[123][2].on_demand).toBe(false) + dirtyVariantOverride = DirtyVariantOverrides.dirtyVariantOverrides[123][2] + expect(dirtyVariantOverride.on_demand).toBe(false) + + describe "when count on hand is null", -> + beforeEach -> + scope.variantOverrides[123][2].count_on_hand = null + + it "does not change to limited stock", -> + scope.selectLimitedStockIfCountOnHandSet(123, 2) + expect(scope.variantOverrides[123][2].on_demand).toBe(true) + + describe "when count on hand is blank string", -> + beforeEach -> + scope.variantOverrides[123][2].count_on_hand = '' + + it "does not change to limited stock", -> + scope.selectLimitedStockIfCountOnHandSet(123, 2) + expect(scope.variantOverrides[123][2].on_demand).toBe(true) + + describe "clearing count on hand when not limited stock", -> + beforeEach -> + scope.variantOverrides = {123: {2: {id: 5, count_on_hand: 1}}} + + describe "when on demand is false", -> + beforeEach -> + scope.variantOverrides[123][2].on_demand = false + + it "does not clear count on hand", -> + scope.clearCountOnHandUnlessLimitedStock(123, 2) + expect(scope.variantOverrides[123][2].count_on_hand).toEqual(1) + + describe "when on demand is true", -> + beforeEach -> + scope.variantOverrides[123][2].on_demand = true + + it "clears count on hand and registers dirty attribute", -> + scope.clearCountOnHandUnlessLimitedStock(123, 2) + expect(scope.variantOverrides[123][2].count_on_hand).toBeNull() + dirtyVariantOverride = DirtyVariantOverrides.dirtyVariantOverrides[123][2] + expect(dirtyVariantOverride.count_on_hand).toBeNull() + + describe "when on demand is null", -> + beforeEach -> + scope.variantOverrides[123][2].on_demand = null + + it "clears count on hand and registers dirty attribute", -> + scope.clearCountOnHandUnlessLimitedStock(123, 2) + expect(scope.variantOverrides[123][2].count_on_hand).toBeNull() + dirtyVariantOverride = DirtyVariantOverrides.dirtyVariantOverrides[123][2] + expect(dirtyVariantOverride.count_on_hand).toBeNull() From 09b9f968b7c4bc03ab2358ec8d6b4d7b15f46cdd Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Thu, 29 Nov 2018 04:08:08 +0800 Subject: [PATCH 05/60] Make VO count on hand readonly unless limited stock --- .../variant_overrides_controller.js.coffee | 6 ---- .../_products_variants.html.haml | 2 +- spec/features/admin/variant_overrides_spec.rb | 24 +++++---------- ...ariant_overrides_controller_spec.js.coffee | 30 ------------------- 4 files changed, 9 insertions(+), 53 deletions(-) diff --git a/app/assets/javascripts/admin/variant_overrides/controllers/variant_overrides_controller.js.coffee b/app/assets/javascripts/admin/variant_overrides/controllers/variant_overrides_controller.js.coffee index c0c6144f49..4294d88966 100644 --- a/app/assets/javascripts/admin/variant_overrides/controllers/variant_overrides_controller.js.coffee +++ b/app/assets/javascripts/admin/variant_overrides/controllers/variant_overrides_controller.js.coffee @@ -110,12 +110,6 @@ angular.module("admin.variantOverrides").controller "AdminVariantOverridesCtrl", .error (data, status) -> $timeout -> StatusMessage.display 'failure', $scope.updateError(data, status) - $scope.selectLimitedStockIfCountOnHandSet = (hubId, variantId) -> - variantOverride = $scope.variantOverrides[hubId][variantId] - if variantOverride.count_on_hand? && variantOverride.count_on_hand != '' && variantOverride.on_demand != false - variantOverride.on_demand = false - DirtyVariantOverrides.set hubId, variantId, variantOverride.id, 'on_demand', false - $scope.clearCountOnHandUnlessLimitedStock = (hubId, variantId) -> variantOverride = $scope.variantOverrides[hubId][variantId] unless variantOverride.on_demand == false && variantOverride.count_on_hand? diff --git a/app/views/admin/variant_overrides/_products_variants.html.haml b/app/views/admin/variant_overrides/_products_variants.html.haml index 38614ad2ba..d0e714e9fa 100644 --- a/app/views/admin/variant_overrides/_products_variants.html.haml +++ b/app/views/admin/variant_overrides/_products_variants.html.haml @@ -8,7 +8,7 @@ %td.price{ ng: { show: 'columns.price.visible' } } %input{name: 'variant-overrides-{{ variant.id }}-price', type: 'text', ng: {model: 'variantOverrides[hub_id][variant.id].price'}, placeholder: '{{ variant.price }}', 'ofn-track-variant-override' => 'price'} %td.on_hand{ ng: { show: 'columns.on_hand.visible' } } - %input{name: 'variant-overrides-{{ variant.id }}-count_on_hand', type: 'text', ng: { model: 'variantOverrides[hub_id][variant.id].count_on_hand', change: 'selectLimitedStockIfCountOnHandSet(hub_id, variant.id)' }, placeholder: '{{ variant.on_hand }}', 'ofn-track-variant-override' => 'count_on_hand'} + %input{name: 'variant-overrides-{{ variant.id }}-count_on_hand', type: 'text', ng: { model: 'variantOverrides[hub_id][variant.id].count_on_hand', readonly: 'variantOverrides[hub_id][variant.id].on_demand != false' }, placeholder: '{{ variant.on_hand }}', 'ofn-track-variant-override' => 'count_on_hand'} %td.on_demand{ ng: { show: 'columns.on_demand.visible' } } %select{ name: 'variant-overrides-{{ variant.id }}-on_demand', ng: { model: 'variantOverrides[hub_id][variant.id].on_demand', change: 'clearCountOnHandUnlessLimitedStock(hub_id, variant.id)', options: 'option.value as option.description for option in onDemandOptions' }, 'ofn-track-variant-override' => 'on_demand' } %option{ value: '' }= t(".on_demand.use_producer_settings") diff --git a/spec/features/admin/variant_overrides_spec.rb b/spec/features/admin/variant_overrides_spec.rb index 9be249de4d..e79e0293b9 100644 --- a/spec/features/admin/variant_overrides_spec.rb +++ b/spec/features/admin/variant_overrides_spec.rb @@ -140,8 +140,8 @@ feature %q{ fill_in "variant-overrides-#{variant.id}-sku", with: 'NEWSKU' fill_in "variant-overrides-#{variant.id}-price", with: '777.77' + select I18n.t("js.variant_overrides.on_demand.no"), from: "variant-overrides-#{variant.id}-on_demand" fill_in "variant-overrides-#{variant.id}-count_on_hand", with: '123' - select I18n.t("js.variant_overrides.on_demand.yes"), from: "variant-overrides-#{variant.id}-on_demand" page.should have_content "Changes to one override remain unsaved." expect do @@ -154,14 +154,15 @@ feature %q{ vo.hub_id.should == hub.id vo.sku.should == "NEWSKU" vo.price.should == 777.77 + expect(vo.on_demand).to eq(false) vo.count_on_hand.should == 123 - vo.on_demand.should == true end describe "creating and then updating the new override" do it "updates the same override instead of creating a duplicate" do # When I create a new override fill_in "variant-overrides-#{variant.id}-price", with: '777.77' + select I18n.t("js.variant_overrides.on_demand.no"), from: "variant-overrides-#{variant.id}-on_demand" fill_in "variant-overrides-#{variant.id}-count_on_hand", with: '123' page.should have_content "Changes to one override remain unsaved." @@ -186,6 +187,7 @@ feature %q{ vo.variant_id.should == variant.id vo.hub_id.should == hub.id vo.price.should == 111.11 + expect(vo.on_demand).to eq(false) vo.count_on_hand.should == 111 end end @@ -241,6 +243,7 @@ feature %q{ it "updates existing overrides" do fill_in "variant-overrides-#{variant.id}-price", with: '22.22' + select I18n.t("js.variant_overrides.on_demand.no"), from: "variant-overrides-#{variant.id}-on_demand" fill_in "variant-overrides-#{variant.id}-count_on_hand", with: '8888' page.should have_content "Changes to one override remain unsaved." @@ -253,6 +256,7 @@ feature %q{ vo.variant_id.should == variant.id vo.hub_id.should == hub.id vo.price.should == 22.22 + expect(vo.on_demand).to eq(false) vo.count_on_hand.should == 8888 end @@ -341,27 +345,15 @@ feature %q{ end describe "ensuring that on demand and count on hand settings are compatible" do - it "changes to limited stock when count on hand is set" do - # It sets on_demand to false when count_on_hand is filled. - fill_in "variant-overrides-#{variant.id}-count_on_hand", with: "200" - expect(page).to have_select "variant-overrides-#{variant.id}-on_demand", selected: I18n.t("js.variant_overrides.on_demand.no") - - # It saves the changes. - click_button I18n.t("save_changes") - expect(page).to have_content I18n.t("js.changes_saved") - - vo.reload - expect(vo.count_on_hand).to eq(200) - expect(vo.on_demand).to eq(false) - end - it "clears count on hand when not limited stock" do # It clears count_on_hand when selecting true on_demand. + select I18n.t("js.variant_overrides.on_demand.no"), from: "variant-overrides-#{variant.id}-on_demand" fill_in "variant-overrides-#{variant.id}-count_on_hand", with: "200" select I18n.t("js.variant_overrides.on_demand.yes"), from: "variant-overrides-#{variant.id}-on_demand" expect(page).to have_input "variant-overrides-#{variant.id}-count_on_hand", with: "" # It clears count_on_hand when selecting nil on_demand. + select I18n.t("js.variant_overrides.on_demand.no"), from: "variant-overrides-#{variant.id}-on_demand" fill_in "variant-overrides-#{variant.id}-count_on_hand", with: "200" select I18n.t("admin.variant_overrides.products_variants.on_demand.use_producer_settings"), from: "variant-overrides-#{variant.id}-on_demand" expect(page).to have_input "variant-overrides-#{variant.id}-count_on_hand", with: "" diff --git a/spec/javascripts/unit/admin/controllers/variant_overrides_controller_spec.js.coffee b/spec/javascripts/unit/admin/controllers/variant_overrides_controller_spec.js.coffee index 1ac20b4318..203e3bc9ce 100644 --- a/spec/javascripts/unit/admin/controllers/variant_overrides_controller_spec.js.coffee +++ b/spec/javascripts/unit/admin/controllers/variant_overrides_controller_spec.js.coffee @@ -89,36 +89,6 @@ describe "VariantOverridesCtrl", -> expect(StatusMessage.display).toHaveBeenCalledWith 'success', 'Stocks reset to defaults.' describe "ensuring that on demand and count on hand settings are compatible", -> - describe "changing to limited stock when count on hand is set", -> - beforeEach -> - scope.variantOverrides = {123: {2: {id: 5, on_demand: true}}} - - describe "when count on hand is set", -> - beforeEach -> - scope.variantOverrides[123][2].count_on_hand = 1 - - it "changes to limited stock and registers dirty attribute", -> - scope.selectLimitedStockIfCountOnHandSet(123, 2) - expect(scope.variantOverrides[123][2].on_demand).toBe(false) - dirtyVariantOverride = DirtyVariantOverrides.dirtyVariantOverrides[123][2] - expect(dirtyVariantOverride.on_demand).toBe(false) - - describe "when count on hand is null", -> - beforeEach -> - scope.variantOverrides[123][2].count_on_hand = null - - it "does not change to limited stock", -> - scope.selectLimitedStockIfCountOnHandSet(123, 2) - expect(scope.variantOverrides[123][2].on_demand).toBe(true) - - describe "when count on hand is blank string", -> - beforeEach -> - scope.variantOverrides[123][2].count_on_hand = '' - - it "does not change to limited stock", -> - scope.selectLimitedStockIfCountOnHandSet(123, 2) - expect(scope.variantOverrides[123][2].on_demand).toBe(true) - describe "clearing count on hand when not limited stock", -> beforeEach -> scope.variantOverrides = {123: {2: {id: 5, count_on_hand: 1}}} From f5dc03e118d99d8dfeac1b2572b6ea64b70e1276 Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Thu, 29 Nov 2018 04:36:06 +0800 Subject: [PATCH 06/60] Style disabled text fields in admin pages --- app/assets/stylesheets/admin/components/input.css.scss | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 app/assets/stylesheets/admin/components/input.css.scss diff --git a/app/assets/stylesheets/admin/components/input.css.scss b/app/assets/stylesheets/admin/components/input.css.scss new file mode 100644 index 0000000000..437e386161 --- /dev/null +++ b/app/assets/stylesheets/admin/components/input.css.scss @@ -0,0 +1,8 @@ +.container { + input { + &[readonly] { + background-color: $disabled-light; + cursor: default; + } + } +} From 4f2d96d763e70a1d886346776533eb73ce9b38c2 Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Thu, 29 Nov 2018 15:18:01 +0800 Subject: [PATCH 07/60] Use correct placeholders for VO count_on_hand --- .../variant_overrides_controller.js.coffee | 10 ++++ .../_products_variants.html.haml | 2 +- config/locales/en.yml | 3 ++ spec/features/admin/variant_overrides_spec.rb | 4 +- ...ariant_overrides_controller_spec.js.coffee | 48 +++++++++++++++++++ 5 files changed, 64 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/admin/variant_overrides/controllers/variant_overrides_controller.js.coffee b/app/assets/javascripts/admin/variant_overrides/controllers/variant_overrides_controller.js.coffee index 4294d88966..4788e367e5 100644 --- a/app/assets/javascripts/admin/variant_overrides/controllers/variant_overrides_controller.js.coffee +++ b/app/assets/javascripts/admin/variant_overrides/controllers/variant_overrides_controller.js.coffee @@ -110,6 +110,16 @@ angular.module("admin.variantOverrides").controller "AdminVariantOverridesCtrl", .error (data, status) -> $timeout -> StatusMessage.display 'failure', $scope.updateError(data, status) + $scope.countOnHandPlaceholder = (variant, hubId) -> + variantOverride = $scope.variantOverrides[hubId][variant.id] + + if variantOverride.on_demand + t('js.variants.on_demand.yes') + else if variantOverride.on_demand == false + '' + else + variant.on_hand + $scope.clearCountOnHandUnlessLimitedStock = (hubId, variantId) -> variantOverride = $scope.variantOverrides[hubId][variantId] unless variantOverride.on_demand == false && variantOverride.count_on_hand? diff --git a/app/views/admin/variant_overrides/_products_variants.html.haml b/app/views/admin/variant_overrides/_products_variants.html.haml index d0e714e9fa..2c915fa0ae 100644 --- a/app/views/admin/variant_overrides/_products_variants.html.haml +++ b/app/views/admin/variant_overrides/_products_variants.html.haml @@ -8,7 +8,7 @@ %td.price{ ng: { show: 'columns.price.visible' } } %input{name: 'variant-overrides-{{ variant.id }}-price', type: 'text', ng: {model: 'variantOverrides[hub_id][variant.id].price'}, placeholder: '{{ variant.price }}', 'ofn-track-variant-override' => 'price'} %td.on_hand{ ng: { show: 'columns.on_hand.visible' } } - %input{name: 'variant-overrides-{{ variant.id }}-count_on_hand', type: 'text', ng: { model: 'variantOverrides[hub_id][variant.id].count_on_hand', readonly: 'variantOverrides[hub_id][variant.id].on_demand != false' }, placeholder: '{{ variant.on_hand }}', 'ofn-track-variant-override' => 'count_on_hand'} + %input{name: 'variant-overrides-{{ variant.id }}-count_on_hand', type: 'text', ng: { model: 'variantOverrides[hub_id][variant.id].count_on_hand', readonly: 'variantOverrides[hub_id][variant.id].on_demand != false' }, placeholder: '{{ countOnHandPlaceholder(variant, hub_id) }}', 'ofn-track-variant-override' => 'count_on_hand'} %td.on_demand{ ng: { show: 'columns.on_demand.visible' } } %select{ name: 'variant-overrides-{{ variant.id }}-on_demand', ng: { model: 'variantOverrides[hub_id][variant.id].on_demand', change: 'clearCountOnHandUnlessLimitedStock(hub_id, variant.id)', options: 'option.value as option.description for option in onDemandOptions' }, 'ofn-track-variant-override' => 'on_demand' } %option{ value: '' }= t(".on_demand.use_producer_settings") diff --git a/config/locales/en.yml b/config/locales/en.yml index 7738fed822..879f431452 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2595,6 +2595,9 @@ See the %{link} to find out more about %{sitename}'s features and to start using in your cart have reduced. Here's what's changed: now_out_of_stock: is now out of stock. only_n_remainging: "now only has %{num} remaining." + variants: + on_demand: + "yes": "On demand" variant_overrides: on_demand: "yes": "Yes" diff --git a/spec/features/admin/variant_overrides_spec.rb b/spec/features/admin/variant_overrides_spec.rb index e79e0293b9..120f5093cb 100644 --- a/spec/features/admin/variant_overrides_spec.rb +++ b/spec/features/admin/variant_overrides_spec.rb @@ -237,7 +237,7 @@ feature %q{ it "product values are affected by overrides" do page.should have_input "variant-overrides-#{variant.id}-price", with: '77.77', placeholder: '1.23' - page.should have_input "variant-overrides-#{variant.id}-count_on_hand", with: '11111', placeholder: '12' + page.should have_input "variant-overrides-#{variant.id}-count_on_hand", with: '11111', placeholder: I18n.t("js.variants.on_demand.yes") expect(page).to have_select "variant-overrides-#{variant.id}-on_demand", selected: I18n.t("js.variant_overrides.on_demand.yes") end @@ -325,7 +325,7 @@ feature %q{ first("div#bulk-actions-dropdown div.menu div.menu_item", text: "Reset Stock Levels To Defaults").click page.should have_content 'Stocks reset to defaults.' vo.reload - page.should have_input "variant-overrides-#{variant.id}-count_on_hand", with: '1000', placeholder: '12' + page.should have_input "variant-overrides-#{variant.id}-count_on_hand", with: '1000', placeholder: I18n.t("js.variants.on_demand.yes") vo.count_on_hand.should == 1000 end diff --git a/spec/javascripts/unit/admin/controllers/variant_overrides_controller_spec.js.coffee b/spec/javascripts/unit/admin/controllers/variant_overrides_controller_spec.js.coffee index 203e3bc9ce..e7e17648e8 100644 --- a/spec/javascripts/unit/admin/controllers/variant_overrides_controller_spec.js.coffee +++ b/spec/javascripts/unit/admin/controllers/variant_overrides_controller_spec.js.coffee @@ -120,3 +120,51 @@ describe "VariantOverridesCtrl", -> expect(scope.variantOverrides[123][2].count_on_hand).toBeNull() dirtyVariantOverride = DirtyVariantOverrides.dirtyVariantOverrides[123][2] expect(dirtyVariantOverride.count_on_hand).toBeNull() + + describe "count on hand placeholder", -> + beforeEach -> + scope.variantOverrides = {123: {}} + + describe "when variant is on demand", -> + variant = null + + beforeEach -> + # Ideally, count_on_hand is blank when the variant is on demand. However, this rule is not + # enforced. + variant = {id: 2, on_demand: true, count_on_hand: 20, on_hand: t("on_demand")} + + it "is 'On demand' when variant override uses producer stock settings", -> + scope.variantOverrides[123][2] = {on_demand: null, count_on_hand: 1} + placeholder = scope.countOnHandPlaceholder(variant, 123) + expect(placeholder).toBe(t("on_demand")) + + it "is 'On demand' when variant override is on demand", -> + scope.variantOverrides[123][2] = {on_demand: true, count_on_hand: 1} + placeholder = scope.countOnHandPlaceholder(variant, 123) + expect(placeholder).toBe(t("js.variants.on_demand.yes")) + + it "is blank when variant override is limited stock", -> + scope.variantOverrides[123][2] = {on_demand: false, count_on_hand: 1} + placeholder = scope.countOnHandPlaceholder(variant, 123) + expect(placeholder).toBe('') + + describe "when variant is limited stock", -> + variant = null + + beforeEach -> + variant = {id: 2, on_demand: false, count_on_hand: 20, on_hand: 20} + + it "is variant count on hand when variant override uses producer stock settings", -> + scope.variantOverrides[123][2] = {on_demand: null, count_on_hand: 1} + placeholder = scope.countOnHandPlaceholder(variant, 123) + expect(placeholder).toBe(20) + + it "is 'On demand' when variant override is on demand", -> + scope.variantOverrides[123][2] = {on_demand: true, count_on_hand: 1} + placeholder = scope.countOnHandPlaceholder(variant, 123) + expect(placeholder).toBe(t("js.variants.on_demand.yes")) + + it "is blank when variant override is limited stock", -> + scope.variantOverrides[123][2] = {on_demand: false, count_on_hand: 1} + placeholder = scope.countOnHandPlaceholder(variant, 123) + expect(placeholder).toBe('') From cff4eb0005e4e8a8707e7fb8dc74ed292a995ce7 Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Thu, 29 Nov 2018 16:33:34 +0800 Subject: [PATCH 08/60] Improve and simplify VO count on hand suggestions Set variant override count_on_hand in UI to variant count_on_hand value if on_demand is changed and both specify limited stock. --- .../variant_overrides_controller.js.coffee | 22 +++-- .../_products_variants.html.haml | 2 +- ...ariant_overrides_controller_spec.js.coffee | 81 +++++++++++++------ 3 files changed, 74 insertions(+), 31 deletions(-) diff --git a/app/assets/javascripts/admin/variant_overrides/controllers/variant_overrides_controller.js.coffee b/app/assets/javascripts/admin/variant_overrides/controllers/variant_overrides_controller.js.coffee index 4788e367e5..7779a9d602 100644 --- a/app/assets/javascripts/admin/variant_overrides/controllers/variant_overrides_controller.js.coffee +++ b/app/assets/javascripts/admin/variant_overrides/controllers/variant_overrides_controller.js.coffee @@ -120,8 +120,20 @@ angular.module("admin.variantOverrides").controller "AdminVariantOverridesCtrl", else variant.on_hand - $scope.clearCountOnHandUnlessLimitedStock = (hubId, variantId) -> - variantOverride = $scope.variantOverrides[hubId][variantId] - unless variantOverride.on_demand == false && variantOverride.count_on_hand? - variantOverride.count_on_hand = null - DirtyVariantOverrides.set hubId, variantId, variantOverride.id, 'count_on_hand', null + # This method should only be used when the variant override on_demand is changed. + # + # Change the count_on_hand value to a suggested value. + $scope.updateCountOnHand = (variant, hubId) -> + variantOverride = $scope.variantOverrides[hubId][variant.id] + + suggested = $scope.countOnHandSuggestion(variant, hubId) + unless suggested == variantOverride.count_on_hand + variantOverride.count_on_hand = suggested + DirtyVariantOverrides.set hubId, variant.id, variantOverride.id, 'count_on_hand', suggested + + # Suggest producer count_on_hand if variant has limited stock and variant override forces limited + # stock. Otherwise, clear whatever value is set. + $scope.countOnHandSuggestion = (variant, hubId) -> + variantOverride = $scope.variantOverrides[hubId][variant.id] + return null unless !variant.on_demand && variantOverride.on_demand == false + variant.on_hand diff --git a/app/views/admin/variant_overrides/_products_variants.html.haml b/app/views/admin/variant_overrides/_products_variants.html.haml index 2c915fa0ae..780590530f 100644 --- a/app/views/admin/variant_overrides/_products_variants.html.haml +++ b/app/views/admin/variant_overrides/_products_variants.html.haml @@ -10,7 +10,7 @@ %td.on_hand{ ng: { show: 'columns.on_hand.visible' } } %input{name: 'variant-overrides-{{ variant.id }}-count_on_hand', type: 'text', ng: { model: 'variantOverrides[hub_id][variant.id].count_on_hand', readonly: 'variantOverrides[hub_id][variant.id].on_demand != false' }, placeholder: '{{ countOnHandPlaceholder(variant, hub_id) }}', 'ofn-track-variant-override' => 'count_on_hand'} %td.on_demand{ ng: { show: 'columns.on_demand.visible' } } - %select{ name: 'variant-overrides-{{ variant.id }}-on_demand', ng: { model: 'variantOverrides[hub_id][variant.id].on_demand', change: 'clearCountOnHandUnlessLimitedStock(hub_id, variant.id)', options: 'option.value as option.description for option in onDemandOptions' }, 'ofn-track-variant-override' => 'on_demand' } + %select{ name: 'variant-overrides-{{ variant.id }}-on_demand', ng: { model: 'variantOverrides[hub_id][variant.id].on_demand', change: 'updateCountOnHand(variant, hub_id)', options: 'option.value as option.description for option in onDemandOptions' }, 'ofn-track-variant-override' => 'on_demand' } %option{ value: '' }= t(".on_demand.use_producer_settings") %td.reset{ ng: { show: 'columns.reset.visible' } } %input{name: 'variant-overrides-{{ variant.id }}-resettable', type: 'checkbox', ng: {model: 'variantOverrides[hub_id][variant.id].resettable'}, placeholder: '{{ variant.resettable }}', 'ofn-track-variant-override' => 'resettable'} diff --git a/spec/javascripts/unit/admin/controllers/variant_overrides_controller_spec.js.coffee b/spec/javascripts/unit/admin/controllers/variant_overrides_controller_spec.js.coffee index e7e17648e8..3ff397eb18 100644 --- a/spec/javascripts/unit/admin/controllers/variant_overrides_controller_spec.js.coffee +++ b/spec/javascripts/unit/admin/controllers/variant_overrides_controller_spec.js.coffee @@ -88,38 +88,69 @@ describe "VariantOverridesCtrl", -> expect(VariantOverrides.updateData).toHaveBeenCalledWith variant_overrides_mock expect(StatusMessage.display).toHaveBeenCalledWith 'success', 'Stocks reset to defaults.' - describe "ensuring that on demand and count on hand settings are compatible", -> - describe "clearing count on hand when not limited stock", -> + describe "suggesting count_on_hand when on_demand is changed", -> + variant = null + + beforeEach -> + scope.variantOverrides = {123: {}} + + describe "when variant is on demand", -> beforeEach -> - scope.variantOverrides = {123: {2: {id: 5, count_on_hand: 1}}} + # Ideally, count_on_hand is blank when the variant is on demand. However, this rule is not + # enforced. + variant = {id: 2, on_demand: true, count_on_hand: 20, on_hand: "On demand"} - describe "when on demand is false", -> - beforeEach -> - scope.variantOverrides[123][2].on_demand = false + it "clears count_on_hand when variant override uses producer stock settings", -> + scope.variantOverrides[123][2] = {on_demand: null, count_on_hand: 1} + scope.updateCountOnHand(variant, 123) - it "does not clear count on hand", -> - scope.clearCountOnHandUnlessLimitedStock(123, 2) - expect(scope.variantOverrides[123][2].count_on_hand).toEqual(1) + expect(scope.variantOverrides[123][2].count_on_hand).toBeNull() + dirtyVariantOverride = DirtyVariantOverrides.dirtyVariantOverrides[123][2] + expect(dirtyVariantOverride.count_on_hand).toBeNull() - describe "when on demand is true", -> - beforeEach -> - scope.variantOverrides[123][2].on_demand = true + it "clears count_on_hand when variant override forces on demand", -> + scope.variantOverrides[123][2] = {on_demand: true, count_on_hand: 1} + scope.updateCountOnHand(variant, 123) - it "clears count on hand and registers dirty attribute", -> - scope.clearCountOnHandUnlessLimitedStock(123, 2) - expect(scope.variantOverrides[123][2].count_on_hand).toBeNull() - dirtyVariantOverride = DirtyVariantOverrides.dirtyVariantOverrides[123][2] - expect(dirtyVariantOverride.count_on_hand).toBeNull() + expect(scope.variantOverrides[123][2].count_on_hand).toBeNull() + dirtyVariantOverride = DirtyVariantOverrides.dirtyVariantOverrides[123][2] + expect(dirtyVariantOverride.count_on_hand).toBeNull() - describe "when on demand is null", -> - beforeEach -> - scope.variantOverrides[123][2].on_demand = null + it "clears count_on_hand when variant override forces limited stock", -> + scope.variantOverrides[123][2] = {on_demand: false, count_on_hand: 1} + scope.updateCountOnHand(variant, 123) - it "clears count on hand and registers dirty attribute", -> - scope.clearCountOnHandUnlessLimitedStock(123, 2) - expect(scope.variantOverrides[123][2].count_on_hand).toBeNull() - dirtyVariantOverride = DirtyVariantOverrides.dirtyVariantOverrides[123][2] - expect(dirtyVariantOverride.count_on_hand).toBeNull() + expect(scope.variantOverrides[123][2].count_on_hand).toBeNull() + dirtyVariantOverride = DirtyVariantOverrides.dirtyVariantOverrides[123][2] + expect(dirtyVariantOverride.count_on_hand).toBeNull() + + describe "when variant has limited stock", -> + beforeEach -> + variant = {id: 2, on_demand: false, count_on_hand: 20, on_hand: 20} + + it "clears count_on_hand when variant override uses producer stock settings", -> + scope.variantOverrides[123][2] = {on_demand: null, count_on_hand: 1} + scope.updateCountOnHand(variant, 123) + + expect(scope.variantOverrides[123][2].count_on_hand).toBeNull() + dirtyVariantOverride = DirtyVariantOverrides.dirtyVariantOverrides[123][2] + expect(dirtyVariantOverride.count_on_hand).toBeNull() + + it "clears count_on_hand when variant override forces on demand", -> + scope.variantOverrides[123][2] = {on_demand: true, count_on_hand: 1} + scope.updateCountOnHand(variant, 123) + + expect(scope.variantOverrides[123][2].count_on_hand).toBeNull() + dirtyVariantOverride = DirtyVariantOverrides.dirtyVariantOverrides[123][2] + expect(dirtyVariantOverride.count_on_hand).toBeNull() + + it "sets to producer count_on_hand when variant override forces limited stock", -> + scope.variantOverrides[123][2] = {on_demand: false, count_on_hand: 1} + scope.updateCountOnHand(variant, 123) + + expect(scope.variantOverrides[123][2].count_on_hand).toBe(20) + dirtyVariantOverride = DirtyVariantOverrides.dirtyVariantOverrides[123][2] + expect(dirtyVariantOverride.count_on_hand).toBe(20) describe "count on hand placeholder", -> beforeEach -> From 34c34b94d1f2d6826adc71f92a716311bab3832d Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Fri, 30 Nov 2018 00:08:49 +0800 Subject: [PATCH 09/60] Describe method countOnHandPlaceholder for VOs --- .../controllers/variant_overrides_controller.js.coffee | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/assets/javascripts/admin/variant_overrides/controllers/variant_overrides_controller.js.coffee b/app/assets/javascripts/admin/variant_overrides/controllers/variant_overrides_controller.js.coffee index 7779a9d602..2727472b5a 100644 --- a/app/assets/javascripts/admin/variant_overrides/controllers/variant_overrides_controller.js.coffee +++ b/app/assets/javascripts/admin/variant_overrides/controllers/variant_overrides_controller.js.coffee @@ -110,6 +110,10 @@ angular.module("admin.variantOverrides").controller "AdminVariantOverridesCtrl", .error (data, status) -> $timeout -> StatusMessage.display 'failure', $scope.updateError(data, status) + # Variant override count_on_hand field placeholder logic: + # on_demand true -- Show "On Demand" + # on_demand false -- Show empty value to be set by the user + # on_demand nil -- Show producer on_hand value $scope.countOnHandPlaceholder = (variant, hubId) -> variantOverride = $scope.variantOverrides[hubId][variant.id] From 47d51ca525923b82dc8e1f229a76c7f3d3de1f50 Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Fri, 30 Nov 2018 00:13:52 +0800 Subject: [PATCH 10/60] Prefer guard clause in updateCountOnHand for VOs --- .../controllers/variant_overrides_controller.js.coffee | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/admin/variant_overrides/controllers/variant_overrides_controller.js.coffee b/app/assets/javascripts/admin/variant_overrides/controllers/variant_overrides_controller.js.coffee index 2727472b5a..933566a191 100644 --- a/app/assets/javascripts/admin/variant_overrides/controllers/variant_overrides_controller.js.coffee +++ b/app/assets/javascripts/admin/variant_overrides/controllers/variant_overrides_controller.js.coffee @@ -131,9 +131,9 @@ angular.module("admin.variantOverrides").controller "AdminVariantOverridesCtrl", variantOverride = $scope.variantOverrides[hubId][variant.id] suggested = $scope.countOnHandSuggestion(variant, hubId) - unless suggested == variantOverride.count_on_hand - variantOverride.count_on_hand = suggested - DirtyVariantOverrides.set hubId, variant.id, variantOverride.id, 'count_on_hand', suggested + return if suggested == variantOverride.count_on_hand + variantOverride.count_on_hand = suggested + DirtyVariantOverrides.set hubId, variant.id, variantOverride.id, 'count_on_hand', suggested # Suggest producer count_on_hand if variant has limited stock and variant override forces limited # stock. Otherwise, clear whatever value is set. From d8908bdf4b30d37dfeadb7f73b47eb2ecd316d14 Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Fri, 30 Nov 2018 00:15:46 +0800 Subject: [PATCH 11/60] Remove unused translation keys js.yes and js.no --- config/locales/en.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index 879f431452..69b55c9125 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2448,8 +2448,6 @@ See the %{link} to find out more about %{sitename}'s features and to start using pending: Pending shipped: Shipped js: - "yes": "Yes" - "no": "No" saving: 'Saving...' changes_saved: 'Changes saved.' save_changes_first: Save changes first. From 802e3bb447599f4c746ec7ab1b0759943d7916c8 Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Fri, 30 Nov 2018 17:40:00 +0800 Subject: [PATCH 12/60] Refactor choosing VO on_demand in feature specs We are still using the Rails view I18n scope for :use_producer_settings. Angular requires this replacement of the default blank option, which we use for nil on_demand, to be in the template itself. If we eventually move this template to a JS template, we can move it to the same I18n scope as the :yes and :no options. --- spec/features/admin/variant_overrides_spec.rb | 34 +++++++++++++------ 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/spec/features/admin/variant_overrides_spec.rb b/spec/features/admin/variant_overrides_spec.rb index 120f5093cb..4b89f87bfd 100644 --- a/spec/features/admin/variant_overrides_spec.rb +++ b/spec/features/admin/variant_overrides_spec.rb @@ -140,7 +140,7 @@ feature %q{ fill_in "variant-overrides-#{variant.id}-sku", with: 'NEWSKU' fill_in "variant-overrides-#{variant.id}-price", with: '777.77' - select I18n.t("js.variant_overrides.on_demand.no"), from: "variant-overrides-#{variant.id}-on_demand" + select_on_demand variant, :no fill_in "variant-overrides-#{variant.id}-count_on_hand", with: '123' page.should have_content "Changes to one override remain unsaved." @@ -162,7 +162,7 @@ feature %q{ it "updates the same override instead of creating a duplicate" do # When I create a new override fill_in "variant-overrides-#{variant.id}-price", with: '777.77' - select I18n.t("js.variant_overrides.on_demand.no"), from: "variant-overrides-#{variant.id}-on_demand" + select_on_demand variant, :no fill_in "variant-overrides-#{variant.id}-count_on_hand", with: '123' page.should have_content "Changes to one override remain unsaved." @@ -243,7 +243,7 @@ feature %q{ it "updates existing overrides" do fill_in "variant-overrides-#{variant.id}-price", with: '22.22' - select I18n.t("js.variant_overrides.on_demand.no"), from: "variant-overrides-#{variant.id}-on_demand" + select_on_demand variant, :no fill_in "variant-overrides-#{variant.id}-count_on_hand", with: '8888' page.should have_content "Changes to one override remain unsaved." @@ -261,21 +261,21 @@ feature %q{ end it "updates on_demand settings" do - select I18n.t("js.variant_overrides.on_demand.no"), from: "variant-overrides-#{variant.id}-on_demand" + select_on_demand variant, :no click_button I18n.t("save_changes") expect(page).to have_content I18n.t("js.changes_saved") vo.reload expect(vo.on_demand).to eq(false) - select I18n.t("js.variant_overrides.on_demand.yes"), from: "variant-overrides-#{variant.id}-on_demand" + select_on_demand variant, :yes click_button I18n.t("save_changes") expect(page).to have_content I18n.t("js.changes_saved") vo.reload expect(vo.on_demand).to eq(true) - select I18n.t("admin.variant_overrides.products_variants.on_demand.use_producer_settings"), from: "variant-overrides-#{variant.id}-on_demand" + select_on_demand variant, :use_producer_settings click_button I18n.t("save_changes") expect(page).to have_content I18n.t("js.changes_saved") @@ -299,7 +299,7 @@ feature %q{ # Clearing values manually fill_in "variant-overrides-#{variant.id}-price", with: '' fill_in "variant-overrides-#{variant.id}-count_on_hand", with: '' - select I18n.t("admin.variant_overrides.products_variants.on_demand.use_producer_settings"), from: "variant-overrides-#{variant.id}-on_demand" + select_on_demand variant, :use_producer_settings fill_in "variant-overrides-#{variant.id}-default_stock", with: '' within "tr#v_#{variant.id}" do vo.tag_list.each do |tag| @@ -347,15 +347,15 @@ feature %q{ describe "ensuring that on demand and count on hand settings are compatible" do it "clears count on hand when not limited stock" do # It clears count_on_hand when selecting true on_demand. - select I18n.t("js.variant_overrides.on_demand.no"), from: "variant-overrides-#{variant.id}-on_demand" + select_on_demand variant, :no fill_in "variant-overrides-#{variant.id}-count_on_hand", with: "200" - select I18n.t("js.variant_overrides.on_demand.yes"), from: "variant-overrides-#{variant.id}-on_demand" + select_on_demand variant, :yes expect(page).to have_input "variant-overrides-#{variant.id}-count_on_hand", with: "" # It clears count_on_hand when selecting nil on_demand. - select I18n.t("js.variant_overrides.on_demand.no"), from: "variant-overrides-#{variant.id}-on_demand" + select_on_demand variant, :no fill_in "variant-overrides-#{variant.id}-count_on_hand", with: "200" - select I18n.t("admin.variant_overrides.products_variants.on_demand.use_producer_settings"), from: "variant-overrides-#{variant.id}-on_demand" + select_on_demand variant, :use_producer_settings expect(page).to have_input "variant-overrides-#{variant.id}-count_on_hand", with: "" # It saves the changes. @@ -432,4 +432,16 @@ feature %q{ end end end + + def select_on_demand(variant, value_sym) + option_label = case value_sym + when :no + I18n.t("js.variant_overrides.on_demand.no") + when :yes + I18n.t("js.variant_overrides.on_demand.yes") + when :use_producer_settings + I18n.t("admin.variant_overrides.products_variants.on_demand.use_producer_settings") + end + select option_label, from: "variant-overrides-#{variant.id}-on_demand" + end end From 842a8e365478e41440d643b17975ca16f5e12825 Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Wed, 5 Dec 2018 16:39:29 +0800 Subject: [PATCH 13/60] Move null option for VO use_producer_settings to JS --- .../controllers/variant_overrides_controller.js.coffee | 1 + .../admin/variant_overrides/_products_variants.html.haml | 1 - config/locales/en.yml | 4 +--- spec/features/admin/variant_overrides_spec.rb | 9 +-------- 4 files changed, 3 insertions(+), 12 deletions(-) diff --git a/app/assets/javascripts/admin/variant_overrides/controllers/variant_overrides_controller.js.coffee b/app/assets/javascripts/admin/variant_overrides/controllers/variant_overrides_controller.js.coffee index 933566a191..6b7cea8243 100644 --- a/app/assets/javascripts/admin/variant_overrides/controllers/variant_overrides_controller.js.coffee +++ b/app/assets/javascripts/admin/variant_overrides/controllers/variant_overrides_controller.js.coffee @@ -14,6 +14,7 @@ angular.module("admin.variantOverrides").controller "AdminVariantOverridesCtrl", $scope.selectView = Views.selectView $scope.currentView = -> Views.currentView $scope.onDemandOptions = [ + { description: t('js.variant_overrides.on_demand.use_producer_settings'), value: null }, { description: t('js.variant_overrides.on_demand.yes'), value: true }, { description: t('js.variant_overrides.on_demand.no'), value: false } ] diff --git a/app/views/admin/variant_overrides/_products_variants.html.haml b/app/views/admin/variant_overrides/_products_variants.html.haml index 780590530f..27de58fdec 100644 --- a/app/views/admin/variant_overrides/_products_variants.html.haml +++ b/app/views/admin/variant_overrides/_products_variants.html.haml @@ -11,7 +11,6 @@ %input{name: 'variant-overrides-{{ variant.id }}-count_on_hand', type: 'text', ng: { model: 'variantOverrides[hub_id][variant.id].count_on_hand', readonly: 'variantOverrides[hub_id][variant.id].on_demand != false' }, placeholder: '{{ countOnHandPlaceholder(variant, hub_id) }}', 'ofn-track-variant-override' => 'count_on_hand'} %td.on_demand{ ng: { show: 'columns.on_demand.visible' } } %select{ name: 'variant-overrides-{{ variant.id }}-on_demand', ng: { model: 'variantOverrides[hub_id][variant.id].on_demand', change: 'updateCountOnHand(variant, hub_id)', options: 'option.value as option.description for option in onDemandOptions' }, 'ofn-track-variant-override' => 'on_demand' } - %option{ value: '' }= t(".on_demand.use_producer_settings") %td.reset{ ng: { show: 'columns.reset.visible' } } %input{name: 'variant-overrides-{{ variant.id }}-resettable', type: 'checkbox', ng: {model: 'variantOverrides[hub_id][variant.id].resettable'}, placeholder: '{{ variant.resettable }}', 'ofn-track-variant-override' => 'resettable'} %td.reset{ ng: { show: 'columns.reset.visible' } } diff --git a/config/locales/en.yml b/config/locales/en.yml index 69b55c9125..1b04166115 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -623,9 +623,6 @@ en: new_powertip: These products are available to be added to your inventory. Click 'Add' to add a product to your inventory, or 'Hide' to hide it from view. You can always change your mind later! controls: back_to_my_inventory: Back to my inventory - products_variants: - on_demand: - use_producer_settings: "Use producer stock settings" orders: invoice_email_sent: 'Invoice email has been sent' order_email_resent: 'Order email has been resent' @@ -2598,6 +2595,7 @@ See the %{link} to find out more about %{sitename}'s features and to start using "yes": "On demand" variant_overrides: on_demand: + use_producer_settings: "Use producer stock settings" "yes": "Yes" "no": "No" inventory_products: "Inventory Products" diff --git a/spec/features/admin/variant_overrides_spec.rb b/spec/features/admin/variant_overrides_spec.rb index 4b89f87bfd..0e2476fdba 100644 --- a/spec/features/admin/variant_overrides_spec.rb +++ b/spec/features/admin/variant_overrides_spec.rb @@ -434,14 +434,7 @@ feature %q{ end def select_on_demand(variant, value_sym) - option_label = case value_sym - when :no - I18n.t("js.variant_overrides.on_demand.no") - when :yes - I18n.t("js.variant_overrides.on_demand.yes") - when :use_producer_settings - I18n.t("admin.variant_overrides.products_variants.on_demand.use_producer_settings") - end + option_label = I18n.t(value_sym, scope: "js.variant_overrides.on_demand") select option_label, from: "variant-overrides-#{variant.id}-on_demand" end end From 71db9f5289d33083827537defeeea793406e2942 Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Thu, 6 Dec 2018 14:03:20 +0800 Subject: [PATCH 14/60] Import CSS variables in admin/components/input --- app/assets/stylesheets/admin/components/input.css.scss | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/assets/stylesheets/admin/components/input.css.scss b/app/assets/stylesheets/admin/components/input.css.scss index 437e386161..5b4cf8ed05 100644 --- a/app/assets/stylesheets/admin/components/input.css.scss +++ b/app/assets/stylesheets/admin/components/input.css.scss @@ -1,3 +1,5 @@ +@import '../../darkswarm/branding'; + .container { input { &[readonly] { From feea499298c68cde233da372d0350db664172430 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Thu, 6 Dec 2018 11:36:21 +0000 Subject: [PATCH 15/60] Make all mailers use appropriate locale when sending emails --- app/helpers/i18n_helper.rb | 16 ++++++- app/mailers/enterprise_mailer.rb | 26 ++++++----- app/mailers/producer_mailer.rb | 7 +-- app/mailers/spree/order_mailer_decorator.rb | 49 ++++++++++++--------- app/mailers/spree/user_mailer_decorator.rb | 18 +++++--- app/mailers/subscription_mailer.rb | 13 +++--- 6 files changed, 83 insertions(+), 46 deletions(-) diff --git a/app/helpers/i18n_helper.rb b/app/helpers/i18n_helper.rb index 4c93bdc0bc..6ed767d675 100644 --- a/app/helpers/i18n_helper.rb +++ b/app/helpers/i18n_helper.rb @@ -1,7 +1,7 @@ module I18nHelper def set_locale # Save a given locale - if params[:locale] && Rails.application.config.i18n.available_locales.include?(params[:locale]) + if params[:locale] && available_locale?(params[:locale]) spree_current_user.update_attributes!(locale: params[:locale]) if spree_current_user cookies[:locale] = params[:locale] end @@ -13,4 +13,18 @@ module I18nHelper I18n.locale = spree_current_user.andand.locale || cookies[:locale] || I18n.default_locale end + + def valid_locale(locale) + if available_locale?(locale) + locale + else + I18n.default_locale + end + end + + private + + def available_locale?(locale) + Rails.application.config.i18n.available_locales.include?(locale) + end end diff --git a/app/mailers/enterprise_mailer.rb b/app/mailers/enterprise_mailer.rb index 03d9279c93..f8ddbe970e 100644 --- a/app/mailers/enterprise_mailer.rb +++ b/app/mailers/enterprise_mailer.rb @@ -1,15 +1,18 @@ require 'devise/mailers/helpers' class EnterpriseMailer < Spree::BaseMailer include Devise::Mailers::Helpers + include I18nHelper def welcome(enterprise) @enterprise = enterprise - subject = t('enterprise_mailer.welcome.subject', - enterprise: @enterprise.name, - sitename: Spree::Config[:site_name]) - mail(:to => enterprise.contact.email, - :from => from_address, - :subject => subject) + I18n.with_locale valid_locale(@enterprise.owner.locale) do + subject = t('enterprise_mailer.welcome.subject', + enterprise: @enterprise.name, + sitename: Spree::Config[:site_name]) + mail(:to => enterprise.contact.email, + :from => from_address, + :subject => subject) + end end def manager_invitation(enterprise, user) @@ -17,11 +20,12 @@ class EnterpriseMailer < Spree::BaseMailer @instance = Spree::Config[:site_name] @instance_email = from_address - subject = t('enterprise_mailer.invite_manager.subject', enterprise: @enterprise.name) - - mail(to: user.email, - from: from_address, - subject: subject) + I18n.with_locale valid_locale(@enterprise.owner.locale) do + subject = t('enterprise_mailer.invite_manager.subject', enterprise: @enterprise.name) + mail(to: user.email, + from: from_address, + subject: subject) + end end private diff --git a/app/mailers/producer_mailer.rb b/app/mailers/producer_mailer.rb index ad7569dad2..32338c1379 100644 --- a/app/mailers/producer_mailer.rb +++ b/app/mailers/producer_mailer.rb @@ -1,4 +1,5 @@ class ProducerMailer < Spree::BaseMailer + include I18nHelper def order_cycle_report(producer, order_cycle) @producer = producer @@ -10,9 +11,10 @@ class ProducerMailer < Spree::BaseMailer @total = total_from_line_items(line_items) @tax_total = tax_total_from_line_items(line_items) - subject = "[#{Spree::Config.site_name}] #{I18n.t('producer_mailer.order_cycle.subject', producer: producer.name)}" + I18n.with_locale valid_locale(@producer.owner.locale) do + subject = "[#{Spree::Config.site_name}] #{I18n.t('producer_mailer.order_cycle.subject', producer: producer.name)}" - if has_orders?(order_cycle, producer) + return unless has_orders?(order_cycle, producer) mail( to: @producer.contact.email, from: from_address, @@ -23,7 +25,6 @@ class ProducerMailer < Spree::BaseMailer end end - private def has_orders?(order_cycle, producer) diff --git a/app/mailers/spree/order_mailer_decorator.rb b/app/mailers/spree/order_mailer_decorator.rb index a4b2db8b70..25ea4a51da 100644 --- a/app/mailers/spree/order_mailer_decorator.rb +++ b/app/mailers/spree/order_mailer_decorator.rb @@ -2,41 +2,50 @@ Spree::OrderMailer.class_eval do helper HtmlHelper helper CheckoutHelper helper SpreeCurrencyHelper + include I18nHelper def cancel_email(order, resend = false) @order = find_order(order) - subject = (resend ? "[#{t(:resend).upcase}] " : '') - subject += "#{Spree::Config[:site_name]} #{t('order_mailer.cancel_email.subject')} ##{order.number}" - mail(to: order.email, from: from_address, subject: subject) + I18n.with_locale valid_locale(@order.user.locale) do + subject = (resend ? "[#{t(:resend).upcase}] " : '') + subject += "#{Spree::Config[:site_name]} #{t('order_mailer.cancel_email.subject')} ##{order.number}" + mail(to: order.email, from: from_address, subject: subject) + end end def confirm_email_for_customer(order, resend = false) find_order(order) # Finds an order instance from an id - subject = (resend ? "[#{t(:resend).upcase}] " : '') - subject += "#{Spree::Config[:site_name]} #{t('order_mailer.confirm_email.subject')} ##{@order.number}" - mail(:to => @order.email, - :from => from_address, - :subject => subject, - :reply_to => @order.distributor.contact.email) + I18n.with_locale valid_locale(@order.user.locale) do + subject = (resend ? "[#{t(:resend).upcase}] " : '') + subject += "#{Spree::Config[:site_name]} #{t('order_mailer.confirm_email.subject')} ##{@order.number}" + mail(:to => @order.email, + :from => from_address, + :subject => subject, + :reply_to => @order.distributor.contact.email) + end end def confirm_email_for_shop(order, resend = false) find_order(order) # Finds an order instance from an id - subject = (resend ? "[#{t(:resend).upcase}] " : '') - subject += "#{Spree::Config[:site_name]} #{t('order_mailer.confirm_email.subject')} ##{@order.number}" - mail(:to => @order.distributor.contact.email, - :from => from_address, - :subject => subject) + I18n.with_locale valid_locale(@order.user.locale) do + subject = (resend ? "[#{t(:resend).upcase}] " : '') + subject += "#{Spree::Config[:site_name]} #{t('order_mailer.confirm_email.subject')} ##{@order.number}" + mail(:to => @order.distributor.contact.email, + :from => from_address, + :subject => subject) + end end def invoice_email(order, pdf) find_order(order) # Finds an order instance from an id - attachments["invoice-#{@order.number}.pdf"] = pdf if pdf.present? - subject = "#{Spree::Config[:site_name]} #{t(:invoice)} ##{@order.number}" - mail(:to => @order.email, - :from => from_address, - :subject => subject, - :reply_to => @order.distributor.contact.email) + I18n.with_locale valid_locale(@order.user.locale) do + attachments["invoice-#{@order.number}.pdf"] = pdf if pdf.present? + subject = "#{Spree::Config[:site_name]} #{t(:invoice)} ##{@order.number}" + mail(:to => @order.email, + :from => from_address, + :subject => subject, + :reply_to => @order.distributor.contact.email) + end end def find_order(order) diff --git a/app/mailers/spree/user_mailer_decorator.rb b/app/mailers/spree/user_mailer_decorator.rb index dced31e7fd..7b7cb38122 100644 --- a/app/mailers/spree/user_mailer_decorator.rb +++ b/app/mailers/spree/user_mailer_decorator.rb @@ -1,8 +1,12 @@ Spree::UserMailer.class_eval do + include I18nHelper + def signup_confirmation(user) @user = user - mail(:to => user.email, :from => from_address, - :subject => t(:welcome_to) + Spree::Config[:site_name]) + I18n.with_locale valid_locale(@user.locale) do + mail(:to => user.email, :from => from_address, + :subject => t(:welcome_to) + Spree::Config[:site_name]) + end end # Overriding `Spree::UserMailer.confirmation_instructions` which is @@ -12,10 +16,12 @@ Spree::UserMailer.class_eval do @instance = Spree::Config[:site_name] @contact = ContentConfig.footer_email - subject = t('spree.user_mailer.confirmation_instructions.subject') - mail(to: confirmation_email_address, - from: from_address, - subject: subject) + I18n.with_locale valid_locale(@user.locale) do + subject = t('spree.user_mailer.confirmation_instructions.subject') + mail(to: confirmation_email_address, + from: from_address, + subject: subject) + end end private diff --git a/app/mailers/subscription_mailer.rb b/app/mailers/subscription_mailer.rb index 426d94f847..448783ceda 100644 --- a/app/mailers/subscription_mailer.rb +++ b/app/mailers/subscription_mailer.rb @@ -1,6 +1,7 @@ class SubscriptionMailer < Spree::BaseMailer helper CheckoutHelper helper ShopMailHelper + include I18nHelper def confirmation_email(order) @type = 'confirmation' @@ -46,10 +47,12 @@ class SubscriptionMailer < Spree::BaseMailer private def send_mail(order) - subject = "#{Spree::Config[:site_name]} #{t('order_mailer.confirm_email.subject')} ##{order.number}" - mail(to: order.email, - from: from_address, - subject: subject, - reply_to: order.distributor.contact.email) + I18n.with_locale valid_locale(order.user.locale) do + subject = "#{Spree::Config[:site_name]} #{t('order_mailer.confirm_email.subject')} ##{order.number}" + mail(to: order.email, + from: from_address, + subject: subject, + reply_to: order.distributor.contact.email) + end end end From 0f442a911e1c06c93d4b00cb2a1c7ad7f9c34b7c Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Thu, 6 Dec 2018 12:48:48 +0000 Subject: [PATCH 16/60] Improve I18nHelper.valid_locale to handle empty objects --- app/helpers/i18n_helper.rb | 6 +++--- app/mailers/enterprise_mailer.rb | 4 ++-- app/mailers/producer_mailer.rb | 2 +- app/mailers/spree/order_mailer_decorator.rb | 8 ++++---- app/mailers/spree/user_mailer_decorator.rb | 4 ++-- app/mailers/subscription_mailer.rb | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/helpers/i18n_helper.rb b/app/helpers/i18n_helper.rb index 6ed767d675..f22f5b0f54 100644 --- a/app/helpers/i18n_helper.rb +++ b/app/helpers/i18n_helper.rb @@ -14,9 +14,9 @@ module I18nHelper I18n.locale = spree_current_user.andand.locale || cookies[:locale] || I18n.default_locale end - def valid_locale(locale) - if available_locale?(locale) - locale + def valid_locale(object_with_locale) + if object_with_locale.present? && object_with_locale.locale.present? && available_locale?(object_with_locale.locale) + object_with_locale.locale else I18n.default_locale end diff --git a/app/mailers/enterprise_mailer.rb b/app/mailers/enterprise_mailer.rb index f8ddbe970e..36a1b071a9 100644 --- a/app/mailers/enterprise_mailer.rb +++ b/app/mailers/enterprise_mailer.rb @@ -5,7 +5,7 @@ class EnterpriseMailer < Spree::BaseMailer def welcome(enterprise) @enterprise = enterprise - I18n.with_locale valid_locale(@enterprise.owner.locale) do + I18n.with_locale valid_locale(@enterprise.owner) do subject = t('enterprise_mailer.welcome.subject', enterprise: @enterprise.name, sitename: Spree::Config[:site_name]) @@ -20,7 +20,7 @@ class EnterpriseMailer < Spree::BaseMailer @instance = Spree::Config[:site_name] @instance_email = from_address - I18n.with_locale valid_locale(@enterprise.owner.locale) do + I18n.with_locale valid_locale(@enterprise.owner) do subject = t('enterprise_mailer.invite_manager.subject', enterprise: @enterprise.name) mail(to: user.email, from: from_address, diff --git a/app/mailers/producer_mailer.rb b/app/mailers/producer_mailer.rb index 32338c1379..a41ec0e0d1 100644 --- a/app/mailers/producer_mailer.rb +++ b/app/mailers/producer_mailer.rb @@ -11,7 +11,7 @@ class ProducerMailer < Spree::BaseMailer @total = total_from_line_items(line_items) @tax_total = tax_total_from_line_items(line_items) - I18n.with_locale valid_locale(@producer.owner.locale) do + I18n.with_locale valid_locale(@producer.owner) do subject = "[#{Spree::Config.site_name}] #{I18n.t('producer_mailer.order_cycle.subject', producer: producer.name)}" return unless has_orders?(order_cycle, producer) diff --git a/app/mailers/spree/order_mailer_decorator.rb b/app/mailers/spree/order_mailer_decorator.rb index 25ea4a51da..c4bedc932a 100644 --- a/app/mailers/spree/order_mailer_decorator.rb +++ b/app/mailers/spree/order_mailer_decorator.rb @@ -6,7 +6,7 @@ Spree::OrderMailer.class_eval do def cancel_email(order, resend = false) @order = find_order(order) - I18n.with_locale valid_locale(@order.user.locale) do + I18n.with_locale valid_locale(@order.user) do subject = (resend ? "[#{t(:resend).upcase}] " : '') subject += "#{Spree::Config[:site_name]} #{t('order_mailer.cancel_email.subject')} ##{order.number}" mail(to: order.email, from: from_address, subject: subject) @@ -15,7 +15,7 @@ Spree::OrderMailer.class_eval do def confirm_email_for_customer(order, resend = false) find_order(order) # Finds an order instance from an id - I18n.with_locale valid_locale(@order.user.locale) do + I18n.with_locale valid_locale(@order.user) do subject = (resend ? "[#{t(:resend).upcase}] " : '') subject += "#{Spree::Config[:site_name]} #{t('order_mailer.confirm_email.subject')} ##{@order.number}" mail(:to => @order.email, @@ -27,7 +27,7 @@ Spree::OrderMailer.class_eval do def confirm_email_for_shop(order, resend = false) find_order(order) # Finds an order instance from an id - I18n.with_locale valid_locale(@order.user.locale) do + I18n.with_locale valid_locale(@order.user) do subject = (resend ? "[#{t(:resend).upcase}] " : '') subject += "#{Spree::Config[:site_name]} #{t('order_mailer.confirm_email.subject')} ##{@order.number}" mail(:to => @order.distributor.contact.email, @@ -38,7 +38,7 @@ Spree::OrderMailer.class_eval do def invoice_email(order, pdf) find_order(order) # Finds an order instance from an id - I18n.with_locale valid_locale(@order.user.locale) do + I18n.with_locale valid_locale(@order.user) do attachments["invoice-#{@order.number}.pdf"] = pdf if pdf.present? subject = "#{Spree::Config[:site_name]} #{t(:invoice)} ##{@order.number}" mail(:to => @order.email, diff --git a/app/mailers/spree/user_mailer_decorator.rb b/app/mailers/spree/user_mailer_decorator.rb index 7b7cb38122..f9e618e348 100644 --- a/app/mailers/spree/user_mailer_decorator.rb +++ b/app/mailers/spree/user_mailer_decorator.rb @@ -3,7 +3,7 @@ Spree::UserMailer.class_eval do def signup_confirmation(user) @user = user - I18n.with_locale valid_locale(@user.locale) do + I18n.with_locale valid_locale(@user) do mail(:to => user.email, :from => from_address, :subject => t(:welcome_to) + Spree::Config[:site_name]) end @@ -16,7 +16,7 @@ Spree::UserMailer.class_eval do @instance = Spree::Config[:site_name] @contact = ContentConfig.footer_email - I18n.with_locale valid_locale(@user.locale) do + I18n.with_locale valid_locale(@user) do subject = t('spree.user_mailer.confirmation_instructions.subject') mail(to: confirmation_email_address, from: from_address, diff --git a/app/mailers/subscription_mailer.rb b/app/mailers/subscription_mailer.rb index 448783ceda..bd2a1fcb21 100644 --- a/app/mailers/subscription_mailer.rb +++ b/app/mailers/subscription_mailer.rb @@ -47,7 +47,7 @@ class SubscriptionMailer < Spree::BaseMailer private def send_mail(order) - I18n.with_locale valid_locale(order.user.locale) do + I18n.with_locale valid_locale(order.user) do subject = "#{Spree::Config[:site_name]} #{t('order_mailer.confirm_email.subject')} ##{order.number}" mail(to: order.email, from: from_address, From b9b91231ae176d68ecd42815543f3e55a482c5a4 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Thu, 6 Dec 2018 13:23:06 +0000 Subject: [PATCH 17/60] Fix rubocop issues in mailers --- app/helpers/i18n_helper.rb | 4 +- app/mailers/producer_mailer.rb | 3 +- app/mailers/spree/order_mailer_decorator.rb | 46 ++++++++++++--------- app/mailers/subscription_mailer.rb | 3 +- 4 files changed, 33 insertions(+), 23 deletions(-) diff --git a/app/helpers/i18n_helper.rb b/app/helpers/i18n_helper.rb index f22f5b0f54..215028e5aa 100644 --- a/app/helpers/i18n_helper.rb +++ b/app/helpers/i18n_helper.rb @@ -15,7 +15,9 @@ module I18nHelper end def valid_locale(object_with_locale) - if object_with_locale.present? && object_with_locale.locale.present? && available_locale?(object_with_locale.locale) + if object_with_locale.present? && + object_with_locale.locale.present? && + available_locale?(object_with_locale.locale) object_with_locale.locale else I18n.default_locale diff --git a/app/mailers/producer_mailer.rb b/app/mailers/producer_mailer.rb index a41ec0e0d1..058d5403ba 100644 --- a/app/mailers/producer_mailer.rb +++ b/app/mailers/producer_mailer.rb @@ -12,7 +12,8 @@ class ProducerMailer < Spree::BaseMailer @tax_total = tax_total_from_line_items(line_items) I18n.with_locale valid_locale(@producer.owner) do - subject = "[#{Spree::Config.site_name}] #{I18n.t('producer_mailer.order_cycle.subject', producer: producer.name)}" + order_cycle_subject = I18n.t('producer_mailer.order_cycle.subject', producer: producer.name) + subject = "[#{Spree::Config.site_name}] #{order_cycle_subject}" return unless has_orders?(order_cycle, producer) mail( diff --git a/app/mailers/spree/order_mailer_decorator.rb b/app/mailers/spree/order_mailer_decorator.rb index c4bedc932a..7d2cce4609 100644 --- a/app/mailers/spree/order_mailer_decorator.rb +++ b/app/mailers/spree/order_mailer_decorator.rb @@ -7,48 +7,54 @@ Spree::OrderMailer.class_eval do def cancel_email(order, resend = false) @order = find_order(order) I18n.with_locale valid_locale(@order.user) do - subject = (resend ? "[#{t(:resend).upcase}] " : '') - subject += "#{Spree::Config[:site_name]} #{t('order_mailer.cancel_email.subject')} ##{order.number}" - mail(to: order.email, from: from_address, subject: subject) + mail(to: order.email, + from: from_address, + subject: mail_subject(t('order_mailer.cancel_email.subject'), resend)) end end def confirm_email_for_customer(order, resend = false) find_order(order) # Finds an order instance from an id I18n.with_locale valid_locale(@order.user) do - subject = (resend ? "[#{t(:resend).upcase}] " : '') - subject += "#{Spree::Config[:site_name]} #{t('order_mailer.confirm_email.subject')} ##{@order.number}" - mail(:to => @order.email, - :from => from_address, - :subject => subject, - :reply_to => @order.distributor.contact.email) + mail(to: @order.email, + from: from_address, + subject: mail_subject(t('order_mailer.confirm_email.subject'), resend), + reply_to: @order.distributor.contact.email) end end def confirm_email_for_shop(order, resend = false) find_order(order) # Finds an order instance from an id I18n.with_locale valid_locale(@order.user) do - subject = (resend ? "[#{t(:resend).upcase}] " : '') - subject += "#{Spree::Config[:site_name]} #{t('order_mailer.confirm_email.subject')} ##{@order.number}" - mail(:to => @order.distributor.contact.email, - :from => from_address, - :subject => subject) + mail(to: @order.distributor.contact.email, + from: from_address, + subject: mail_subject(t('order_mailer.confirm_email.subject'), resend)) end end def invoice_email(order, pdf) find_order(order) # Finds an order instance from an id + attach_file("invoice-#{@order.number}.pdf", pdf) I18n.with_locale valid_locale(@order.user) do - attachments["invoice-#{@order.number}.pdf"] = pdf if pdf.present? - subject = "#{Spree::Config[:site_name]} #{t(:invoice)} ##{@order.number}" - mail(:to => @order.email, - :from => from_address, - :subject => subject, - :reply_to => @order.distributor.contact.email) + mail(to: @order.email, + from: from_address, + subject: mail_subject(t(:invoice), false), + reply_to: @order.distributor.contact.email) end end def find_order(order) @order = order.respond_to?(:id) ? order : Spree::Order.find(order) end + + private + + def mail_subject(base_subject, resend) + resend_prefix = (resend ? "[#{t(:resend).upcase}] " : '') + "#{resend_prefix}#{Spree::Config[:site_name]} #{base_subject} ##{@order.number}" + end + + def attach_file(filename, file) + attachments[filename] = file if file.present? + end end diff --git a/app/mailers/subscription_mailer.rb b/app/mailers/subscription_mailer.rb index bd2a1fcb21..0046155499 100644 --- a/app/mailers/subscription_mailer.rb +++ b/app/mailers/subscription_mailer.rb @@ -48,7 +48,8 @@ class SubscriptionMailer < Spree::BaseMailer def send_mail(order) I18n.with_locale valid_locale(order.user) do - subject = "#{Spree::Config[:site_name]} #{t('order_mailer.confirm_email.subject')} ##{order.number}" + confirm_email_subject = t('order_mailer.confirm_email.subject') + subject = "#{Spree::Config[:site_name]} #{confirm_email_subject} ##{order.number}" mail(to: order.email, from: from_address, subject: subject, From 83b6973bc2b5ea6f3a222b6705f176699753085d Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Thu, 29 Nov 2018 17:10:35 +0800 Subject: [PATCH 18/60] Require compatible VO on_demand and count_on_hand --- app/models/variant_override.rb | 36 ++++++++++++ config/locales/en.yml | 5 ++ spec/models/variant_override_spec.rb | 86 ++++++++++++++++++++++++++-- 3 files changed, 123 insertions(+), 4 deletions(-) diff --git a/app/models/variant_override.rb b/app/models/variant_override.rb index 89d2fdcd13..d28bb2771f 100644 --- a/app/models/variant_override.rb +++ b/app/models/variant_override.rb @@ -10,6 +10,8 @@ class VariantOverride < ActiveRecord::Base # Default stock can be nil, indicating stock should not be reset or zero, meaning reset to zero. Need to ensure this can be set by the user. validates :default_stock, numericality: { greater_than_or_equal_to: 0 }, allow_nil: true + before_validation :require_compatible_on_demand_and_count_on_hand + after_save :refresh_products_cache_from_save after_destroy :refresh_products_cache_from_destroy @@ -104,4 +106,38 @@ class VariantOverride < ActiveRecord::Base def refresh_products_cache_from_destroy OpenFoodNetwork::ProductsCache.variant_override_destroyed self end + + def require_compatible_on_demand_and_count_on_hand + disallow_count_on_hand_if_using_producer_stock_settings + disallow_count_on_hand_if_on_demand + require_count_on_hand_if_limited_stock + end + + def disallow_count_on_hand_if_using_producer_stock_settings + return unless on_demand.nil? && count_on_hand.present? + + error_message = I18n.t("using_producer_stock_settings_but_count_on_hand_set", + scope: [i18n_scope_for_error, "count_on_hand"]) + errors.add(:count_on_hand, error_message) + end + + def disallow_count_on_hand_if_on_demand + return unless on_demand? && count_on_hand.present? + + error_message = I18n.t("on_demand_but_count_on_hand_set", + scope: [i18n_scope_for_error, "count_on_hand"]) + errors.add(:count_on_hand, error_message) + end + + def require_count_on_hand_if_limited_stock + return unless on_demand == false && count_on_hand.blank? + + error_message = I18n.t("limited_stock_but_no_count_on_hand", + scope: [i18n_scope_for_error, "count_on_hand"]) + errors.add(:count_on_hand, error_message) + end + + def i18n_scope_for_error + "activerecord.errors.models.variant_override" + end end diff --git a/config/locales/en.yml b/config/locales/en.yml index 1b04166115..4962171a82 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -47,6 +47,11 @@ en: attributes: orders_close_at: after_orders_open_at: must be after open date + variant_override: + count_on_hand: + using_producer_stock_settings_but_count_on_hand_set: "must be blank because using producer stock settings" + on_demand_but_count_on_hand_set: "must be blank if on demand" + limited_stock_but_no_count_on_hand: "must be specified because forcing limited stock" activemodel: errors: models: diff --git a/spec/models/variant_override_spec.rb b/spec/models/variant_override_spec.rb index bb799f8603..258971e110 100644 --- a/spec/models/variant_override_spec.rb +++ b/spec/models/variant_override_spec.rb @@ -35,6 +35,81 @@ describe VariantOverride do end end + describe "validation" do + describe "ensuring that on_demand and count_on_hand are compatible" do + let(:variant_override) { build(:variant_override, hub: hub, variant: variant, + on_demand: on_demand, count_on_hand: count_on_hand) } + + context "when using producer stock settings" do + let(:on_demand) { nil } + + context "when count_on_hand is blank" do + let(:count_on_hand) { nil } + + it "is valid" do + expect(variant_override.save).to be_truthy + end + end + + context "when count_on_hand is set" do + let(:count_on_hand) { 1 } + + it "is invalid" do + expect(variant_override.save).to be_falsey + error_message = I18n.t("using_producer_stock_settings_but_count_on_hand_set", + scope: [i18n_scope_for_error, "count_on_hand"]) + expect(variant_override.errors[:count_on_hand]).to eq([error_message]) + end + end + end + + context "when on demand" do + let(:on_demand) { true } + + context "when count_on_hand is blank" do + let(:count_on_hand) { nil } + + it "is valid" do + expect(variant_override.save).to be_truthy + end + end + + context "when count_on_hand is set" do + let(:count_on_hand) { 1 } + + it "is invalid" do + expect(variant_override.save).to be_falsey + error_message = I18n.t("on_demand_but_count_on_hand_set", + scope: [i18n_scope_for_error, "count_on_hand"]) + expect(variant_override.errors[:count_on_hand]).to eq([error_message]) + end + end + end + + context "when limited stock" do + let(:on_demand) { false } + + context "when count_on_hand is blank" do + let(:count_on_hand) { nil } + + it "is invalid" do + expect(variant_override.save).to be_falsey + error_message = I18n.t("limited_stock_but_no_count_on_hand", + scope: [i18n_scope_for_error, "count_on_hand"]) + expect(variant_override.errors[:count_on_hand]).to eq([error_message]) + end + end + + context "when count_on_hand is set" do + let(:count_on_hand) { 1 } + + it "is valid" do + expect(variant_override.save).to be_truthy + end + end + end + end + end describe "callbacks" do let!(:vo) { create(:variant_override, hub: hub, variant: variant) } @@ -51,7 +126,6 @@ describe VariantOverride do end end - describe "looking up prices" do it "returns the numeric price when present" do VariantOverride.create!(variant: variant, hub: hub, price: 12.34) @@ -65,7 +139,7 @@ describe VariantOverride do describe "looking up count on hand" do it "returns the numeric stock level when present" do - VariantOverride.create!(variant: variant, hub: hub, count_on_hand: 12) + VariantOverride.create!(variant: variant, hub: hub, count_on_hand: 12, on_demand: false) VariantOverride.count_on_hand_for(hub, variant).should == 12 end @@ -76,12 +150,12 @@ describe VariantOverride do describe "checking if stock levels have been overriden" do it "returns true when stock level has been overridden" do - create(:variant_override, variant: variant, hub: hub, count_on_hand: 12) + create(:variant_override, variant: variant, hub: hub, on_demand: false, count_on_hand: 12) VariantOverride.stock_overridden?(hub, variant).should be true end it "returns false when the override has no stock level" do - create(:variant_override, variant: variant, hub: hub, count_on_hand: nil) + create(:variant_override, variant: variant, hub: hub, on_demand: nil, count_on_hand: nil) VariantOverride.stock_overridden?(hub, variant).should be false end @@ -157,4 +231,8 @@ describe VariantOverride do context "extends LocalizedNumber" do it_behaves_like "a model using the LocalizedNumber module", [:price] end + + def i18n_scope_for_error + "activerecord.errors.models.variant_override" + end end From 4c0c0bbfd09b259a42c02a2e18a98fbfe8fcdfa6 Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Thu, 29 Nov 2018 17:56:32 +0800 Subject: [PATCH 19/60] Simplify stock configuration in existing variant overrides --- ...nt_override_on_demand_and_count_on_hand.rb | 29 +++++++++++++++++++ db/schema.rb | 2 +- 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20181128054803_simplify_variant_override_on_demand_and_count_on_hand.rb diff --git a/db/migrate/20181128054803_simplify_variant_override_on_demand_and_count_on_hand.rb b/db/migrate/20181128054803_simplify_variant_override_on_demand_and_count_on_hand.rb new file mode 100644 index 0000000000..eeb5eb5e37 --- /dev/null +++ b/db/migrate/20181128054803_simplify_variant_override_on_demand_and_count_on_hand.rb @@ -0,0 +1,29 @@ +# This simplifies variant overrides to have only the following combinations: +# +# on_demand | count_on_hand +# -----------+--------------- +# true | nil +# false | set +# nil | nil +# +# Refer to the table {here}[https://github.com/openfoodfoundation/openfoodnetwork/issues/3067] for +# the effect of different variant and variant override stock configurations. +# +# Furthermore, this will allow all existing variant overrides to satisfy the newly added model +# validation rules. +class SimplifyVariantOverrideOnDemandAndCountOnHand < ActiveRecord::Migration + def up + # When on_demand is nil but count_on_hand is set, force limited stock. + VariantOverride.where(on_demand: nil).where("count_on_hand IS NOT NULL") + .update_all(on_demand: false) + + # Clear count_on_hand if forcing on demand. + VariantOverride.where(on_demand: true).update_all(count_on_hand: nil) + + # When on_demand is false but count on hand is not specified, set this to use producer stock + # settings. + VariantOverride.where(on_demand: false, count_on_hand: nil).update_all(on_demand: nil) + end + + def down; end +end diff --git a/db/schema.rb b/db/schema.rb index 7f3b49ca3c..8f067d9bb7 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 => 20181123012635) do +ActiveRecord::Schema.define(:version => 20181128054803) do create_table "account_invoices", :force => true do |t| t.integer "user_id", :null => false From 210a11783cecd3104b9cc1c2591405761ba36f56 Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Fri, 7 Dec 2018 15:34:03 +0800 Subject: [PATCH 20/60] Test that saving invalid variant override provides error --- spec/features/admin/variant_overrides_spec.rb | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/spec/features/admin/variant_overrides_spec.rb b/spec/features/admin/variant_overrides_spec.rb index 0e2476fdba..c218d6099b 100644 --- a/spec/features/admin/variant_overrides_spec.rb +++ b/spec/features/admin/variant_overrides_spec.rb @@ -365,6 +365,27 @@ feature %q{ expect(vo.count_on_hand).to be_nil expect(vo.on_demand).to be_nil end + + it "provides explanation when attempting to save variant override with incompatible stock settings" do + # Successfully change stock settings. + select_on_demand variant, :no + fill_in "variant-overrides-#{variant.id}-count_on_hand", with: "1111" + click_button I18n.t("save_changes") + expect(page).to have_content I18n.t("js.changes_saved") + + # Make stock settings incompatible. + select_on_demand variant, :no + fill_in "variant-overrides-#{variant.id}-count_on_hand", with: "" + + # It does not save the changes. + click_button I18n.t("save_changes") + expect(page).to have_content I18n.t("activerecord.errors.models.variant_override.count_on_hand.limited_stock_but_no_count_on_hand") + expect(page).to have_no_content I18n.t("js.changes_saved") + + vo.reload + expect(vo.count_on_hand).to eq(1111) + expect(vo.on_demand).to eq(false) + end end end end From ad35ea1102ffa613e9adb2c820324e4d5910e685 Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Sun, 9 Dec 2018 21:46:31 +0800 Subject: [PATCH 21/60] Add factory stock traits for variant overrides --- spec/factories.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/spec/factories.rb b/spec/factories.rb index 8751094d45..eee3cb553f 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -189,9 +189,20 @@ FactoryBot.define do factory :variant_override, :class => VariantOverride do price 77.77 + on_demand false count_on_hand 11111 default_stock 2000 resettable false + + trait :on_demand do + on_demand true + count_on_hand nil + end + + trait :use_producer_stock_settings do + on_demand nil + count_on_hand nil + end end factory :inventory_item, :class => InventoryItem do From 34313c94ca7a31ab000b50908593815c42637158 Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Sun, 9 Dec 2018 21:18:43 +0800 Subject: [PATCH 22/60] Make reset stock settings for VO force limited stock --- app/models/variant_override.rb | 2 +- spec/features/admin/variant_overrides_spec.rb | 4 +-- spec/models/variant_override_spec.rb | 33 ++++++++++++++++--- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/app/models/variant_override.rb b/app/models/variant_override.rb index d28bb2771f..5527f29af7 100644 --- a/app/models/variant_override.rb +++ b/app/models/variant_override.rb @@ -84,7 +84,7 @@ class VariantOverride < ActiveRecord::Base def reset_stock! if resettable if default_stock? - self.attributes = { count_on_hand: default_stock } + self.attributes = { on_demand: false, count_on_hand: default_stock } self.save else Bugsnag.notify RuntimeError.new "Attempting to reset stock level for a variant with no default stock level." diff --git a/spec/features/admin/variant_overrides_spec.rb b/spec/features/admin/variant_overrides_spec.rb index c218d6099b..c215abe933 100644 --- a/spec/features/admin/variant_overrides_spec.rb +++ b/spec/features/admin/variant_overrides_spec.rb @@ -325,7 +325,7 @@ feature %q{ first("div#bulk-actions-dropdown div.menu div.menu_item", text: "Reset Stock Levels To Defaults").click page.should have_content 'Stocks reset to defaults.' vo.reload - page.should have_input "variant-overrides-#{variant.id}-count_on_hand", with: '1000', placeholder: I18n.t("js.variants.on_demand.yes") + expect(page).to have_input "variant-overrides-#{variant.id}-count_on_hand", with: "1000", placeholder: "" vo.count_on_hand.should == 1000 end @@ -333,7 +333,7 @@ feature %q{ first("div#bulk-actions-dropdown").click first("div#bulk-actions-dropdown div.menu div.menu_item", text: "Reset Stock Levels To Defaults").click vo_no_reset.reload - page.should have_input "variant-overrides-#{variant2.id}-count_on_hand", with: '40', placeholder: '12' + expect(page).to have_input "variant-overrides-#{variant2.id}-count_on_hand", with: "40", placeholder: "" vo_no_reset.count_on_hand.should == 40 end diff --git a/spec/models/variant_override_spec.rb b/spec/models/variant_override_spec.rb index 258971e110..f785bf352c 100644 --- a/spec/models/variant_override_spec.rb +++ b/spec/models/variant_override_spec.rb @@ -210,17 +210,42 @@ describe VariantOverride do end describe "resetting stock levels" do - it "resets the on hand level to the value in the default_stock field" do - vo = create(:variant_override, variant: variant, hub: hub, count_on_hand: 12, default_stock: 20, resettable: true) - vo.reset_stock! - vo.reload.count_on_hand.should == 20 + describe "forcing the on hand level to the value in the default_stock field" do + it "succeeds for variant override that forces limited stock" do + vo = create(:variant_override, variant: variant, hub: hub, count_on_hand: 12, default_stock: 20, resettable: true) + vo.reset_stock! + + vo.reload + expect(vo.on_demand).to eq(false) + expect(vo.count_on_hand).to eq(20) + end + + it "succeeds for variant override that forces unlimited stock" do + vo = create(:variant_override, :on_demand, variant: variant, hub: hub, default_stock: 20, resettable: true) + vo.reset_stock! + + vo.reload + expect(vo.on_demand).to eq(false) + expect(vo.count_on_hand).to eq(20) + end + + it "succeeds for variant override that uses producer stock settings" do + vo = create(:variant_override, :use_producer_stock_settings, variant: variant, hub: hub, default_stock: 20, resettable: true) + vo.reset_stock! + + vo.reload + expect(vo.on_demand).to eq(false) + expect(vo.count_on_hand).to eq(20) + end end + it "silently logs an error if the variant override doesn't have a default stock level" do vo = create(:variant_override, variant: variant, hub: hub, count_on_hand: 12, default_stock:nil, resettable: true) Bugsnag.should_receive(:notify) vo.reset_stock! vo.reload.count_on_hand.should == 12 end + it "doesn't reset the level if the behaviour is disabled" do vo = create(:variant_override, variant: variant, hub: hub, count_on_hand: 12, default_stock: 10, resettable: false) vo.reset_stock! From d67b3faf015f3452114182bdce5625ebdb42d747 Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Fri, 7 Dec 2018 15:44:32 +0800 Subject: [PATCH 23/60] Address affected specs from new VO validations --- spec/features/admin/variant_overrides_spec.rb | 6 ++++-- spec/features/consumer/shopping/variant_overrides_spec.rb | 2 +- spec/lib/open_food_network/scope_variant_to_hub_spec.rb | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/spec/features/admin/variant_overrides_spec.rb b/spec/features/admin/variant_overrides_spec.rb index c215abe933..f2b0bb916b 100644 --- a/spec/features/admin/variant_overrides_spec.rb +++ b/spec/features/admin/variant_overrides_spec.rb @@ -220,7 +220,7 @@ feature %q{ end context "with overrides" do - let!(:vo) { create(:variant_override, variant: variant, hub: hub, price: 77.77, on_demand: true, count_on_hand: 11111, default_stock: 1000, resettable: true, tag_list: ["tag1","tag2","tag3"]) } + let!(:vo) { create(:variant_override, :on_demand, variant: variant, hub: hub, price: 77.77, default_stock: 1000, resettable: true, tag_list: ["tag1","tag2","tag3"]) } let!(:vo_no_auth) { create(:variant_override, variant: variant, hub: hub2, price: 1, count_on_hand: 2) } let!(:product2) { create(:simple_product, supplier: producer, variant_unit: 'weight', variant_unit_scale: 1) } let!(:variant2) { create(:variant, product: product2, unit_value: 8, price: 1.00, on_hand: 12) } @@ -237,8 +237,10 @@ feature %q{ it "product values are affected by overrides" do page.should have_input "variant-overrides-#{variant.id}-price", with: '77.77', placeholder: '1.23' - page.should have_input "variant-overrides-#{variant.id}-count_on_hand", with: '11111', placeholder: I18n.t("js.variants.on_demand.yes") + expect(page).to have_input "variant-overrides-#{variant.id}-count_on_hand", with: "", placeholder: I18n.t("js.variants.on_demand.yes") expect(page).to have_select "variant-overrides-#{variant.id}-on_demand", selected: I18n.t("js.variant_overrides.on_demand.yes") + + expect(page).to have_input "variant-overrides-#{variant2.id}-count_on_hand", with: "40", placeholder: "" end it "updates existing overrides" do diff --git a/spec/features/consumer/shopping/variant_overrides_spec.rb b/spec/features/consumer/shopping/variant_overrides_spec.rb index ff101fd5a0..6fb52c3e1f 100644 --- a/spec/features/consumer/shopping/variant_overrides_spec.rb +++ b/spec/features/consumer/shopping/variant_overrides_spec.rb @@ -22,7 +22,7 @@ feature "shopping with variant overrides defined", js: true, retry: 3 do let(:v4) { create(:variant, product: p1, price: 44.44, unit_value: 4) } let(:v5) { create(:variant, product: p3, price: 55.55, unit_value: 5, on_demand: true) } let(:v6) { create(:variant, product: p3, price: 66.66, unit_value: 6, on_demand: true) } - let!(:vo1) { create(:variant_override, hub: hub, variant: v1, price: 55.55, count_on_hand: nil, default_stock: nil, resettable: false) } + let!(:vo1) { create(:variant_override, :use_producer_stock_settings, hub: hub, variant: v1, price: 55.55, default_stock: nil, resettable: false) } let!(:vo2) { create(:variant_override, hub: hub, variant: v2, count_on_hand: 0, default_stock: nil, resettable: false) } let!(:vo3) { create(:variant_override, hub: hub, variant: v3, count_on_hand: 0, default_stock: nil, resettable: false) } let!(:vo4) { create(:variant_override, hub: hub, variant: v4, count_on_hand: 3, default_stock: nil, resettable: false) } diff --git a/spec/lib/open_food_network/scope_variant_to_hub_spec.rb b/spec/lib/open_food_network/scope_variant_to_hub_spec.rb index c3b2f2f8ec..aa5ce4b317 100644 --- a/spec/lib/open_food_network/scope_variant_to_hub_spec.rb +++ b/spec/lib/open_food_network/scope_variant_to_hub_spec.rb @@ -5,7 +5,7 @@ module OpenFoodNetwork let(:hub) { create(:distributor_enterprise) } let(:v) { create(:variant, price: 11.11, count_on_hand: 1, on_demand: true, sku: "VARIANTSKU") } let(:vo) { create(:variant_override, hub: hub, variant: v, price: 22.22, count_on_hand: 2, on_demand: false, sku: "VOSKU") } - let(:vo_price_only) { create(:variant_override, hub: hub, variant: v, price: 22.22, count_on_hand: nil) } + let(:vo_price_only) { create(:variant_override, :use_producer_stock_settings, hub: hub, variant: v, price: 22.22) } let(:scoper) { ScopeVariantToHub.new(hub) } describe "overriding price" do From 1bfdb708c1ea4bf13c5422730f5c6078a315661f Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Sun, 9 Dec 2018 23:22:46 +0800 Subject: [PATCH 24/60] Add app/models/concerns to autoload path --- config/application.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/config/application.rb b/config/application.rb index 14c0b82b86..f80c91aee1 100644 --- a/config/application.rb +++ b/config/application.rb @@ -88,6 +88,7 @@ module Openfoodnetwork # Custom directories with classes and modules you want to be autoloadable. config.autoload_paths += %W( + #{config.root}/app/models/concerns #{config.root}/app/presenters #{config.root}/app/jobs ) From c873a7b8e3e322fc4f1892ed3d8b274ae020febc Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Sun, 9 Dec 2018 23:23:29 +0800 Subject: [PATCH 25/60] Move stock settings override validation to concern --- .../stock_settings_override_validation.rb | 41 +++++++++++++++++++ app/models/variant_override.rb | 37 +---------------- 2 files changed, 42 insertions(+), 36 deletions(-) create mode 100644 app/models/concerns/stock_settings_override_validation.rb diff --git a/app/models/concerns/stock_settings_override_validation.rb b/app/models/concerns/stock_settings_override_validation.rb new file mode 100644 index 0000000000..b9e3624aec --- /dev/null +++ b/app/models/concerns/stock_settings_override_validation.rb @@ -0,0 +1,41 @@ +module StockSettingsOverrideValidation + extend ActiveSupport::Concern + + included do + before_validation :require_compatible_on_demand_and_count_on_hand + end + + def require_compatible_on_demand_and_count_on_hand + disallow_count_on_hand_if_using_producer_stock_settings + disallow_count_on_hand_if_on_demand + require_count_on_hand_if_limited_stock + end + + def disallow_count_on_hand_if_using_producer_stock_settings + return unless on_demand.nil? && count_on_hand.present? + + error_message = I18n.t("count_on_hand.using_producer_stock_settings_but_count_on_hand_set", + scope: i18n_scope_for_stock_settings_override_validation_error) + errors.add(:count_on_hand, error_message) + end + + def disallow_count_on_hand_if_on_demand + return unless on_demand? && count_on_hand.present? + + error_message = I18n.t("count_on_hand.on_demand_but_count_on_hand_set", + scope: i18n_scope_for_stock_settings_override_validation_error) + errors.add(:count_on_hand, error_message) + end + + def require_count_on_hand_if_limited_stock + return unless on_demand == false && count_on_hand.blank? + + error_message = I18n.t("count_on_hand.limited_stock_but_no_count_on_hand", + scope: i18n_scope_for_stock_settings_override_validation_error) + errors.add(:count_on_hand, error_message) + end + + def i18n_scope_for_stock_settings_override_validation_error + "activerecord.errors.models.#{self.class.name.underscore}" + end +end diff --git a/app/models/variant_override.rb b/app/models/variant_override.rb index 5527f29af7..dd3b22a5e0 100644 --- a/app/models/variant_override.rb +++ b/app/models/variant_override.rb @@ -1,5 +1,6 @@ class VariantOverride < ActiveRecord::Base extend Spree::LocalizedNumber + include StockSettingsOverrideValidation acts_as_taggable @@ -10,8 +11,6 @@ class VariantOverride < ActiveRecord::Base # Default stock can be nil, indicating stock should not be reset or zero, meaning reset to zero. Need to ensure this can be set by the user. validates :default_stock, numericality: { greater_than_or_equal_to: 0 }, allow_nil: true - before_validation :require_compatible_on_demand_and_count_on_hand - after_save :refresh_products_cache_from_save after_destroy :refresh_products_cache_from_destroy @@ -106,38 +105,4 @@ class VariantOverride < ActiveRecord::Base def refresh_products_cache_from_destroy OpenFoodNetwork::ProductsCache.variant_override_destroyed self end - - def require_compatible_on_demand_and_count_on_hand - disallow_count_on_hand_if_using_producer_stock_settings - disallow_count_on_hand_if_on_demand - require_count_on_hand_if_limited_stock - end - - def disallow_count_on_hand_if_using_producer_stock_settings - return unless on_demand.nil? && count_on_hand.present? - - error_message = I18n.t("using_producer_stock_settings_but_count_on_hand_set", - scope: [i18n_scope_for_error, "count_on_hand"]) - errors.add(:count_on_hand, error_message) - end - - def disallow_count_on_hand_if_on_demand - return unless on_demand? && count_on_hand.present? - - error_message = I18n.t("on_demand_but_count_on_hand_set", - scope: [i18n_scope_for_error, "count_on_hand"]) - errors.add(:count_on_hand, error_message) - end - - def require_count_on_hand_if_limited_stock - return unless on_demand == false && count_on_hand.blank? - - error_message = I18n.t("limited_stock_but_no_count_on_hand", - scope: [i18n_scope_for_error, "count_on_hand"]) - errors.add(:count_on_hand, error_message) - end - - def i18n_scope_for_error - "activerecord.errors.models.variant_override" - end end From 0de829017ab55f8c595ff899add6333e82038dcc Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Mon, 10 Dec 2018 00:16:49 +0800 Subject: [PATCH 26/60] Refactor finding or initializing VO for product import --- app/models/product_import/entry_validator.rb | 23 +++++++++++--------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/app/models/product_import/entry_validator.rb b/app/models/product_import/entry_validator.rb index b7f055e445..ab6486a627 100644 --- a/app/models/product_import/entry_validator.rb +++ b/app/models/product_import/entry_validator.rb @@ -68,6 +68,18 @@ module ProductImport private + def find_or_initialize_variant_override(entry, existing_variant) + existing_variant_override = VariantOverride.where( + variant_id: existing_variant.id, + hub_id: entry.enterprise_id + ).first + + existing_variant_override || VariantOverride.new( + variant_id: existing_variant.id, + hub_id: entry.enterprise_id + ) + end + def enterprise_validation(entry) return if name_presence_error entry return if enterprise_not_found_error entry @@ -310,16 +322,7 @@ module ProductImport end def create_inventory_item(entry, existing_variant) - existing_variant_override = VariantOverride.where( - variant_id: existing_variant.id, - hub_id: entry.enterprise_id - ).first - - variant_override = existing_variant_override || VariantOverride.new( - variant_id: existing_variant.id, - hub_id: entry.enterprise_id - ) - + variant_override = find_or_initialize_variant_override(entry, existing_variant) variant_override.assign_attributes(count_on_hand: entry.on_hand, import_date: @import_time) check_on_hand_nil(entry, variant_override) variant_override.assign_attributes(entry.attributes.slice('price', 'on_demand')) From cec50e81f5714e9a06c90bfb3939cb7caf8efc3d Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Sun, 9 Dec 2018 21:20:18 +0800 Subject: [PATCH 27/60] Make product import set correct VO stock settings --- app/models/product_import/entry_validator.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/models/product_import/entry_validator.rb b/app/models/product_import/entry_validator.rb index ab6486a627..1511160c65 100644 --- a/app/models/product_import/entry_validator.rb +++ b/app/models/product_import/entry_validator.rb @@ -323,8 +323,10 @@ module ProductImport def create_inventory_item(entry, existing_variant) variant_override = find_or_initialize_variant_override(entry, existing_variant) - variant_override.assign_attributes(count_on_hand: entry.on_hand, import_date: @import_time) - check_on_hand_nil(entry, variant_override) + + check_variant_override_stock_settings(entry, variant_override) + + variant_override.assign_attributes(import_date: @import_time) variant_override.assign_attributes(entry.attributes.slice('price', 'on_demand')) variant_override @@ -358,5 +360,11 @@ module ProductImport object.count_on_hand = 0 if object.respond_to?(:count_on_hand) entry.on_hand_nil = true end + + def check_variant_override_stock_settings(entry, object) + object.count_on_hand = entry.on_hand.presence + object.on_demand = object.count_on_hand.blank? if entry.on_demand.blank? + entry.on_hand_nil = object.count_on_hand.blank? + end end end From df51d137dc87a819b3646e501798079ac387046e Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Mon, 10 Dec 2018 00:21:13 +0800 Subject: [PATCH 28/60] Update some code style for product import --- app/models/product_import/entry_validator.rb | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/app/models/product_import/entry_validator.rb b/app/models/product_import/entry_validator.rb index 1511160c65..11c0aab7dd 100644 --- a/app/models/product_import/entry_validator.rb +++ b/app/models/product_import/entry_validator.rb @@ -322,14 +322,12 @@ module ProductImport end def create_inventory_item(entry, existing_variant) - variant_override = find_or_initialize_variant_override(entry, existing_variant) + find_or_initialize_variant_override(entry, existing_variant).tap do |variant_override| + check_variant_override_stock_settings(entry, variant_override) - check_variant_override_stock_settings(entry, variant_override) - - variant_override.assign_attributes(import_date: @import_time) - variant_override.assign_attributes(entry.attributes.slice('price', 'on_demand')) - - variant_override + variant_override.assign_attributes(import_date: @import_time) + variant_override.assign_attributes(entry.attributes.slice('price', 'on_demand')) + end end def mark_as_inventory_item(entry, variant_override) From e274442d77a3541de50127cbfb5af4443d73744c Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Thu, 6 Dec 2018 15:13:32 +0000 Subject: [PATCH 29/60] Cover i18nhelper.valid_locale and user mailer with tests related to localized emails --- .rubocop_todo.yml | 1 - app/helpers/i18n_helper.rb | 10 +++--- spec/helpers/i18n_helper_spec.rb | 58 +++++++++++++++++++++++++------- spec/mailers/user_mailer_spec.rb | 29 ++++++++++++++-- 4 files changed, 76 insertions(+), 22 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 99c836deb1..e8b203c9d6 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -845,7 +845,6 @@ Layout/SpaceInsideHashLiteralBraces: - 'spec/features/admin/reports_spec.rb' - 'spec/features/consumer/shopping/checkout_spec.rb' - 'spec/helpers/checkout_helper_spec.rb' - - 'spec/helpers/i18n_helper_spec.rb' - 'spec/helpers/order_cycles_helper_spec.rb' - 'spec/lib/open_food_network/enterprise_fee_calculator_spec.rb' - 'spec/lib/open_food_network/feature_toggle_spec.rb' diff --git a/app/helpers/i18n_helper.rb b/app/helpers/i18n_helper.rb index 215028e5aa..3293d42d98 100644 --- a/app/helpers/i18n_helper.rb +++ b/app/helpers/i18n_helper.rb @@ -14,11 +14,11 @@ module I18nHelper I18n.locale = spree_current_user.andand.locale || cookies[:locale] || I18n.default_locale end - def valid_locale(object_with_locale) - if object_with_locale.present? && - object_with_locale.locale.present? && - available_locale?(object_with_locale.locale) - object_with_locale.locale + def valid_locale(user) + if user.present? && + user.locale.present? && + available_locale?(user.locale) + user.locale else I18n.default_locale end diff --git a/spec/helpers/i18n_helper_spec.rb b/spec/helpers/i18n_helper_spec.rb index 62c58e2345..fba8ab882b 100644 --- a/spec/helpers/i18n_helper_spec.rb +++ b/spec/helpers/i18n_helper_spec.rb @@ -24,13 +24,13 @@ describe I18nHelper, type: :helper do end it "sets the chosen locale" do - allow(helper).to receive(:params) { {locale: "es"} } + allow(helper).to receive(:params) { { locale: "es" } } helper.set_locale expect(I18n.locale).to eq :es end it "remembers the chosen locale" do - allow(helper).to receive(:params) { {locale: "es"} } + allow(helper).to receive(:params) { { locale: "es" } } helper.set_locale allow(helper).to receive(:params) { {} } @@ -39,16 +39,16 @@ describe I18nHelper, type: :helper do end it "ignores unavailable locales" do - allow(helper).to receive(:params) { {locale: "xx"} } + allow(helper).to receive(:params) { { locale: "xx" } } helper.set_locale expect(I18n.locale).to eq :en end it "remembers the last chosen locale" do - allow(helper).to receive(:params) { {locale: "en"} } + allow(helper).to receive(:params) { { locale: "en" } } helper.set_locale - allow(helper).to receive(:params) { {locale: "es"} } + allow(helper).to receive(:params) { { locale: "es" } } helper.set_locale allow(helper).to receive(:params) { {} } @@ -57,7 +57,7 @@ describe I18nHelper, type: :helper do end it "remembers the chosen locale after logging in" do - allow(helper).to receive(:params) { {locale: "es"} } + allow(helper).to receive(:params) { { locale: "es" } } helper.set_locale # log in @@ -68,7 +68,7 @@ describe I18nHelper, type: :helper do end it "forgets the chosen locale without cookies" do - allow(helper).to receive(:params) { {locale: "es"} } + allow(helper).to receive(:params) { { locale: "es" } } helper.set_locale # clean up cookies @@ -91,14 +91,14 @@ describe I18nHelper, type: :helper do end it "sets the chosen locale" do - allow(helper).to receive(:params) { {locale: "es"} } + allow(helper).to receive(:params) { { locale: "es" } } helper.set_locale expect(I18n.locale).to eq :es expect(user.locale).to eq "es" end it "remembers the chosen locale" do - allow(helper).to receive(:params) { {locale: "es"} } + allow(helper).to receive(:params) { { locale: "es" } } helper.set_locale allow(helper).to receive(:params) { {} } @@ -107,10 +107,10 @@ describe I18nHelper, type: :helper do end it "remembers the last chosen locale" do - allow(helper).to receive(:params) { {locale: "en"} } + allow(helper).to receive(:params) { { locale: "en" } } helper.set_locale - allow(helper).to receive(:params) { {locale: "es"} } + allow(helper).to receive(:params) { { locale: "es" } } helper.set_locale allow(helper).to receive(:params) { {} } @@ -119,7 +119,7 @@ describe I18nHelper, type: :helper do end it "remembers the chosen locale after logging out" do - allow(helper).to receive(:params) { {locale: "es"} } + allow(helper).to receive(:params) { { locale: "es" } } helper.set_locale # log out @@ -130,7 +130,7 @@ describe I18nHelper, type: :helper do end it "remembers the chosen locale on another computer" do - allow(helper).to receive(:params) { {locale: "es"} } + allow(helper).to receive(:params) { { locale: "es" } } helper.set_locale expect(cookies[:locale]).to eq "es" @@ -142,4 +142,36 @@ describe I18nHelper, type: :helper do expect(I18n.locale).to eq :es end end + + context "#valid_locale" do + around do |example| + original_default_locale = I18n.default_locale + original_available_locales = Rails.application.config.i18n.available_locales + I18n.default_locale = "es" + Rails.application.config.i18n.available_locales = ["es", "pt"] + example.run + I18n.default_locale = original_default_locale + Rails.application.config.i18n.available_locales = original_available_locales + end + + let(:user) { build(:user) } + + it "returns default locale if given user is nil" do + expect(helper.valid_locale(nil)).to eq I18n.default_locale + end + + it "returns default locale if locale of given user is nil" do + expect(helper.valid_locale(user)).to eq I18n.default_locale + end + + it "returns default locale if locale of given user is not available" do + user.locale = "cn" + expect(helper.valid_locale(user)).to eq I18n.default_locale + end + + it "returns the locale of the given user if available" do + user.locale = "pt" + expect(helper.valid_locale(user)).to eq "pt" + end + end end diff --git a/spec/mailers/user_mailer_spec.rb b/spec/mailers/user_mailer_spec.rb index 8082d0f6a6..9b4790e5ad 100644 --- a/spec/mailers/user_mailer_spec.rb +++ b/spec/mailers/user_mailer_spec.rb @@ -17,9 +17,32 @@ describe Spree::UserMailer do setup_email end - it "sends an email when given a user" do - Spree::UserMailer.signup_confirmation(user).deliver - ActionMailer::Base.deliveries.count.should == 1 + describe '#signup_confirmation' do + it "sends email when given a user" do + Spree::UserMailer.signup_confirmation(user).deliver + expect(ActionMailer::Base.deliveries.count).to eq(1) + end + + describe "user locale" do + around do |example| + original_default_locale = I18n.default_locale + I18n.default_locale = 'pt' + example.run + I18n.default_locale = original_default_locale + end + + it "sends email in user locale when user locale is defined" do + user.locale = 'es' + Spree::UserMailer.signup_confirmation(user).deliver + expect(ActionMailer::Base.deliveries.first.body).to include "Gracias por unirte" + end + + it "sends email in default locale when user locale is not available" do + user.locale = 'cn' + Spree::UserMailer.signup_confirmation(user).deliver + expect(ActionMailer::Base.deliveries.first.body).to include "Obrigada por juntar-se" + end + end end # adapted from https://github.com/spree/spree_auth_devise/blob/70737af/spec/mailers/user_mailer_spec.rb From 9e3332ba2aea02133cb9619b3b367d57c238ce38 Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Thu, 13 Dec 2018 23:25:48 +0800 Subject: [PATCH 30/60] Rename DB migration file --- ... 20181128054803_simplify_variant_override_stock_settings.rb} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename db/migrate/{20181128054803_simplify_variant_override_on_demand_and_count_on_hand.rb => 20181128054803_simplify_variant_override_stock_settings.rb} (93%) diff --git a/db/migrate/20181128054803_simplify_variant_override_on_demand_and_count_on_hand.rb b/db/migrate/20181128054803_simplify_variant_override_stock_settings.rb similarity index 93% rename from db/migrate/20181128054803_simplify_variant_override_on_demand_and_count_on_hand.rb rename to db/migrate/20181128054803_simplify_variant_override_stock_settings.rb index eeb5eb5e37..ed42708d0d 100644 --- a/db/migrate/20181128054803_simplify_variant_override_on_demand_and_count_on_hand.rb +++ b/db/migrate/20181128054803_simplify_variant_override_stock_settings.rb @@ -11,7 +11,7 @@ # # Furthermore, this will allow all existing variant overrides to satisfy the newly added model # validation rules. -class SimplifyVariantOverrideOnDemandAndCountOnHand < ActiveRecord::Migration +class SimplifyVariantOverrideStockSettings < ActiveRecord::Migration def up # When on_demand is nil but count_on_hand is set, force limited stock. VariantOverride.where(on_demand: nil).where("count_on_hand IS NOT NULL") From aa92dd877109cafcdbe6c89ecd3c0d5610fbc5cc Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Wed, 12 Dec 2018 01:27:52 +0800 Subject: [PATCH 31/60] Declare VariantOverride in migration for safe use --- ...simplify_variant_override_stock_settings.rb | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/db/migrate/20181128054803_simplify_variant_override_stock_settings.rb b/db/migrate/20181128054803_simplify_variant_override_stock_settings.rb index ed42708d0d..7bb370d9f4 100644 --- a/db/migrate/20181128054803_simplify_variant_override_stock_settings.rb +++ b/db/migrate/20181128054803_simplify_variant_override_stock_settings.rb @@ -12,17 +12,27 @@ # Furthermore, this will allow all existing variant overrides to satisfy the newly added model # validation rules. class SimplifyVariantOverrideStockSettings < ActiveRecord::Migration + class VariantOverride < ActiveRecord::Base + scope :with_count_on_hand, -> { where("count_on_hand IS NOT NULL") } + scope :without_count_on_hand, -> { where(count_on_hand: nil) } + end + def up # When on_demand is nil but count_on_hand is set, force limited stock. - VariantOverride.where(on_demand: nil).where("count_on_hand IS NOT NULL") - .update_all(on_demand: false) + VariantOverride.where(on_demand: nil).with_count_on_hand.find_each do |variant_override| + variant_override.update_attributes!(on_demand: false) + end # Clear count_on_hand if forcing on demand. - VariantOverride.where(on_demand: true).update_all(count_on_hand: nil) + VariantOverride.where(on_demand: true).with_count_on_hand.find_each do |variant_override| + variant_override.update_attributes!(count_on_hand: nil) + end # When on_demand is false but count on hand is not specified, set this to use producer stock # settings. - VariantOverride.where(on_demand: false, count_on_hand: nil).update_all(on_demand: nil) + VariantOverride.where(on_demand: false).without_count_on_hand.find_each do |variant_override| + variant_override.update_attributes!(on_demand: nil) + end end def down; end From 2ecec93514634af215e5766ca68ac03918d6fd46 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" Date: Thu, 13 Dec 2018 19:19:36 +0000 Subject: [PATCH 32/60] Bump wkhtmltopdf-binary from 0.12.3.1 to 0.12.4 Bumps [wkhtmltopdf-binary](https://github.com/zakird/wkhtmltopdf_binary_gem) from 0.12.3.1 to 0.12.4. - [Release notes](https://github.com/zakird/wkhtmltopdf_binary_gem/releases) - [Changelog](https://github.com/zakird/wkhtmltopdf_binary_gem/blob/master/CHANGELOG) - [Commits](https://github.com/zakird/wkhtmltopdf_binary_gem/compare/0.12.3.1...0.12.4) Signed-off-by: dependabot[bot] --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 440504aa5e..05d8b08104 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -744,7 +744,7 @@ GEM activesupport (>= 2.3.4) chronic (>= 0.6.3) wicked_pdf (1.1.0) - wkhtmltopdf-binary (0.12.3.1) + wkhtmltopdf-binary (0.12.4) xml-simple (1.1.5) xpath (2.1.0) nokogiri (~> 1.3) From 842a11b564bbd6b14a2d4ddb158c6bd9dd95bf41 Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Thu, 13 Dec 2018 19:15:31 +0800 Subject: [PATCH 33/60] Refactor DB migration script --- ...implify_variant_override_stock_settings.rb | 45 ++++++++++++------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/db/migrate/20181128054803_simplify_variant_override_stock_settings.rb b/db/migrate/20181128054803_simplify_variant_override_stock_settings.rb index 7bb370d9f4..be0718e163 100644 --- a/db/migrate/20181128054803_simplify_variant_override_stock_settings.rb +++ b/db/migrate/20181128054803_simplify_variant_override_stock_settings.rb @@ -18,22 +18,37 @@ class SimplifyVariantOverrideStockSettings < ActiveRecord::Migration end def up - # When on_demand is nil but count_on_hand is set, force limited stock. - VariantOverride.where(on_demand: nil).with_count_on_hand.find_each do |variant_override| - variant_override.update_attributes!(on_demand: false) - end - - # Clear count_on_hand if forcing on demand. - VariantOverride.where(on_demand: true).with_count_on_hand.find_each do |variant_override| - variant_override.update_attributes!(count_on_hand: nil) - end - - # When on_demand is false but count on hand is not specified, set this to use producer stock - # settings. - VariantOverride.where(on_demand: false).without_count_on_hand.find_each do |variant_override| - variant_override.update_attributes!(on_demand: nil) - end + update_use_producer_stock_settings_with_count_on_hand + update_on_demand_with_count_on_hand + update_limited_stock_without_count_on_hand end def down; end + + private + + # When on_demand is nil but count_on_hand is set, force limited stock. + def update_use_producer_stock_settings_with_count_on_hand + variant_overrides = VariantOverride.where(on_demand: nil).with_count_on_hand + variant_overrides.find_each do |variant_override| + variant_override.update_attributes!(on_demand: false) + end + end + + # Clear count_on_hand if forcing on demand. + def update_on_demand_with_count_on_hand + variant_overrides = VariantOverride.where(on_demand: true).with_count_on_hand + variant_overrides.find_each do |variant_override| + variant_override.update_attributes!(count_on_hand: nil) + end + end + + # When on_demand is false but count on hand is not specified, set this to use producer stock + # settings. + def update_limited_stock_without_count_on_hand + variant_overrides = VariantOverride.where(on_demand: false).without_count_on_hand + variant_overrides.find_each do |variant_override| + variant_override.update_attributes!(on_demand: nil) + end + end end From 5a98acd101948ea922aa10bee42dc802ff59f340 Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Thu, 13 Dec 2018 23:36:16 +0800 Subject: [PATCH 34/60] Log changes from DB migration to CSV file --- ...implify_variant_override_stock_settings.rb | 88 +++++++++++++++++-- 1 file changed, 79 insertions(+), 9 deletions(-) diff --git a/db/migrate/20181128054803_simplify_variant_override_stock_settings.rb b/db/migrate/20181128054803_simplify_variant_override_stock_settings.rb index be0718e163..965106cfa9 100644 --- a/db/migrate/20181128054803_simplify_variant_override_stock_settings.rb +++ b/db/migrate/20181128054803_simplify_variant_override_stock_settings.rb @@ -13,42 +13,112 @@ # validation rules. class SimplifyVariantOverrideStockSettings < ActiveRecord::Migration class VariantOverride < ActiveRecord::Base + belongs_to :variant + belongs_to :hub, class_name: "Enterprise" + scope :with_count_on_hand, -> { where("count_on_hand IS NOT NULL") } scope :without_count_on_hand, -> { where(count_on_hand: nil) } end + class Variant < ActiveRecord::Base + self.table_name = "spree_variants" + + belongs_to :product + + def name + namer = OpenFoodNetwork::OptionValueNamer.new(self) + namer.name + end + end + + class Product < ActiveRecord::Base + self.table_name = "spree_products" + + belongs_to :supplier, class_name: "Enterprise" + end + + class Enterprise < ActiveRecord::Base; end + def up - update_use_producer_stock_settings_with_count_on_hand - update_on_demand_with_count_on_hand - update_limited_stock_without_count_on_hand + CSV.open(csv_path, "w") do |csv| + csv << csv_header_row + + update_use_producer_stock_settings_with_count_on_hand(csv) + update_on_demand_with_count_on_hand(csv) + update_limited_stock_without_count_on_hand(csv) + end end def down; end private + def csv_path + Rails.root.join("reports", "SimplifyVariantOverrideStockSettings-changed_variant_overrides.csv") + end + # When on_demand is nil but count_on_hand is set, force limited stock. - def update_use_producer_stock_settings_with_count_on_hand + def update_use_producer_stock_settings_with_count_on_hand(csv) variant_overrides = VariantOverride.where(on_demand: nil).with_count_on_hand - variant_overrides.find_each do |variant_override| + update_variant_overrides_and_log(csv, variant_overrides) do |variant_override| variant_override.update_attributes!(on_demand: false) end end # Clear count_on_hand if forcing on demand. - def update_on_demand_with_count_on_hand + def update_on_demand_with_count_on_hand(csv) variant_overrides = VariantOverride.where(on_demand: true).with_count_on_hand - variant_overrides.find_each do |variant_override| + update_variant_overrides_and_log(csv, variant_overrides) do |variant_override| variant_override.update_attributes!(count_on_hand: nil) end end # When on_demand is false but count on hand is not specified, set this to use producer stock # settings. - def update_limited_stock_without_count_on_hand + def update_limited_stock_without_count_on_hand(csv) variant_overrides = VariantOverride.where(on_demand: false).without_count_on_hand - variant_overrides.find_each do |variant_override| + update_variant_overrides_and_log(csv, variant_overrides) do |variant_override| variant_override.update_attributes!(on_demand: nil) end end + + def update_variant_overrides_and_log(csv, variant_overrides) + variant_overrides.find_each do |variant_override| + csv << variant_override_log_row(variant_override) do + yield variant_override + end + end + end + + def csv_header_row + %w( + variant_override_id + distributor_name distributor_id + producer_name producer_id + product_name product_id + variant_description variant_id + previous_on_demand previous_count_on_hand + updated_on_demand updated_count_on_hand + ) + end + + def variant_override_log_row(variant_override) + variant = variant_override.variant + distributor = variant_override.hub + product = variant.andand.product + supplier = product.andand.supplier + + row = [ + variant_override.id, + distributor.andand.name, distributor.andand.id, + supplier.andand.name, supplier.andand.id, + product.andand.name, product.andand.id, + variant.andand.name, variant.andand.id, + variant_override.on_demand, variant_override.count_on_hand + ] + + yield variant_override + + row + [variant_override.on_demand, variant_override.count_on_hand] + end end From 645812789216aa22dc288dc7f34b5b01e1605a5a Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Thu, 13 Dec 2018 23:59:51 +0800 Subject: [PATCH 35/60] Add undo logic for DB migration script --- ...1128054803_simplify_variant_override_stock_settings.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/db/migrate/20181128054803_simplify_variant_override_stock_settings.rb b/db/migrate/20181128054803_simplify_variant_override_stock_settings.rb index 965106cfa9..0fac5c1ab6 100644 --- a/db/migrate/20181128054803_simplify_variant_override_stock_settings.rb +++ b/db/migrate/20181128054803_simplify_variant_override_stock_settings.rb @@ -49,7 +49,13 @@ class SimplifyVariantOverrideStockSettings < ActiveRecord::Migration end end - def down; end + def down + CSV.foreach(csv_path, headers: true) do |row| + VariantOverride.where(id: row["variant_override_id"]) + .update_all(on_demand: row["previous_on_demand"], + count_on_hand: row["previous_count_on_hand"]) + end + end private From d859939c7989106aafe831abb41aa30704cb7057 Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Fri, 14 Dec 2018 10:24:26 +0800 Subject: [PATCH 36/60] Add README.md to reports/ directory --- reports/README.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 reports/README.md diff --git a/reports/README.md b/reports/README.md new file mode 100644 index 0000000000..84c8566c33 --- /dev/null +++ b/reports/README.md @@ -0,0 +1,4 @@ +## `reports/` Directory + +This directory may be used for reports generated for the OFN instance. For example, a database +migration may save in this directory a spreadsheet of changes it made during execution. From 91e5a523f0abb9d3cfaa82b552d0b234f820436e Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Fri, 14 Dec 2018 10:08:29 +0800 Subject: [PATCH 37/60] Add /reports/ to .gitignore but ignore README Using the first slash to make sure that other reports/ directories are not ignored. --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 4c0d217d06..370eba9a90 100644 --- a/.gitignore +++ b/.gitignore @@ -41,3 +41,5 @@ libpeerconnection.log node_modules vendor/bundle/ coverage +/reports/ +!/reports/README.md From a6664d0ac675a5479e75169fdc625e0961540ec2 Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Fri, 14 Dec 2018 11:41:56 +0800 Subject: [PATCH 38/60] Move report generated by migration to subdirectory This is in preparation of an upcoming change to split the main CSV file by distributor. --- ...54803_simplify_variant_override_stock_settings.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/db/migrate/20181128054803_simplify_variant_override_stock_settings.rb b/db/migrate/20181128054803_simplify_variant_override_stock_settings.rb index 0fac5c1ab6..2db448389c 100644 --- a/db/migrate/20181128054803_simplify_variant_override_stock_settings.rb +++ b/db/migrate/20181128054803_simplify_variant_override_stock_settings.rb @@ -40,6 +40,8 @@ class SimplifyVariantOverrideStockSettings < ActiveRecord::Migration class Enterprise < ActiveRecord::Base; end def up + ensure_reports_path_exists + CSV.open(csv_path, "w") do |csv| csv << csv_header_row @@ -59,8 +61,16 @@ class SimplifyVariantOverrideStockSettings < ActiveRecord::Migration private + def reports_path + Rails.root.join("reports", "SimplifyVariantOverrideStockSettings") + end + + def ensure_reports_path_exists + Dir.mkdir(reports_path) unless File.exist?(reports_path) + end + def csv_path - Rails.root.join("reports", "SimplifyVariantOverrideStockSettings-changed_variant_overrides.csv") + reports_path.join("changed_variant_overrides.csv") end # When on_demand is nil but count_on_hand is set, force limited stock. From 77a656276209c68ab23db00646a5c3d0106a214c Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Fri, 14 Dec 2018 13:00:02 +0800 Subject: [PATCH 39/60] Make DB migration generate summary by distributor --- ...implify_variant_override_stock_settings.rb | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/db/migrate/20181128054803_simplify_variant_override_stock_settings.rb b/db/migrate/20181128054803_simplify_variant_override_stock_settings.rb index 2db448389c..6627dca015 100644 --- a/db/migrate/20181128054803_simplify_variant_override_stock_settings.rb +++ b/db/migrate/20181128054803_simplify_variant_override_stock_settings.rb @@ -49,6 +49,8 @@ class SimplifyVariantOverrideStockSettings < ActiveRecord::Migration update_on_demand_with_count_on_hand(csv) update_limited_stock_without_count_on_hand(csv) end + + split_csv_by_distributor end def down @@ -73,6 +75,10 @@ class SimplifyVariantOverrideStockSettings < ActiveRecord::Migration reports_path.join("changed_variant_overrides.csv") end + def distributor_csv_path(name, id) + reports_path.join("changed_variant_overrides-#{name.parameterize('_')}-#{id}.csv") + end + # When on_demand is nil but count_on_hand is set, force limited stock. def update_use_producer_stock_settings_with_count_on_hand(csv) variant_overrides = VariantOverride.where(on_demand: nil).with_count_on_hand @@ -137,4 +143,23 @@ class SimplifyVariantOverrideStockSettings < ActiveRecord::Migration row + [variant_override.on_demand, variant_override.count_on_hand] end + + def split_csv_by_distributor + table = CSV.read(csv_path) + distributor_ids = table[1..-1].map { |row| row[2] }.uniq # Don't use the header row. + + distributor_ids.each do |distributor_id| + distributor_data_rows = filter_data_rows_for_distributor(table[1..-1], distributor_id) + distributor_name = distributor_data_rows.first[1] + + CSV.open(distributor_csv_path(distributor_name, distributor_id), "w") do |csv| + csv << table[0] # Header row + distributor_data_rows.each { |row| csv << row } + end + end + end + + def filter_data_rows_for_distributor(data_rows, distributor_id) + data_rows.select { |row| row[2] == distributor_id } + end end From 2f19b37b542530c4ebcdef80f8e56d01a79775ee Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" Date: Fri, 14 Dec 2018 14:29:42 +0000 Subject: [PATCH 40/60] Bump angularjs-file-upload-rails from 1.1.6 to 2.4.1 Bumps [angularjs-file-upload-rails](https://github.com/marthyn/angularjs-file-upload-rails) from 1.1.6 to 2.4.1. - [Release notes](https://github.com/marthyn/angularjs-file-upload-rails/releases) - [Commits](https://github.com/marthyn/angularjs-file-upload-rails/commits/v2.4.1) Signed-off-by: dependabot[bot] --- Gemfile | 2 +- Gemfile.lock | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index f4569c7a31..c2762a6aa9 100644 --- a/Gemfile +++ b/Gemfile @@ -63,7 +63,7 @@ gem 'spinjs-rails' gem 'rack-ssl', require: 'rack/ssl' gem 'rack-rewrite' gem 'custom_error_message', github: 'jeremydurham/custom-err-msg' -gem 'angularjs-file-upload-rails', '~> 1.1.6' +gem 'angularjs-file-upload-rails', '~> 2.4.1' gem 'roadie-rails', '~> 1.1.1' gem 'figaro' gem 'blockenspiel' diff --git a/Gemfile.lock b/Gemfile.lock index ce6d927e2b..26e4ac81ed 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -186,7 +186,7 @@ GEM railties (>= 3.1) sprockets (~> 2.0) tilt - angularjs-file-upload-rails (1.1.6) + angularjs-file-upload-rails (2.4.1) angularjs-rails (1.5.5) arel (3.0.3) ast (2.4.0) @@ -758,7 +758,7 @@ DEPENDENCIES acts-as-taggable-on (~> 3.4) andand angular-rails-templates (~> 0.3.0) - angularjs-file-upload-rails (~> 1.1.6) + angularjs-file-upload-rails (~> 2.4.1) angularjs-rails (= 1.5.5) atomic awesome_print From 93940ced3a712f20c7a126f629e018bfced298c2 Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Fri, 16 Nov 2018 14:47:26 +0800 Subject: [PATCH 41/60] Remove outdated comment recommending knapsack We are already using this. --- .travis.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 952e999999..dcb097a3e0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,9 +9,6 @@ addons: # Set the timezone for phantomjs with TZ # Set the timezone for karma with TIMEZONE -# -# The test cases are roughly split according to their test times. -# It would be better to use https://github.com/ArturT/knapsack. env: global: - TZ="Australia/Melbourne" From fb5a9356dc61b339fc85980b418ee9166772c3fc Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Tue, 20 Nov 2018 17:24:02 +0800 Subject: [PATCH 42/60] Fix spec_helper.rb of web engine This fixes the tests of the web engine when running the following from its root: bundle exec rspec An engine is meant to have some independence from the main application, and its tests should be run independently. This should be using the engine's own dummy application, actually, or the dummy application of a dependency. --- engines/web/spec/spec_helper.rb | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/engines/web/spec/spec_helper.rb b/engines/web/spec/spec_helper.rb index 3306063166..9cfd0bc717 100644 --- a/engines/web/spec/spec_helper.rb +++ b/engines/web/spec/spec_helper.rb @@ -1,8 +1,3 @@ -ENV["RAILS_ENV"] = "test" - -require File.expand_path("dummy/config/environment.rb", __dir__) -require "rails/test_help" - -Rails.backtrace_cleaner.remove_silencers! +require "../../spec/spec_helper.rb" Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f } From 216c598e74bc234ccaf09d4ba66f65427cff5ae2 Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Mon, 17 Dec 2018 05:20:02 +0800 Subject: [PATCH 43/60] Ignore more methods in Metrics/BlockLength cop Ignore these additional methods: * collection * member * namespace * resource * resources --- .rubocop_styleguide.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.rubocop_styleguide.yml b/.rubocop_styleguide.yml index 61419eb02f..13214b0aed 100644 --- a/.rubocop_styleguide.yml +++ b/.rubocop_styleguide.yml @@ -187,7 +187,7 @@ Metrics/AbcSize: Max: 15 Metrics/BlockLength: - ExcludedMethods: ["context", "describe", "it"] + ExcludedMethods: ["collection", "context", "describe", "it", "member", "namespace", "resource", "resources"] Metrics/BlockNesting: Max: 3 From a9222665b84c19140b3da182ac272b327f68b24f Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Tue, 18 Dec 2018 15:26:49 +0000 Subject: [PATCH 44/60] Refactor user registrations controller, early return to reduce indentation --- .../user_registrations_controller.rb | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/app/controllers/user_registrations_controller.rb b/app/controllers/user_registrations_controller.rb index cc43badbb8..cb7cb61684 100644 --- a/app/controllers/user_registrations_controller.rb +++ b/app/controllers/user_registrations_controller.rb @@ -8,22 +8,22 @@ class UserRegistrationsController < Spree::UserRegistrationsController # POST /resource/sign_up def create @user = build_resource(params[:spree_user]) - if resource.save - session[:spree_user_signup] = true - session[:confirmation_return_url] = params[:return_url] - associate_user + unless resource.save + return render_error(@user.errors) + end - respond_to do |format| - format.html do - set_flash_message(:success, :signed_up_but_unconfirmed) - redirect_to after_sign_in_path_for(@user) - end - format.js do - render json: { email: @user.email } - end + session[:spree_user_signup] = true + session[:confirmation_return_url] = params[:return_url] + associate_user + + respond_to do |format| + format.html do + set_flash_message(:success, :signed_up_but_unconfirmed) + redirect_to after_sign_in_path_for(@user) + end + format.js do + render json: { email: @user.email } end - else - render_error(@user.errors) end rescue StandardError => error OpenFoodNetwork::ErrorLogger.notify(error) From 5e960512aceedd443c6b299cd6037e4da585e537 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Tue, 18 Dec 2018 15:29:50 +0000 Subject: [PATCH 45/60] Set user locale on user registrations #create This is done so that user.locale is used in the first confirmation email. This also stores user.locale in the DB from registration. --- app/controllers/user_registrations_controller.rb | 4 ++++ spec/controllers/user_registrations_controller_spec.rb | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/app/controllers/user_registrations_controller.rb b/app/controllers/user_registrations_controller.rb index cb7cb61684..e8e75dc5ee 100644 --- a/app/controllers/user_registrations_controller.rb +++ b/app/controllers/user_registrations_controller.rb @@ -5,9 +5,13 @@ class UserRegistrationsController < Spree::UserRegistrationsController before_filter :set_checkout_redirect, only: :create + include I18nHelper + before_filter :set_locale + # POST /resource/sign_up def create @user = build_resource(params[:spree_user]) + @user.locale = I18n.locale.to_s unless resource.save return render_error(@user.errors) end diff --git a/spec/controllers/user_registrations_controller_spec.rb b/spec/controllers/user_registrations_controller_spec.rb index 7ed7951c50..22d14b383f 100644 --- a/spec/controllers/user_registrations_controller_spec.rb +++ b/spec/controllers/user_registrations_controller_spec.rb @@ -48,6 +48,16 @@ describe UserRegistrationsController, type: :controller do expect(json).to eq({"email" => "test@test.com"}) expect(controller.spree_current_user).to be_nil end + + it "sets user.locale from cookie on create" do + original_locale_cookie = cookies[:locale] + cookies[:locale] = "pt" + + xhr :post, :create, spree_user: user_params, use_route: :spree + + expect(assigns[:user].locale).to eq("pt") + cookies[:locale] = original_locale_cookie + end end context "when registration fails" do From 6de1844b7c7e18183196ce30785dfea09a19b17b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" Date: Tue, 18 Dec 2018 19:14:54 +0000 Subject: [PATCH 46/60] Bump momentjs-rails from 2.5.1 to 2.20.1 Bumps [momentjs-rails](https://github.com/derekprior/momentjs-rails) from 2.5.1 to 2.20.1. - [Release notes](https://github.com/derekprior/momentjs-rails/releases) - [Changelog](https://github.com/derekprior/momentjs-rails/blob/master/news.md) - [Commits](https://github.com/derekprior/momentjs-rails/compare/v2.5.1...v2.20.1) Signed-off-by: dependabot[bot] --- Gemfile.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 389222a6a7..f7d3a3d1ce 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -525,7 +525,7 @@ GEM mini_portile2 (2.1.0) mini_racer (0.1.15) libv8 (~> 6.3) - momentjs-rails (2.5.1) + momentjs-rails (2.20.1) railties (>= 3.1) money (5.1.0) i18n (~> 0.6.0) @@ -611,7 +611,7 @@ GEM thor (>= 0.14.6, < 2.0) rainbow (3.0.0) raindrops (0.19.0) - rake (12.3.1) + rake (12.3.2) ransack (0.7.2) actionpack (~> 3.0) activerecord (~> 3.0) From f7e03ca60e86c466762f4d55e0ddc21579c8653b Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Mon, 17 Dec 2018 04:02:46 +0800 Subject: [PATCH 47/60] Add Rake tasks openfoodnetwork:specs:engines:NAME:rspec The task name follows the directory name under engines/. For example, for the Web engine in engines/web, run: bundle exec rake openfoodnetwork:specs:engines:web:rspec --- lib/tasks/specs.rake | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 lib/tasks/specs.rake diff --git a/lib/tasks/specs.rake b/lib/tasks/specs.rake new file mode 100644 index 0000000000..544c011ce6 --- /dev/null +++ b/lib/tasks/specs.rake @@ -0,0 +1,30 @@ +namespace :openfoodnetwork do + namespace :specs do + namespace :engines do + def detect_engine_paths + Pathname("engines/").children.select(&:directory?) + end + + def engine_name_for_engine(engine_path) + engine_path.basename.to_path + end + + def execute_rspec_for_engine(engine_path) + system "cd #{engine_path.expand_path} && bundle exec rspec" + end + + engine_paths = detect_engine_paths + + engine_paths.each do |engine_path| + engine_name = engine_name_for_engine(engine_path) + + namespace engine_name do + task :rspec do + success = execute_rspec_for_engine(engine_path) + abort "Failure when running tests for engine \"#{engine_name}\"" unless success + end + end + end + end + end +end From 571ad37c3ef89b97c9761103339c7b04fe05f048 Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Mon, 17 Dec 2018 04:04:10 +0800 Subject: [PATCH 48/60] Add Rake task openfoodnetwork:specs:engines:rspec --- lib/tasks/specs.rake | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/tasks/specs.rake b/lib/tasks/specs.rake index 544c011ce6..ef092a0bd8 100644 --- a/lib/tasks/specs.rake +++ b/lib/tasks/specs.rake @@ -25,6 +25,20 @@ namespace :openfoodnetwork do end end end + + namespace :all do + task :rspec do + success = true + + engine_paths.each do |engine_path| + success = !!execute_rspec_for_engine(engine_path) && success + end + + abort "Failure encountered when running tests for engines" unless success + end + end + + task rspec: "all:rspec" end end end From 74ea1eee6b28716ec3de9a006bce7aa131ef1069 Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Mon, 17 Dec 2018 03:46:48 +0800 Subject: [PATCH 49/60] Add description for Rake tasks --- lib/tasks/specs.rake | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/tasks/specs.rake b/lib/tasks/specs.rake index ef092a0bd8..6f9b2068cf 100644 --- a/lib/tasks/specs.rake +++ b/lib/tasks/specs.rake @@ -19,6 +19,7 @@ namespace :openfoodnetwork do engine_name = engine_name_for_engine(engine_path) namespace engine_name do + desc "Run RSpec tests for engine \"#{engine_name}\"" task :rspec do success = execute_rspec_for_engine(engine_path) abort "Failure when running tests for engine \"#{engine_name}\"" unless success @@ -27,6 +28,7 @@ namespace :openfoodnetwork do end namespace :all do + desc "Run RSpec tests for all engines" task :rspec do success = true @@ -38,6 +40,7 @@ namespace :openfoodnetwork do end end + desc "Alias for openfoodnetwork:specs:engines:all:rspec" task rspec: "all:rspec" end end From 12780b722ed36363a7dc926111c58b817a77c2bf Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Tue, 20 Nov 2018 18:33:08 +0800 Subject: [PATCH 50/60] Make Travis CI run RSpec tests in app engines --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index dcb097a3e0..db818fad23 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,7 +18,7 @@ env: - CI_NODE_INDEX=0 - CI_NODE_INDEX=1 - CI_NODE_INDEX=2 - - CI_NODE_INDEX=3 + - CI_NODE_INDEX=3 RSPEC_ENGINES="true" - CI_NODE_INDEX=4 KARMA="true" GITHUB_DEPLOY="true" before_script: @@ -39,6 +39,7 @@ before_script: script: - 'if [ "$KARMA" = "true" ]; then bundle exec rake karma:run; else echo "Skipping karma run"; fi' + - 'if [ "$RSPEC_ENGINES" = "true" ]; then bundle exec rake openfoodnetwork:specs:engines:rspec; else echo "Skipping RSpec run in engines"; fi' - "bundle exec rake 'knapsack:rspec[--format progress --tag ~performance]'" after_success: From abcb71f8b37578cf8ede91d3de89968c329d75ee Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Tue, 20 Nov 2018 21:35:53 +1100 Subject: [PATCH 51/60] Document running app engine RSpec tests --- GETTING_STARTED.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/GETTING_STARTED.md b/GETTING_STARTED.md index 93cff8dad0..5a2e7eea54 100644 --- a/GETTING_STARTED.md +++ b/GETTING_STARTED.md @@ -69,10 +69,14 @@ Tests, both unit and integration, are based on RSpec. To run the test suite, fir bundle exec rake db:test:prepare -Then the tests can be run with: +Then the main application tests can be run with: bundle exec rspec spec +The tests of all custom engines can be run with: + + bundle exec rake openfoodnetwork:specs:engines:rspec + Note: If your OS is not explicitly supported in the setup guides then not all tests may pass. However, you may still be able to develop. Get in touch with the [#dev][slack-dev] channel on Slack to troubleshoot issues and determine if they will preclude you from contributing to OFN. Note: The time zone on your machine should match the one defined in `config/application.yml`. From a460e9d35fd1a19c286a3607761e379caecac51d Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Wed, 21 Nov 2018 15:41:32 +0800 Subject: [PATCH 52/60] Allow disabling Knapsack when running RSpec tests --- spec/spec_helper.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c198a68fbb..66924edea8 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -6,9 +6,13 @@ require 'rubygems' # Require pry when we're not inside Travis-CI require 'pry' unless ENV['CI'] -require 'knapsack' -Knapsack.tracker.config({enable_time_offset_warning: false}) unless ENV['CI'] -Knapsack::Adapters::RSpecAdapter.bind +# This spec_helper.rb is being used by the custom engines in engines/. The engines are not set up to +# use Knapsack, and this provides the option to disable it when running the tests in CI services. +unless ENV['DISABLE_KNAPSACK'] + require 'knapsack' + Knapsack.tracker.config({enable_time_offset_warning: false}) unless ENV['CI'] + Knapsack::Adapters::RSpecAdapter.bind +end ENV["RAILS_ENV"] ||= 'test' require_relative "../config/environment" From 4adae0a1e84d08eb5c21d02e5e3a3efbf0f67688 Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Wed, 19 Dec 2018 17:50:10 +0800 Subject: [PATCH 53/60] Disable Knapsack when running engine RSpec tests --- lib/tasks/specs.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/specs.rake b/lib/tasks/specs.rake index 6f9b2068cf..dddb5ffb54 100644 --- a/lib/tasks/specs.rake +++ b/lib/tasks/specs.rake @@ -10,7 +10,7 @@ namespace :openfoodnetwork do end def execute_rspec_for_engine(engine_path) - system "cd #{engine_path.expand_path} && bundle exec rspec" + system "cd #{engine_path.expand_path} && DISABLE_KNAPSACK=true bundle exec rspec" end engine_paths = detect_engine_paths From e680559169f382043d7e1c0e6c66c2c90bf4fba2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" Date: Thu, 20 Dec 2018 19:18:59 +0000 Subject: [PATCH 54/60] Bump guard from 2.14.1 to 2.15.0 Bumps [guard](https://github.com/guard/guard) from 2.14.1 to 2.15.0. - [Release notes](https://github.com/guard/guard/releases) - [Changelog](https://github.com/guard/guard/blob/master/CHANGELOG.md) - [Commits](https://github.com/guard/guard/compare/v2.14.1...v2.15.0) Signed-off-by: dependabot[bot] --- Gemfile.lock | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index b7abc02c6a..8ee213c3a4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -452,10 +452,10 @@ GEM ruby-progressbar (~> 1.4) geocoder (1.1.8) gmaps4rails (1.5.6) - guard (2.14.1) + guard (2.15.0) formatador (>= 0.2.4) listen (>= 2.7, < 4.0) - lumberjack (~> 1.0) + lumberjack (>= 1.0.12, < 2.0) nenv (~> 0.1) notiffany (~> 0.0) pry (>= 0.9.12) @@ -515,11 +515,11 @@ GEM listen (3.0.8) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) - lumberjack (1.0.12) + lumberjack (1.0.13) mail (2.5.5) mime-types (~> 1.16) treetop (~> 1.4.8) - method_source (0.9.0) + method_source (0.9.2) mime-types (1.25.1) mini_mime (1.0.1) mini_portile2 (2.1.0) @@ -571,7 +571,7 @@ GEM activerecord (~> 3.0) polyglot (0.3.5) powerpack (0.1.1) - pry (0.11.2) + pry (0.12.2) coderay (~> 1.1.0) method_source (~> 0.9.0) pry-byebug (3.4.3) From 5d515712edc368682b4dd0a63805e008e3b7b0d8 Mon Sep 17 00:00:00 2001 From: albarnaz Date: Fri, 21 Dec 2018 01:42:28 -0200 Subject: [PATCH 55/60] Fix for instagram links (#2849) * Add new attribute instagram_placeholder to local yml * Add placeholder to instagram link input * Add migration to fix wrong instagram links * Add new attribute facebook_placeholder to local yml * Add placeholder to facebook link input * Add new attribute linkedin_placeholder to local yml * Add placeholder to linkedin link input * Change each for find_each in migration * Add new attribute instagram_placeholder to local yml * Add migration to fix wrong instagram links * Add new attribute linkedin_placeholder to local yml * Add placeholder to linkedin link input --- app/views/admin/enterprises/form/_social.html.haml | 6 +++--- config/locales/en.yml | 3 +++ db/migrate/20181008201815_update_instagram_data.rb | 8 ++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20181008201815_update_instagram_data.rb diff --git a/app/views/admin/enterprises/form/_social.html.haml b/app/views/admin/enterprises/form/_social.html.haml index 11939739c1..0df88d7d46 100644 --- a/app/views/admin/enterprises/form/_social.html.haml +++ b/app/views/admin/enterprises/form/_social.html.haml @@ -2,17 +2,17 @@ .alpha.three.columns = f.label :facebook, 'Facebook' .omega.eight.columns - = f.text_field :facebook + = f.text_field :facebook, { placeholder: t('.facebook_placeholder') } .row .alpha.three.columns = f.label :instagram, 'Instagram' .omega.eight.columns - = f.text_field :instagram + = f.text_field :instagram, { placeholder: t('.instagram_placeholder') } .row .alpha.three.columns = f.label :linkedin, 'LinkedIn' .omega.eight.columns - = f.text_field :linkedin + = f.text_field :linkedin, { placeholder: t('.linkedin_placeholder') } .row .alpha.three.columns = f.label :twitter diff --git a/config/locales/en.yml b/config/locales/en.yml index 5775c90452..6fc4f61cbe 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -776,6 +776,9 @@ en: close_date: Close Date social: twitter_placeholder: eg. @the_prof + instagram_placeholder: eg. the_prof + facebook_placeholder: eg. www.facebook.com/PageNameHere + linkedin_placeholder: eg. www.linkedin.com/in/YourNameHere stripe_connect: connect_with_stripe: "Connect with Stripe" stripe_connect_intro: "To accept payments using credit card, you will need to connect your stripe account to the Open Food Network. Use the button to the right to get started." diff --git a/db/migrate/20181008201815_update_instagram_data.rb b/db/migrate/20181008201815_update_instagram_data.rb new file mode 100644 index 0000000000..d1a45dc155 --- /dev/null +++ b/db/migrate/20181008201815_update_instagram_data.rb @@ -0,0 +1,8 @@ +class UpdateInstagramData < ActiveRecord::Migration + def change + Enterprise.where("instagram like ?", "%instagram.com%").find_each do |e| + e.instagram = e.instagram.split('/').last + e.save + end + end +end From fd21914a15818b4d0ea41676cbd1b6ce286f0e0c Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Wed, 26 Dec 2018 12:47:52 +0000 Subject: [PATCH 56/60] Add spring, a rails preloader alternative to zeus, to our gemfile Add /bin to gitignore, bin is used by spring, rails preloader --- .gitignore | 1 + Gemfile | 2 ++ Gemfile.lock | 5 +++++ 3 files changed, 8 insertions(+) diff --git a/.gitignore b/.gitignore index 370eba9a90..21ff15e147 100644 --- a/.gitignore +++ b/.gitignore @@ -43,3 +43,4 @@ vendor/bundle/ coverage /reports/ !/reports/README.md +bin/ diff --git a/Gemfile b/Gemfile index c2762a6aa9..f354ea0512 100644 --- a/Gemfile +++ b/Gemfile @@ -145,6 +145,8 @@ group :development do gem 'guard-rails' gem 'guard-rspec', '~> 4.7.3' gem 'rubocop', '>= 0.49.1' + gem 'spring', '=1.1.3' + gem 'spring-commands-rspec' # 1.0.9 fixed openssl issues on macOS https://github.com/eventmachine/eventmachine/issues/602 # While we don't require this gem directly, no dependents forced the upgrade to a version diff --git a/Gemfile.lock b/Gemfile.lock index b7abc02c6a..adffe1f781 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -696,6 +696,9 @@ GEM rails (>= 3.1) spreadsheet (1.1.4) ruby-ole (>= 1.0) + spring (1.1.3) + spring-commands-rspec (1.0.4) + spring (>= 0.9.1) sprockets (2.2.3) hike (~> 1.2) multi_json (~> 1.0) @@ -839,6 +842,8 @@ DEPENDENCIES spree_auth_devise! spree_i18n! spree_paypal_express! + spring (= 1.1.3) + spring-commands-rspec stripe (~> 3.3.2) timecop truncate_html From 817093770801ced6881b5fdabde0694807e86b78 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" Date: Thu, 27 Dec 2018 19:16:35 +0000 Subject: [PATCH 57/60] Bump webmock from 3.4.2 to 3.5.1 Bumps [webmock](https://github.com/bblimke/webmock) from 3.4.2 to 3.5.1. - [Release notes](https://github.com/bblimke/webmock/releases) - [Changelog](https://github.com/bblimke/webmock/blob/master/CHANGELOG.md) - [Commits](https://github.com/bblimke/webmock/compare/v3.4.2...v3.5.1) Signed-off-by: dependabot[bot] --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 8ee213c3a4..2278403ebb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -733,7 +733,7 @@ GEM railties (>= 3.0) warden (1.2.7) rack (>= 1.0) - webmock (3.4.2) + webmock (3.5.1) addressable (>= 2.3.6) crack (>= 0.3.2) hashdiff From 112080d8c63982249dcff55c6ddc49ce28ae80ef Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Wed, 2 Jan 2019 13:10:33 +0100 Subject: [PATCH 58/60] Fix menu_1_url translation for fr_BE The first menu item in OFN BE is currently broken. --- config/locales/fr_BE.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/locales/fr_BE.yml b/config/locales/fr_BE.yml index 7a2990aeda..97fb8d6710 100644 --- a/config/locales/fr_BE.yml +++ b/config/locales/fr_BE.yml @@ -1144,7 +1144,7 @@ fr_BE: ticket_column_unit_price: "Prix unitaire" ticket_column_total_price: "Prix total" menu_1_title: "Comptoir" - menu_1_url: "/Comptoir" + menu_1_url: "/shops" menu_2_title: "Carte" menu_2_url: "/map" menu_3_title: "Producteurs" From 89bf819b37645fbdcc667dcc3e43a45f88020b38 Mon Sep 17 00:00:00 2001 From: Transifex-Openfoodnetwork Date: Thu, 3 Jan 2019 00:33:56 +1100 Subject: [PATCH 59/60] Updating translations for config/locales/en_US.yml --- config/locales/en_US.yml | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/config/locales/en_US.yml b/config/locales/en_US.yml index 3ede2a5dc4..4da7c84c1f 100644 --- a/config/locales/en_US.yml +++ b/config/locales/en_US.yml @@ -24,6 +24,11 @@ en_US: attributes: orders_close_at: after_orders_open_at: must be after open date + variant_override: + count_on_hand: + using_producer_stock_settings_but_count_on_hand_set: "must be blank because using producer stock settings" + on_demand_but_count_on_hand_set: "must be blank if on demand" + limited_stock_but_no_count_on_hand: "must be specified because forcing limited stock" activemodel: errors: models: @@ -195,6 +200,7 @@ en_US: admin_and_handling: Admin & Handling profile: Profile supplier_only: Supplier Only + has_shopfront: Has Shopfront weight: Weight volume: Volume items: Items @@ -219,6 +225,7 @@ en_US: password_confirmation: Password Confirmation reset_password_token: Reset password token expired: has expired, please request a new one + back_to_payments_list: "Back to Payments List" actions: create_and_add_another: "Create and Add Another" admin: @@ -572,6 +579,7 @@ en_US: tip: "Use this page to alter product quantities across multiple orders. Products may also be removed from orders entirely, if required." shared: "Shared Resource?" order_no: "Order No." + order_date: "Completed at" max: "Max" product_unit: "Product: Unit" weight_volume: "Weight/Volume" @@ -712,6 +720,9 @@ en_US: close_date: Close Date social: twitter_placeholder: eg. @the_prof + instagram_placeholder: eg. the_prof + facebook_placeholder: eg. www.facebook.com/PageNameHere + linkedin_placeholder: eg. www.linkedin.com/in/YourNameHere stripe_connect: connect_with_stripe: "Connect with Stripe" stripe_connect_intro: "To accept payments using credit card, you will need to connect your stripe account to the Open Food Network. Use the button to the right to get started." @@ -1702,6 +1713,11 @@ en_US: update_and_recalculate_fees: "Update And Recalculate Fees" registration: steps: + images: + continue: "Continue" + back: "Back" + headline: "Thanks!" + description: "Let's upload some pretty pictures so your profile looks great! :)" type: headline: "Last step to add %{enterprise}!" question: "Are you a producer?" @@ -1836,8 +1852,6 @@ en_US: registration_type_error: "Please choose one. Are you are producer?" registration_type_producer_help: "Producers make yummy things to eat and/or drink. You're a producer if you grow it, raise it, brew it, bake it, ferment it, milk it or mould it." registration_type_no_producer_help: "If you’re not a producer, you’re probably someone who sells and distributes food. You might be a hub, coop, buying group, retailer, wholesaler or other." - registration_images_headline: "Thanks!" - registration_images_description: "Let's upload some pretty pictures so your profile looks great! :)" registration_detail_headline: "Let's get started" registration_detail_enterprise: "Hooray! First we need to know a little bit about your enterprise:" registration_detail_producer: "Oh Yeah! First we need to know a little bit about your farm:" @@ -2234,6 +2248,7 @@ en_US: validation_msg_relationship_already_established: "^That relationship is already established." validation_msg_at_least_one_hub: "^At least one hub must be selected" validation_msg_product_category_cant_be_blank: "^Product Category cant be blank" + validation_msg_tax: "^Tax Category is required" validation_msg_tax_category_cant_be_blank: "^Tax Category can't be blank" validation_msg_is_associated_with_an_exising_customer: "is associated with an existing customer" content_configuration_pricing_table: "(TODO: Pricing table)" @@ -2434,7 +2449,14 @@ en_US: in your cart have reduced. Here's what's changed: now_out_of_stock: is now out of stock. only_n_remainging: "now only has %{num} remaining." + variants: + on_demand: + 'yes': "On demand" variant_overrides: + on_demand: + use_producer_settings: "Use producer stock settings" + 'yes': "Yes" + 'no': "No" inventory_products: "Inventory Products" hidden_products: "Hidden Products" new_products: "New Products" @@ -2538,6 +2560,12 @@ en_US: other: "You have %{count} active order cycles." manage_order_cycles: "MANAGE ORDER CYCLES" payment_methods: + new: + new_payment_method: "New Payment Method" + back_to_payment_methods_list: "Back To Payment Methods List" + edit: + editing_payment_method: "Editing Payment Method" + back_to_payment_methods_list: "Back To Payment Methods List" stripe_connect: enterprise_select_placeholder: Choose... loading_account_information_msg: Loading account information from stripe, please wait... @@ -2598,14 +2626,21 @@ en_US: bulk_coop_customer_payments: 'Bulk Co-op - Customer Payments' users: index: + listing_users: "Listing Users" + new_user: "New User" user: "User" enterprise_limit: "Enterprise Limit" search: "Search" email: "Email" + edit: + editing_user: "Editing User" + back_to_users_list: "Back To Users List" + general_settings: "General Settings" form: email: "Email" roles: "Roles" enterprise_limit: "Enterprise Limit" + confirm_password: "Confirm Password" password: "Password" email_confirmation: confirmation_pending: "Email confirmation is pending. We've sent a confirmation email to %{address}." From 9da7ff5698bbf47f7a5c9d3dbe102251467429e3 Mon Sep 17 00:00:00 2001 From: Transifex-Openfoodnetwork Date: Fri, 4 Jan 2019 02:15:57 +1100 Subject: [PATCH 60/60] Updating translations for config/locales/fr.yml --- config/locales/fr.yml | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 16c118266a..1fa30bd680 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -24,6 +24,11 @@ fr: attributes: orders_close_at: after_orders_open_at: doit être postérieure à Date d'ouverture + variant_override: + count_on_hand: + using_producer_stock_settings_but_count_on_hand_set: "doit être vide car utilise les informations de stock du producteur" + on_demand_but_count_on_hand_set: "doit être vide si \"à volonté\"" + limited_stock_but_no_count_on_hand: "doit être spécifié car pas \"à volonté\"" activemodel: errors: models: @@ -117,7 +122,7 @@ fr: explainer: Ces commandes ont été traitées mais pour certains produits, le stock était insuffisant empty: title: Pas de stock (%{count} commandes) - explainer: Ces commandes n'ont pas pu être traitées car les produits souhaités étaient en rupture de stok + explainer: Ces commandes n'ont pas pu être traitées car les produits souhaités étaient en rupture de stock complete: title: Déjà traité (%{count} commandes) explainer: Ces commandes étaient déjà marquées comme passées, et n'ont donc pas été retouchées @@ -716,6 +721,9 @@ fr: close_date: Date de fermeture social: twitter_placeholder: ex. @OpenFoodNet_fr + instagram_placeholder: 'ex: OpenFoodNet_fr' + facebook_placeholder: 'ex: www.facebook.com/NomDeLaPage' + linkedin_placeholder: 'ex: www.linkedin.com/in/VotreNom' stripe_connect: connect_with_stripe: "Connecter avec Stripe" stripe_connect_intro: "Pour accepter des paiements utilisant la carte bancaire, vous devez connecter votre compte Stripe à Open Food France. Cliquez sur le bouton à droite pour commencer." @@ -1706,6 +1714,11 @@ fr: update_and_recalculate_fees: "Mettre à jour et recalculer les frais" registration: steps: + images: + continue: "Suivant" + back: "Retour" + headline: "Merci!" + description: "Ajoutez maintenant de jolies photos pour que votre profil soit attractif! :)" type: headline: "Dernière étape pour ajouter %{enterprise} !" question: "Etes-vous un producteur ?" @@ -1840,8 +1853,6 @@ fr: registration_type_error: "Veuillez faire un choix. Etes vous un producteur?" registration_type_producer_help: "Un producteur fabrique de bonnes choses à boire et à manger. Vous êtes un producteur si vous les faites pousser, les élevez, les pétrissez, transformez, fermentez, les réduisez en grains, etc." registration_type_no_producer_help: "Si vous n'êtes pas un producteur, vous êtes probablement un revendeur ou distributeur alimentaire: un \"hub\", une coopérative, un groupement d'achat, un revendeur, un grossiste, ou autre." - registration_images_headline: "Merci!" - registration_images_description: "Ajoutez maintenant de jolies photos pour que votre profil soit attractif! :)" registration_detail_headline: "Commençons" registration_detail_enterprise: "Woohoo! Dites-nous déjà quelques mots à propos de votre entreprise:" registration_detail_producer: "Woohoo! Dites-nous déjà quelques mots à propos de votre ferme:" @@ -2450,7 +2461,14 @@ fr: à votre demande. Voilà les modifications opérées: now_out_of_stock: est maintenant en rupture de stock. only_n_remainging: "plus que %{num} en stock." + variants: + on_demand: + 'yes': "A volonté" variant_overrides: + on_demand: + use_producer_settings: "Utiliser les infos de stock producteur" + 'yes': "Oui" + 'no': "Non" inventory_products: "Produits du Catalogue Boutique" hidden_products: "Produits Masqués" new_products: "Nouveaux Produits" @@ -2554,6 +2572,12 @@ fr: other: "Vous avez %{count} cycles de vente actifs." manage_order_cycles: "GERER LES CYCLES DE VENTE" payment_methods: + new: + new_payment_method: "Nouvelle méthode de paiement" + back_to_payment_methods_list: "Retour à la liste des méthodes de paiement" + edit: + editing_payment_method: "Modification de la méthode de paiement" + back_to_payment_methods_list: "Retour à la liste des méthodes de paiement" stripe_connect: enterprise_select_placeholder: Choisir... loading_account_information_msg: Informations de compte en cours de chargement depuis Stripe, veuillez patienter...