From 32069cffe101193220b6e43320ae51a1de91413a Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Tue, 5 Jun 2018 18:42:19 +0200 Subject: [PATCH 1/3] Revert "Removing useless spaces" This reverts commit d81b6be25990b056ae57641e99bc673ed5db9fc9. --- app/controllers/base_controller.rb | 2 +- app/controllers/spree/orders_controller_decorator.rb | 8 ++++---- app/helpers/enterprises_helper.rb | 2 +- app/helpers/order_cycles_helper.rb | 2 +- app/helpers/shared_helper.rb | 2 +- app/helpers/spree/orders_helper.rb | 2 +- app/services/reset_order_service.rb | 2 +- app/views/spree/products/_add_to_cart.html.haml | 2 +- .../spree/products/_distributor_details.html.haml | 2 +- app/views/spree/products/_source.html.haml | 2 +- spec/controllers/checkout_controller_spec.rb | 2 +- spec/controllers/enterprises_controller_spec.rb | 2 +- spec/controllers/spree/checkout_controller_spec.rb | 2 +- spec/controllers/spree/orders_controller_spec.rb | 10 +++++----- spec/controllers/spree/paypal_controller_spec.rb | 2 +- spec/performance/orders_controller_spec.rb | 2 +- 16 files changed, 23 insertions(+), 23 deletions(-) diff --git a/app/controllers/base_controller.rb b/app/controllers/base_controller.rb index 14f7e52371..58a6c932b3 100644 --- a/app/controllers/base_controller.rb +++ b/app/controllers/base_controller.rb @@ -37,7 +37,7 @@ class BaseController < ApplicationController # And default to the only order cycle if there's only the one if @order_cycles.count == 1 - current_order(create_order_if_necessary: true).set_order_cycle! @order_cycles.first + current_order( create_order_if_necessary: true ).set_order_cycle! @order_cycles.first end end end diff --git a/app/controllers/spree/orders_controller_decorator.rb b/app/controllers/spree/orders_controller_decorator.rb index 739aad3a7d..2816ab6e26 100644 --- a/app/controllers/spree/orders_controller_decorator.rb +++ b/app/controllers/spree/orders_controller_decorator.rb @@ -18,7 +18,7 @@ Spree::OrdersController.class_eval do # Patching to redirect to shop if order is empty def edit - @order = current_order(create_order_if_necessary: true) + @order = current_order( create_order_if_necessary: true ) @insufficient_stock_lines = @order.insufficient_stock_lines if @order.line_items.empty? @@ -78,7 +78,7 @@ Spree::OrdersController.class_eval do # callbacks on Spree::Adjustment and then manually invoke Spree::Order#update! on success. Spree::Adjustment.without_callbacks do - populator = Spree::OrderPopulator.new(current_order(create_order_if_necessary: true), current_currency) + populator = Spree::OrderPopulator.new(current_order( create_order_if_necessary: true ), current_currency) if populator.populate(params.slice(:products, :variants, :quantity), true) fire_event('spree.cart.add') @@ -127,7 +127,7 @@ Spree::OrdersController.class_eval do end def update_distribution - @order = current_order(create_order_if_necessary: true) + @order = current_order( create_order_if_necessary: true ) if params[:commit] == 'Choose Hub' distributor = Enterprise.is_distributor.find params[:order][:distributor_id] @@ -159,7 +159,7 @@ Spree::OrdersController.class_eval do end def clear - @order = current_order(create_order_if_necessary: true) + @order = current_order( create_order_if_necessary: true ) @order.empty! @order.set_order_cycle! nil redirect_to main_app.enterprise_path(@order.distributor.id) diff --git a/app/helpers/enterprises_helper.rb b/app/helpers/enterprises_helper.rb index 549c86f573..511c55df04 100644 --- a/app/helpers/enterprises_helper.rb +++ b/app/helpers/enterprises_helper.rb @@ -2,7 +2,7 @@ require 'open_food_network/available_payment_method_filter' module EnterprisesHelper def current_distributor - @current_distributor ||= current_order(create_order_if_necessary: false).andand.distributor + @current_distributor ||= current_order( create_order_if_necessary: false ).andand.distributor end def current_customer diff --git a/app/helpers/order_cycles_helper.rb b/app/helpers/order_cycles_helper.rb index 064582aba5..07a0ea488a 100644 --- a/app/helpers/order_cycles_helper.rb +++ b/app/helpers/order_cycles_helper.rb @@ -1,6 +1,6 @@ module OrderCyclesHelper def current_order_cycle - @current_order_cycle ||= current_order(create_order_if_necessary: false).andand.order_cycle + @current_order_cycle ||= current_order( create_order_if_necessary: false ).andand.order_cycle end def permitted_enterprises_for(order_cycle) diff --git a/app/helpers/shared_helper.rb b/app/helpers/shared_helper.rb index bacf123814..253dceacb5 100644 --- a/app/helpers/shared_helper.rb +++ b/app/helpers/shared_helper.rb @@ -1,6 +1,6 @@ module SharedHelper def distributor_link_class(distributor) - cart = current_order(create_order_if_necessary: true) + cart = current_order( create_order_if_necessary: true ) @active_distributors ||= Enterprise.distributors_with_active_order_cycles klass = "shop-distributor" diff --git a/app/helpers/spree/orders_helper.rb b/app/helpers/spree/orders_helper.rb index a37f409199..12e90bd482 100644 --- a/app/helpers/spree/orders_helper.rb +++ b/app/helpers/spree/orders_helper.rb @@ -1,7 +1,7 @@ module Spree module OrdersHelper def cart_is_empty - order = current_order(create_order_if_necessary: false) + order = current_order( create_order_if_necessary: false ) order.nil? || order.line_items.empty? end diff --git a/app/services/reset_order_service.rb b/app/services/reset_order_service.rb index 95e73290c9..3ffdf1ffb5 100644 --- a/app/services/reset_order_service.rb +++ b/app/services/reset_order_service.rb @@ -23,7 +23,7 @@ class ResetOrderService # Builds an order setting the token and distributor of the one specified def build_new_order - new_order = controller.current_order(create_order_if_necessary: true) + new_order = controller.current_order( create_order_if_necessary: true ) new_order.set_distributor!(distributor) new_order.tokenized_permission.token = token new_order.tokenized_permission.save! diff --git a/app/views/spree/products/_add_to_cart.html.haml b/app/views/spree/products/_add_to_cart.html.haml index dbc09929b7..e5d5248f2f 100644 --- a/app/views/spree/products/_add_to_cart.html.haml +++ b/app/views/spree/products/_add_to_cart.html.haml @@ -1,5 +1,5 @@ .add-to-cart - - order = current_order(create_order_if_necessary: false) + - order = current_order( create_order_if_necessary: false ) - if product_out_of_stock = content_tag('strong', t(:out_of_stock)) diff --git a/app/views/spree/products/_distributor_details.html.haml b/app/views/spree/products/_distributor_details.html.haml index 1329a03f8a..f044c622a7 100644 --- a/app/views/spree/products/_distributor_details.html.haml +++ b/app/views/spree/products/_distributor_details.html.haml @@ -2,7 +2,7 @@ %legend = t :products_distributor .distributor-details - - order = current_order(create_order_if_necessary: false) + - order = current_order( create_order_if_necessary: false ) - if order.andand.distributor.present? = render 'enterprises/distributor_details', :distributor => order.distributor - else diff --git a/app/views/spree/products/_source.html.haml b/app/views/spree/products/_source.html.haml index 461a4dc6c9..8c5ac66fe3 100644 --- a/app/views/spree/products/_source.html.haml +++ b/app/views/spree/products/_source.html.haml @@ -10,7 +10,7 @@ %h6.product-section-title= t(:distributors) %table#product-source.table-display{:width => "100%"} %tbody - - order = current_order(create_order_if_necessary: false) + - order = current_order( create_order_if_necessary: false ) - validator = DistributionChangeValidator.new(order) - Enterprise.distributing_products(@product).each do |distributor| - if !order.nil? && distributor == order.distributor diff --git a/spec/controllers/checkout_controller_spec.rb b/spec/controllers/checkout_controller_spec.rb index 5335b1f387..151af21ae8 100644 --- a/spec/controllers/checkout_controller_spec.rb +++ b/spec/controllers/checkout_controller_spec.rb @@ -94,7 +94,7 @@ describe CheckoutController, type: :controller do end it "sets the new order's token to the same as the old order" do - order = controller.current_order(create_order_if_necessary: true) + order = controller.current_order( create_order_if_necessary: true ) spree_post :update, order: {} expect(controller.current_order.token).to eq order.token end diff --git a/spec/controllers/enterprises_controller_spec.rb b/spec/controllers/enterprises_controller_spec.rb index bcd434302e..d459c937fb 100644 --- a/spec/controllers/enterprises_controller_spec.rb +++ b/spec/controllers/enterprises_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' describe EnterprisesController, type: :controller do describe "shopping for a distributor" do - let(:order) { controller.current_order(create_order_if_necessary: true) } + let(:order) { controller.current_order( create_order_if_necessary: true ) } let!(:current_distributor) { create(:distributor_enterprise, with_payment_and_shipping: true) } diff --git a/spec/controllers/spree/checkout_controller_spec.rb b/spec/controllers/spree/checkout_controller_spec.rb index 37bd483d55..47537e2133 100644 --- a/spec/controllers/spree/checkout_controller_spec.rb +++ b/spec/controllers/spree/checkout_controller_spec.rb @@ -5,7 +5,7 @@ require 'support/request/authentication_workflow' describe Spree::CheckoutController, type: :controller do context 'rendering edit from within spree for the current checkout state' do - let(:order) { controller.current_order(create_order_if_necessary: true) } + let(:order) { controller.current_order( create_order_if_necessary: true ) } let(:user) { create(:user) } before do diff --git a/spec/controllers/spree/orders_controller_spec.rb b/spec/controllers/spree/orders_controller_spec.rb index ce15c8cacc..9574d5f41b 100644 --- a/spec/controllers/spree/orders_controller_spec.rb +++ b/spec/controllers/spree/orders_controller_spec.rb @@ -30,7 +30,7 @@ describe Spree::OrdersController, type: :controller do it "redirects home with message if hub is not ready for checkout" do VariantOverride.stub(:indexed).and_return({}) - order = subject.current_order(create_order_if_necessary: true) + order = subject.current_order( create_order_if_necessary: true ) distributor.stub(:ready_for_checkout?) { false } order.stub(distributor: distributor, order_cycle: order_cycle) @@ -44,7 +44,7 @@ describe Spree::OrdersController, type: :controller do end describe "when an item has insufficient stock" do - let(:order) { subject.current_order(create_order_if_necessary: true) } + let(:order) { subject.current_order( create_order_if_necessary: true ) } let(:oc) { create(:simple_order_cycle, distributors: [d], variants: [variant]) } let(:d) { create(:distributor_enterprise, shipping_methods: [create(:shipping_method)], payment_methods: [create(:payment_method)]) } let(:variant) { create(:variant, on_demand: false, on_hand: 5) } @@ -129,7 +129,7 @@ describe Spree::OrdersController, type: :controller do distributor_product = create(:distributor_enterprise) p = create(:product, :distributors => [distributor_product], :group_buy => true) - order = subject.current_order(create_order_if_necessary: true) + order = subject.current_order( create_order_if_necessary: true ) order.stub(:distributor) { distributor_product } order.should_receive(:set_variant_attributes).with(p.master, {'max_quantity' => '3'}) controller.stub(:current_order).and_return(order) @@ -164,7 +164,7 @@ describe Spree::OrdersController, type: :controller do describe "removing line items from cart" do describe "when I pass params that includes a line item no longer in our cart" do it "should silently ignore the missing line item" do - order = subject.current_order(create_order_if_necessary: true) + order = subject.current_order( create_order_if_necessary: true ) li = order.add_variant(create(:simple_product, on_hand: 110).variants.first) spree_get :update, order: { line_items_attributes: { "0" => {quantity: "0", id: "9999"}, @@ -176,7 +176,7 @@ describe Spree::OrdersController, type: :controller do end it "filters line items that are missing from params" do - order = subject.current_order(create_order_if_necessary: true) + order = subject.current_order( create_order_if_necessary: true ) li = order.add_variant(create(:simple_product).master) attrs = { diff --git a/spec/controllers/spree/paypal_controller_spec.rb b/spec/controllers/spree/paypal_controller_spec.rb index 4843eef98d..4ce004183c 100644 --- a/spec/controllers/spree/paypal_controller_spec.rb +++ b/spec/controllers/spree/paypal_controller_spec.rb @@ -9,7 +9,7 @@ module Spree end context 'when confirming' do - let(:previous_order) { controller.current_order(create_order_if_necessary: true) } + let(:previous_order) { controller.current_order( create_order_if_necessary: true ) } let(:payment_method) { create(:payment_method) } before do diff --git a/spec/performance/orders_controller_spec.rb b/spec/performance/orders_controller_spec.rb index ee85690121..58adf05540 100644 --- a/spec/performance/orders_controller_spec.rb +++ b/spec/performance/orders_controller_spec.rb @@ -4,7 +4,7 @@ describe Spree::OrdersController, type: :controller, performance: true do let(:distributor) { create(:distributor_enterprise) } let(:order_cycle) { create(:simple_order_cycle, distributors: [distributor], variants: products.map { |p| p.variants.first }) } let(:products) { (0...num_products).map { create(:product) } } - let(:order) { subject.current_order(create_order_if_necessary: true) } + let(:order) { subject.current_order( create_order_if_necessary: true ) } let(:num_products) { 20 } before do From 89c2733f509c93634a413a17a6b161b5be6deee7 Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Tue, 5 Jun 2018 18:42:31 +0200 Subject: [PATCH 2/3] Revert "Removing redundant curly braces" This reverts commit 03173d4f7b113cc9f1e093cca1809ed86bcea132. --- app/controllers/base_controller.rb | 2 +- app/controllers/enterprises_controller.rb | 4 ++-- app/controllers/shop_controller.rb | 2 +- app/controllers/spree/orders_controller_decorator.rb | 8 ++++---- app/helpers/enterprises_helper.rb | 2 +- app/helpers/order_cycles_helper.rb | 2 +- app/helpers/shared_helper.rb | 2 +- app/helpers/spree/orders_helper.rb | 2 +- app/services/reset_order_service.rb | 2 +- app/views/spree/products/_add_to_cart.html.haml | 2 +- .../spree/products/_distributor_details.html.haml | 2 +- app/views/spree/products/_source.html.haml | 2 +- spec/controllers/checkout_controller_spec.rb | 2 +- spec/controllers/enterprises_controller_spec.rb | 2 +- spec/controllers/spree/checkout_controller_spec.rb | 2 +- spec/controllers/spree/orders_controller_spec.rb | 10 +++++----- spec/controllers/spree/paypal_controller_spec.rb | 2 +- spec/performance/orders_controller_spec.rb | 2 +- 18 files changed, 26 insertions(+), 26 deletions(-) diff --git a/app/controllers/base_controller.rb b/app/controllers/base_controller.rb index 58a6c932b3..18bc679fbe 100644 --- a/app/controllers/base_controller.rb +++ b/app/controllers/base_controller.rb @@ -37,7 +37,7 @@ class BaseController < ApplicationController # And default to the only order cycle if there's only the one if @order_cycles.count == 1 - current_order( create_order_if_necessary: true ).set_order_cycle! @order_cycles.first + current_order({ create_order_if_necessary: true }).set_order_cycle! @order_cycles.first end end end diff --git a/app/controllers/enterprises_controller.rb b/app/controllers/enterprises_controller.rb index 17874c7e0e..88621ec53c 100644 --- a/app/controllers/enterprises_controller.rb +++ b/app/controllers/enterprises_controller.rb @@ -49,14 +49,14 @@ class EnterprisesController < BaseController end def check_stock_levels - if current_order(create_order_if_necessary: true).insufficient_stock_lines.present? + if current_order({ create_order_if_necessary: true }).insufficient_stock_lines.present? redirect_to spree.cart_path end end def reset_order distributor = Enterprise.is_distributor.find_by_permalink(params[:id]) || Enterprise.is_distributor.find(params[:id]) - order = current_order(create_order_if_necessary: true) + order = current_order({ create_order_if_necessary: true }) reset_distributor(order, distributor) diff --git a/app/controllers/shop_controller.rb b/app/controllers/shop_controller.rb index c127e24ca9..b9136c01bb 100644 --- a/app/controllers/shop_controller.rb +++ b/app/controllers/shop_controller.rb @@ -26,7 +26,7 @@ class ShopController < BaseController def order_cycle if request.post? if oc = OrderCycle.with_distributor(@distributor).active.find_by_id(params[:order_cycle_id]) - current_order(create_order_if_necessary: true).set_order_cycle! oc + current_order({ create_order_if_necessary: true }).set_order_cycle! oc render partial: "json/order_cycle" else render status: 404, json: "" diff --git a/app/controllers/spree/orders_controller_decorator.rb b/app/controllers/spree/orders_controller_decorator.rb index 2816ab6e26..9d22a33b64 100644 --- a/app/controllers/spree/orders_controller_decorator.rb +++ b/app/controllers/spree/orders_controller_decorator.rb @@ -18,7 +18,7 @@ Spree::OrdersController.class_eval do # Patching to redirect to shop if order is empty def edit - @order = current_order( create_order_if_necessary: true ) + @order = current_order({ create_order_if_necessary: true }) @insufficient_stock_lines = @order.insufficient_stock_lines if @order.line_items.empty? @@ -78,7 +78,7 @@ Spree::OrdersController.class_eval do # callbacks on Spree::Adjustment and then manually invoke Spree::Order#update! on success. Spree::Adjustment.without_callbacks do - populator = Spree::OrderPopulator.new(current_order( create_order_if_necessary: true ), current_currency) + populator = Spree::OrderPopulator.new(current_order({ create_order_if_necessary: true }), current_currency) if populator.populate(params.slice(:products, :variants, :quantity), true) fire_event('spree.cart.add') @@ -127,7 +127,7 @@ Spree::OrdersController.class_eval do end def update_distribution - @order = current_order( create_order_if_necessary: true ) + @order = current_order({ create_order_if_necessary: true }) if params[:commit] == 'Choose Hub' distributor = Enterprise.is_distributor.find params[:order][:distributor_id] @@ -159,7 +159,7 @@ Spree::OrdersController.class_eval do end def clear - @order = current_order( create_order_if_necessary: true ) + @order = current_order({ create_order_if_necessary: true }) @order.empty! @order.set_order_cycle! nil redirect_to main_app.enterprise_path(@order.distributor.id) diff --git a/app/helpers/enterprises_helper.rb b/app/helpers/enterprises_helper.rb index 511c55df04..432ef6777c 100644 --- a/app/helpers/enterprises_helper.rb +++ b/app/helpers/enterprises_helper.rb @@ -2,7 +2,7 @@ require 'open_food_network/available_payment_method_filter' module EnterprisesHelper def current_distributor - @current_distributor ||= current_order( create_order_if_necessary: false ).andand.distributor + @current_distributor ||= current_order({ create_order_if_necessary: false }).andand.distributor end def current_customer diff --git a/app/helpers/order_cycles_helper.rb b/app/helpers/order_cycles_helper.rb index 07a0ea488a..6c83ca5d09 100644 --- a/app/helpers/order_cycles_helper.rb +++ b/app/helpers/order_cycles_helper.rb @@ -1,6 +1,6 @@ module OrderCyclesHelper def current_order_cycle - @current_order_cycle ||= current_order( create_order_if_necessary: false ).andand.order_cycle + @current_order_cycle ||= current_order({ create_order_if_necessary: false }).andand.order_cycle end def permitted_enterprises_for(order_cycle) diff --git a/app/helpers/shared_helper.rb b/app/helpers/shared_helper.rb index 253dceacb5..4ec9f88926 100644 --- a/app/helpers/shared_helper.rb +++ b/app/helpers/shared_helper.rb @@ -1,6 +1,6 @@ module SharedHelper def distributor_link_class(distributor) - cart = current_order( create_order_if_necessary: true ) + cart = current_order({ create_order_if_necessary: true }) @active_distributors ||= Enterprise.distributors_with_active_order_cycles klass = "shop-distributor" diff --git a/app/helpers/spree/orders_helper.rb b/app/helpers/spree/orders_helper.rb index 12e90bd482..78d45c34b8 100644 --- a/app/helpers/spree/orders_helper.rb +++ b/app/helpers/spree/orders_helper.rb @@ -1,7 +1,7 @@ module Spree module OrdersHelper def cart_is_empty - order = current_order( create_order_if_necessary: false ) + order = current_order({ create_order_if_necessary: false }) order.nil? || order.line_items.empty? end diff --git a/app/services/reset_order_service.rb b/app/services/reset_order_service.rb index 3ffdf1ffb5..ff369caee9 100644 --- a/app/services/reset_order_service.rb +++ b/app/services/reset_order_service.rb @@ -23,7 +23,7 @@ class ResetOrderService # Builds an order setting the token and distributor of the one specified def build_new_order - new_order = controller.current_order( create_order_if_necessary: true ) + new_order = controller.current_order({ create_order_if_necessary: true }) new_order.set_distributor!(distributor) new_order.tokenized_permission.token = token new_order.tokenized_permission.save! diff --git a/app/views/spree/products/_add_to_cart.html.haml b/app/views/spree/products/_add_to_cart.html.haml index e5d5248f2f..c2e967dd6d 100644 --- a/app/views/spree/products/_add_to_cart.html.haml +++ b/app/views/spree/products/_add_to_cart.html.haml @@ -1,5 +1,5 @@ .add-to-cart - - order = current_order( create_order_if_necessary: false ) + - order = current_order({ create_order_if_necessary: false }) - if product_out_of_stock = content_tag('strong', t(:out_of_stock)) diff --git a/app/views/spree/products/_distributor_details.html.haml b/app/views/spree/products/_distributor_details.html.haml index f044c622a7..e762ed97e1 100644 --- a/app/views/spree/products/_distributor_details.html.haml +++ b/app/views/spree/products/_distributor_details.html.haml @@ -2,7 +2,7 @@ %legend = t :products_distributor .distributor-details - - order = current_order( create_order_if_necessary: false ) + - order = current_order({ create_order_if_necessary: false }) - if order.andand.distributor.present? = render 'enterprises/distributor_details', :distributor => order.distributor - else diff --git a/app/views/spree/products/_source.html.haml b/app/views/spree/products/_source.html.haml index 8c5ac66fe3..ca952bb517 100644 --- a/app/views/spree/products/_source.html.haml +++ b/app/views/spree/products/_source.html.haml @@ -10,7 +10,7 @@ %h6.product-section-title= t(:distributors) %table#product-source.table-display{:width => "100%"} %tbody - - order = current_order( create_order_if_necessary: false ) + - order = current_order({ create_order_if_necessary: false }) - validator = DistributionChangeValidator.new(order) - Enterprise.distributing_products(@product).each do |distributor| - if !order.nil? && distributor == order.distributor diff --git a/spec/controllers/checkout_controller_spec.rb b/spec/controllers/checkout_controller_spec.rb index 151af21ae8..ed11ad2955 100644 --- a/spec/controllers/checkout_controller_spec.rb +++ b/spec/controllers/checkout_controller_spec.rb @@ -94,7 +94,7 @@ describe CheckoutController, type: :controller do end it "sets the new order's token to the same as the old order" do - order = controller.current_order( create_order_if_necessary: true ) + order = controller.current_order({ create_order_if_necessary: true }) spree_post :update, order: {} expect(controller.current_order.token).to eq order.token end diff --git a/spec/controllers/enterprises_controller_spec.rb b/spec/controllers/enterprises_controller_spec.rb index d459c937fb..7aef356a8d 100644 --- a/spec/controllers/enterprises_controller_spec.rb +++ b/spec/controllers/enterprises_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' describe EnterprisesController, type: :controller do describe "shopping for a distributor" do - let(:order) { controller.current_order( create_order_if_necessary: true ) } + let(:order) { controller.current_order({ create_order_if_necessary: true }) } let!(:current_distributor) { create(:distributor_enterprise, with_payment_and_shipping: true) } diff --git a/spec/controllers/spree/checkout_controller_spec.rb b/spec/controllers/spree/checkout_controller_spec.rb index 47537e2133..bc21a068bd 100644 --- a/spec/controllers/spree/checkout_controller_spec.rb +++ b/spec/controllers/spree/checkout_controller_spec.rb @@ -5,7 +5,7 @@ require 'support/request/authentication_workflow' describe Spree::CheckoutController, type: :controller do context 'rendering edit from within spree for the current checkout state' do - let(:order) { controller.current_order( create_order_if_necessary: true ) } + let(:order) { controller.current_order({ create_order_if_necessary: true }) } let(:user) { create(:user) } before do diff --git a/spec/controllers/spree/orders_controller_spec.rb b/spec/controllers/spree/orders_controller_spec.rb index 9574d5f41b..6aa80973b8 100644 --- a/spec/controllers/spree/orders_controller_spec.rb +++ b/spec/controllers/spree/orders_controller_spec.rb @@ -30,7 +30,7 @@ describe Spree::OrdersController, type: :controller do it "redirects home with message if hub is not ready for checkout" do VariantOverride.stub(:indexed).and_return({}) - order = subject.current_order( create_order_if_necessary: true ) + order = subject.current_order({ create_order_if_necessary: true }) distributor.stub(:ready_for_checkout?) { false } order.stub(distributor: distributor, order_cycle: order_cycle) @@ -44,7 +44,7 @@ describe Spree::OrdersController, type: :controller do end describe "when an item has insufficient stock" do - let(:order) { subject.current_order( create_order_if_necessary: true ) } + let(:order) { subject.current_order({ create_order_if_necessary: true }) } let(:oc) { create(:simple_order_cycle, distributors: [d], variants: [variant]) } let(:d) { create(:distributor_enterprise, shipping_methods: [create(:shipping_method)], payment_methods: [create(:payment_method)]) } let(:variant) { create(:variant, on_demand: false, on_hand: 5) } @@ -129,7 +129,7 @@ describe Spree::OrdersController, type: :controller do distributor_product = create(:distributor_enterprise) p = create(:product, :distributors => [distributor_product], :group_buy => true) - order = subject.current_order( create_order_if_necessary: true ) + order = subject.current_order({ create_order_if_necessary: true }) order.stub(:distributor) { distributor_product } order.should_receive(:set_variant_attributes).with(p.master, {'max_quantity' => '3'}) controller.stub(:current_order).and_return(order) @@ -164,7 +164,7 @@ describe Spree::OrdersController, type: :controller do describe "removing line items from cart" do describe "when I pass params that includes a line item no longer in our cart" do it "should silently ignore the missing line item" do - order = subject.current_order( create_order_if_necessary: true ) + order = subject.current_order({ create_order_if_necessary: true }) li = order.add_variant(create(:simple_product, on_hand: 110).variants.first) spree_get :update, order: { line_items_attributes: { "0" => {quantity: "0", id: "9999"}, @@ -176,7 +176,7 @@ describe Spree::OrdersController, type: :controller do end it "filters line items that are missing from params" do - order = subject.current_order( create_order_if_necessary: true ) + order = subject.current_order({ create_order_if_necessary: true }) li = order.add_variant(create(:simple_product).master) attrs = { diff --git a/spec/controllers/spree/paypal_controller_spec.rb b/spec/controllers/spree/paypal_controller_spec.rb index 4ce004183c..6c284858e8 100644 --- a/spec/controllers/spree/paypal_controller_spec.rb +++ b/spec/controllers/spree/paypal_controller_spec.rb @@ -9,7 +9,7 @@ module Spree end context 'when confirming' do - let(:previous_order) { controller.current_order( create_order_if_necessary: true ) } + let(:previous_order) { controller.current_order({ create_order_if_necessary: true }) } let(:payment_method) { create(:payment_method) } before do diff --git a/spec/performance/orders_controller_spec.rb b/spec/performance/orders_controller_spec.rb index 58adf05540..5b6fb97e95 100644 --- a/spec/performance/orders_controller_spec.rb +++ b/spec/performance/orders_controller_spec.rb @@ -4,7 +4,7 @@ describe Spree::OrdersController, type: :controller, performance: true do let(:distributor) { create(:distributor_enterprise) } let(:order_cycle) { create(:simple_order_cycle, distributors: [distributor], variants: products.map { |p| p.variants.first }) } let(:products) { (0...num_products).map { create(:product) } } - let(:order) { subject.current_order( create_order_if_necessary: true ) } + let(:order) { subject.current_order({ create_order_if_necessary: true }) } let(:num_products) { 20 } before do From daf12d1300e2fcb10b5c991b193a877df5c938c8 Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Tue, 5 Jun 2018 18:42:41 +0200 Subject: [PATCH 3/3] Revert "Refactor Order#current_order argument" This reverts commit ae935202be00ddddcce76a900d228f3121ba2d8b. --- app/controllers/base_controller.rb | 2 +- app/controllers/enterprises_controller.rb | 4 ++-- app/controllers/shop_controller.rb | 2 +- app/controllers/spree/orders_controller_decorator.rb | 8 ++++---- app/helpers/enterprises_helper.rb | 2 +- app/helpers/order_cycles_helper.rb | 2 +- app/helpers/shared_helper.rb | 2 +- app/helpers/spree/orders_helper.rb | 2 +- app/services/reset_order_service.rb | 2 +- app/views/spree/products/_add_to_cart.html.haml | 2 +- .../spree/products/_distributor_details.html.haml | 2 +- app/views/spree/products/_source.html.haml | 2 +- lib/spree/core/controller_helpers/order_decorator.rb | 4 ++-- spec/controllers/checkout_controller_spec.rb | 2 +- spec/controllers/enterprises_controller_spec.rb | 2 +- spec/controllers/spree/checkout_controller_spec.rb | 2 +- spec/controllers/spree/orders_controller_spec.rb | 10 +++++----- spec/controllers/spree/paypal_controller_spec.rb | 2 +- spec/performance/orders_controller_spec.rb | 2 +- 19 files changed, 28 insertions(+), 28 deletions(-) diff --git a/app/controllers/base_controller.rb b/app/controllers/base_controller.rb index 18bc679fbe..36bf72fd9c 100644 --- a/app/controllers/base_controller.rb +++ b/app/controllers/base_controller.rb @@ -37,7 +37,7 @@ class BaseController < ApplicationController # And default to the only order cycle if there's only the one if @order_cycles.count == 1 - current_order({ create_order_if_necessary: true }).set_order_cycle! @order_cycles.first + current_order(true).set_order_cycle! @order_cycles.first end end end diff --git a/app/controllers/enterprises_controller.rb b/app/controllers/enterprises_controller.rb index 88621ec53c..2b2a639b87 100644 --- a/app/controllers/enterprises_controller.rb +++ b/app/controllers/enterprises_controller.rb @@ -49,14 +49,14 @@ class EnterprisesController < BaseController end def check_stock_levels - if current_order({ create_order_if_necessary: true }).insufficient_stock_lines.present? + if current_order(true).insufficient_stock_lines.present? redirect_to spree.cart_path end end def reset_order distributor = Enterprise.is_distributor.find_by_permalink(params[:id]) || Enterprise.is_distributor.find(params[:id]) - order = current_order({ create_order_if_necessary: true }) + order = current_order(true) reset_distributor(order, distributor) diff --git a/app/controllers/shop_controller.rb b/app/controllers/shop_controller.rb index b9136c01bb..a32d5d0b85 100644 --- a/app/controllers/shop_controller.rb +++ b/app/controllers/shop_controller.rb @@ -26,7 +26,7 @@ class ShopController < BaseController def order_cycle if request.post? if oc = OrderCycle.with_distributor(@distributor).active.find_by_id(params[:order_cycle_id]) - current_order({ create_order_if_necessary: true }).set_order_cycle! oc + current_order(true).set_order_cycle! oc render partial: "json/order_cycle" else render status: 404, json: "" diff --git a/app/controllers/spree/orders_controller_decorator.rb b/app/controllers/spree/orders_controller_decorator.rb index 9d22a33b64..47425bcbf2 100644 --- a/app/controllers/spree/orders_controller_decorator.rb +++ b/app/controllers/spree/orders_controller_decorator.rb @@ -18,7 +18,7 @@ Spree::OrdersController.class_eval do # Patching to redirect to shop if order is empty def edit - @order = current_order({ create_order_if_necessary: true }) + @order = current_order(true) @insufficient_stock_lines = @order.insufficient_stock_lines if @order.line_items.empty? @@ -78,7 +78,7 @@ Spree::OrdersController.class_eval do # callbacks on Spree::Adjustment and then manually invoke Spree::Order#update! on success. Spree::Adjustment.without_callbacks do - populator = Spree::OrderPopulator.new(current_order({ create_order_if_necessary: true }), current_currency) + populator = Spree::OrderPopulator.new(current_order(true), current_currency) if populator.populate(params.slice(:products, :variants, :quantity), true) fire_event('spree.cart.add') @@ -127,7 +127,7 @@ Spree::OrdersController.class_eval do end def update_distribution - @order = current_order({ create_order_if_necessary: true }) + @order = current_order(true) if params[:commit] == 'Choose Hub' distributor = Enterprise.is_distributor.find params[:order][:distributor_id] @@ -159,7 +159,7 @@ Spree::OrdersController.class_eval do end def clear - @order = current_order({ create_order_if_necessary: true }) + @order = current_order(true) @order.empty! @order.set_order_cycle! nil redirect_to main_app.enterprise_path(@order.distributor.id) diff --git a/app/helpers/enterprises_helper.rb b/app/helpers/enterprises_helper.rb index 432ef6777c..8cef0281b1 100644 --- a/app/helpers/enterprises_helper.rb +++ b/app/helpers/enterprises_helper.rb @@ -2,7 +2,7 @@ require 'open_food_network/available_payment_method_filter' module EnterprisesHelper def current_distributor - @current_distributor ||= current_order({ create_order_if_necessary: false }).andand.distributor + @current_distributor ||= current_order(false).andand.distributor end def current_customer diff --git a/app/helpers/order_cycles_helper.rb b/app/helpers/order_cycles_helper.rb index 6c83ca5d09..8afca2b949 100644 --- a/app/helpers/order_cycles_helper.rb +++ b/app/helpers/order_cycles_helper.rb @@ -1,6 +1,6 @@ module OrderCyclesHelper def current_order_cycle - @current_order_cycle ||= current_order({ create_order_if_necessary: false }).andand.order_cycle + @current_order_cycle ||= current_order(false).andand.order_cycle end def permitted_enterprises_for(order_cycle) diff --git a/app/helpers/shared_helper.rb b/app/helpers/shared_helper.rb index 4ec9f88926..a1e1f84ec2 100644 --- a/app/helpers/shared_helper.rb +++ b/app/helpers/shared_helper.rb @@ -1,6 +1,6 @@ module SharedHelper def distributor_link_class(distributor) - cart = current_order({ create_order_if_necessary: true }) + cart = current_order(true) @active_distributors ||= Enterprise.distributors_with_active_order_cycles klass = "shop-distributor" diff --git a/app/helpers/spree/orders_helper.rb b/app/helpers/spree/orders_helper.rb index 78d45c34b8..99540f6ed4 100644 --- a/app/helpers/spree/orders_helper.rb +++ b/app/helpers/spree/orders_helper.rb @@ -1,7 +1,7 @@ module Spree module OrdersHelper def cart_is_empty - order = current_order({ create_order_if_necessary: false }) + order = current_order(false) order.nil? || order.line_items.empty? end diff --git a/app/services/reset_order_service.rb b/app/services/reset_order_service.rb index ff369caee9..402c377eb7 100644 --- a/app/services/reset_order_service.rb +++ b/app/services/reset_order_service.rb @@ -23,7 +23,7 @@ class ResetOrderService # Builds an order setting the token and distributor of the one specified def build_new_order - new_order = controller.current_order({ create_order_if_necessary: true }) + new_order = controller.current_order(true) new_order.set_distributor!(distributor) new_order.tokenized_permission.token = token new_order.tokenized_permission.save! diff --git a/app/views/spree/products/_add_to_cart.html.haml b/app/views/spree/products/_add_to_cart.html.haml index c2e967dd6d..dd406ff50b 100644 --- a/app/views/spree/products/_add_to_cart.html.haml +++ b/app/views/spree/products/_add_to_cart.html.haml @@ -1,5 +1,5 @@ .add-to-cart - - order = current_order({ create_order_if_necessary: false }) + - order = current_order(false) - if product_out_of_stock = content_tag('strong', t(:out_of_stock)) diff --git a/app/views/spree/products/_distributor_details.html.haml b/app/views/spree/products/_distributor_details.html.haml index e762ed97e1..e91c0ea6e5 100644 --- a/app/views/spree/products/_distributor_details.html.haml +++ b/app/views/spree/products/_distributor_details.html.haml @@ -2,7 +2,7 @@ %legend = t :products_distributor .distributor-details - - order = current_order({ create_order_if_necessary: false }) + - order = current_order(false) - if order.andand.distributor.present? = render 'enterprises/distributor_details', :distributor => order.distributor - else diff --git a/app/views/spree/products/_source.html.haml b/app/views/spree/products/_source.html.haml index ca952bb517..7751ba36ef 100644 --- a/app/views/spree/products/_source.html.haml +++ b/app/views/spree/products/_source.html.haml @@ -10,7 +10,7 @@ %h6.product-section-title= t(:distributors) %table#product-source.table-display{:width => "100%"} %tbody - - order = current_order({ create_order_if_necessary: false }) + - order = current_order(false) - validator = DistributionChangeValidator.new(order) - Enterprise.distributing_products(@product).each do |distributor| - if !order.nil? && distributor == order.distributor diff --git a/lib/spree/core/controller_helpers/order_decorator.rb b/lib/spree/core/controller_helpers/order_decorator.rb index d72fc7b22f..dc38e861e6 100644 --- a/lib/spree/core/controller_helpers/order_decorator.rb +++ b/lib/spree/core/controller_helpers/order_decorator.rb @@ -1,6 +1,6 @@ Spree::Core::ControllerHelpers::Order.class_eval do - def current_order_with_scoped_variants(options = {}) - order = current_order_without_scoped_variants(options) + def current_order_with_scoped_variants(create_order_if_necessary = false) + order = current_order_without_scoped_variants(create_order_if_necessary) if order scoper = OpenFoodNetwork::ScopeVariantToHub.new(order.distributor) diff --git a/spec/controllers/checkout_controller_spec.rb b/spec/controllers/checkout_controller_spec.rb index ed11ad2955..b373ae64b5 100644 --- a/spec/controllers/checkout_controller_spec.rb +++ b/spec/controllers/checkout_controller_spec.rb @@ -94,7 +94,7 @@ describe CheckoutController, type: :controller do end it "sets the new order's token to the same as the old order" do - order = controller.current_order({ create_order_if_necessary: true }) + order = controller.current_order(true) spree_post :update, order: {} expect(controller.current_order.token).to eq order.token end diff --git a/spec/controllers/enterprises_controller_spec.rb b/spec/controllers/enterprises_controller_spec.rb index 7aef356a8d..eedcb5ad16 100644 --- a/spec/controllers/enterprises_controller_spec.rb +++ b/spec/controllers/enterprises_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' describe EnterprisesController, type: :controller do describe "shopping for a distributor" do - let(:order) { controller.current_order({ create_order_if_necessary: true }) } + let(:order) { controller.current_order(true) } let!(:current_distributor) { create(:distributor_enterprise, with_payment_and_shipping: true) } diff --git a/spec/controllers/spree/checkout_controller_spec.rb b/spec/controllers/spree/checkout_controller_spec.rb index bc21a068bd..b91c19f744 100644 --- a/spec/controllers/spree/checkout_controller_spec.rb +++ b/spec/controllers/spree/checkout_controller_spec.rb @@ -5,7 +5,7 @@ require 'support/request/authentication_workflow' describe Spree::CheckoutController, type: :controller do context 'rendering edit from within spree for the current checkout state' do - let(:order) { controller.current_order({ create_order_if_necessary: true }) } + let(:order) { controller.current_order(true) } let(:user) { create(:user) } before do diff --git a/spec/controllers/spree/orders_controller_spec.rb b/spec/controllers/spree/orders_controller_spec.rb index 6aa80973b8..fbcd5ec107 100644 --- a/spec/controllers/spree/orders_controller_spec.rb +++ b/spec/controllers/spree/orders_controller_spec.rb @@ -30,7 +30,7 @@ describe Spree::OrdersController, type: :controller do it "redirects home with message if hub is not ready for checkout" do VariantOverride.stub(:indexed).and_return({}) - order = subject.current_order({ create_order_if_necessary: true }) + order = subject.current_order(true) distributor.stub(:ready_for_checkout?) { false } order.stub(distributor: distributor, order_cycle: order_cycle) @@ -44,7 +44,7 @@ describe Spree::OrdersController, type: :controller do end describe "when an item has insufficient stock" do - let(:order) { subject.current_order({ create_order_if_necessary: true }) } + let(:order) { subject.current_order(true) } let(:oc) { create(:simple_order_cycle, distributors: [d], variants: [variant]) } let(:d) { create(:distributor_enterprise, shipping_methods: [create(:shipping_method)], payment_methods: [create(:payment_method)]) } let(:variant) { create(:variant, on_demand: false, on_hand: 5) } @@ -129,7 +129,7 @@ describe Spree::OrdersController, type: :controller do distributor_product = create(:distributor_enterprise) p = create(:product, :distributors => [distributor_product], :group_buy => true) - order = subject.current_order({ create_order_if_necessary: true }) + order = subject.current_order(true) order.stub(:distributor) { distributor_product } order.should_receive(:set_variant_attributes).with(p.master, {'max_quantity' => '3'}) controller.stub(:current_order).and_return(order) @@ -164,7 +164,7 @@ describe Spree::OrdersController, type: :controller do describe "removing line items from cart" do describe "when I pass params that includes a line item no longer in our cart" do it "should silently ignore the missing line item" do - order = subject.current_order({ create_order_if_necessary: true }) + order = subject.current_order(true) li = order.add_variant(create(:simple_product, on_hand: 110).variants.first) spree_get :update, order: { line_items_attributes: { "0" => {quantity: "0", id: "9999"}, @@ -176,7 +176,7 @@ describe Spree::OrdersController, type: :controller do end it "filters line items that are missing from params" do - order = subject.current_order({ create_order_if_necessary: true }) + order = subject.current_order(true) li = order.add_variant(create(:simple_product).master) attrs = { diff --git a/spec/controllers/spree/paypal_controller_spec.rb b/spec/controllers/spree/paypal_controller_spec.rb index 6c284858e8..90f97fcb7d 100644 --- a/spec/controllers/spree/paypal_controller_spec.rb +++ b/spec/controllers/spree/paypal_controller_spec.rb @@ -9,7 +9,7 @@ module Spree end context 'when confirming' do - let(:previous_order) { controller.current_order({ create_order_if_necessary: true }) } + let(:previous_order) { controller.current_order(true) } let(:payment_method) { create(:payment_method) } before do diff --git a/spec/performance/orders_controller_spec.rb b/spec/performance/orders_controller_spec.rb index 5b6fb97e95..e151e4f506 100644 --- a/spec/performance/orders_controller_spec.rb +++ b/spec/performance/orders_controller_spec.rb @@ -4,7 +4,7 @@ describe Spree::OrdersController, type: :controller, performance: true do let(:distributor) { create(:distributor_enterprise) } let(:order_cycle) { create(:simple_order_cycle, distributors: [distributor], variants: products.map { |p| p.variants.first }) } let(:products) { (0...num_products).map { create(:product) } } - let(:order) { subject.current_order({ create_order_if_necessary: true }) } + let(:order) { subject.current_order(true) } let(:num_products) { 20 } before do