From 1b1f2e579a6c073c74aaac4bd78d057d678f4265 Mon Sep 17 00:00:00 2001 From: Dumitru Ceban Date: Fri, 15 Mar 2019 12:55:51 +0100 Subject: [PATCH] Don't run validations in Order#record_ip_address When updating the user's latest IP address for an Order, don't run order validations and callbacks. The IP address tracking should not interfere with/block the request in case validation check is not met. --- core/app/models/spree/order.rb | 2 +- core/spec/models/spree/order_spec.rb | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/core/app/models/spree/order.rb b/core/app/models/spree/order.rb index b0d5f5321e1..3795dd84aca 100644 --- a/core/app/models/spree/order.rb +++ b/core/app/models/spree/order.rb @@ -765,7 +765,7 @@ def add_default_payment_from_wallet def record_ip_address(ip_address) if last_ip_address != ip_address - update_attributes!(last_ip_address: ip_address) + update_column(:last_ip_address, ip_address) end end diff --git a/core/spec/models/spree/order_spec.rb b/core/spec/models/spree/order_spec.rb index 291e4bcd598..bdb885a1835 100644 --- a/core/spec/models/spree/order_spec.rb +++ b/core/spec/models/spree/order_spec.rb @@ -1470,6 +1470,25 @@ def generate end end + describe "#record_ip_address" do + let(:ip_address) { "127.0.0.1" } + + subject { -> { order.record_ip_address(ip_address) } } + + it "updates the last used IP address" do + expect(subject).to change(order, :last_ip_address).to(ip_address) + end + + # IP address tracking should not raise validation exceptions + context "with an invalid order" do + before { allow(order).to receive(:valid?).and_return(false) } + + it "updates the IP address" do + expect(subject).to change(order, :last_ip_address).to(ip_address) + end + end + end + describe "#display_order_total_after_store_credit" do let(:order_total_after_store_credit) { 10.00 }