Merge pull request #7421 from andrewpbrett/rails-5-2-prep-2

Prepare for Rails 5.2
This commit is contained in:
Andy Brett
2021-04-19 11:32:21 -07:00
committed by GitHub
12 changed files with 26 additions and 18 deletions

View File

@@ -46,6 +46,6 @@ class Customer < ActiveRecord::Base
return true unless orders.any?
errors[:base] << I18n.t('admin.customers.destroy.has_associated_orders')
false
throw :abort
end
end

View File

@@ -201,7 +201,7 @@ module Spree
end
def update_order
order.reload.update!
order.update!
end
# Necessary because some payment gateways will refuse payments with

View File

@@ -106,13 +106,15 @@ class CartService
end
def read_variants_hash(data)
(data[:variants] || []).map do |variant_id, quantity|
if quantity.is_a?(Hash)
{ variant_id: variant_id, quantity: quantity[:quantity], max_quantity: quantity[:max_quantity] }
variants_array = []
(data[:variants] || []).each do |variant_id, quantity|
if quantity.is_a?(ActionController::Parameters)
variants_array.push({ variant_id: variant_id, quantity: quantity[:quantity], max_quantity: quantity[:max_quantity] })
else
{ variant_id: variant_id, quantity: quantity }
variants_array.push({ variant_id: variant_id, quantity: quantity })
end
end
variants_array
end
def cart_remove(variant_id)

View File

@@ -7,7 +7,7 @@ module PermittedAttributes
end
def call
return @params[:enterprise] if @params[:enterprise].blank?
return {} if @params[:enterprise].blank?
@params.require(:enterprise).permit(self.class.attributes)
end

View File

@@ -7,7 +7,7 @@ module PermittedAttributes
end
def call
return @params[:order_cycle] if @params[:order_cycle].blank?
return {} if @params[:order_cycle].blank?
@params.require(:order_cycle).permit(attributes)
end

View File

@@ -7,7 +7,7 @@ module PermittedAttributes
end
def call
return @params[:subscription] if @params[:subscription].blank?
return {} if @params[:subscription].blank?
@params.require(:subscription).permit(basic_permitted_attributes + other_permitted_attributes)
end

View File

@@ -52,7 +52,7 @@ module Spree
return unless @current_order
@current_order.last_ip_address = ip_address
@current_order.update_columns(last_ip_address: ip_address)
session[:order_id] = @current_order.id
@current_order
end

View File

@@ -274,7 +274,7 @@ module Api
before do
order.finalize!
create(:check_payment, order: order, amount: order.total)
order.payments << create(:check_payment, order: order, amount: order.total)
allow(controller).to receive(:spree_current_user) { order.distributor.owner }
end

View File

@@ -65,7 +65,7 @@ feature '
context "with a capturable order" do
before do
order.finalize! # ensure order has a payment to capture
create :check_payment, order: order, amount: order.total
order.payments << create(:check_payment, order: order, amount: order.total)
end
scenario "capture payment" do

View File

@@ -1239,7 +1239,7 @@ describe Spree::Order do
it "advances to complete state without error" do
advance_to_delivery_state(order)
order.next!
create(:payment, order: order)
order.payments << create(:payment, order: order)
expect { order.next! }.to change { order.state }.from("payment").to("complete")
end

View File

@@ -27,7 +27,8 @@ describe CartService do
describe "#populate" do
it "adds a variant" do
cart_service.populate(
{ variants: { variant.id.to_s => { quantity: '1', max_quantity: '2' } } },
ActionController::Parameters.new({ variants: { variant.id.to_s => { quantity: '1',
max_quantity: '2' } } }),
true
)
li = order.find_line_item_by_variant(variant)
@@ -41,7 +42,8 @@ describe CartService do
order.add_variant variant, 1, 2
cart_service.populate(
{ variants: { variant.id.to_s => { quantity: '2', max_quantity: '3' } } },
ActionController::Parameters.new({ variants: { variant.id.to_s => { quantity: '2',
max_quantity: '3' } } }),
true
)
li = order.find_line_item_by_variant(variant)
@@ -54,7 +56,7 @@ describe CartService do
it "removes a variant" do
order.add_variant variant, 1, 2
cart_service.populate({ variants: {} }, true)
cart_service.populate(ActionController::Parameters.new({ variants: {} }), true)
order.line_items.reload
li = order.find_line_item_by_variant(variant)
expect(li).not_to be
@@ -67,7 +69,7 @@ describe CartService do
it "does not add the deleted variant to the cart" do
variant.delete
cart_service.populate({ variants: { variant.id.to_s => { quantity: '2' } } }, true)
cart_service.populate(ActionController::Parameters.new({ variants: { variant.id.to_s => { quantity: '2' } } }), true)
expect(relevant_line_item).to be_nil
expect(cart_service.errors.count).to be 0
@@ -82,7 +84,7 @@ describe CartService do
it "removes the line_item from the cart" do
variant.delete
cart_service.populate({ variants: { variant.id.to_s => { quantity: '3' } } }, true)
cart_service.populate(ActionController::Parameters.new({ variants: { variant.id.to_s => { quantity: '3' } } }), true)
expect(Spree::LineItem.where(id: relevant_line_item).first).to be_nil
expect(cart_service.errors.count).to be 0

View File

@@ -21,6 +21,10 @@ describe "spree/admin/orders/invoice.html.haml" do
before do
assign(:order, order)
allow(view).to receive_messages checkout_adjustments_for: [],
display_checkout_tax_total: '10',
display_checkout_total_less_tax: '8',
outstanding_balance_label: 'Outstanding Balance'
end
it "displays the customer code" do