diff --git a/app/controllers/admin/subscription_line_items_controller.rb b/app/controllers/admin/subscription_line_items_controller.rb index 5011129c5f6..d981b71fe1f 100644 --- a/app/controllers/admin/subscription_line_items_controller.rb +++ b/app/controllers/admin/subscription_line_items_controller.rb @@ -1,5 +1,6 @@ require 'open_food_network/permissions' require 'open_food_network/order_cycle_permissions' +require 'open_food_network/scope_variant_to_hub' module Admin class SubscriptionLineItemsController < ResourceController diff --git a/app/controllers/spree/admin/line_items_controller_decorator.rb b/app/controllers/spree/admin/line_items_controller_decorator.rb index 7210a6abb10..3ef85234df4 100644 --- a/app/controllers/spree/admin/line_items_controller_decorator.rb +++ b/app/controllers/spree/admin/line_items_controller_decorator.rb @@ -1,3 +1,5 @@ +require 'open_food_network/scope_variant_to_hub' + Spree::Admin::LineItemsController.class_eval do prepend_before_filter :load_order, except: :index around_filter :apply_enterprise_fees_with_lock, only: :update diff --git a/app/models/order_cycle.rb b/app/models/order_cycle.rb index 4d8f443a681..7948d1ed434 100644 --- a/app/models/order_cycle.rb +++ b/app/models/order_cycle.rb @@ -1,3 +1,5 @@ +require 'open_food_network/scope_variant_to_hub' + class OrderCycle < ActiveRecord::Base belongs_to :coordinator, :class_name => 'Enterprise' diff --git a/app/models/spree/inventory_unit_decorator.rb b/app/models/spree/inventory_unit_decorator.rb index 9868596b41f..f3f5481a619 100644 --- a/app/models/spree/inventory_unit_decorator.rb +++ b/app/models/spree/inventory_unit_decorator.rb @@ -1,3 +1,5 @@ +require 'open_food_network/scope_variant_to_hub' + module Spree InventoryUnit.class_eval do def self.assign_opening_inventory(order) diff --git a/app/models/spree/line_item_decorator.rb b/app/models/spree/line_item_decorator.rb index 6f74e195304..acc4e308b68 100644 --- a/app/models/spree/line_item_decorator.rb +++ b/app/models/spree/line_item_decorator.rb @@ -1,3 +1,4 @@ +require 'open_food_network/scope_variant_to_hub' require 'open_food_network/variant_and_line_item_naming' Spree::LineItem.class_eval do diff --git a/app/services/order_factory.rb b/app/services/order_factory.rb index fdef7b6b667..68e7224158b 100644 --- a/app/services/order_factory.rb +++ b/app/services/order_factory.rb @@ -1,3 +1,5 @@ +require 'open_food_network/scope_variant_to_hub' + # Builds orders based on a set of attributes # There are some idiosyncracies in the order creation process, # and it is nice to have them dealt with in one place. diff --git a/app/services/subscription_estimator.rb b/app/services/subscription_estimator.rb index 5abe3880292..8e69e310ac9 100644 --- a/app/services/subscription_estimator.rb +++ b/app/services/subscription_estimator.rb @@ -1,3 +1,5 @@ +require 'open_food_network/scope_variant_to_hub' + # Responsible for estimating prices and fees for subscriptions # Used by SubscriptionForm as part of the create/update process # The values calculated here are intended to be persisted in the db diff --git a/app/views/spree/admin/payments/_form.html.erb b/app/views/spree/admin/payments/_form.html.erb index e46b2febcda..e075d1288a7 100644 --- a/app/views/spree/admin/payments/_form.html.erb +++ b/app/views/spree/admin/payments/_form.html.erb @@ -1,5 +1,5 @@ <%= admin_inject_json "admin.payments", "currentOrderNumber", @order.number %> -<%= admin_inject_json_ams_array "admin.payments", "paymentMethods", @payment_methods, Api::PaymentMethodSerializer %> +<%= admin_inject_json_ams_array "admin.payments", "paymentMethods", @payment_methods, Api::PaymentMethodSerializer, current_order: @order %>
diff --git a/lib/open_food_network/products_and_inventory_report_base.rb b/lib/open_food_network/products_and_inventory_report_base.rb index 121df3221ec..15110047d9e 100644 --- a/lib/open_food_network/products_and_inventory_report_base.rb +++ b/lib/open_food_network/products_and_inventory_report_base.rb @@ -1,3 +1,5 @@ +require 'open_food_network/scope_variant_to_hub' + module OpenFoodNetwork class ProductsAndInventoryReportBase attr_reader :params diff --git a/lib/open_food_network/scope_variants_for_search.rb b/lib/open_food_network/scope_variants_for_search.rb index d04502dd4cf..9befef53044 100644 --- a/lib/open_food_network/scope_variants_for_search.rb +++ b/lib/open_food_network/scope_variants_for_search.rb @@ -1,3 +1,5 @@ +require 'open_food_network/scope_variant_to_hub' + # Used to return a set of variants which match the criteria provided # A query string is required, which will be match to the name and/or SKU of a product # Further restrictions on the schedule, order_cycle or distributor through which the diff --git a/lib/spree/core/controller_helpers/order_decorator.rb b/lib/spree/core/controller_helpers/order_decorator.rb index dc38e861e64..eb9ad451eb4 100644 --- a/lib/spree/core/controller_helpers/order_decorator.rb +++ b/lib/spree/core/controller_helpers/order_decorator.rb @@ -1,3 +1,5 @@ +require 'open_food_network/scope_variant_to_hub' + Spree::Core::ControllerHelpers::Order.class_eval do def current_order_with_scoped_variants(create_order_if_necessary = false) order = current_order_without_scoped_variants(create_order_if_necessary) diff --git a/spec/features/admin/payments_spec.rb b/spec/features/admin/payments_spec.rb new file mode 100644 index 00000000000..0a667e98332 --- /dev/null +++ b/spec/features/admin/payments_spec.rb @@ -0,0 +1,37 @@ +require 'spec_helper' + +feature ' + As an admin + I want to manage payments +' do + include AuthenticationWorkflow + + let(:order) { create(:completed_order_with_fees) } + + scenario "visiting the payment form" do + quick_login_as_admin + + visit spree.new_admin_order_payment_path order + + expect(page).to have_content "New Payment" + end + + context "with sensitive payment fee" do + let(:payment_method) { order.distributor.payment_methods.first } + + before do + # This calculator doesn't handle a `nil` order well. + # That has been useful in finding bugs. ;-) + payment_method.calculator = Spree::Calculator::FlatPercentItemTotal.new + payment_method.save! + end + + scenario "visiting the payment form" do + quick_login_as_admin + + visit spree.new_admin_order_payment_path order + + expect(page).to have_content "New Payment" + end + end +end