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

[pull] main from solidusio:main #399

Merged
merged 27 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5b3a66c
Spec coverage: Test calculate_eligibility for non-promo-adjustments
mamhoff Feb 28, 2024
83d9d07
Test Spree::Adjustment#finalize
mamhoff Feb 28, 2024
8909443
Test Spree::Adjustment#unfinalize
mamhoff Feb 28, 2024
18b7ce4
Test Spree::Adjustment#unfinalize!
mamhoff Feb 28, 2024
14531c0
Test Spree::Adjustment#cancellation?
mamhoff Feb 28, 2024
57c7644
Test Spree::Order.find_by_param{!}
mamhoff Feb 28, 2024
1849098
Test Spree::Order.by_customer
mamhoff Feb 28, 2024
4208072
Test Spree::Order.by_state
mamhoff Feb 28, 2024
ea8c4a4
Test Spree::Order#to_param
mamhoff Feb 28, 2024
f37ee4f
Test Spree::Order#shipped_shipments
mamhoff Feb 28, 2024
531e854
Test Spree::Order#name
mamhoff Feb 28, 2024
e0f5d3d
Test Spree::Order#valid_credit_cards
mamhoff Feb 28, 2024
1b514f1
Test Spree::Order#coupon_code=
mamhoff Feb 28, 2024
779ed4c
Test Spree::Order#create_proposed_shipments fully
mamhoff Feb 28, 2024
c5aea96
Test Spree::Order#refresh_shipment_rates
mamhoff Feb 28, 2024
951c3ae
Test Spree::Order#shipping_eq_billing_address?
mamhoff Feb 28, 2024
371853d
Test Spree::Order#can_approve?
mamhoff Feb 28, 2024
ddabeef
Merge pull request #5672 from mamhoff/adjustment-coverage
tvdeyen Feb 28, 2024
7497ad2
Test Spree::Order#bill_address_attributes=
mamhoff Feb 28, 2024
7181828
Test Spree::Order#payments_attributes=
mamhoff Feb 28, 2024
dc61c5b
Test order completion without payments
mamhoff Feb 28, 2024
9afebab
Order state machine: Test resuming
mamhoff Feb 28, 2024
208717f
Test Spree::Order#can_add_coupon?
mamhoff Feb 28, 2024
36d1c02
Test Spree::Order#shipped?
mamhoff Feb 28, 2024
49e3da4
Merge pull request #5673 from mamhoff/order-coverage
tvdeyen Feb 29, 2024
2b88945
Fix specs failing after Money 6.18.0 release
spaghetticode Mar 5, 2024
7d380c9
Merge pull request #5680 from nebulab/spaghetticode/money-fix
spaghetticode Mar 6, 2024
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
4 changes: 2 additions & 2 deletions core/spec/lib/spree/money_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,13 @@
it "formats as HTML if asked (nicely) to" do
money = Spree::Money.new(10, format: '%n %u')
# The HTML'ified version of "10.00 €"
expect(money.to_html).to eq("<span class=\"money-whole\">10</span><span class=\"money-decimal-mark\">.</span><span class=\"money-decimal\">00</span> <span class=\"money-currency-symbol\">&#x20AC;</span>")
expect(money.to_html).to eq("<span class=\"money-whole\">10</span><span class=\"money-decimal-mark\">.</span><span class=\"money-decimal\">00</span> <span class=\"money-currency-symbol\"></span>")
end

it "formats as HTML with currency" do
money = Spree::Money.new(10, format: '%n %u', with_currency: true)
# The HTML'ified version of "10.00 €"
expect(money.to_html).to eq("<span class=\"money-whole\">10</span><span class=\"money-decimal-mark\">.</span><span class=\"money-decimal\">00</span> <span class=\"money-currency-symbol\">&#x20AC;</span> <span class=\"money-currency\">EUR</span>")
expect(money.to_html).to eq("<span class=\"money-whole\">10</span><span class=\"money-decimal-mark\">.</span><span class=\"money-decimal\">00</span> <span class=\"money-currency-symbol\"></span> <span class=\"money-currency\">EUR</span>")
end
end

