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 }