From 3e2117134fbf8d177bf1e171ba65ff1a951b05d5 Mon Sep 17 00:00:00 2001 From: Rick Giner Date: Sun, 10 May 2015 16:50:00 +1000 Subject: [PATCH 01/11] ginerr_#531_remove Google map road markers --- .../javascripts/darkswarm/services/map_configuration.js.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/darkswarm/services/map_configuration.js.coffee b/app/assets/javascripts/darkswarm/services/map_configuration.js.coffee index 8f1d735357..9c5a375d8c 100644 --- a/app/assets/javascripts/darkswarm/services/map_configuration.js.coffee +++ b/app/assets/javascripts/darkswarm/services/map_configuration.js.coffee @@ -7,5 +7,5 @@ Darkswarm.factory "MapConfiguration", -> zoom: 12 additional_options: {} #mapTypeId: 'satellite' - styles: [{"featureType":"landscape","stylers":[{"saturation":-100},{"lightness":65},{"visibility":"on"}]},{"featureType":"poi","stylers":[{"saturation":-100},{"lightness":51},{"visibility":"simplified"}]},{"featureType":"road.highway","stylers":[{"saturation":-100},{"visibility":"simplified"}]},{"featureType":"road.arterial","stylers":[{"saturation":-100},{"lightness":30},{"visibility":"on"}]},{"featureType":"road.local","stylers":[{"saturation":-100},{"lightness":40},{"visibility":"on"}]},{"featureType":"transit","stylers":[{"saturation":-100},{"visibility":"simplified"}]},{"featureType":"administrative.province","stylers":[{"visibility":"off"}]},{"featureType":"water","elementType":"labels","stylers":[{"visibility":"on"},{"lightness":-25},{"saturation":-100}]},{"featureType":"water","elementType":"geometry","stylers":[{"hue":"#ffff00"},{"lightness":-25},{"saturation":-97}]}] + styles: [{"featureType":"landscape","stylers":[{"saturation":-100},{"lightness":65},{"visibility":"on"}]},{"featureType":"poi","stylers":[{"saturation":-100},{"lightness":51},{"visibility":"simplified"}]},{"featureType":"road.highway","stylers":[{"saturation":-100},{"visibility":"simplified"}]},{"featureType":"road.arterial","stylers":[{"saturation":-100},{"lightness":30},{"visibility":"on"}]},{"featureType":"road.local","stylers":[{"saturation":-100},{"lightness":40},{"visibility":"on"}]},{"featureType":"transit","stylers":[{"saturation":-100},{"visibility":"simplified"}]},{"featureType":"administrative.province","stylers":[{"visibility":"off"}]},{"featureType":"water","elementType":"labels","stylers":[{"visibility":"on"},{"lightness":-25},{"saturation":-100}]},{"featureType":"water","elementType":"geometry","stylers":[{"hue":"#ffff00"},{"lightness":-25},{"saturation":-97}]},{"featureType":"road","elementType": "labels.icon","stylers":[{"visibility":"off"}]}] From 9c3ec950fcd27a5d8163560fa48efa188ad95c84 Mon Sep 17 00:00:00 2001 From: Rick Giner Date: Sun, 10 May 2015 16:50:58 +1000 Subject: [PATCH 02/11] Revert "ginerr_#531_remove Google map road markers" This reverts commit 3e2117134fbf8d177bf1e171ba65ff1a951b05d5. --- .../javascripts/darkswarm/services/map_configuration.js.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/darkswarm/services/map_configuration.js.coffee b/app/assets/javascripts/darkswarm/services/map_configuration.js.coffee index 9c5a375d8c..8f1d735357 100644 --- a/app/assets/javascripts/darkswarm/services/map_configuration.js.coffee +++ b/app/assets/javascripts/darkswarm/services/map_configuration.js.coffee @@ -7,5 +7,5 @@ Darkswarm.factory "MapConfiguration", -> zoom: 12 additional_options: {} #mapTypeId: 'satellite' - styles: [{"featureType":"landscape","stylers":[{"saturation":-100},{"lightness":65},{"visibility":"on"}]},{"featureType":"poi","stylers":[{"saturation":-100},{"lightness":51},{"visibility":"simplified"}]},{"featureType":"road.highway","stylers":[{"saturation":-100},{"visibility":"simplified"}]},{"featureType":"road.arterial","stylers":[{"saturation":-100},{"lightness":30},{"visibility":"on"}]},{"featureType":"road.local","stylers":[{"saturation":-100},{"lightness":40},{"visibility":"on"}]},{"featureType":"transit","stylers":[{"saturation":-100},{"visibility":"simplified"}]},{"featureType":"administrative.province","stylers":[{"visibility":"off"}]},{"featureType":"water","elementType":"labels","stylers":[{"visibility":"on"},{"lightness":-25},{"saturation":-100}]},{"featureType":"water","elementType":"geometry","stylers":[{"hue":"#ffff00"},{"lightness":-25},{"saturation":-97}]},{"featureType":"road","elementType": "labels.icon","stylers":[{"visibility":"off"}]}] + styles: [{"featureType":"landscape","stylers":[{"saturation":-100},{"lightness":65},{"visibility":"on"}]},{"featureType":"poi","stylers":[{"saturation":-100},{"lightness":51},{"visibility":"simplified"}]},{"featureType":"road.highway","stylers":[{"saturation":-100},{"visibility":"simplified"}]},{"featureType":"road.arterial","stylers":[{"saturation":-100},{"lightness":30},{"visibility":"on"}]},{"featureType":"road.local","stylers":[{"saturation":-100},{"lightness":40},{"visibility":"on"}]},{"featureType":"transit","stylers":[{"saturation":-100},{"visibility":"simplified"}]},{"featureType":"administrative.province","stylers":[{"visibility":"off"}]},{"featureType":"water","elementType":"labels","stylers":[{"visibility":"on"},{"lightness":-25},{"saturation":-100}]},{"featureType":"water","elementType":"geometry","stylers":[{"hue":"#ffff00"},{"lightness":-25},{"saturation":-97}]}] From 98c1a95bd18892627af8a73f8cf967d2a0e1ff03 Mon Sep 17 00:00:00 2001 From: Rick Giner Date: Sun, 10 May 2015 16:51:56 +1000 Subject: [PATCH 03/11] Issue #531 remove Google map road markers --- .../javascripts/darkswarm/services/map_configuration.js.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/darkswarm/services/map_configuration.js.coffee b/app/assets/javascripts/darkswarm/services/map_configuration.js.coffee index 8f1d735357..9c5a375d8c 100644 --- a/app/assets/javascripts/darkswarm/services/map_configuration.js.coffee +++ b/app/assets/javascripts/darkswarm/services/map_configuration.js.coffee @@ -7,5 +7,5 @@ Darkswarm.factory "MapConfiguration", -> zoom: 12 additional_options: {} #mapTypeId: 'satellite' - styles: [{"featureType":"landscape","stylers":[{"saturation":-100},{"lightness":65},{"visibility":"on"}]},{"featureType":"poi","stylers":[{"saturation":-100},{"lightness":51},{"visibility":"simplified"}]},{"featureType":"road.highway","stylers":[{"saturation":-100},{"visibility":"simplified"}]},{"featureType":"road.arterial","stylers":[{"saturation":-100},{"lightness":30},{"visibility":"on"}]},{"featureType":"road.local","stylers":[{"saturation":-100},{"lightness":40},{"visibility":"on"}]},{"featureType":"transit","stylers":[{"saturation":-100},{"visibility":"simplified"}]},{"featureType":"administrative.province","stylers":[{"visibility":"off"}]},{"featureType":"water","elementType":"labels","stylers":[{"visibility":"on"},{"lightness":-25},{"saturation":-100}]},{"featureType":"water","elementType":"geometry","stylers":[{"hue":"#ffff00"},{"lightness":-25},{"saturation":-97}]}] + styles: [{"featureType":"landscape","stylers":[{"saturation":-100},{"lightness":65},{"visibility":"on"}]},{"featureType":"poi","stylers":[{"saturation":-100},{"lightness":51},{"visibility":"simplified"}]},{"featureType":"road.highway","stylers":[{"saturation":-100},{"visibility":"simplified"}]},{"featureType":"road.arterial","stylers":[{"saturation":-100},{"lightness":30},{"visibility":"on"}]},{"featureType":"road.local","stylers":[{"saturation":-100},{"lightness":40},{"visibility":"on"}]},{"featureType":"transit","stylers":[{"saturation":-100},{"visibility":"simplified"}]},{"featureType":"administrative.province","stylers":[{"visibility":"off"}]},{"featureType":"water","elementType":"labels","stylers":[{"visibility":"on"},{"lightness":-25},{"saturation":-100}]},{"featureType":"water","elementType":"geometry","stylers":[{"hue":"#ffff00"},{"lightness":-25},{"saturation":-97}]},{"featureType":"road","elementType": "labels.icon","stylers":[{"visibility":"off"}]}] From b7c1a43125b711c00899ff293bc8fcdc8eec1b65 Mon Sep 17 00:00:00 2001 From: Rick Giner Date: Sun, 10 May 2015 18:13:30 +1000 Subject: [PATCH 04/11] Issue #540 Fix up hub list navigation --- .../controllers/hub_node_controller.js.coffee | 4 ++-- .../stylesheets/darkswarm/hub_node.css.sass | 9 +++++++++ app/views/home/_skinny.html.haml | 15 ++++++++++----- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/darkswarm/controllers/hub_node_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/hub_node_controller.js.coffee index e73ca5fa27..922dc8abb4 100644 --- a/app/assets/javascripts/darkswarm/controllers/hub_node_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/hub_node_controller.js.coffee @@ -1,6 +1,6 @@ Darkswarm.controller "HubNodeCtrl", ($scope, HashNavigation, Navigation, $location, $templateCache, CurrentHub) -> - $scope.toggle = -> - HashNavigation.toggle $scope.hub.hash + $scope.toggle = (e) -> + HashNavigation.toggle $scope.hub.hash if !angular.element(e.target).inheritedData('is-link') $scope.open = -> HashNavigation.active $scope.hub.hash diff --git a/app/assets/stylesheets/darkswarm/hub_node.css.sass b/app/assets/stylesheets/darkswarm/hub_node.css.sass index d02f9b5299..87bc9addef 100644 --- a/app/assets/stylesheets/darkswarm/hub_node.css.sass +++ b/app/assets/stylesheets/darkswarm/hub_node.css.sass @@ -30,9 +30,18 @@ float: right margin-left: 0.5rem + //Hub Link + @media all and (max-width: 640px) + a.hub + display: block + //Hub Name span.hub-name-listing font-weight: 700 + &:after + content: ">>" + display: inline-block + margin-left: 5px //CLOSED row &.closed diff --git a/app/views/home/_skinny.html.haml b/app/views/home/_skinny.html.haml index cf001371f7..c69e4beaaa 100644 --- a/app/views/home/_skinny.html.haml +++ b/app/views/home/_skinny.html.haml @@ -1,7 +1,7 @@ -.row.active_table_row{"ng-if" => "hub.is_distributor", "ng-click" => "toggle()", "ng-class" => "{'closed' : !open(), 'is_distributor' : producer.is_distributor}", bindonce: true} +.row.active_table_row{"ng-if" => "hub.is_distributor", "ng-click" => "toggle($event)", "ng-class" => "{'closed' : !open(), 'is_distributor' : producer.is_distributor}", bindonce: true} - .columns.small-12.medium-6.large-5.skinny-head - %a.hub{"bo-href" => "hub.path", "ng-class" => "{primary: hub.active, secondary: !hub.active}", "ofn-empties-cart" => "hub"} + .columns.small-12.medium-5.large-5.skinny-head + %a.hub{"bo-href" => "hub.path", "ng-class" => "{primary: hub.active, secondary: !hub.active}", "ofn-empties-cart" => "hub", "data-is-link" => "true"} %i{bo: {class: "hub.icon_font"}} %span.margin-top.hub-name-listing{"bo-bind" => "hub.name | truncate:40"} @@ -10,7 +10,7 @@ .columns.small-2.medium-1.large-1 %span.margin-top{"bo-bind" => "hub.address.state_name | uppercase"} - .columns.small-6.medium-3.large-4.text-right{"bo-if" => "hub.active"} + .columns.small-4.medium-3.large-3.text-right{"bo-if" => "hub.active"} %a.hub.open_closed{"bo-href" => "hub.path", "ng-class" => "{primary: hub.active, secondary: !hub.active}", "ofn-empties-cart" => "hub"} %i.ofn-i_033-open-sign %span.margin-top{ bo: { if: "current()" } } @@ -18,13 +18,17 @@ %span.margin-top{ bo: { if: "!current()" } } %span{"bo-bind" => "hub.orders_close_at | sensible_timeframe"} - .columns.small-6.medium-3.large-4.text-right{"bo-if" => "!hub.active"} + .columns.small-4.medium-3.large-3.text-right{"bo-if" => "!hub.active"} %a.hub.open_closed{"bo-href" => "hub.path", "ng-class" => "{primary: hub.active, secondary: !hub.active}", "ofn-empties-cart" => "hub"} %i.ofn-i_032-closed-sign %span.margin-top{ bo: { if: "current()" } } %em Shopping here %span.margin-top{ bo: { if: "!current()" } } Orders closed + .columns.small-2.medium-1.large-1.text-right + %span.margin-top + %i{"ng-class" => "{'ofn-i_005-caret-down' : !open(), 'ofn-i_006-caret-up' : open()}"} + .row.active_table_row{"ng-if" => "!hub.is_distributor", "ng-class" => "closed"} .columns.small-12.medium-6.large-5.skinny-head %a.hub{"ng-click" => "openModal(hub)", "ng-class" => "{primary: hub.active, secondary: !hub.active}"} @@ -39,3 +43,4 @@ .columns.small-6.medium-3.large-4.text-right %span.margin-top{ bo: { if: "!current()" } } %em Profile only + From e801d6199a5aec1bdffeff1c1b19b1408c7766f2 Mon Sep 17 00:00:00 2001 From: Rick Giner Date: Mon, 11 May 2015 20:33:35 +1000 Subject: [PATCH 05/11] Passing in $event in other views that call toggle() --- app/views/home/_fat.html.haml | 2 +- app/views/producers/_fat.html.haml | 2 +- app/views/producers/_skinny.html.haml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/home/_fat.html.haml b/app/views/home/_fat.html.haml index 6796601637..8242f3c6fe 100644 --- a/app/views/home/_fat.html.haml +++ b/app/views/home/_fat.html.haml @@ -1,4 +1,4 @@ -.row.active_table_row{"ng-show" => "open()", "ng-click" => "toggle()", "ng-class" => "{'open' : !ofn-i_032-closed-sign()}"} +.row.active_table_row{"ng-show" => "open()", "ng-click" => "toggle($event)", "ng-class" => "{'open' : !ofn-i_032-closed-sign()}"} .columns.small-12.medium-6.large-5.fat %div{"bo-if" => "hub.taxons"} %label Shop for diff --git a/app/views/producers/_fat.html.haml b/app/views/producers/_fat.html.haml index a6d6661501..99099a31f8 100644 --- a/app/views/producers/_fat.html.haml +++ b/app/views/producers/_fat.html.haml @@ -1,4 +1,4 @@ -.row.active_table_row{"ng-if" => "open()", "ng-click" => "toggle()", "ng-class" => "{'open' : !ofn-i_032-closed-sign()}"} +.row.active_table_row{"ng-if" => "open()", "ng-click" => "toggle($event)", "ng-class" => "{'open' : !ofn-i_032-closed-sign()}"} .columns.small-12.medium-7.large-7.fat / Will add in long description available once clean up HTML formatting producer.long_description diff --git a/app/views/producers/_skinny.html.haml b/app/views/producers/_skinny.html.haml index 49ab0a35be..11860d35d6 100644 --- a/app/views/producers/_skinny.html.haml +++ b/app/views/producers/_skinny.html.haml @@ -1,4 +1,4 @@ -.row.active_table_row{"ng-click" => "toggle()", "ng-class" => "{'closed' : !open(), 'is_distributor' : producer.is_distributor}"} +.row.active_table_row{"ng-click" => "toggle($event)", "ng-class" => "{'closed' : !open(), 'is_distributor' : producer.is_distributor}"} .columns.small-12.medium-4.large-4.skinny-head %span{"bo-if" => "producer.is_distributor" } %a.is_distributor{"bo-href" => "producer.path" } From ee01113fe10ddb441c435d06a5f86b85ec9d6200 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 10 Jun 2015 15:31:53 +1000 Subject: [PATCH 06/11] Fix duplicate factory value spec error --- spec/factories.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/factories.rb b/spec/factories.rb index 5e1f985778..bdb99b3235 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -212,7 +212,7 @@ FactoryGirl.define do factory :customer, :class => Customer do email { Faker::Internet.email } enterprise - code { Faker::Lorem.word } + code { SecureRandom.base64(150) } user end end From d79129880ecfd85d0a48b052af659162647926d9 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 10 Jun 2015 17:02:30 +1000 Subject: [PATCH 07/11] Put lock around adjustment clear/re-create to avoid race condition resulting in duplicate fees --- app/models/spree/order_decorator.rb | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/app/models/spree/order_decorator.rb b/app/models/spree/order_decorator.rb index 3c0f212945..df478d8d2f 100644 --- a/app/models/spree/order_decorator.rb +++ b/app/models/spree/order_decorator.rb @@ -157,20 +157,22 @@ Spree::Order.class_eval do end def update_distribution_charge! - EnterpriseFee.clear_all_adjustments_on_order self + with_lock do + EnterpriseFee.clear_all_adjustments_on_order self - line_items.each do |line_item| - if provided_by_order_cycle? line_item - OpenFoodNetwork::EnterpriseFeeCalculator.new.create_line_item_adjustments_for line_item + line_items.each do |line_item| + if provided_by_order_cycle? line_item + OpenFoodNetwork::EnterpriseFeeCalculator.new.create_line_item_adjustments_for line_item - else - pd = product_distribution_for line_item - pd.create_adjustment_for line_item if pd + else + pd = product_distribution_for line_item + pd.create_adjustment_for line_item if pd + end end - end - if order_cycle - OpenFoodNetwork::EnterpriseFeeCalculator.new.create_order_adjustments_for self + if order_cycle + OpenFoodNetwork::EnterpriseFeeCalculator.new.create_order_adjustments_for self + end end end From a0fd91dc57dace93d1e200624cebdfca8b4e1a5a Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 10 Jun 2015 17:03:56 +1000 Subject: [PATCH 08/11] Do not preload_app with unicorn, update newrelic agent so that it doesn't require this setting. --- Gemfile.lock | 2 +- config/unicorn.rb | 29 ++--------------------------- 2 files changed, 3 insertions(+), 28 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index eddc27ee84..864870b280 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -354,7 +354,7 @@ GEM net-scp (1.1.2) net-ssh (>= 2.6.5) net-ssh (2.6.8) - newrelic_rpm (3.6.7.152) + newrelic_rpm (3.12.0.288) nokogiri (1.6.6.2) mini_portile (~> 0.6.0) oj (2.1.2) diff --git a/config/unicorn.rb b/config/unicorn.rb index e5d7317940..22e954b4d0 100644 --- a/config/unicorn.rb +++ b/config/unicorn.rb @@ -1,27 +1,2 @@ -preload_app true # https://newrelic.com/docs/ruby/no-data-with-unicorn -worker_processes 4 # amount of unicorn workers to spin up -timeout 60 # restarts workers that hang for 30 seconds - - -# https://devcenter.heroku.com/articles/forked-pg-connections -before_fork do |server, worker| - - Signal.trap 'TERM' do - puts 'Unicorn master intercepting TERM and sending myself QUIT instead' - Process.kill 'QUIT', Process.pid - end - - defined?(ActiveRecord::Base) and - ActiveRecord::Base.connection.disconnect! -end - -after_fork do |server, worker| - - Signal.trap 'TERM' do - puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to sent QUIT' - end - - defined?(ActiveRecord::Base) and - ActiveRecord::Base.establish_connection - -end +worker_processes 2 # amount of unicorn workers to spin up +timeout 120 # restarts workers that hang for 30 seconds From 604360034b6fffe3c2253c2734b626e0e0205cc4 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 10 Jun 2015 17:04:09 +1000 Subject: [PATCH 09/11] Make filter method private --- app/controllers/spree/api/line_items_controller_decorator.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/controllers/spree/api/line_items_controller_decorator.rb b/app/controllers/spree/api/line_items_controller_decorator.rb index 35fca864f4..5493c74043 100644 --- a/app/controllers/spree/api/line_items_controller_decorator.rb +++ b/app/controllers/spree/api/line_items_controller_decorator.rb @@ -1,5 +1,8 @@ Spree::Api::LineItemsController.class_eval do - after_filter :apply_enterprise_fees, :only => :update + after_filter :apply_enterprise_fees, only: :update + + + private def apply_enterprise_fees authorize! :read, order From bfeb63c8d7f84799ba64dd2dfb60cd0f67907c96 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Thu, 11 Jun 2015 14:16:18 +1000 Subject: [PATCH 10/11] Ensure that changes to Spree::Config.products_require_tax_category do not leak out of the relevant spec --- spec/features/admin/products_spec.rb | 43 +++++++++++++++------------- spec/models/spree/product_spec.rb | 4 +-- spec/spec_helper.rb | 1 + spec/support/products_helper.rb | 12 ++++++++ 4 files changed, 38 insertions(+), 22 deletions(-) create mode 100644 spec/support/products_helper.rb diff --git a/spec/features/admin/products_spec.rb b/spec/features/admin/products_spec.rb index a82674ddaf..57b3aa0dfe 100644 --- a/spec/features/admin/products_spec.rb +++ b/spec/features/admin/products_spec.rb @@ -117,31 +117,34 @@ feature %q{ end end - scenario "creating a new product", js: true do - Spree::Config.products_require_tax_category = false - click_link 'Products' - click_link 'New Product' + context "products do not require a tax category" do + around { |example| with_products_require_tax_category(false) { example.run } } - fill_in 'product_name', :with => 'A new product !!!' - fill_in 'product_price', :with => '19.99' + scenario "creating a new product", js: true do + click_link 'Products' + click_link 'New Product' - page.should have_selector('#product_supplier_id') - select 'Another Supplier', :from => 'product_supplier_id' - select 'Weight (g)', from: 'product_variant_unit_with_scale' - fill_in 'product_unit_value_with_description', with: '500' - select taxon.name, from: "product_primary_taxon_id" - select 'None', from: "product_tax_category_id" + fill_in 'product_name', :with => 'A new product !!!' + fill_in 'product_price', :with => '19.99' - # Should only have suppliers listed which the user can manage - page.should have_select 'product_supplier_id', with_options: [@supplier2.name, @supplier_permitted.name] - page.should_not have_select 'product_supplier_id', with_options: [@supplier.name] + page.should have_selector('#product_supplier_id') + select 'Another Supplier', :from => 'product_supplier_id' + select 'Weight (g)', from: 'product_variant_unit_with_scale' + fill_in 'product_unit_value_with_description', with: '500' + select taxon.name, from: "product_primary_taxon_id" + select 'None', from: "product_tax_category_id" - click_button 'Create' + # Should only have suppliers listed which the user can manage + page.should have_select 'product_supplier_id', with_options: [@supplier2.name, @supplier_permitted.name] + page.should_not have_select 'product_supplier_id', with_options: [@supplier.name] - flash_message.should == 'Product "A new product !!!" has been successfully created!' - product = Spree::Product.find_by_name('A new product !!!') - product.supplier.should == @supplier2 - product.tax_category.should be_nil + click_button 'Create' + + flash_message.should == 'Product "A new product !!!" has been successfully created!' + product = Spree::Product.find_by_name('A new product !!!') + product.supplier.should == @supplier2 + product.tax_category.should be_nil + end end scenario "editing a product" do diff --git a/spec/models/spree/product_spec.rb b/spec/models/spree/product_spec.rb index 505ac8ee2e..dfaf715b35 100644 --- a/spec/models/spree/product_spec.rb +++ b/spec/models/spree/product_spec.rb @@ -40,7 +40,7 @@ module Spree describe "tax category" do context "when a tax category is required" do - before { Spree::Config.products_require_tax_category = true } + around { |example| with_products_require_tax_category(true) { example.run } } it "is invalid when a tax category is not provided" do build(:product, tax_category_id: nil).should_not be_valid @@ -48,7 +48,7 @@ module Spree end context "when a tax category is not required" do - before { Spree::Config.products_require_tax_category = false } + around { |example| with_products_require_tax_category(false) { example.run } } it "is valid when a tax category is not provided" do build(:product, tax_category_id: nil).should be_valid diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a911fe7742..2b3903dece 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -91,6 +91,7 @@ RSpec.configure do |config| config.include OpenFoodNetwork::ControllerHelper, :type => :controller config.include OpenFoodNetwork::FeatureToggleHelper config.include OpenFoodNetwork::EnterpriseGroupsHelper + config.include OpenFoodNetwork::ProductsHelper config.include OpenFoodNetwork::DistributionHelper config.include OpenFoodNetwork::HtmlHelper config.include ActionView::Helpers::DateHelper diff --git a/spec/support/products_helper.rb b/spec/support/products_helper.rb new file mode 100644 index 0000000000..8e9ebc1c98 --- /dev/null +++ b/spec/support/products_helper.rb @@ -0,0 +1,12 @@ +module OpenFoodNetwork + module ProductsHelper + def with_products_require_tax_category(value) + original_value = Spree::Config.products_require_tax_category + + Spree::Config.products_require_tax_category = value + yield + ensure + Spree::Config.products_require_tax_category = original_value + end + end +end From ecbf3c8fa7febbc6df078292db3c07685a9c9aaa Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Thu, 11 Jun 2015 16:16:36 +1000 Subject: [PATCH 11/11] Ensure we start with consistent config settings --- spec/spec_helper.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2b3903dece..20dfcc8bca 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -80,6 +80,9 @@ RSpec.configure do |config| # Geocoding config.before(:each) { Spree::Address.any_instance.stub(:geocode).and_return([1,1]) } + # Ensure we start with consistent config settings + config.before(:all) { Spree::Config.products_require_tax_category = false } + # Helpers config.include Rails.application.routes.url_helpers config.include Spree::UrlHelpers