Expand Down
103 changes: 103 additions & 0 deletions core/spec/models/spree/adjustment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,4 +229,107 @@
end
end
end

describe "#calculate_eligibility" do
subject { adjustment.calculate_eligibility }

around do |example|
Spree.deprecator.silence do
example.run
end
end

context "when the adjustment is not a promotion adjustment" do
let(:adjustment) { build(:adjustment, eligible: true, source: nil) }

it { is_expected.to eq true }
end
end

describe "#finalize" do
let(:adjustable) { create(:order) }
let(:adjustment) { build(:adjustment, finalized: false, adjustable: adjustable) }

subject { adjustment.finalize }

it "sets the adjustment as finalized" do
expect { subject }.to change { adjustment.finalized }.from(false).to(true)
end

it "persists the adjustment" do
expect { subject }.to change { adjustment.persisted? }.from(false).to(true)
end

context "for an invalid adjustment" do
let(:adjustment) { build(:adjustment, finalized: false, amount: nil, adjustable: adjustable) }

it "raises no error, returns false, does not persist the adjustment" do
expect { subject }.not_to change { adjustment.persisted? }.from(false)
expect(subject).to eq false
end
end
end

describe "#unfinalize" do
let(:adjustable) { create(:order) }
let(:adjustment) { build(:adjustment, finalized: true, adjustable: adjustable) }

subject { adjustment.unfinalize }

it "sets the adjustment as finalized" do
expect { subject }.to change { adjustment.finalized }.from(true).to(false)
end

it "persists the adjustment" do
expect { subject }.to change { adjustment.persisted? }.from(false).to(true)
end

context "for an invalid adjustment" do
let(:adjustment) { build(:adjustment, finalized: false, amount: nil, adjustable: adjustable) }

it "raises no error, returns false, does not persist the adjustment" do
expect { subject }.not_to change { adjustment.persisted? }.from(false)
expect(subject).to eq false
end
end
end

describe "#unfinalize!" do
let(:adjustable) { create(:order) }
let(:adjustment) { build(:adjustment, finalized: true, adjustable: adjustable) }

subject { adjustment.unfinalize! }

it "sets the adjustment as finalized" do
expect { subject }.to change { adjustment.finalized }.from(true).to(false)
end

it "persists the adjustment" do
expect { subject }.to change { adjustment.persisted? }.from(false).to(true)
end

context "for an invalid adjustment" do
let(:adjustment) { build(:adjustment, finalized: false, amount: nil, adjustable: adjustable) }

it "raises an error" do
expect { subject }.to raise_exception(ActiveRecord::RecordInvalid)
end
end
end

describe "#cancellation?" do
subject { adjustment.cancellation? }

context "when the adjustment is a cancellation" do
let(:adjustment) { build(:adjustment, source_type: "Spree::UnitCancel") }

it { is_expected.to eq true }
end

context "when the adjustment is not a cancellation" do
let(:adjustment) { build(:adjustment) }

it { is_expected.to eq false }
end
end
end
26 changes: 26 additions & 0 deletions core/spec/models/spree/order/checkout_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,18 @@ def assert_state_changed(order, from, to)
end
end

context "no payment present" do
let(:order) { create :order_ready_to_complete }
before do
order.payments.destroy_all
end

it "does not allow the order to complete" do
expect { order.complete! }.to raise_exception(StateMachines::InvalidTransition)
expect(order.errors[:base]).to include("No payment found")
end
end

context "exchange order completion" do
before do
order.email = 'solidus@example.org'
Expand Down Expand Up @@ -611,6 +623,20 @@ def assert_state_changed(order, from, to)
end
end

context "resuming a canceled order" do
let(:order) { create(:completed_order_with_totals) }

before do
order.cancel!
end

it "also resumes the shipments" do
expect(order.shipments.map(&:state)).to eq %w(canceled)
order.resume!
expect(order.shipments.map(&:state)).to eq %w(pending)
end
end

context "re-define checkout flow" do
before do
@old_checkout_flow = Spree::Order.checkout_flow
Expand Down
Loading
Loading