Skip to content

Commit

Permalink
Merge fa14a80 into 76112fc
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewpbrett authored Apr 14, 2021
2 parents 76112fc + fa14a80 commit 265cf84
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 18 deletions.
2 changes: 1 addition & 1 deletion app/models/customer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ def check_for_orders
return true unless orders.any?

errors[:base] << I18n.t('admin.customers.destroy.has_associated_orders')
false
throw :abort
end
end
2 changes: 1 addition & 1 deletion app/models/spree/payment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def invalidate_old_payments
end

def update_order
order.reload.update!
order.update!
end

# Necessary because some payment gateways will refuse payments with
Expand Down
10 changes: 6 additions & 4 deletions app/services/cart_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,15 @@ def read_variants(data)
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)
Expand Down
2 changes: 1 addition & 1 deletion app/services/permitted_attributes/enterprise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def initialize(params)
end

def call
return @params[:enterprise] if @params[:enterprise].blank?
return {} if @params[:enterprise].blank?

@params.require(:enterprise).permit(self.class.attributes)
end
Expand Down
2 changes: 1 addition & 1 deletion app/services/permitted_attributes/order_cycle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def initialize(params)
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
Expand Down
2 changes: 1 addition & 1 deletion app/services/permitted_attributes/subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def initialize(params)
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
Expand Down
2 changes: 1 addition & 1 deletion lib/spree/core/controller_helpers/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def spree_current_order(create_order_if_necessary = false)

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
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/api/v0/orders_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion spec/features/admin/orders_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
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
Expand Down
2 changes: 1 addition & 1 deletion spec/models/spree/order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,7 @@
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
Expand Down
12 changes: 7 additions & 5 deletions spec/services/cart_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
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)
Expand All @@ -41,7 +42,8 @@
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)
Expand All @@ -54,7 +56,7 @@
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
Expand All @@ -67,7 +69,7 @@
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
Expand All @@ -82,7 +84,7 @@
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
Expand Down
4 changes: 4 additions & 0 deletions spec/views/spree/admin/orders/invoice.html.haml_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@

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
Expand Down

0 comments on commit 265cf84

Please sign in to comment.