diff --git a/Gemfile.lock b/Gemfile.lock index 00569c7fa6..e0a2e5e8ce 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -353,7 +353,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/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"}]}] diff --git a/app/assets/stylesheets/darkswarm/hub_node.css.sass b/app/assets/stylesheets/darkswarm/hub_node.css.sass index 94950fa22c..4d175681f2 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/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 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 diff --git a/app/views/home/_skinny.html.haml b/app/views/home/_skinny.html.haml index 9cf7a01c77..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($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 + 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 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 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..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 @@ -91,6 +94,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