diff --git a/app/models/customer.rb b/app/models/customer.rb index c1af111f4f9..71025435ffa 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -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 diff --git a/app/models/spree/payment.rb b/app/models/spree/payment.rb index c664a59a32f..a94e1ab32d5 100644 --- a/app/models/spree/payment.rb +++ b/app/models/spree/payment.rb @@ -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 diff --git a/app/services/cart_service.rb b/app/services/cart_service.rb index 35dcb720f05..c4f3b5a5c06 100644 --- a/app/services/cart_service.rb +++ b/app/services/cart_service.rb @@ -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) diff --git a/app/services/permitted_attributes/enterprise.rb b/app/services/permitted_attributes/enterprise.rb index 1f20a62b13d..0989511d695 100644 --- a/app/services/permitted_attributes/enterprise.rb +++ b/app/services/permitted_attributes/enterprise.rb @@ -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 diff --git a/app/services/permitted_attributes/order_cycle.rb b/app/services/permitted_attributes/order_cycle.rb index 046726a96f7..f46a4c63d20 100644 --- a/app/services/permitted_attributes/order_cycle.rb +++ b/app/services/permitted_attributes/order_cycle.rb @@ -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 diff --git a/app/services/permitted_attributes/subscription.rb b/app/services/permitted_attributes/subscription.rb index 21e523e4fef..e80469767f1 100644 --- a/app/services/permitted_attributes/subscription.rb +++ b/app/services/permitted_attributes/subscription.rb @@ -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 diff --git a/lib/spree/core/controller_helpers/order.rb b/lib/spree/core/controller_helpers/order.rb index d3f093cfd2f..e0f7423613a 100644 --- a/lib/spree/core/controller_helpers/order.rb +++ b/lib/spree/core/controller_helpers/order.rb @@ -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 diff --git a/spec/controllers/api/v0/orders_controller_spec.rb b/spec/controllers/api/v0/orders_controller_spec.rb index cfae14f85af..4a76605138f 100644 --- a/spec/controllers/api/v0/orders_controller_spec.rb +++ b/spec/controllers/api/v0/orders_controller_spec.rb @@ -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 diff --git a/spec/features/admin/orders_spec.rb b/spec/features/admin/orders_spec.rb index 7408d530058..63e9feb6873 100644 --- a/spec/features/admin/orders_spec.rb +++ b/spec/features/admin/orders_spec.rb @@ -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 diff --git a/spec/models/spree/order_spec.rb b/spec/models/spree/order_spec.rb index bcd3deba269..f9e258dc9d5 100644 --- a/spec/models/spree/order_spec.rb +++ b/spec/models/spree/order_spec.rb @@ -1239,7 +1239,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 diff --git a/spec/services/cart_service_spec.rb b/spec/services/cart_service_spec.rb index b8144f867bc..51e8f2b8827 100644 --- a/spec/services/cart_service_spec.rb +++ b/spec/services/cart_service_spec.rb @@ -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) @@ -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) @@ -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 @@ -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 @@ -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 diff --git a/spec/views/spree/admin/orders/invoice.html.haml_spec.rb b/spec/views/spree/admin/orders/invoice.html.haml_spec.rb index 32c3dd169d9..8b49a142e83 100644 --- a/spec/views/spree/admin/orders/invoice.html.haml_spec.rb +++ b/spec/views/spree/admin/orders/invoice.html.haml_spec.rb @@ -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