Skip to content

Commit

Permalink
Merge pull request #3145 from nebulab/cedum/record-ip-address-novalid…
Browse files Browse the repository at this point in the history
…ations

Don't run validations in Order#record_ip_address
  • Loading branch information
kennyadsl authored Mar 20, 2019
2 parents 4d968a1 + 1b1f2e5 commit 4189c6c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/app/models/spree/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
19 changes: 19 additions & 0 deletions core/spec/models/spree/order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down

0 comments on commit 4189c6c

Please sign in to comment.