Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't run validations in Order#record_ip_address #3145

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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