Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2655 fix admin payments #2697

Merged
merged 3 commits into from
Sep 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions app/models/order_cycle.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'open_food_network/scope_variant_to_hub'

class OrderCycle < ActiveRecord::Base
belongs_to :coordinator, :class_name => 'Enterprise'

Expand Down
2 changes: 2 additions & 0 deletions app/models/spree/inventory_unit_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'open_food_network/scope_variant_to_hub'

module Spree
InventoryUnit.class_eval do
def self.assign_opening_inventory(order)
Expand Down
1 change: 1 addition & 0 deletions app/models/spree/line_item_decorator.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions app/services/order_factory.rb
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 2 additions & 0 deletions app/services/subscription_estimator.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/views/spree/admin/payments/_form.html.erb
Original file line number Diff line number Diff line change
@@ -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 %>

<div data-hook="admin_payment_form_fields" class="row">
<div class="alpha three columns">
Expand Down
2 changes: 2 additions & 0 deletions lib/open_food_network/products_and_inventory_report_base.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'open_food_network/scope_variant_to_hub'

module OpenFoodNetwork
class ProductsAndInventoryReportBase
attr_reader :params
Expand Down
2 changes: 2 additions & 0 deletions lib/open_food_network/scope_variants_for_search.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions lib/spree/core/controller_helpers/order_decorator.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
37 changes: 37 additions & 0 deletions spec/features/admin/payments_spec.rb
Original file line number Diff line number Diff line change
@@ -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