Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Removed redundant specs, fixed specs that could never fail and deprecation warnings in specs (#14868)

Damian Legawiec26541b089137
diff --git a/spree/core/lib/generators/spree/dummy/templates/rails/test.rb b/spree/core/lib/generators/spree/dummy/templates/rails/test.rb
index 1c47088354..7ae3d63ccd 100644
--- a/spree/core/lib/generators/spree/dummy/templates/rails/test.rb
+++ b/spree/core/lib/generators/spree/dummy/templates/rails/test.rb
@@ -42,9 +42,28 @@ Dummy::Application.configure do
# Print deprecation notices to the stderr
config.active_support.deprecation = :stderr
- # Spree's own code must not call the deprecated Spree.t.
+ # Spree's own code and specs must not call these deprecated APIs. A spec
+ # covering one on purpose stubs Spree::Deprecation.warn or silences it.
config.active_support.disallowed_deprecation = :raise
- config.active_support.disallowed_deprecation_warnings = [/Spree\.t is deprecated/]
+ config.active_support.disallowed_deprecation_warnings = [
+ /Spree\.t is deprecated/,
+ /Spree::Product#(master|variants_including_master) is deprecated/,
+ /Spree::(Order|Cart)#(shipment_total|promo_total|item_count|shipping_discount) is deprecated/,
+ /Spree::Order#finalize! is deprecated/,
+ /Spree::Payment#state=? is deprecated/,
+ /Spree::Payment#(process|authorize|purchase|capture|void_transaction)! is deprecated/,
+ /Spree::(Category|Product)#classifications is deprecated/,
+ /Spree::Product#taxons=? is deprecated/,
+ /Spree::Promotion::Rules::Category#taxon/,
+ /Spree::Fulfillment#(add_)?shipping_method is deprecated/,
+ /Spree::Stock::Package#shipping_methods is deprecated/,
+ /Calling Spree::(Carts::AddItem|StockReservations::(Reserve|Extend)) with order: is deprecated/,
+ /Spree::Config\[:admin_url\] is deprecated/,
+ /private_metadata=? is deprecated/,
+ /Spree::Pricing::Resolver is deprecated/,
+ /Spree::Invitation#accept! is deprecated/,
+ /`preference :\w+, in:` is deprecated/
+ ]
config.active_job.queue_adapter = :test
diff --git a/spree/core/spec/jobs/spree/price_lists/sync_currencies_job_spec.rb b/spree/core/spec/jobs/spree/price_lists/sync_currencies_job_spec.rb
index 4bd8ef5390..312fd2625a 100644
--- a/spree/core/spec/jobs/spree/price_lists/sync_currencies_job_spec.rb
+++ b/spree/core/spec/jobs/spree/price_lists/sync_currencies_job_spec.rb
@@ -20,7 +20,7 @@ describe Spree::PriceLists::SyncCurrenciesJob, type: :job do
it 'adds the missing currency\'s placeholder rows and leaves the rest alone' do
usd_before = price_list.prices.where(currency: 'USD').pluck(:id, :amount)
- expect { subject }.to change { price_list.prices.where(currency: 'EUR').count }.from(0).to(product.variants_including_master.count)
+ expect { subject }.to change { price_list.prices.where(currency: 'EUR').count }.from(0).to(product.variants.count)
expect(price_list.prices.where(currency: 'EUR').pluck(:amount).uniq).to eq([nil])
expect(price_list.prices.where(currency: 'USD').pluck(:id, :amount)).to match_array(usd_before)
@@ -70,7 +70,7 @@ describe Spree::PriceLists::SyncCurrenciesJob, type: :job do
perform_enqueued_jobs
- expect(second_list.prices.where(currency: 'EUR').count).to eq(other_product.variants_including_master.count)
+ expect(second_list.prices.where(currency: 'EUR').count).to eq(other_product.variants.count)
end
end
end
diff --git a/spree/core/spec/lib/spree/core/pricing/catalog_pricing_spec.rb b/spree/core/spec/lib/spree/core/pricing/catalog_pricing_spec.rb
index ec0c7e48eb..7cbece5aac 100644
--- a/spree/core/spec/lib/spree/core/pricing/catalog_pricing_spec.rb
+++ b/spree/core/spec/lib/spree/core/pricing/catalog_pricing_spec.rb
@@ -150,7 +150,7 @@ describe 'catalog-aware pricing' do
context = Spree::Pricing::Context.new(variant: variant, currency: 'USD', store: store,
channel: channel)
- expect(Spree::Pricing::Resolver.new(context).resolve.amount).to eq(95)
+ expect(Spree::Pricing::PriceResolution.call(context).amount).to eq(95)
end
# An inactive catalog is off, and its owned list goes dormant WITH it: the
diff --git a/spree/core/spec/lib/spree/core_spec.rb b/spree/core/spec/lib/spree/core_spec.rb
index b0392a9a79..1f51e88d86 100644
--- a/spree/core/spec/lib/spree/core_spec.rb
+++ b/spree/core/spec/lib/spree/core_spec.rb
@@ -45,6 +45,9 @@ describe Spree do
end
it 'delegates reads and writes to customer_class' do
+ expect(Spree::Deprecation).to receive(:warn).with(/Spree.user_class= is deprecated/)
+ expect(Spree::Deprecation).to receive(:warn).with(/Spree.user_class is deprecated/)
+
described_class.user_class = 'Spree::Customer'
expect(described_class.user_class).to eq(Spree::Customer)
diff --git a/spree/core/spec/lib/tasks/single_store_associations_spec.rb b/spree/core/spec/lib/tasks/single_store_associations_spec.rb
index c65717af83..912cfd4471 100644
--- a/spree/core/spec/lib/tasks/single_store_associations_spec.rb
+++ b/spree/core/spec/lib/tasks/single_store_associations_spec.rb
@@ -45,6 +45,8 @@ describe 'spree:upgrade:populate_single_store_associations' do
end
it 'assigns the earliest store and reports the shared record' do
+ expect(Spree::Deprecation).to receive(:warn).with(/Promotion \S+ was shared across 2 stores/)
+
expect { subject.invoke }
.to output(/shared across stores/).to_stdout
.and change { promotion.reload.store_id }.from(nil).to(default_store.id)
@@ -79,6 +81,8 @@ describe 'spree:upgrade:populate_single_store_associations' do
# No timestamps on the join — the lowest store_id is the deterministic owner.
it 'assigns the lowest store_id' do
+ expect(Spree::Deprecation).to receive(:warn).with(/PaymentMethod \S+ was shared across 2 stores/)
+
subject.invoke
expect(payment_method.reload.store_id).to eq([default_store.id, other_store.id].min)
end
diff --git a/spree/core/spec/lib/tasks/six_zero_data_migrations_spec.rb b/spree/core/spec/lib/tasks/six_zero_data_migrations_spec.rb
index bbd87cdb86..393504536a 100644
--- a/spree/core/spec/lib/tasks/six_zero_data_migrations_spec.rb
+++ b/spree/core/spec/lib/tasks/six_zero_data_migrations_spec.rb
@@ -472,7 +472,7 @@ describe '6.0 data migration tasks' do
expect(fee.kind).to eq('surcharge')
expect(order.reload.attributes.slice('total', 'discount_total', 'additional_tax_total')).to eq(totals_before)
- expect(order.private_metadata['typed_adjustments_frozen']).to be_nil
+ expect(order.metadata['typed_adjustments_frozen']).to be_nil
end
it 'freezes orders whose typed sums do not reconcile' do
@@ -483,7 +483,7 @@ describe '6.0 data migration tasks' do
run_task('spree:migrate_adjustments_to_typed_rows')
- expect(order.reload.private_metadata['typed_adjustments_frozen']).to eq('totals_do_not_reconcile')
+ expect(order.reload.metadata['typed_adjustments_frozen']).to eq('totals_do_not_reconcile')
end
it 'skips orders that already carry typed rows' do
diff --git a/spree/core/spec/mailers/spree/invitation_mailer_spec.rb b/spree/core/spec/mailers/spree/invitation_mailer_spec.rb
index 92055ee4e6..7970c50df8 100644
--- a/spree/core/spec/mailers/spree/invitation_mailer_spec.rb
+++ b/spree/core/spec/mailers/spree/invitation_mailer_spec.rb
@@ -70,11 +70,11 @@ RSpec.describe Spree::InvitationMailer, type: :mailer do
before do
allow(spree).to receive(:respond_to?).and_call_original
allow(spree).to receive(:respond_to?).with(:admin_invitation_url).and_return(false)
- Spree::Config[:admin_url] = 'https://admin.example.com'
+ Spree::Config[:dashboard_url] = 'https://admin.example.com'
end
after do
- Spree::Config[:admin_url] = nil
+ Spree::Config[:dashboard_url] = nil
end
it 'uses the admin_invitation_acceptance helper for the accept link' do
@@ -83,7 +83,7 @@ RSpec.describe Spree::InvitationMailer, type: :mailer do
expect(email_body(mail)).not_to include(legacy_admin_url)
end
- it 'honors Spree::Config[:admin_url] in the rendered URL' do
+ it 'honors Spree::Config[:dashboard_url] in the rendered URL' do
expect(email_body(mail)).to include(
"https://admin.example.com/accept-invitation/#{invitation.prefixed_id}"
)
@@ -122,7 +122,7 @@ RSpec.describe Spree::InvitationMailer, type: :mailer do
end
end
- context 'when neither the legacy gem nor admin_url is configured' do
+ context 'when neither the legacy gem nor dashboard_url is configured' do
before do
allow(spree).to receive(:respond_to?).and_call_original
allow(spree).to receive(:respond_to?).with(:admin_invitation_url).and_return(false)
diff --git a/spree/core/spec/models/concerns/spree/acted_by_spec.rb b/spree/core/spec/models/concerns/spree/acted_by_spec.rb
index 519ab00d19..0a897b3455 100644
--- a/spree/core/spec/models/concerns/spree/acted_by_spec.rb
+++ b/spree/core/spec/models/concerns/spree/acted_by_spec.rb
@@ -13,17 +13,6 @@ RSpec.describe Spree::ActedBy do
expect(Spree::Refund.acted_by_associations).to eq([:refunder])
expect(Spree::StockReceipt.acted_by_associations).to eq([:received_by])
end
-
- it 'is polymorphic and optional' do
- association = Spree::Order.reflect_on_association(:canceler)
-
- expect(association).to be_polymorphic
- expect(association.options[:optional]).to be(true)
- end
-
- it 'does not leak one model\'s names into another' do
- expect(Spree::Refund.acted_by_associations).not_to include(:canceler)
- end
end
describe 'accepting each registered actor kind' do
@@ -74,6 +63,7 @@ RSpec.describe Spree::ActedBy do
end
it 'resolves through the admin user class' do
+ allow(Spree::Deprecation).to receive(:warn)
expect(order.reload.canceler).to eq(admin_user)
end
@@ -104,6 +94,7 @@ RSpec.describe Spree::ActedBy do
count
end
+ allow(Spree::Deprecation).to receive(:warn)
3.times { create(:order, store: store, canceler: admin_user) }
read_page = -> { Spree::Order.preload_associations_lazily.last(3).each(&:canceler) }
@@ -115,6 +106,7 @@ RSpec.describe Spree::ActedBy do
end
it 'names the type in memory only, never saving it' do
+ allow(Spree::Deprecation).to receive(:warn)
order.reload.canceler
expect(Spree::Order.where(id: order.id).pick(:canceler_type)).to be_nil
diff --git a/spree/core/spec/models/concerns/spree/has_custom_fields_spec.rb b/spree/core/spec/models/concerns/spree/has_custom_fields_spec.rb
index b29d1974ba..527829009f 100644
--- a/spree/core/spec/models/concerns/spree/has_custom_fields_spec.rb
+++ b/spree/core/spec/models/concerns/spree/has_custom_fields_spec.rb
@@ -3,16 +3,6 @@ require 'spec_helper'
RSpec.describe Spree::HasCustomFields, type: :concern do
let(:product) { create(:product) }
- describe 'associations' do
- it 'has many custom_fields' do
- expect(product).to respond_to(:custom_fields)
- end
-
- it 'has many storefront_custom_fields' do
- expect(product).to respond_to(:storefront_custom_fields)
- end
- end
-
describe '.with_custom_field_key' do
let!(:definition) { create(:custom_field_definition, namespace: 'custom', key: 'foo', resource_type: 'Spree::Product') }
let!(:custom_field) { create(:custom_field, resource: product, custom_field_definition: definition) }
@@ -190,15 +180,6 @@ RSpec.describe Spree::HasCustomFields, type: :concern do
}.not_to change { Spree::CustomField.count }
end
end
-
- it 'accepts a definition owned by the record\'s own store' do
- definition = create(:custom_field_definition, store: product.store, namespace: 'custom',
- key: 'material', resource_type: 'Spree::Product')
-
- product.set_custom_field(definition, 'wool')
-
- expect(product.get_custom_field('custom.material').value).to eq('wool')
- end
end
describe '#has_custom_field?' do
@@ -285,22 +266,6 @@ RSpec.describe Spree::HasCustomFields, type: :concern do
value: 'initial value', type: definition.field_type_class_name)
end
- it 'destroys existing custom_field when value is set to empty string' do
- attrs = {
- custom_fields_attributes: [
- {
- id: custom_field.id,
- custom_field_definition_id: definition.id,
- value: '',
- type: definition.field_type_class_name
- }
- ]
- }
- expect {
- product.update(attrs)
- }.to change { product.custom_fields.count }.by(-1)
- end
-
it 'destroys existing custom_field when value is set to nil' do
attrs = {
custom_fields_attributes: [
@@ -317,23 +282,6 @@ RSpec.describe Spree::HasCustomFields, type: :concern do
}.to change { product.custom_fields.count }.by(-1)
end
- it 'updates existing custom_field when value is not empty' do
- attrs = {
- custom_fields_attributes: [
- {
- id: custom_field.id,
- custom_field_definition_id: definition.id,
- value: 'updated value',
- type: definition.field_type_class_name
- }
- ]
- }
- expect {
- product.update(attrs)
- }.not_to change { product.custom_fields.count }
- expect(custom_field.reload.value).to eq('updated value')
- end
-
it 'handles multiple custom_fields correctly' do
other_definition = create(:custom_field_definition, namespace: 'custom', key: 'bar', resource_type: 'Spree::Product')
other_custom_field = create(:custom_field, resource: product, custom_field_definition: other_definition,
@@ -367,6 +315,8 @@ RSpec.describe Spree::HasCustomFields, type: :concern do
describe '#metafields_attributes=' do
let(:definition) { create(:custom_field_definition, namespace: 'custom', key: 'legacy', resource_type: 'Spree::Product') }
+ before { allow(Spree::Deprecation).to receive(:warn) }
+
# Legacy payloads name the foreign key `metafield_definition_id`, which the
# current writer would otherwise reject and silently drop.
it 'accepts the legacy definition key' do
@@ -376,6 +326,7 @@ RSpec.describe Spree::HasCustomFields, type: :concern do
}.to change { product.custom_fields.count }.by(1)
expect(product.get_custom_field('custom.legacy').value).to eq('legacy value')
+ expect(Spree::Deprecation).to have_received(:warn).with(/metafields_attributes= is deprecated/)
end
it 'still accepts the current definition key' do
diff --git a/spree/core/spec/models/concerns/spree/publishable_spec.rb b/spree/core/spec/models/concerns/spree/publishable_spec.rb
index b395c65323..6b5b4811ca 100644
--- a/spree/core/spec/models/concerns/spree/publishable_spec.rb
+++ b/spree/core/spec/models/concerns/spree/publishable_spec.rb
@@ -164,25 +164,6 @@ RSpec.describe Spree::Publishable, events: true do
end
end
- context 'with model override' do
- let(:override_class) do
- serializer = v3_serializer_class
- Class.new(Spree::Base) do
- self.table_name = 'spree_products'
- include Spree::Publishable
-
- define_method(:event_serializer_class) { serializer }
- end
- end
-
- it 'uses the overridden serializer' do
- stub_const('Spree::CustomModel', override_class)
- instance = override_class.new(id: 1)
-
- expect(instance.event_serializer_class).to eq(v3_serializer_class)
- end
- end
-
context 'with anonymous class' do
it 'returns nil' do
anon_class = Class.new(Spree::Base) do
@@ -258,10 +239,6 @@ RSpec.describe Spree::Publishable, events: true do
stub_const('Spree::TestProduct', lifecycle_class)
end
- it 'enables lifecycle events' do
- expect(lifecycle_class.lifecycle_events_enabled).to be true
- end
-
# Note: These specs use ApplicationRecord directly to test Publishable in isolation
# since Spree::Base now has lifecycle events enabled by default
context 'with only option' do
@@ -277,7 +254,7 @@ RSpec.describe Spree::Publishable, events: true do
it 'only registers specified callbacks' do
expect(limited_class._commit_callbacks.map(&:filter)).to include(:publish_create_event)
expect(limited_class._commit_callbacks.map(&:filter)).not_to include(:publish_update_event)
- expect(limited_class._commit_callbacks.map(&:filter)).not_to include(:publish_destroy_event)
+ expect(limited_class._commit_callbacks.map(&:filter)).not_to include(:publish_delete_event)
end
end
@@ -366,11 +343,5 @@ RSpec.describe Spree::Publishable, events: true do
it 'derives from model name' do
expect(Spree::OrderLineItem.event_prefix).to eq('order_line_item')
end
-
- it 'can be customized' do
- stub_const('Spree::CustomModel', publishable_class)
- Spree::CustomModel.event_prefix = 'custom'
- expect(Spree::CustomModel.event_prefix).to eq('custom')
- end
end
end
diff --git a/spree/core/spec/models/concerns/spree/purchase/addresses_spec.rb b/spree/core/spec/models/concerns/spree/purchase/addresses_spec.rb
index 69f9fd6032..b538ef068b 100644
--- a/spree/core/spec/models/concerns/spree/purchase/addresses_spec.rb
+++ b/spree/core/spec/models/concerns/spree/purchase/addresses_spec.rb
@@ -389,6 +389,7 @@ RSpec.describe Spree::Purchase::Addresses do
let(:order) { build(:order) }
before do
+ allow(Spree::Deprecation).to receive(:warn)
order.bill_address = create(:address)
order.ship_address = nil
end
@@ -410,6 +411,7 @@ RSpec.describe Spree::Purchase::Addresses do
it 'does not clone the bill address to the shipping' do
order.valid?
expect(order.ship_address).to be_nil
+ expect(Spree::Deprecation).to have_received(:warn).with(/use_billing is deprecated/)
end
end
diff --git a/spree/core/spec/models/concerns/spree/purchase/digital_items_spec.rb b/spree/core/spec/models/concerns/spree/purchase/digital_items_spec.rb
index ca49924467..60b05bfe8c 100644
--- a/spree/core/spec/models/concerns/spree/purchase/digital_items_spec.rb
+++ b/spree/core/spec/models/concerns/spree/purchase/digital_items_spec.rb
@@ -8,19 +8,6 @@ RSpec.shared_examples 'a digital items host' do
end
context 'line_item analysis' do
- it 'understands that all products are digital' do
- 3.times { add_line_item(record, digital_variant, 1) }
- expect(record.digital?).to be true
-
- add_line_item(record, digital_variant, 4)
- expect(record.digital?).to be true
- end
-
- it 'understands that no products are digital' do
- 3.times { add_line_item(record, create(:variant), 1) }
- expect(record.digital?).to be false
- end
-
it 'understands that an empty record is not digital' do
expect(record.digital?).to be false
end
@@ -75,11 +62,13 @@ RSpec.shared_examples 'a digital items host' do
it 'correctly loads the links' do
digital_assets.each { |digital_asset| add_line_item(record, create(:variant, digital_assets: [digital_asset]), 1) }
add_line_item(record, create(:variant), 1)
+ expected_links = record.digital_line_items.map do |line_item|
+ create(:digital_link, line_item: line_item, digital_asset: line_item.variant.digital_assets.first)
+ end
+ create(:digital_link)
- links = record.digital_links
- links_from_digitals = digital_assets.map(&:reload).map(&:digital_links).flatten
- expect(links.size).to eq(links_from_digitals.size)
- links.each { |link| expect(links_from_digitals).to include(link) }
+ expect(expected_links.size).to eq(2)
+ expect(record.digital_links).to match_array(expected_links)
end
end
diff --git a/spree/core/spec/models/concerns/spree/purchase/line_item_currencies_spec.rb b/spree/core/spec/models/concerns/spree/purchase/line_item_currencies_spec.rb
index 9e61c60d24..8b96191f17 100644
--- a/spree/core/spec/models/concerns/spree/purchase/line_item_currencies_spec.rb
+++ b/spree/core/spec/models/concerns/spree/purchase/line_item_currencies_spec.rb
@@ -5,10 +5,6 @@ RSpec.shared_examples 'a line item currencies host' do
let!(:euro_price) { create(:price, variant: line_item.variant, amount: 8, currency: 'EUR') }
describe '#homogenize_line_item_currencies' do
- it 'succeeds without error' do
- expect { record.update!(currency: 'EUR') }.not_to raise_error
- end
-
it 'changes the line_item currencies' do
expect { record.update!(currency: 'EUR') }.to change { line_item.reload.currency }.from('USD').to('EUR')
end
diff --git a/spree/core/spec/models/concerns/spree/purchase/store_credits_spec.rb b/spree/core/spec/models/concerns/spree/purchase/store_credits_spec.rb
index f38925f78f..1f22bf4466 100644
--- a/spree/core/spec/models/concerns/spree/purchase/store_credits_spec.rb
+++ b/spree/core/spec/models/concerns/spree/purchase/store_credits_spec.rb
@@ -134,14 +134,15 @@ RSpec.shared_examples 'a store credits host' do
context 'when the record is complete' do
let(:record) { completed_record_with_store_credit_payment }
- let(:store_credit_payments) { record.payments.checkout.store_credits }
- before do
+ it 'leaves the store credit payments untouched' do
+ store_credit_payments = record.payments.store_credits.map { |payment| [payment.id, payment.status] }
+ expect(store_credit_payments).not_to be_empty
+
subject
- record.reload
- end
- it { expect(record.payments.checkout.store_credits).to eq store_credit_payments }
+ expect(record.reload.payments.store_credits.map { |payment| [payment.id, payment.status] }).to eq(store_credit_payments)
+ end
end
end
diff --git a/spree/core/spec/models/concerns/spree/webhook_payload_redaction_spec.rb b/spree/core/spec/models/concerns/spree/webhook_payload_redaction_spec.rb
index 3e159e8f7f..956d4bc6f5 100644
--- a/spree/core/spec/models/concerns/spree/webhook_payload_redaction_spec.rb
+++ b/spree/core/spec/models/concerns/spree/webhook_payload_redaction_spec.rb
@@ -189,16 +189,6 @@ describe Spree::WebhookPayloadRedaction do
expect(described_class.split('data' => nil)).to eq([{ 'data' => nil }, {}])
end
- it 'redacts both data hashes when the payload carries :data and "data"' do
- payload, _secrets = described_class.split(
- :data => { 'reset_token' => 'sym-side' },
- 'data' => { 'reset_token' => 'str-side' }
- )
-
- expect(payload[:data]['reset_token']).to eq(placeholder)
- expect(payload['data']['reset_token']).to eq(placeholder)
- end
-
it 'redacts every form of a sensitive key present in the same data hash' do
payload, secrets = described_class.split(
'data' => { :reset_token => 'sym-tok', 'reset_token' => 'str-tok' }
@@ -220,15 +210,6 @@ describe Spree::WebhookPayloadRedaction do
end
describe '.merge' do
- it 'restores extracted secrets' do
- redacted = { 'data' => { 'email' => '[email protected]', 'reset_token' => placeholder } }
-
- restored = described_class.merge(redacted, 'reset_token' => 'live-token')
-
- expect(restored['data']['reset_token']).to eq('live-token')
- expect(restored['data']['email']).to eq('[email protected]')
- end
-
it 'leaves the payload redacted when no secrets are held' do
redacted = { 'data' => { 'reset_token' => placeholder } }
@@ -262,10 +243,4 @@ describe Spree::WebhookPayloadRedaction do
expect(restored['data']['child']['reset_token']).to eq(placeholder)
end
end
-
- it 'round-trips to the original payload' do
- original = { 'data' => { 'email' => '[email protected]', 'reset_token' => 'live-token' } }
-
- expect(described_class.merge(*described_class.split(original))).to eq(original)
- end
end
diff --git a/spree/core/spec/models/spree/ability_spec.rb b/spree/core/spec/models/spree/ability_spec.rb
index f4f0f63acb..dd7c26f5e3 100644
--- a/spree/core/spec/models/spree/ability_spec.rb
+++ b/spree/core/spec/models/spree/ability_spec.rb
@@ -17,11 +17,6 @@ describe Spree::Ability, type: :model do
it_behaves_like 'access granted'
it_behaves_like 'index allowed'
end
-
- context 'with customer' do
- it_behaves_like 'access denied'
- it_behaves_like 'no index allowed'
- end
end
context 'for admin protected resources' do
@@ -63,13 +58,6 @@ describe Spree::Ability, type: :model do
end
context 'with customer' do
- it 'is not able to admin' do
- expect(ability).not_to be_able_to :admin, resource
- expect(ability).not_to be_able_to :admin, resource_order
- expect(ability).not_to be_able_to :admin, resource_product
- expect(ability).not_to be_able_to :admin, resource_user
- end
-
it 'is not able to admin even with an admin role assignment' do
user.save!
user.spree_roles << Spree::Role.default_admin_role
@@ -277,22 +265,6 @@ describe Spree::Ability, type: :model do
end
end
- # A role belongs to one store, so "the same role on two stores" is two
- # roles. Holding both grants each store's keys on that store alone.
- context 'with a same-named role on two stores' do
- let(:store_b) { create(:store) }
-
- before do
- admin.role_users.create!(role: create(:role, name: 'shared', permissions: %w[write_orders], resource: store))
- admin.role_users.create!(role: create(:role, name: 'shared', permissions: %w[write_products], resource: store_b))
- end
-
- it 'grants each store only its own role keys' do
- expect(staff_ability.permission_keys).to eq(%w[read_orders write_orders])
- expect(Spree::Ability.new(admin, store: store_b).permission_keys).to eq(%w[read_products write_products])
- end
- end
-
# A marketplace seller's staff hold roles owned by the seller. Store-admin
# authority must come only from the store's own roles, or a seller picker
# would inherit the whole store — including, for an `admin`-named seller
@@ -383,24 +355,4 @@ describe Spree::Ability, type: :model do
end
end
end
-
- context 'role resolution uses the store of a role user' do
- let(:admin) { create(:admin_user, :without_admin_role) }
- let(:store_a) { @default_store }
- let(:store_b) { create(:store) }
-
- before do
- admin.role_users.create!(role: Spree::Role.default_admin_role(store_a))
- end
-
- it "grants authority on the role assignment's store" do
- ability = Spree::Ability.new(admin, store: store_a)
- expect(ability).to be_able_to :manage, Spree::Product.new
- end
-
- it 'does not grant authority on a different store' do
- ability = Spree::Ability.new(admin, store: store_b)
- expect(ability).not_to be_able_to :manage, Spree::Product.new
- end
- end
end
diff --git a/spree/core/spec/models/spree/address_spec.rb b/spree/core/spec/models/spree/address_spec.rb
index 4592e5e043..d7ecc8dd61 100644
--- a/spree/core/spec/models/spree/address_spec.rb
+++ b/spree/core/spec/models/spree/address_spec.rb
@@ -95,24 +95,6 @@ describe Spree::Address, type: :model do
let(:country) { @default_store.default_country }
let(:address) { create(:address, country: country) }
- context '#country_name' do
- it 'return proper country_iso_name' do
- expect(address.country_name).to eq 'United States'
- end
- end
-
- context '#country_iso_name' do
- it 'return proper country_iso_name' do
- expect(address.country_iso_name).to eq 'UNITED STATES OF AMERICA'
- end
- end
-
- context '#country_code' do
- it 'return proper country_iso_name' do
- expect(address.country_code).to eq 'US'
- end
- end
-
context '#country_iso3' do
it 'return proper country_iso_name' do
expect(address.country_iso3).to eq 'USA'
@@ -121,20 +103,6 @@ describe Spree::Address, type: :model do
end
end
- context 'aliased attributes' do
- let(:address) { Spree::Address.new }
-
- it 'first_name' do
- address.first_name = 'Ryan'
- expect(address.first_name).to eq('Ryan')
- end
-
- it 'last_name' do
- address.last_name = 'Bigg'
- expect(address.last_name).to eq('Bigg')
- end
- end
-
context 'validation' do
# Countries and subdivisions are reference data now, so these are real
# places rather than invented ones: Maryland is a subdivision of the US,
@@ -218,12 +186,6 @@ describe Spree::Address, type: :model do
expect(address).to be_valid
end
- it 'does not require phone' do
- address.state_code = state.abbr
- address.phone = ''
- expect(address).to be_valid
- end
-
context 'when phone is required' do
before { @default_store.update!(preferred_address_requires_phone: true) }
@@ -342,16 +304,6 @@ describe Spree::Address, type: :model do
end
end
- context 'phone not required' do
- before { allow(address).to receive_messages require_phone?: false }
-
- it 'shows no errors when phone is blank' do
- address.phone = ''
- address.valid?
- expect(address.errors[:phone].size).to eq 0
- end
- end
-
context 'postal code not required' do
before { allow(address).to receive_messages require_postal_code?: false }
@@ -417,26 +369,6 @@ describe Spree::Address, type: :model do
end
end
- describe '#country_code' do
- let(:address) { build(:address, country: country) }
- let(:country) { Spree::Country.by_iso('US') }
-
- it 'returns the country iso' do
- expect(address.country_code).to eq('US')
- end
-
- it 'returns nil if the country is nil' do
- address.country_code = nil
- expect(address.country_code).to be_nil
- end
- end
-
- context 'defines require_phone? helper method' do
- let(:address) { create(:address) }
-
- specify { expect(address.instance_eval { require_phone? }).to be(false) }
- end
-
context '#clear_state' do
let (:address) { create(:address) }
@@ -594,6 +526,8 @@ describe Spree::Address, type: :model do
end
it 'can be deleted when there is an incomplete associated order' do
+ create(:order, customer: user, bill_address: address3)
+
expect(address3).to be_can_be_deleted
end
@@ -602,12 +536,6 @@ describe Spree::Address, type: :model do
expect(Spree::Address.where(['id = (?)', address.id])).to be_empty
end
- it 'is destroyed deleted timestamp' do
- address2.destroy
- expect(Spree::Address.where(['id = (?)', address2.id])).not_to be_empty
- expect(Spree::Address.not_deleted.where(['id = (?)', address2.id])).to be_empty
- end
-
context 'when an incomplete order references the address' do
let!(:incomplete_order) do
create(:order, customer: user, bill_address: address, ship_address: address, state: 'delivery')
@@ -880,15 +808,6 @@ describe Spree::Address, type: :model do
address.valid?
expect(address.country).to be_nil
end
-
- it 'clears the input after normalization' do
- address = build(:address, country: nil)
- address.country_code = 'US'
- address.valid?
- # The input should be cleared so it doesn't re-run on next validation
- address.valid?
- expect(address.country).to eq(country)
- end
end
describe '#state_code=' do
diff --git a/spree/core/spec/models/spree/adjusters/promotion_spec.rb b/spree/core/spec/models/spree/adjusters/promotion_spec.rb
index d17347d9fe..2c46a92cb9 100644
--- a/spree/core/spec/models/spree/adjusters/promotion_spec.rb
+++ b/spree/core/spec/models/spree/adjusters/promotion_spec.rb
@@ -61,16 +61,17 @@ describe Spree::Adjusters::Promotion, type: :model do
it 'clamps so a line never goes below zero' do
promo = create(:promotion, kind: :automatic, code: nil, store: store)
- action = Spree::Promotion::Actions::CreateItemAdjustments.create!(
+ Spree::Promotion::Actions::CreateItemAdjustments.create!(
promotion: promo,
calculator: Spree::Calculator::FlatRate.new(preferred_amount: 999)
)
promo.activate(order: order)
- order.discounts.reload.each do |row|
+ rows = order.discounts.reload
+ expect(rows.size).to eq(2)
+ rows.each do |row|
expect(row.amount).to eq(-row.line_item.amount)
end
- expect(action.reload).to be_present
end
describe 'order-level distribution' do
diff --git a/spree/core/spec/models/spree/admin_user_spec.rb b/spree/core/spec/models/spree/admin_user_spec.rb
index eb105e60f8..a2d64ad26a 100644
--- a/spree/core/spec/models/spree/admin_user_spec.rb
+++ b/spree/core/spec/models/spree/admin_user_spec.rb
@@ -18,15 +18,6 @@ describe Spree.admin_user_class, type: :model do
admin_user.update!(password: 'new-secret-123', password_confirmation: 'new-secret-123')
expect(described_class.find_by_password_reset_token(token)).to be_nil
end
-
- # The token payload keys off the password salt/digest so it invalidates
- # when the password changes. has_secure_password provides #password_salt
- # (derived from password_digest); the generator also falls back through
- # encrypted_password for a legacy bcrypt column on a custom model without a
- # password_salt, so it never raises NameError.
- it 'generates a password reset token from the password digest' do
- expect(admin_user.generate_token_for(:password_reset)).to be_present
- end
end
describe '#can_be_deleted?' do
diff --git a/spree/core/spec/models/spree/allowed_origin_spec.rb b/spree/core/spec/models/spree/allowed_origin_spec.rb
index 50057a9203..25a70458e7 100644
--- a/spree/core/spec/models/spree/allowed_origin_spec.rb
+++ b/spree/core/spec/models/spree/allowed_origin_spec.rb
@@ -13,13 +13,9 @@ RSpec.describe Spree::AllowedOrigin, type: :model do
duplicate = build(:allowed_origin, store: store, origin: 'https://example.com')
expect(duplicate).not_to be_valid
expect(duplicate.errors[:origin]).to include('has already been taken')
- end
- it 'allows same origin for different stores' do
other_store = create(:store, code: 'other')
- create(:allowed_origin, store: store, origin: 'https://example.com')
- other = build(:allowed_origin, store: other_store, origin: 'https://example.com')
- expect(other).to be_valid
+ expect(build(:allowed_origin, store: other_store, origin: 'https://example.com')).to be_valid
end
end
@@ -169,20 +165,4 @@ RSpec.describe Spree::AllowedOrigin, type: :model do
end
end
end
-
- describe 'SingleStoreResource' do
- it 'prevents changing store after creation' do
- origin = create(:allowed_origin, store: store)
- other_store = create(:store, code: 'other2')
- origin.store = other_store
- expect(origin).not_to be_valid
- end
- end
-
- describe 'prefix_id' do
- it 'generates ao_ prefixed id' do
- origin = create(:allowed_origin, store: store)
- expect(origin.prefixed_id).to start_with('ao_')
- end
- end
end
diff --git a/spree/core/spec/models/spree/api_key_spec.rb b/spree/core/spec/models/spree/api_key_spec.rb
index 05081be4fc..86169363c7 100644
--- a/spree/core/spec/models/spree/api_key_spec.rb
+++ b/spree/core/spec/models/spree/api_key_spec.rb
@@ -5,16 +5,6 @@ RSpec.describe Spree::ApiKey, type: :model do
let(:api_key) { create(:api_key, store: store) }
describe 'validations' do
- it 'is valid with valid attributes' do
- expect(api_key).to be_valid
- end
-
- it 'requires a name' do
- api_key.name = nil
- expect(api_key).not_to be_valid
- expect(api_key.errors[:name]).to be_present
- end
-
it 'requires a name unique among the store\'s active keys' do
store = create(:store)
existing = create(:api_key, name: 'Storefront', store: store)
@@ -36,23 +26,12 @@ RSpec.describe Spree::ApiKey, type: :model do
expect(older.reload.revoked_at).to be_present
end
- it 'requires a key_type' do
- api_key.key_type = nil
- expect(api_key).not_to be_valid
- expect(api_key.errors[:key_type]).to be_present
- end
-
it 'requires key_type to be publishable or secret' do
api_key.key_type = 'invalid'
expect(api_key).not_to be_valid
expect(api_key.errors[:key_type]).to be_present
end
- it 'requires a store' do
- api_key.store = nil
- expect(api_key).not_to be_valid
- end
-
it 'requires unique token for publishable keys' do
duplicate = build(:api_key, :publishable, store: store, token: api_key.token)
expect(duplicate).not_to be_valid
@@ -223,11 +202,6 @@ RSpec.describe Spree::ApiKey, type: :model do
api_key.revoke!(user)
expect(api_key.revoked_by).to eq(user)
end
-
- it 'marks key as inactive' do
- api_key.revoke!
- expect(api_key.active?).to be false
- end
end
describe '.find_by_secret_token' do
@@ -260,24 +234,6 @@ RSpec.describe Spree::ApiKey, type: :model do
end
end
- describe 'associations' do
- it 'belongs to store' do
- expect(api_key.store).to eq(store)
- end
-
- it 'can have created_by' do
- user = create(:user)
- key = create(:api_key, store: store, created_by: user)
- expect(key.created_by).to eq(user)
- end
-
- it 'can have revoked_by' do
- user = create(:user)
- api_key.revoke!(user)
- expect(api_key.revoked_by).to eq(user)
- end
- end
-
describe 'channel binding' do
let(:channel) { create(:channel, store: store) }
diff --git a/spree/core/spec/models/spree/app_dependencies_spec.rb b/spree/core/spec/models/spree/app_dependencies_spec.rb
index d2c5ae0002..25ffdf9ef9 100644
--- a/spree/core/spec/models/spree/app_dependencies_spec.rb
+++ b/spree/core/spec/models/spree/app_dependencies_spec.rb
@@ -23,10 +23,6 @@ describe Spree::Core::Dependencies, type: :model do
deps.cart_add_item_workflow = 'MyCustomAddItemService'
expect(deps.cart_add_item_workflow).to eq 'MyCustomAddItemService'
end
-
- it 'works with constantize for string values' do
- expect(deps.cart_add_item_workflow.constantize).to eq Spree::Carts::AddItem
- end
end
describe '#<dependency>_class' do
@@ -34,20 +30,10 @@ describe Spree::Core::Dependencies, type: :model do
expect(deps.cart_add_item_workflow_class).to eq Spree::Carts::AddItem
end
- it 'returns the class directly when set as class' do
- deps.cart_add_item_workflow = MyCustomAddItemService
- expect(deps.cart_add_item_workflow_class).to eq MyCustomAddItemService
- end
-
- it 'memoizes the resolved class' do
- deps.cart_add_item_workflow_class
- expect(deps.instance_variable_get(:@cart_add_item_workflow_resolved)).to eq Spree::Carts::AddItem
- end
-
- it 'clears memoization when value changes' do
+ it 'returns the class directly when set as class, even after resolving the previous value' do
deps.cart_add_item_workflow_class
deps.cart_add_item_workflow = MyCustomAddItemService
- expect(deps.instance_variable_defined?(:@cart_add_item_workflow_resolved)).to be false
+ expect(deps.cart_add_item_workflow_class).to eq MyCustomAddItemService
end
end
@@ -56,11 +42,6 @@ describe Spree::Core::Dependencies, type: :model do
expect(deps.overrides).to eq({})
end
- it 'tracks overridden dependencies' do
- deps.cart_add_item_workflow = MyCustomAddItemService
- expect(deps.overrides).to have_key(:cart_add_item_workflow)
- end
-
it 'includes override metadata' do
deps.cart_add_item_workflow = MyCustomAddItemService
override = deps.overrides[:cart_add_item_workflow]
@@ -136,14 +117,6 @@ describe Spree::Core::Dependencies, type: :model do
it 'returns nil for non-overridden dependencies' do
expect(deps.override_info(:cart_add_item_workflow)).to be_nil
end
-
- it 'returns override info for overridden dependencies' do
- deps.cart_add_item_workflow = MyCustomAddItemService
- info = deps.override_info(:cart_add_item_workflow)
-
- expect(info[:value]).to eq MyCustomAddItemService
- expect(info[:source]).to include('app_dependencies_spec.rb')
- end
end
describe '#current_values' do
@@ -217,10 +190,6 @@ describe 'Spree module dependency accessors' do
it 'sets the dependency via Spree module' do
Spree.cart_add_item_workflow = MyCustomAddItemService
expect(Spree::Dependencies.cart_add_item_workflow).to eq MyCustomAddItemService
- end
-
- it 'returns the new class via Spree module' do
- Spree.cart_add_item_workflow = MyCustomAddItemService
expect(Spree.cart_add_item_workflow).to eq MyCustomAddItemService
end
diff --git a/spree/core/spec/models/spree/authentication/strategies/base_strategy_spec.rb b/spree/core/spec/models/spree/authentication/strategies/base_strategy_spec.rb
index 12772a1711..652469610d 100644
--- a/spree/core/spec/models/spree/authentication/strategies/base_strategy_spec.rb
+++ b/spree/core/spec/models/spree/authentication/strategies/base_strategy_spec.rb
@@ -10,18 +10,6 @@ describe Spree::Authentication::Strategies::BaseStrategy do
end
describe '#initialize' do
- it 'sets params' do
- expect(strategy.params).to eq(params)
- end
-
- it 'sets request_env' do
- expect(strategy.request_env).to eq(request_env)
- end
-
- it 'sets user_class' do
- expect(strategy.user_class).to eq(user_class)
- end
-
context 'when user_class is not provided' do
subject(:strategy) do
described_class.new(params: params, request_env: request_env)
@@ -45,30 +33,6 @@ describe Spree::Authentication::Strategies::BaseStrategy do
end
end
- describe '#success' do
- let(:user) { create(:user) }
-
- it 'returns a successful Result' do
- result = strategy.send(:success, user)
-
- expect(result).to be_a(Spree::ServiceModule::Result)
- expect(result).to be_success
- expect(result.value).to eq(user)
- end
- end
-
- describe '#failure' do
- let(:message) { 'Authentication failed' }
-
- it 'returns a failed Result' do
- result = strategy.send(:failure, message)
-
- expect(result).to be_a(Spree::ServiceModule::Result)
- expect(result).not_to be_success
- expect(result.error).to eq(message)
- end
- end
-
describe '#find_user_by_email' do
let!(:user) { create(:user, email: '[email protected]') }
@@ -92,11 +56,8 @@ describe Spree::Authentication::Strategies::BaseStrategy do
context 'when the stored email is capitalized' do
let!(:user) { create(:user, email: '[email protected]') }
- it 'finds the user from a lowercase email' do
- expect(strategy.send(:find_user_by_email, '[email protected]')).to eq(user)
- end
-
it 'finds the user from a differently-cased email' do
+ expect(strategy.send(:find_user_by_email, '[email protected]')).to eq(user)
expect(strategy.send(:find_user_by_email, '[email protected]')).to eq(user)
end
end
@@ -123,24 +84,5 @@ describe Spree::Authentication::Strategies::BaseStrategy do
info: info,
tokens: tokens)
end
-
- it 'passes the user_class' do
- admin_user_class = Spree.admin_user_class
- admin_strategy = described_class.new(
- params: params,
- request_env: request_env,
- user_class: admin_user_class
- )
-
- expect(Spree::UserIdentity).to receive(:find_or_create_from_oauth).with(
- hash_including(user_class: admin_user_class)
- )
-
- admin_strategy.send(:find_or_create_user_from_oauth,
- provider: provider,
- uid: uid,
- info: info,
- tokens: tokens)
- end
end
end
diff --git a/spree/core/spec/models/spree/authentication/strategies/email_password_strategy_spec.rb b/spree/core/spec/models/spree/authentication/strategies/email_password_strategy_spec.rb
index a42b07a77b..ad9fb94009 100644
--- a/spree/core/spec/models/spree/authentication/strategies/email_password_strategy_spec.rb
+++ b/spree/core/spec/models/spree/authentication/strategies/email_password_strategy_spec.rb
@@ -191,10 +191,7 @@ describe Spree::Authentication::Strategies::EmailPasswordStrategy do
end
it 'authenticates with admin user class' do
- admin_user # ensure admin user exists
- # Mock password validation for admin user
- allow(admin_user).to receive(:valid_password?).with('admin123').and_return(true)
- allow(strategy).to receive(:find_user_by_email).with('[email protected]').and_return(admin_user)
+ admin_user
result = strategy.authenticate
diff --git a/spree/core/spec/models/spree/base_spec.rb b/spree/core/spec/models/spree/base_spec.rb
index b8bfd8ac32..7a0354e562 100644
--- a/spree/core/spec/models/spree/base_spec.rb
+++ b/spree/core/spec/models/spree/base_spec.rb
@@ -73,9 +73,6 @@ describe Spree::Base do
# Backwards-compatible alias retained for extensions that still call
# the old name; must delegate so subclass overrides (e.g.
# `Spree::Gateway.api_type`) propagate.
- it { expect(Spree::FulfillmentItem.json_api_type).to eq('fulfillment_item') }
- it { expect(Spree::Address.json_api_type).to eq('address') }
-
it 'honors subclass overrides of .api_type' do
klass = Class.new(Spree::Base) do
def self.api_type
@@ -94,7 +91,6 @@ describe Spree::Base do
end
it { expect(Spree::Address.json_api_columns).to contain_exactly('address1', 'address2', 'alternative_phone', 'city', 'company', 'country_code', 'created_at', 'deleted_at', 'first_name', 'label', 'last_name', 'phone', 'postal_code', 'state_code', 'state_name', 'updated_at', 'metadata', 'quick_checkout', 'latitude', 'longitude') }
- it { expect(Spree::Address.json_api_columns).not_to include('country_id') }
end
describe '.json_api_permitted_attributes' do
diff --git a/spree/core/spec/models/spree/calculator/flat_rate_spec.rb b/spree/core/spec/models/spree/calculator/flat_rate_spec.rb
index 4ed51ea271..8f881e1326 100644
--- a/spree/core/spec/models/spree/calculator/flat_rate_spec.rb
+++ b/spree/core/spec/models/spree/calculator/flat_rate_spec.rb
@@ -7,8 +7,6 @@ describe Spree::Calculator::FlatRate, type: :model do
before { allow(line_item).to receive_messages quantity: 10 }
describe '#compute' do
- it { expect(calculator.preferred_apply_only_on_full_priced_items).to be false }
-
shared_examples 'computing amount correctly' do
it "computes the amount as the rate when currency matches the line_item's currency" do
calculator.preferred_amount = 25.0
diff --git a/spree/core/spec/models/spree/calculator/flexi_rate_spec.rb b/spree/core/spec/models/spree/calculator/flexi_rate_spec.rb
index 5f1d5116e6..2e6333c964 100644
--- a/spree/core/spec/models/spree/calculator/flexi_rate_spec.rb
+++ b/spree/core/spec/models/spree/calculator/flexi_rate_spec.rb
@@ -7,8 +7,6 @@ describe Spree::Calculator::FlexiRate, type: :model do
before { allow(line_item).to receive_messages quantity: 10 }
describe '#compute' do
- it { expect(calculator.preferred_apply_only_on_full_priced_items).to be false }
-
shared_examples 'computes amount correctly' do
it 'computes amount correctly when all fees are 0' do
expect(calculator.compute(line_item).round(2)).to eq(0.0)
@@ -33,10 +31,6 @@ describe Spree::Calculator::FlexiRate, type: :model do
allow(calculator).to receive_messages preferred_first_item: 5.0, preferred_additional_item: 1.0, preferred_max_items: 3
expect(calculator.compute(line_item).round(2)).to eq(7.0)
end
-
- it 'allows creation of new object with all the attributes' do
- Spree::Calculator::FlexiRate.new(preferred_first_item: 1, preferred_additional_item: 1, preferred_max_items: 1)
- end
end
context 'when apply_only_on_full_priced_items is true' do
diff --git a/spree/core/spec/models/spree/calculator/percent_on_line_item_spec.rb b/spree/core/spec/models/spree/calculator/percent_on_line_item_spec.rb
index e988a16f65..39e206343f 100644
--- a/spree/core/spec/models/spree/calculator/percent_on_line_item_spec.rb
+++ b/spree/core/spec/models/spree/calculator/percent_on_line_item_spec.rb
@@ -7,8 +7,6 @@ describe Spree::Calculator::PercentOnLineItem, type: :model do
before { allow(calculator).to receive_messages preferred_percent: 10 }
describe '#compute' do
- it { expect(calculator.preferred_apply_only_on_full_priced_items).to be false }
-
shared_examples 'computing amount correctly' do
it 'rounds result correctly' do
allow(line_item).to receive_messages amount: 31.08
diff --git a/spree/core/spec/models/spree/calculator/price_sack_spec.rb b/spree/core/spec/models/spree/calculator/price_sack_spec.rb
index 78d6f064d4..634973cabd 100644
--- a/spree/core/spec/models/spree/calculator/price_sack_spec.rb
+++ b/spree/core/spec/models/spree/calculator/price_sack_spec.rb
@@ -15,12 +15,12 @@ describe Spree::Calculator::PriceSack, type: :model do
# Regression test for #714 and #739
it 'computes with an order object' do
- calculator.compute(order)
+ expect(calculator.compute(order)).to eq(calculator.preferred_normal_amount)
end
# Regression test for #1156
it 'computes with a shipment object' do
- calculator.compute(shipment)
+ expect(calculator.compute(shipment)).to eq(calculator.preferred_discount_amount)
end
# Regression test for #2055
diff --git a/spree/core/spec/models/spree/calculator/shipping/digital_delivery_spec.rb b/spree/core/spec/models/spree/calculator/shipping/digital_delivery_spec.rb
index b4542a5977..34ee4940bc 100644
--- a/spree/core/spec/models/spree/calculator/shipping/digital_delivery_spec.rb
+++ b/spree/core/spec/models/spree/calculator/shipping/digital_delivery_spec.rb
@@ -3,10 +3,6 @@ require 'spec_helper'
RSpec.describe Spree::Calculator::Shipping::DigitalDelivery do
subject { Spree::Calculator::Shipping::DigitalDelivery.new }
- it 'has a description for the class' do
- expect(Spree::Calculator::Shipping::DigitalDelivery).to respond_to(:description)
- end
-
describe '#compute_package' do
it 'quotes the package currency from the per-currency amounts' do
subject.preferred_amounts = { 'EUR' => 3.5 }
diff --git a/spree/core/spec/models/spree/calculator/shipping/flat_rate_spec.rb b/spree/core/spec/models/spree/calculator/shipping/flat_rate_spec.rb
index c7aff78567..58ce8bf9e9 100644
--- a/spree/core/spec/models/spree/calculator/shipping/flat_rate_spec.rb
+++ b/spree/core/spec/models/spree/calculator/shipping/flat_rate_spec.rb
@@ -51,6 +51,8 @@ RSpec.describe Spree::Calculator::Shipping::FlatRate, type: :model do
end
context 'with weight constraints' do
+ before { allow(Spree::Deprecation).to receive(:warn) }
+
let(:calculator_1) { described_class.new(preferred_amount: 5, preferred_minimum_weight: 2, preferred_maximum_weight: 4) }
let(:calculator_2) { described_class.new(preferred_amount: 5, preferred_minimum_weight: 4, preferred_maximum_weight: 8) }
@@ -71,10 +73,13 @@ RSpec.describe Spree::Calculator::Shipping::FlatRate, type: :model do
expect(calculator_5.compute(package)).to eq(5.00)
expect(calculator_6.compute(package)).to be_nil
expect(calculator_7.compute(package)).to be_nil
+ expect(Spree::Deprecation).to have_received(:warn).with(/`minimum_weight` is deprecated/).at_least(:once)
end
end
context 'with price constraints' do
+ before { allow(Spree::Deprecation).to receive(:warn) }
+
let(:calculator_1) { described_class.new(preferred_amount: 5, preferred_minimum_item_total: 20, preferred_maximum_item_total: 35) }
let(:calculator_2) { described_class.new(preferred_amount: 5, preferred_minimum_item_total: 35, preferred_maximum_item_total: 80) }
@@ -95,10 +100,13 @@ RSpec.describe Spree::Calculator::Shipping::FlatRate, type: :model do
expect(calculator_5.compute(package)).to eq(5.00)
expect(calculator_6.compute(package)).to be_nil
expect(calculator_7.compute(package)).to be_nil
+ expect(Spree::Deprecation).to have_received(:warn).with(/`minimum_item_total` is deprecated/).at_least(:once)
end
end
context 'with both weight and price constraints' do
+ before { allow(Spree::Deprecation).to receive(:warn) }
+
let(:calculator_1) do
described_class.new(
preferred_amount: 5,
diff --git a/spree/core/spec/models/spree/calculator/shipping/flexi_rate_spec.rb b/spree/core/spec/models/spree/calculator/shipping/flexi_rate_spec.rb
index 33c695717f..c06f1a9003 100644
--- a/spree/core/spec/models/spree/calculator/shipping/flexi_rate_spec.rb
+++ b/spree/core/spec/models/spree/calculator/shipping/flexi_rate_spec.rb
@@ -39,14 +39,6 @@ module Spree
subject.preferred_max_items = 3
expect(subject.compute(package).round(2)).to eq(7.0)
end
-
- it 'allows creation of new object with all the attributes' do
- FlexiRate.new(
- preferred_first_item: 1,
- preferred_additional_item: 1,
- preferred_max_items: 1
- )
- end
end
end
end
diff --git a/spree/core/spec/models/spree/calculator/shipping/price_sack_spec.rb b/spree/core/spec/models/spree/calculator/shipping/price_sack_spec.rb
index 5451ae7f2c..55e82b9864 100644
--- a/spree/core/spec/models/spree/calculator/shipping/price_sack_spec.rb
+++ b/spree/core/spec/models/spree/calculator/shipping/price_sack_spec.rb
@@ -14,8 +14,6 @@ module Spree
let(:line_item) { build(:line_item, variant: variant, price: variant.amount_in(variant.cost_currency)) }
let(:variant) { create(:variant, price: 2) }
- let(:inventory_unit1) { }
-
let(:normal_package) do
iu = build(:fulfillment_item, quantity: 2, variant: variant, line_item: line_item)
build(:stock_package, contents: [::Spree::Stock::ContentItem.new(iu)])
diff --git a/spree/core/spec/models/spree/cart_spec.rb b/spree/core/spec/models/spree/cart_spec.rb
index 8706f56261..c3dbd6a82b 100644
--- a/spree/core/spec/models/spree/cart_spec.rb
+++ b/spree/core/spec/models/spree/cart_spec.rb
@@ -67,14 +67,6 @@ describe Spree::Cart, type: :model do
expect(cart.checkout_steps).to eq(%w(address delivery complete))
end
end
-
- context 'when payment required' do
- before { allow(cart).to receive_messages payment_required?: true }
-
- specify do
- expect(cart.checkout_steps).to eq(%w(address delivery payment complete))
- end
- end
end
describe '#current_checkout_step' do
@@ -135,14 +127,6 @@ describe Spree::Cart, type: :model do
end
describe 'lifecycle events' do
- it 'publishes cart.* lifecycle events' do
- expect(described_class.lifecycle_events_enabled).to be true
- expect(described_class.event_prefix).to eq('cart')
-
- registered = described_class._commit_callbacks.map(&:filter)
- expect(registered).to include(:publish_create_event, :publish_update_event, :publish_delete_event)
- end
-
# The V3 cart serializer resolves by convention when spree_api is loaded;
# core's dummy app only sees the fallback payload.
it 'carries the prefixed id in the event payload' do
@@ -173,20 +157,6 @@ describe Spree::Cart, type: :model do
end
describe 'lifecycle' do
- it 'generates a token on create' do
- expect(create(:cart).token).to be_present
- end
-
- it 'is completed when completed_at is set' do
- expect(build(:cart, completed_at: Time.current)).to be_completed
- expect(build(:cart)).not_to be_completed
- end
-
- it 'is completing while completing_at holds the cart' do
- expect(build(:cart, completing_at: Time.current)).to be_completing
- expect(build(:cart)).not_to be_completing
- end
-
it 'scopes complete/incomplete on completed_at' do
incomplete = create(:cart)
complete = create(:cart, completed_at: Time.current)
@@ -196,40 +166,6 @@ describe Spree::Cart, type: :model do
end
end
- describe 'line item ownership' do
- let(:cart) { create(:cart) }
-
- it 'owns line items and destroys them with the cart' do
- line_item = create(:line_item, order: nil, cart: cart, currency: cart.currency)
-
- expect(line_item.owner).to eq(cart)
- expect { cart.destroy }.to change(Spree::LineItem, :count).by(-1)
- end
- end
-
- describe 'order link' do
- it 'links to the order completed from it' do
- cart = create(:cart, completed_at: Time.current)
- order = create(:order, cart: cart)
-
- expect(cart.order).to eq(order)
- end
- end
-
- describe '#warnings' do
- let(:cart) { build(:cart) }
-
- it 'defaults to empty array' do
- expect(cart.warnings).to eq([])
- end
-
- it 'is a transient attribute (not persisted)' do
- cart.warnings = [{ code: 'test', message: 'test' }]
- cart.save!
- expect(cart.reload.warnings).to eq([])
- end
- end
-
describe '#orderable_variants' do
let(:company) { create(:company, store: store) }
let(:catalog) { create(:catalog, store: store) }
@@ -327,15 +263,6 @@ describe Spree::Cart, type: :model do
cart.remove_out_of_stock_items!
end
-
- context 'when cart is empty' do
- let(:order) { create(:order, store: store, customer: user) }
-
- it 'does nothing' do
- cart.remove_out_of_stock_items!
- expect(cart.warnings).to eq([])
- end
- end
end
describe '#coupon_code=' do
diff --git a/spree/core/spec/models/spree/catalog_spec.rb b/spree/core/spec/models/spree/catalog_spec.rb
index d7ad398e95..eb9aff1c09 100644
--- a/spree/core/spec/models/spree/catalog_spec.rb
+++ b/spree/core/spec/models/spree/catalog_spec.rb
@@ -22,10 +22,12 @@ describe Spree::Catalog, type: :model do
it 'adds store products once, skipping duplicates and foreign rows' do
product = create(:product, store: store)
foreign = create(:product, store: create(:store))
+ fresh = create(:product, store: store)
catalog.add_products([product.id, foreign.id])
expect(catalog.add_products([product.id])).to eq(0)
- expect(catalog.products.reload).to contain_exactly(product)
+ expect(catalog.add_products([product.id, fresh.id])).to eq(1)
+ expect(catalog.products.reload).to contain_exactly(product, fresh)
end
# An owned list prices the assortment and nothing else, so it follows it
@@ -62,15 +64,6 @@ describe Spree::Catalog, type: :model do
expect(catalog.products.reload).to contain_exactly(first, *later)
end
-
- it 'adds a batch alongside an existing row without raising on the duplicate' do
- existing = create(:product, store: store)
- fresh = create(:product, store: store)
- catalog.add_products([existing.id])
-
- expect(catalog.add_products([existing.id, fresh.id])).to eq(1)
- expect(catalog.products.reload).to contain_exactly(existing, fresh)
- end
end
describe '.for_company' do
@@ -367,17 +360,6 @@ describe Spree::Catalog, type: :model do
expect(Spree::PriceList.with_deleted.find(price_list.id)).to be_present
end
- it 'does not leave the destroyed catalog list pricing the store' do
- price_list.update!(status: 'active')
- catalog = create(:catalog, store: store, price_list: price_list)
- Spree::Current.store = store
- expect(Spree::Current.price_lists.map(&:id)).not_to include(price_list.id)
-
- catalog.destroy!
-
- expect(Spree::Current.price_lists.map(&:id)).not_to include(price_list.id)
- end
-
# The binding is written with update_all, which never touches the
# instance the caller holds. Left unsynced, that copy still reads
# catalog_id as nil and detaching from the list side looks like a no-op.
diff --git a/spree/core/spec/models/spree/category_spec.rb b/spree/core/spec/models/spree/category_spec.rb
index 09245ca115..70fd262d2c 100644
--- a/spree/core/spec/models/spree/category_spec.rb
+++ b/spree/core/spec/models/spree/category_spec.rb
@@ -13,12 +13,6 @@ RSpec.describe Spree::Category, type: :model do
expect(described_class.new(name: 'Shoes', store: other)).to be_valid
end
- it 'rejects a duplicate permalink within the same store' do
- described_class.create!(name: 'Shoes', store: store)
-
- expect(described_class.new(name: 'Shoes', store: store)).not_to be_valid
- end
-
# Guards the index itself, not the validation: top-level categories have
# parent_id IS NULL, and the previous (permalink, parent_id, taxonomy_id)
# index left them unconstrained because unique indexes treat NULLs as distinct.
@@ -141,20 +135,6 @@ RSpec.describe Spree::Category, type: :model do
expect(category.parent).to be_nil
expect(category.store).to eq(store)
end
-
- it 'does not require a taxonomy' do
- category = described_class.new(name: 'Kitchen', store: store)
- expect(category).to be_valid
- expect(category.errors[:taxonomy]).to be_empty
- end
-
- it 'copies the store from its parent' do
- parent = described_class.create!(name: 'Kitchen', store: store)
- child = described_class.create!(name: 'Pots', parent: parent)
-
- expect(child.store).to eq(store)
- expect(child.taxonomy).to be_nil
- end
end
describe 'store auto-resolution (#ensure_store)' do
@@ -186,11 +166,6 @@ RSpec.describe Spree::Category, type: :model do
end
describe '.for_store / .for_stores' do
- it 'finds categories by store_id' do
- category = described_class.create!(name: 'Kitchen', store: store)
- expect(described_class.for_store(store)).to include(category)
- end
-
it 'excludes categories owned by another store' do
other = create(:store)
mine = described_class.create!(name: 'Mine', store: store)
@@ -223,7 +198,7 @@ RSpec.describe Spree::Category, type: :model do
add(create(:product, store: store), phones)
expect(phones.reload.products_count).to eq(1)
- expect(phones.classifications.count).to eq(1) # direct
+ expect(phones.product_categories.count).to eq(1) # direct
end
it 'rolls subcategory products up to ancestors' do
@@ -231,7 +206,7 @@ RSpec.describe Spree::Category, type: :model do
add(create(:product, store: store), laptops)
expect(electronics.reload.products_count).to eq(2) # inclusive
- expect(electronics.classifications.count).to eq(0) # nothing direct
+ expect(electronics.product_categories.count).to eq(0) # nothing direct
expect(phones.reload.products_count).to eq(1)
expect(laptops.reload.products_count).to eq(1)
end
@@ -275,7 +250,6 @@ RSpec.describe Spree::Category, type: :model do
expect(other_root.reload.products_count).to eq(1) # gained it
end
end
- let(:store) { @default_store }
let(:category) { build(:category, name: 'Ruby on Rails', parent: nil) }
it_behaves_like 'metadata'
@@ -370,14 +344,6 @@ RSpec.describe Spree::Category, type: :model do
expect(category.permalink).to eql 'ni-hao'
end
- it 'stores old slugs in FriendlyIds history' do
- # Stub out the unrelated methods that cannot handle a save without an id
- allow(subject).to receive(:set_depth!)
- expect(subject).to receive(:create_slug)
- subject.permalink = 'custom-slug'
- subject.run_callbacks :save
- end
-
context 'with parent category' do
let(:parent) { FactoryBot.build(:category, permalink: 'brands') }
@@ -456,10 +422,6 @@ RSpec.describe Spree::Category, type: :model do
it { expect(described_class.whitelisted_ransackable_associations).not_to include('taxonomy') }
end
- describe '#cached_self_and_descendants_ids' do
- it { expect(category.cached_self_and_descendants_ids).to eq(category.self_and_descendants.ids) }
- end
-
describe '#localized_slugs_for_store' do
let(:store) { create(:store, default_locale: 'fr', supported_locales: 'en,pl,fr') }
let!(:root_category) { create(:category, name: 'Categories', store: store) }
@@ -655,61 +617,6 @@ RSpec.describe Spree::Category, type: :model do
expect(category.pretty_name).to eq(category.name)
end
end
-
- context '2+ lvl deep' do
- let(:category_parent) { create(:category, name: 'Parent') }
-
- before do
- category.parent = category_parent
- category.save!
- end
-
- it 'returns parent name and category name' do
- expect(category.reload.pretty_name).to eq('Parent -> Category#1')
- end
-
- context 'when name is updated' do
- before do
- category.name = 'New Name'
- category.save!
- end
-
- it 'returns the updated pretty name' do
- expect(category.reload.pretty_name).to eq('Parent -> New Name')
- end
- end
-
- context 'when parent name is updated' do
- before do
- category_parent.name = 'New Parent'
- category_parent.save!
- end
-
- it 'returns the updated pretty name' do
- expect(category.reload.pretty_name).to eq('New Parent -> Category#1')
- end
- end
- end
-
- context 'when `always_use_translations` is disabled' do
- before do
- allow(Spree::Config).to receive(:always_use_translations).and_return(false)
- end
-
- it 'sets the pretty name' do
- expect(category.reload.pretty_name).to eq(category.name)
- end
- end
-
- context 'when `always_use_translations` is enabled' do
- before do
- allow(Spree::Config).to receive(:always_use_translations).and_return(true)
- end
-
- it 'sets the pretty name' do
- expect(category.reload.pretty_name).to eq(category.name)
- end
- end
end
describe '#active_products_with_descendants' do
@@ -721,12 +628,6 @@ RSpec.describe Spree::Category, type: :model do
it 'returns true' do
expect(root_category.reload.active_products_with_descendants.exists?).to be true
end
-
- it 'returns true when products aren\'t active' do
- product.update(status: 'draft')
-
- expect(root_category.reload.products.exists?).to be true
- end
end
context 'when only children categories have products' do
diff --git a/spree/core/spec/models/spree/channel/gating_spec.rb b/spree/core/spec/models/spree/channel/gating_spec.rb
index dd9bf5f79f..6e582249be 100644
--- a/spree/core/spec/models/spree/channel/gating_spec.rb
+++ b/spree/core/spec/models/spree/channel/gating_spec.rb
@@ -19,12 +19,6 @@ RSpec.describe Spree::Channel::Gating, type: :model do
expect(channel.resolved_storefront_access).to eq('prices_hidden')
end
- it 'prefers the channel value over the store value' do
- store.update!(preferred_storefront_access: 'login_required')
- channel.update!(preferred_storefront_access: 'public')
- expect(channel.resolved_storefront_access).to eq('public')
- end
-
it 'clears the override (restores inheritance) when written blank' do
store.update!(preferred_storefront_access: 'login_required')
channel.update!(preferred_storefront_access: 'public')
@@ -40,10 +34,6 @@ RSpec.describe Spree::Channel::Gating, type: :model do
end
describe '#resolved_guest_checkout' do
- it 'is nil on the channel by default (inherit)' do
- expect(channel.preferred_guest_checkout).to be_nil
- end
-
it 'falls back to the store default (true) when the channel is unset' do
expect(channel.resolved_guest_checkout).to be true
end
diff --git a/spree/core/spec/models/spree/channel_spec.rb b/spree/core/spec/models/spree/channel_spec.rb
index 67befb7a43..1c278f1190 100644
--- a/spree/core/spec/models/spree/channel_spec.rb
+++ b/spree/core/spec/models/spree/channel_spec.rb
@@ -4,18 +4,6 @@ RSpec.describe Spree::Channel, type: :model do
let(:store) { @default_store }
describe 'validations' do
- it 'requires name' do
- channel = described_class.new(store: store, code: 'pos')
- expect(channel).not_to be_valid
- expect(channel.errors[:name]).to be_present
- end
-
- it 'requires code' do
- channel = described_class.new(store: store)
- expect(channel).not_to be_valid
- expect(channel.errors[:code]).to be_present
- end
-
it 'derives code from name when blank' do
channel = described_class.new(store: store, name: 'Point of Sale')
channel.valid?
@@ -33,27 +21,14 @@ RSpec.describe Spree::Channel, type: :model do
expect { described_class.find_by(code: ascii8) }.not_to raise_error
end
- it 'requires code unique within a store' do
+ it 'requires code unique within a store only' do
described_class.create!(store: store, name: 'POS', code: 'pos')
duplicate = described_class.new(store: store, name: 'POS 2', code: 'pos')
expect(duplicate).not_to be_valid
expect(duplicate.errors[:code]).to be_present
- end
-
- it 'allows the same code across different stores' do
- described_class.create!(store: store, name: 'POS', code: 'pos')
- other_store = create(:store)
# Auto-seeded 'online' channel is fine; we test the same arbitrary code.
- cross = described_class.new(store: other_store, name: 'POS', code: 'pos')
-
- expect(cross).to be_valid
- end
- end
-
- describe 'defaults' do
- it 'is active by default' do
- expect(described_class.new(store: store).active).to be true
+ expect(described_class.new(store: create(:store), name: 'POS', code: 'pos')).to be_valid
end
end
@@ -106,13 +81,6 @@ RSpec.describe Spree::Channel, type: :model do
end
end
- describe 'prefixed_id' do
- it 'starts with ch_' do
- channel = described_class.create!(store: store, name: 'POS', code: 'pos')
- expect(channel.prefixed_id).to start_with('ch_')
- end
- end
-
describe '#can_be_deleted?' do
let(:fresh_store) { create(:store).tap { |s| s.channels.delete_all } }
let!(:default_channel) { described_class.create!(store: fresh_store, name: 'Default', code: 'online', default: true) }
diff --git a/spree/core/spec/models/spree/claim_spec.rb b/spree/core/spec/models/spree/claim_spec.rb
index b572ca953f..cd1caf4c53 100644
--- a/spree/core/spec/models/spree/claim_spec.rb
+++ b/spree/core/spec/models/spree/claim_spec.rb
@@ -10,19 +10,7 @@ RSpec.describe Spree::Claim do
expect(claim).to be_open
end
- it 'is reachable from its order' do
- claim = create(:claim, store: store)
-
- expect(claim.order.reload.claims).to include(claim)
- end
-
describe 'reason' do
- it 'records the merchant-owned reason' do
- reason = create(:claim_reason, store: store, name: 'Arrived damaged')
-
- expect(create(:claim, store: store, reason: reason).reason).to eq(reason)
- end
-
# A merchant mid-claim should not be blocked because nobody has curated
# the vocabulary yet.
it 'is optional' do
diff --git a/spree/core/spec/models/spree/classification_spec.rb b/spree/core/spec/models/spree/classification_spec.rb
index a9aca6faaf..fae22d650a 100644
--- a/spree/core/spec/models/spree/classification_spec.rb
+++ b/spree/core/spec/models/spree/classification_spec.rb
@@ -22,19 +22,14 @@ module Spree
end
def positions_to_be_valid(category)
- positions = category.reload.classifications.map(&:position)
- expect(positions).to eq((1..category.classifications.count).to_a)
- end
-
- it 'has a valid fixtures' do
- expect positions_to_be_valid(taxon_with_5_products)
- expect(Spree::ProductCategory.count).to eq 5
+ positions = category.reload.product_categories.map(&:position)
+ expect(positions).to eq((1..category.product_categories.count).to_a)
end
context 'removing product from category' do
before do
p = taxon_with_5_products.products[1]
- expect(p.classifications.first.position).to eq(2)
+ expect(p.product_categories.first.position).to eq(2)
taxon_with_5_products.products.destroy(p)
end
@@ -59,7 +54,7 @@ module Spree
context 'removing category from product' do
before do
p = taxon_with_5_products.products[1]
- p.taxons.destroy(taxon_with_5_products)
+ p.categories.destroy(taxon_with_5_products)
p.save!
end
@@ -68,10 +63,10 @@ module Spree
end
end
- context "replacing product's taxons" do
+ context "replacing product's categories" do
before do
p = taxon_with_5_products.products[1]
- p.taxons = []
+ p.categories = []
p.save!
end
@@ -82,7 +77,7 @@ module Spree
context 'destroying classification' do
before do
- classification = taxon_with_5_products.classifications[1]
+ classification = taxon_with_5_products.product_categories[1]
classification.destroy
end
@@ -112,12 +107,6 @@ module Spree
classification.destroy
}.to change { category.reload.products_count }.from(1).to(0)
end
-
- it 'correctly counts multiple classifications' do
- products = create_list(:product, 3)
- products.each { |p| create(:product_category, category: category, product: p) }
- expect(category.reload.products_count).to eq(3)
- end
end
describe 'categories_count on product' do
@@ -133,12 +122,6 @@ module Spree
classification.destroy
}.to change { product.reload.categories_count }.from(1).to(0)
end
-
- it 'correctly counts multiple classifications' do
- taxons = create_list(:category, 3)
- taxons.each { |t| create(:product_category, category: t, product: product) }
- expect(product.reload.categories_count).to eq(3)
- end
end
end
diff --git a/spree/core/spec/models/spree/collection_rule_spec.rb b/spree/core/spec/models/spree/collection_rule_spec.rb
index 4737bb2306..a9651458e5 100644
--- a/spree/core/spec/models/spree/collection_rule_spec.rb
+++ b/spree/core/spec/models/spree/collection_rule_spec.rb
@@ -14,13 +14,6 @@ RSpec.describe Spree::CollectionRule, type: :model do
expect(rule).not_to be_valid
expect(rule.errors[:match_policy]).to be_present
end
-
- it 'requires a value' do
- rule = build(:tag_collection_rule, :is_equal_to, collection: collection, value: nil)
-
- expect(rule).not_to be_valid
- expect(rule.errors[:value]).to be_present
- end
end
# Assert the callback reaches the collection's regeneration; stub only the
diff --git a/spree/core/spec/models/spree/collection_spec.rb b/spree/core/spec/models/spree/collection_spec.rb
index 53936b15ad..c205e6ad87 100644
--- a/spree/core/spec/models/spree/collection_spec.rb
+++ b/spree/core/spec/models/spree/collection_spec.rb
@@ -3,14 +3,6 @@ require 'spec_helper'
RSpec.describe Spree::Collection, type: :model do
let(:store) { @default_store }
- describe 'metadata' do
- it 'defaults to an empty hash and round-trips a JSON value' do
- collection = create(:collection, metadata: { erp_id: '123' })
- expect(create(:collection).metadata).to eq({})
- expect(collection.reload.metadata).to eq({ 'erp_id' => '123' })
- end
- end
-
describe 'permalink generation' do
it 'derives a url-safe permalink from the name' do
expect(create(:collection, name: 'Summer Sale').permalink).to eq('summer-sale')
diff --git a/spree/core/spec/models/spree/commission_rate_spec.rb b/spree/core/spec/models/spree/commission_rate_spec.rb
index 768aa447e7..79261ffb71 100644
--- a/spree/core/spec/models/spree/commission_rate_spec.rb
+++ b/spree/core/spec/models/spree/commission_rate_spec.rb
@@ -180,12 +180,6 @@ RSpec.describe Spree::CommissionRate, type: :model do
expect(rate.amount_for('EUR')).to be_nil
end
- # A flat fee charging nothing anywhere is skipped for every sale, which
- # reads as a broken rate rather than a disabled one.
- it 'refuses a flat fee that states no amount at all' do
- expect(build(:commission_rate, kind: 'fixed', value: 0)).not_to be_valid
- end
-
# Charging the flat amount again per parcel would bill one sale twice, so
# a marketplace wanting a flat delivery charge states it as its own rate.
it 'refuses to also charge delivery' do
@@ -375,13 +369,6 @@ RSpec.describe Spree::CommissionRate, type: :model do
# The list IS the precedence, so a new rate has to take effect on
# creation — appending would file it behind the catch-all that already
# matches everything, leaving it dead on arrival.
- it 'puts a new rate at the top of the list' do
- first = create(:commission_rate, store: store)
- second = create(:commission_rate, store: store)
-
- expect(described_class.ordered.to_a).to eq([second, first])
- end
-
it 'walks the list top-down' do
bottom = create(:commission_rate, store: store)
top = create(:commission_rate, store: store)
diff --git a/spree/core/spec/models/spree/company_spec.rb b/spree/core/spec/models/spree/company_spec.rb
index 1e1639f97f..efe19ead8a 100644
--- a/spree/core/spec/models/spree/company_spec.rb
+++ b/spree/core/spec/models/spree/company_spec.rb
@@ -44,24 +44,11 @@ describe Spree::Company, type: :model do
expect(build(:company, store: store)).to be_valid
end
-
- it 'carries one identity per external system' do
- company = create(:company, store: store)
- company.set_external_id('erp', 'ACME')
- company.set_external_id('crm', 'CUST-1')
-
- expect(company.external_id_for('erp')).to eq('ACME')
- expect(company.external_id_for('crm')).to eq('CUST-1')
- end
end
describe 'the tree' do
let(:root) { create(:company, store: store) }
- it 'defaults a node to the company kind' do
- expect(Spree::Company.new.kind).to eq('company')
- end
-
it 'refuses a division at the root' do
expect(build(:company, store: store, kind: 'division')).not_to be_valid
end
@@ -259,14 +246,6 @@ describe Spree::Company, type: :model do
end
end
- describe 'metadata' do
- it 'persists to the single metadata column' do
- company = create(:company, store: store, metadata: { 'erp_ref' => 'X-1' })
-
- expect(company.reload.metadata['erp_ref']).to eq('X-1')
- end
- end
-
describe 'deletion' do
# There is no foreign key behind spree_orders.company_id and children are
# destroyed with the node, so an unguarded delete would strand a placed
@@ -299,15 +278,4 @@ describe Spree::Company, type: :model do
expect(company.destroy).to be_truthy
end
end
-
- it 'destroys its memberships, addresses and invitations' do
- company = create(:company, store: store)
- create(:company_membership, company: company)
- create(:company_address, owner: company)
- create(:company_invitation, company: company)
-
- expect { company.destroy }.to change(Spree::CompanyMembership, :count).by(-1).
- and change(Spree::Address, :count).by(-1).
- and change(Spree::CompanyInvitation, :count).by(-1)
- end
end
diff --git a/spree/core/spec/models/spree/concerns/admin_user_methods_spec.rb b/spree/core/spec/models/spree/concerns/admin_user_methods_spec.rb
index 5e4e38e421..265251bc18 100644
--- a/spree/core/spec/models/spree/concerns/admin_user_methods_spec.rb
+++ b/spree/core/spec/models/spree/concerns/admin_user_methods_spec.rb
@@ -4,16 +4,6 @@ describe Spree::AdminUserMethods do
let(:admin_user) { create(:admin_user) }
let(:current_store) { @default_store }
- describe 'prefixed_id' do
- it 'generates a prefixed_id starting with adm_' do
- expect(admin_user.prefixed_id).to start_with('adm_')
- end
-
- it 'uses prefixed_id as to_param' do
- expect(admin_user.to_param).to eq(admin_user.prefixed_id)
- end
- end
-
describe 'normalizations' do
it 'normalizes email' do
admin_user.update(email: ' [email protected] ')
@@ -67,44 +57,9 @@ describe Spree::AdminUserMethods do
end
end
- describe 'selected_locale' do
- # The admin-UI display language is a client concern (the React dashboard
- # ships its own locale bundles); the backend just stores the preference and
- # does NOT validate it against Spree.available_locales (Rails/Spree
- # locales), which is an unrelated list. Each consumer applies it against its
- # own supported set.
- it 'stores any locale code, including ones the Rails backend has no translations for' do
- admin_user.update(selected_locale: 'pl')
- expect(admin_user.reload.selected_locale).to eq('pl')
- end
-
- it 'accepts a blank value' do
- admin_user.update!(selected_locale: 'pl')
- admin_user.update!(selected_locale: nil)
- expect(admin_user.reload.selected_locale).to be_nil
- end
- end
-
- describe 'ransackable attributes' do
- it 'allows searching by id' do
- expect(Spree.admin_user_class.ransackable_attributes).to include('id')
- end
-
- it 'allows searching by email' do
- expect(Spree.admin_user_class.ransackable_attributes).to include('email')
- end
-
- it 'allows searching by first_name' do
- expect(Spree.admin_user_class.ransackable_attributes).to include('first_name')
- end
-
- it 'allows searching by last_name' do
- expect(Spree.admin_user_class.ransackable_attributes).to include('last_name')
- end
- end
-
- describe 'ransackable associations' do
- it 'allows searching by spree_roles' do
+ describe 'ransackable attributes and associations' do
+ it 'allows searching by id, email, names and roles' do
+ expect(Spree.admin_user_class.ransackable_attributes).to include('id', 'email', 'first_name', 'last_name')
expect(Spree.admin_user_class.ransackable_associations).to include('spree_roles')
end
end
@@ -181,43 +136,4 @@ describe Spree::AdminUserMethods do
end
end
end
-
- describe 'class configuration' do
- it 'uses a different class than Spree.customer_class' do
- expect(Spree.admin_user_class).to eq(Spree::AdminUser)
- expect(Spree.customer_class).to eq(Spree::Customer)
- expect(Spree.admin_user_class).not_to eq(Spree.customer_class)
- end
-
- it 'does not include CustomerMethods' do
- expect(Spree::AdminUser.included_modules).not_to include(Spree::CustomerMethods)
- end
-
- it 'includes AdminUserMethods' do
- expect(Spree::AdminUser.included_modules).to include(Spree::AdminUserMethods)
- end
- end
-
- describe 'avatar attachment' do
- it 'can attach an avatar' do
- admin_user.avatar.attach(
- io: File.open(Spree::Core::Engine.root.join('spec', 'fixtures', 'thinking-cat.jpg')),
- filename: 'avatar.jpg',
- content_type: 'image/jpeg'
- )
- expect(admin_user.avatar).to be_attached
- end
- end
-
- describe 'roles integration' do
- it 'can have roles assigned' do
- role = create(:role, name: 'custom_role')
- admin_user.add_role('custom_role', current_store)
- expect(admin_user.has_spree_role?('custom_role', current_store)).to be(true)
- end
-
- it 'can check admin status' do
- expect(admin_user.spree_admin?(current_store)).to be(true)
- end
- end
end
diff --git a/spree/core/spec/models/spree/concerns/metadata_spec.rb b/spree/core/spec/models/spree/concerns/metadata_spec.rb
index 32ca5ae800..3b87faff5d 100644
--- a/spree/core/spec/models/spree/concerns/metadata_spec.rb
+++ b/spree/core/spec/models/spree/concerns/metadata_spec.rb
@@ -3,26 +3,6 @@ require 'spec_helper'
RSpec.describe Spree::Metadata do
let(:product) { build(:product) }
- describe '#metadata' do
- it 'defaults to an empty hash' do
- expect(product.metadata).to eq({})
- end
-
- it 'reads back with indifferent access' do
- product.metadata = { 'key' => 'value' }
- expect(product.metadata[:key]).to eq('value')
- expect(product.metadata['key']).to eq('value')
- end
- end
-
- describe 'merge semantics' do
- it 'supports merging metadata' do
- product.metadata = { 'a' => '1' }
- product.metadata = product.metadata.merge('b' => '2')
- expect(product.metadata).to eq('a' => '1', 'b' => '2')
- end
- end
-
describe 'the private_metadata deprecation bridge' do
it 'reads through to metadata with a warning' do
product.metadata = { 'key' => 'value' }
@@ -38,10 +18,4 @@ RSpec.describe Spree::Metadata do
expect(product.metadata).to eq('key' => 'value')
end
end
-
- describe 'public_metadata' do
- it 'is gone' do
- expect(product).not_to respond_to(:public_metadata)
- end
- end
end
diff --git a/spree/core/spec/models/spree/concerns/prefixed_id_spec.rb b/spree/core/spec/models/spree/concerns/prefixed_id_spec.rb
index 7d93d376c1..554a29d90e 100644
--- a/spree/core/spec/models/spree/concerns/prefixed_id_spec.rb
+++ b/spree/core/spec/models/spree/concerns/prefixed_id_spec.rb
@@ -87,14 +87,6 @@ RSpec.describe Spree::PrefixedId do
expect(session.external_id).to eq('seti_test456')
end
end
-
- context 'with no prefixed IDs present' do
- it 'does not modify attributes' do
- product = build(:product)
- product.assign_attributes(name: 'Updated Name')
- expect(product.name).to eq('Updated Name')
- end
- end
end
describe '.find_by_prefix_id!' do
diff --git a/spree/core/spec/models/spree/concerns/user_management_spec.rb b/spree/core/spec/models/spree/concerns/user_management_spec.rb
index 1a38530fbe..ef5e30ba49 100644
--- a/spree/core/spec/models/spree/concerns/user_management_spec.rb
+++ b/spree/core/spec/models/spree/concerns/user_management_spec.rb
@@ -49,34 +49,4 @@ describe Spree::UserManagement do
end
end
end
-
- describe 'associations' do
- it 'has many roles' do
- association = test_store.class.reflect_on_association(:roles)
- expect(association.macro).to eq :has_many
- expect(association.options[:class_name]).to eq 'Spree::Role'
- expect(association.options[:as]).to eq :resource
- end
-
- # Assignments reach the resource through its roles, not directly.
- it 'has many role_users through roles' do
- association = test_store.class.reflect_on_association(:role_users)
- expect(association.macro).to eq :has_many
- expect(association.options[:through]).to eq :roles
- end
-
- it 'has many users through role_users' do
- association = test_store.class.reflect_on_association(:users)
- expect(association.macro).to eq :has_many
- expect(association.options[:through]).to eq :role_users
- expect(association.options[:source]).to eq :user
- expect(association.options[:source_type]).to eq Spree.admin_user_class.to_s
- end
-
- it 'has many invitations' do
- association = test_store.class.reflect_on_association(:invitations)
- expect(association.macro).to eq :has_many
- expect(association.options[:class_name]).to eq 'Spree::Invitation'
- end
- end
end
diff --git a/spree/core/spec/models/spree/concerns/user_methods_spec.rb b/spree/core/spec/models/spree/concerns/user_methods_spec.rb
index 10a0b3b311..a69a5e246f 100644
--- a/spree/core/spec/models/spree/concerns/user_methods_spec.rb
+++ b/spree/core/spec/models/spree/concerns/user_methods_spec.rb
@@ -48,7 +48,7 @@ describe Spree::CustomerMethods do
end
context 'with incomplete canceled order' do
- let(:canceled_order) { create(:order, customer: test_user, created_at: 1.day.ago, store: current_store, state: 'canceled') }
+ let!(:canceled_order) { create(:order, customer: test_user, created_at: 1.day.ago, store: current_store, state: 'canceled') }
it { is_expected.to be_nil }
end
@@ -132,19 +132,14 @@ describe Spree::CustomerMethods do
# Superseded by Spree::Customers::Anonymize, which this now delegates to.
# The tombstone names changed with it — the anonymizer's coverage is in
# spec/workflows/spree/customers/anonymize_spec.rb.
- it 'erases the email and names' do
+ it 'warns and erases the email and names' do
expect { test_user.scramble_email_and_names }.
to change(test_user, :email).and change(test_user, :first_name).and change(test_user, :last_name)
+ expect(Spree::Deprecation).to have_received(:warn).at_least(:once)
expect(test_user.first_name).to eq(Spree::Customers::Anonymize::REDACTED_NAME)
expect(test_user.last_name).to eq(Spree::Customers::Anonymize::REDACTED_NAME)
end
-
- it 'warns that it is deprecated' do
- expect(Spree::Deprecation).to receive(:warn).at_least(:once)
-
- test_user.scramble_email_and_names
- end
end
describe '#invited_by' do
diff --git a/spree/core/spec/models/spree/concerns/user_roles_spec.rb b/spree/core/spec/models/spree/concerns/user_roles_spec.rb
index 0def909def..7d18c9de1c 100644
--- a/spree/core/spec/models/spree/concerns/user_roles_spec.rb
+++ b/spree/core/spec/models/spree/concerns/user_roles_spec.rb
@@ -11,26 +11,11 @@ describe Spree::UserRoles do
expect(test_user.has_spree_role?('test', current_store)).to be_truthy
end
-
- context 'when a resource parameter is provided' do
- let(:resource) { create(:store) }
- # A role belongs to what it governs, so the grant needs one here.
- let!(:resource_role) { create(:role, name: 'test', resource: resource) }
-
- before { test_user.add_role('test', resource) }
-
- it 'adds a role to the user for the resource' do
- expect(test_user.has_spree_role?('test', resource)).to be_truthy
- end
- end
end
describe '#remove_role' do
it 'removes a role from the user' do
test_user.add_role('test')
-
- expect(test_user.has_spree_role?('test')).to be_truthy
-
test_user.remove_role('test')
expect(test_user.has_spree_role?('test')).to be_falsy
@@ -93,8 +78,6 @@ describe Spree::UserRoles do
context 'when a resource parameter is provided' do
let(:resource) { create(:store) }
- # A role belongs to what it governs, so the grant needs one here.
- let!(:resource_role) { create(:role, name: 'test', resource: resource) }
it 'checks against the resource' do
Spree::Role.default_admin_role(resource)
diff --git a/spree/core/spec/models/spree/country_spec.rb b/spree/core/spec/models/spree/country_spec.rb
index 16af73f512..e40c312bbd 100644
--- a/spree/core/spec/models/spree/country_spec.rb
+++ b/spree/core/spec/models/spree/country_spec.rb
@@ -97,10 +97,6 @@ describe Spree::Country, type: :model do
end
describe '#default?' do
- before do
- allow_any_instance_of(Spree::Store).to receive(:default).and_return(store)
- end
-
context 'no arguments' do
it 'returns true for store default country' do
expect(america.default?).to eq(true)
diff --git a/spree/core/spec/models/spree/coupon_code_spec.rb b/spree/core/spec/models/spree/coupon_code_spec.rb
index da254e7e75..2c02e0783a 100644
--- a/spree/core/spec/models/spree/coupon_code_spec.rb
+++ b/spree/core/spec/models/spree/coupon_code_spec.rb
@@ -6,11 +6,6 @@ RSpec.describe Spree::CouponCode, type: :model do
describe 'validations' do
describe 'code' do
- it 'validates presence' do
- coupon_code.code = nil
- expect(coupon_code).not_to be_valid
- end
-
it 'validates uniqueness' do
other_coupon_code = promotion.coupon_codes.last
diff --git a/spree/core/spec/models/spree/credit_card_spec.rb b/spree/core/spec/models/spree/credit_card_spec.rb
index a5c538ec27..3212b089cf 100644
--- a/spree/core/spec/models/spree/credit_card_spec.rb
+++ b/spree/core/spec/models/spree/credit_card_spec.rb
@@ -16,8 +16,6 @@ describe Spree::CreditCard, type: :model do
let(:payment) { create(:payment, amount: 100, order: order) }
let(:payment_method) { create(:payment_method) }
- before { allow(payment).to receive_messages payment_method: payment_method }
-
describe '#can_capture?' do
shared_examples 'can be captured' do
it 'can be captured' do
@@ -111,18 +109,6 @@ describe Spree::CreditCard, type: :model do
expect(credit_card.errors[:verification_value]).to eq(["can't be blank"])
end
- it 'validates name presence' do
- credit_card.valid?
- expect(credit_card.errors).not_to be_empty
- expect(credit_card.errors.messages[:name]).to be_present
- end
-
- it 'only validates on create' do
- credit_card.attributes = valid_credit_card_attributes
- credit_card.save
- expect(credit_card).to be_valid
- end
-
context 'encrypted data is present' do
it 'does not validate presence of number or cvv' do
credit_card.encrypted_data = '$fdgsfgdgfgfdg&gfdgfdgsf-'
@@ -338,12 +324,6 @@ describe Spree::CreditCard, type: :model do
end
end
- context 'Associations' do
- it 'is able to access its payments' do
- expect { credit_card.payments.to_a }.not_to raise_error
- end
- end
-
describe '#first_name' do
before do
credit_card.name = 'Ludwig van Beethoven'
@@ -398,6 +378,8 @@ describe Spree::CreditCard, type: :model do
context 'Scopes' do
describe '#not_expired' do
+ around { |example| Timecop.freeze(Time.current.change(month: 6, day: 15)) { example.run } }
+
let(:previous_year) { DateTime.now.year - 1 }
let(:current_year) { DateTime.now.year }
let(:next_year) { DateTime.now.year + 1 }
@@ -500,7 +482,7 @@ describe Spree::CreditCard, type: :model do
it 'invalidates the payment' do
card.destroy
- expect(checkout_payment.reload.state).to eq('invalid')
+ expect(checkout_payment.reload.status).to eq('invalid')
end
end
@@ -511,8 +493,8 @@ describe Spree::CreditCard, type: :model do
it 'voids the payments' do
card.destroy
- expect(completed_payment.reload.state).to eq('void')
- expect(pending_payment.reload.state).to eq('void')
+ expect(completed_payment.reload.status).to eq('void')
+ expect(pending_payment.reload.status).to eq('void')
end
end
@@ -523,14 +505,8 @@ describe Spree::CreditCard, type: :model do
it 'does not modify payments on completed orders' do
card.destroy
- expect(completed_order_payment.reload.state).to eq('completed')
+ expect(completed_order_payment.reload.status).to eq('completed')
end
end
-
- it 'soft deletes the credit card' do
- card.destroy
-
- expect(card.reload.deleted_at).not_to be_nil
- end
end
end
diff --git a/spree/core/spec/models/spree/current_spec.rb b/spree/core/spec/models/spree/current_spec.rb
index 10ec4c6b51..6b2f3b19b5 100644
--- a/spree/core/spec/models/spree/current_spec.rb
+++ b/spree/core/spec/models/spree/current_spec.rb
@@ -6,16 +6,6 @@ RSpec.describe Spree::Current do
end
describe '#store' do
- context 'when store is set' do
- let(:store) { create(:store) }
-
- before { described_class.store = store }
-
- it 'returns the set store' do
- expect(described_class.store).to eq(store)
- end
- end
-
context 'when store is not set' do
it 'returns the default store' do
expect(described_class.store).to eq(Spree::Store.default)
@@ -24,14 +14,6 @@ RSpec.describe Spree::Current do
end
describe '#currency' do
- context 'when currency is set' do
- before { described_class.currency = 'EUR' }
-
- it 'returns the set currency' do
- expect(described_class.currency).to eq('EUR')
- end
- end
-
context 'when currency is not set' do
let!(:store) { create(:store, default: true, default_currency: 'GBP') }
@@ -42,16 +24,6 @@ RSpec.describe Spree::Current do
end
describe '#tax_country' do
- context 'when tax_country is set' do
- let(:country) { create(:country) }
-
- before { described_class.tax_country = country }
-
- it 'returns the set country' do
- expect(described_class.tax_country).to eq(country)
- end
- end
-
context 'when tax_country is not set' do
let!(:store) { create(:store, default: true) }
let(:market) { create(:market, store: store) }
@@ -72,14 +44,6 @@ RSpec.describe Spree::Current do
end
describe '#locale' do
- context 'when locale is set' do
- before { described_class.locale = 'fr' }
-
- it 'returns the set locale' do
- expect(described_class.locale).to eq('fr')
- end
- end
-
context 'when locale is not set but market has a default locale' do
let!(:store) { create(:store, default: true, default_locale: 'en') }
let!(:market) { create(:market, store: store, default: true, default_locale: 'de') }
@@ -107,14 +71,6 @@ RSpec.describe Spree::Current do
end
describe '#content_locale' do
- context 'when content_locale is set' do
- before { described_class.content_locale = 'de' }
-
- it 'returns the set content locale' do
- expect(described_class.content_locale).to eq('de')
- end
- end
-
context 'when content_locale is not set' do
it 'falls back to the application default locale' do
expect(described_class.content_locale).to eq(I18n.default_locale.to_s)
@@ -131,16 +87,6 @@ RSpec.describe Spree::Current do
end
describe '#market' do
- context 'when market is set' do
- let(:market) { create(:market) }
-
- before { described_class.market = market }
-
- it 'returns the set market' do
- expect(described_class.market).to eq(market)
- end
- end
-
context 'when market is not set' do
let!(:store) { create(:store, default: true) }
let!(:market) { create(:market, store: store, default: true) }
@@ -149,14 +95,6 @@ RSpec.describe Spree::Current do
expect(described_class.market).to eq(market)
end
end
-
- context 'when market is not set' do
- let!(:store) { create(:store, default: true) }
-
- it 'falls back to the store default market' do
- expect(described_class.market).to eq(store.default_market)
- end
- end
end
describe '#global_pricing_context' do
@@ -169,10 +107,6 @@ RSpec.describe Spree::Current do
described_class.market = market
end
- it 'returns a Spree::Pricing::Context' do
- expect(described_class.global_pricing_context).to be_a(Spree::Pricing::Context)
- end
-
it 'uses the current store' do
expect(described_class.global_pricing_context.store).to eq(store)
end
@@ -220,10 +154,6 @@ RSpec.describe Spree::Current do
expect(described_class.price_lists).not_to include(other_store_price_list)
end
- it 'includes active price lists' do
- expect(described_class.price_lists).to include(active_price_list)
- end
-
it 'includes scheduled price lists within date range' do
expect(described_class.price_lists).to include(scheduled_price_list)
end
@@ -367,12 +297,6 @@ RSpec.describe Spree::Current do
end
describe '#provider_cache' do
- it 'defaults to a hash providers can memoize into' do
- described_class.provider_cache[:quote] = 'cached'
-
- expect(described_class.provider_cache[:quote]).to eq('cached')
- end
-
# Carrier quotes are request-scoped; leaking them across requests would
# price one customer's checkout with another's destination.
it 'is cleared between requests' do
diff --git a/spree/core/spec/models/spree/custom_field_definition_spec.rb b/spree/core/spec/models/spree/custom_field_definition_spec.rb
index 69c48293db..7c09a4c03c 100644
--- a/spree/core/spec/models/spree/custom_field_definition_spec.rb
+++ b/spree/core/spec/models/spree/custom_field_definition_spec.rb
@@ -181,13 +181,6 @@ RSpec.describe Spree::CustomFieldDefinition, type: :model do
Spree::Current.store = nil
end
- it 'is reachable through the store association' do
- custom_field_definition = create(:custom_field_definition, store: other_store)
-
- expect(other_store.custom_field_definitions).to include(custom_field_definition)
- expect(@default_store.custom_field_definitions).not_to include(custom_field_definition)
- end
-
it 'allows the same namespace and key in two stores' do
create(:custom_field_definition, store: @default_store, resource_type: 'Spree::Product',
namespace: 'custom', key: 'material')
@@ -218,15 +211,6 @@ RSpec.describe Spree::CustomFieldDefinition, type: :model do
expect(colliding.errors[:filter_key]).to be_present
end
- it 'allows the same filter_key in a different store' do
- create(:custom_field_definition, store: @default_store, resource_type: 'Spree::Product',
- namespace: 'a_b', key: 'c')
- other_store = build(:custom_field_definition, store: create(:store), resource_type: 'Spree::Product',
- namespace: 'a', key: 'b_c')
-
- expect(other_store).to be_valid
- end
-
it 'allows the same namespace/key split on a different resource type' do
create(:custom_field_definition, resource_type: 'Spree::Product', namespace: 'a_b', key: 'c')
other_resource = build(:custom_field_definition, resource_type: 'Spree::Variant', namespace: 'a', key: 'b_c')
diff --git a/spree/core/spec/models/spree/custom_field_spec.rb b/spree/core/spec/models/spree/custom_field_spec.rb
index 5a6e6c459b..1ef896a2f2 100644
--- a/spree/core/spec/models/spree/custom_field_spec.rb
+++ b/spree/core/spec/models/spree/custom_field_spec.rb
@@ -29,13 +29,6 @@ RSpec.describe Spree::CustomField, type: :model do
end
end
- describe '#serialize_value' do
- it 'returns the value' do
- custom_field = build(:custom_field, value: 'Test Value')
- expect(custom_field.serialize_value).to eq('Test Value')
- end
- end
-
describe '#csv_value' do
context 'for base CustomField' do
it 'returns the value as string' do
@@ -76,24 +69,6 @@ RSpec.describe Spree::CustomField, type: :model do
end
end
- context 'for ShortText custom_field' do
- let(:custom_field_definition) { create(:custom_field_definition, field_type: 'Spree::CustomFields::ShortText') }
-
- it 'returns the text value' do
- custom_field = Spree::CustomFields::ShortText.new(custom_field_definition: custom_field_definition, value: 'Short text')
- expect(custom_field.csv_value).to eq('Short text')
- end
- end
-
- context 'for LongText custom_field' do
- let(:custom_field_definition) { create(:custom_field_definition, field_type: 'Spree::CustomFields::LongText') }
-
- it 'returns the text value' do
- custom_field = Spree::CustomFields::LongText.new(custom_field_definition: custom_field_definition, value: 'Long text content')
- expect(custom_field.csv_value).to eq('Long text content')
- end
- end
-
context 'for RichText custom_field' do
let(:custom_field_definition) { create(:custom_field_definition, field_type: 'Spree::CustomFields::RichText') }
@@ -188,6 +163,7 @@ RSpec.describe Spree::CustomField, type: :model do
it 'assigns through metafield_definition=' do
definition = create(:custom_field_definition)
custom_field = Spree::CustomField.new
+ expect(Spree::Deprecation).to receive(:warn).with(/metafield_definition= is deprecated/)
custom_field.metafield_definition = definition
expect(custom_field.custom_field_definition).to eq(definition)
diff --git a/spree/core/spec/models/spree/custom_fields/boolean_spec.rb b/spree/core/spec/models/spree/custom_fields/boolean_spec.rb
index 6e5a2eaf7a..1fc422c741 100644
--- a/spree/core/spec/models/spree/custom_fields/boolean_spec.rb
+++ b/spree/core/spec/models/spree/custom_fields/boolean_spec.rb
@@ -24,11 +24,4 @@ describe Spree::CustomFields::Boolean, type: :model do
expect(custom_field.csv_value).to eq('Yes')
end
end
-
- describe '.searchable? / .sortable?' do
- it 'is neither searchable nor sortable (filterable in Phase 6)' do
- expect(described_class.searchable?).to eq(false)
- expect(described_class.sortable?).to eq(false)
- end
- end
end
diff --git a/spree/core/spec/models/spree/custom_fields/number_spec.rb b/spree/core/spec/models/spree/custom_fields/number_spec.rb
index 87d1dafd90..722c31452b 100644
--- a/spree/core/spec/models/spree/custom_fields/number_spec.rb
+++ b/spree/core/spec/models/spree/custom_fields/number_spec.rb
@@ -26,11 +26,4 @@ describe Spree::CustomFields::Number, type: :model do
expect(custom_field.csv_value).to eq('123.0')
end
end
-
- describe '.searchable? / .sortable?' do
- it 'is searchable and sortable' do
- expect(described_class.searchable?).to eq(true)
- expect(described_class.sortable?).to eq(true)
- end
- end
end
diff --git a/spree/core/spec/models/spree/custom_fields/rich_text_spec.rb b/spree/core/spec/models/spree/custom_fields/rich_text_spec.rb
index fa8b616ac0..9d9a14b3fc 100644
--- a/spree/core/spec/models/spree/custom_fields/rich_text_spec.rb
+++ b/spree/core/spec/models/spree/custom_fields/rich_text_spec.rb
@@ -8,12 +8,6 @@ describe Spree::CustomFields::RichText, type: :model do
value: '<p>Rich text with <strong>formatting</strong></p>')
end
- describe '#value' do
- it 'stores HTML in the shared value column' do
- expect(custom_field.value).to eq('<p>Rich text with <strong>formatting</strong></p>')
- end
- end
-
describe '#serialize_value' do
it 'returns the stored HTML' do
expect(custom_field.serialize_value).to eq('<p>Rich text with <strong>formatting</strong></p>')
diff --git a/spree/core/spec/models/spree/custom_fields/short_text_spec.rb b/spree/core/spec/models/spree/custom_fields/short_text_spec.rb
deleted file mode 100644
index addb106b5a..0000000000
--- a/spree/core/spec/models/spree/custom_fields/short_text_spec.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-describe Spree::CustomFields::ShortText, type: :model do
- describe '.searchable? / .sortable?' do
- it 'is searchable and sortable' do
- expect(described_class.searchable?).to eq(true)
- expect(described_class.sortable?).to eq(true)
- end
- end
-end
diff --git a/spree/core/spec/models/spree/customer_group_spec.rb b/spree/core/spec/models/spree/customer_group_spec.rb
index 6250e98e92..8f7fd4e26b 100644
--- a/spree/core/spec/models/spree/customer_group_spec.rb
+++ b/spree/core/spec/models/spree/customer_group_spec.rb
@@ -5,32 +5,11 @@ RSpec.describe Spree::CustomerGroup, type: :model do
let(:customer_group) { create(:customer_group, store: store) }
describe 'validations' do
- context 'uniqueness' do
- let!(:existing_group) { create(:customer_group, name: 'VIP', store: store) }
+ it 'validates uniqueness of name within store scope' do
+ create(:customer_group, name: 'VIP', store: store)
- it 'validates uniqueness of name within store scope' do
- new_group = build(:customer_group, name: 'VIP', store: store)
- expect(new_group).not_to be_valid
- expect(new_group.errors[:name]).to include('has already been taken')
- end
-
- it 'allows same name in different store' do
- other_store = create(:store)
- new_group = build(:customer_group, name: 'VIP', store: other_store)
- expect(new_group).to be_valid
- end
- end
- end
-
- describe 'scopes' do
- describe '.for_store' do
- let!(:group1) { create(:customer_group, store: store) }
- let!(:group2) { create(:customer_group, store: create(:store)) }
-
- it 'returns groups for the specified store' do
- expect(described_class.for_store(store)).to include(group1)
- expect(described_class.for_store(store)).not_to include(group2)
- end
+ expect(build(:customer_group, name: 'VIP', store: store)).not_to be_valid
+ expect(build(:customer_group, name: 'VIP', store: create(:store))).to be_valid
end
end
@@ -48,30 +27,19 @@ RSpec.describe Spree::CustomerGroup, type: :model do
end
end
- describe 'soft delete' do
- it 'supports soft deletion' do
- customer_group.destroy
- expect(described_class.with_deleted.find(customer_group.id)).to be_present
- expect(described_class.find_by(id: customer_group.id)).to be_nil
- end
- end
-
describe '#add_customers' do
let(:user1) { create(:user) }
let(:user2) { create(:user) }
let(:user3) { create(:user) }
- it 'adds customers to the group' do
+ it 'adds customers to the group and returns how many were added' do
+ count = nil
expect {
- customer_group.add_customers([user1.id, user2.id])
+ count = customer_group.add_customers([user1.id, user2.id])
}.to change { customer_group.customer_group_users.count }.by(2)
- expect(customer_group.users).to include(user1, user2)
- end
-
- it 'returns the count of added customers' do
- count = customer_group.add_customers([user1.id, user2.id])
expect(count).to eq(2)
+ expect(customer_group.users).to include(user1, user2)
end
it 'skips users already in the group' do
@@ -131,20 +99,17 @@ RSpec.describe Spree::CustomerGroup, type: :model do
customer_group.add_customers([user1.id, user2.id, user3.id])
end
- it 'removes customers from the group' do
+ it 'removes customers from the group and returns how many were removed' do
+ count = nil
expect {
- customer_group.remove_customers([user1.id, user2.id])
+ count = customer_group.remove_customers([user1.id, user2.id])
}.to change { customer_group.customer_group_users.count }.by(-2)
+ expect(count).to eq(2)
expect(customer_group.users).not_to include(user1, user2)
expect(customer_group.users).to include(user3)
end
- it 'returns the count of removed customers' do
- count = customer_group.remove_customers([user1.id, user2.id])
- expect(count).to eq(2)
- end
-
it 'returns 0 when users are not in the group' do
other_user = create(:user)
count = customer_group.remove_customers([other_user.id])
diff --git a/spree/core/spec/models/spree/customer_group_user_spec.rb b/spree/core/spec/models/spree/customer_group_user_spec.rb
deleted file mode 100644
index cc01155fdd..0000000000
--- a/spree/core/spec/models/spree/customer_group_user_spec.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-require 'spec_helper'
-
-RSpec.describe Spree::CustomerGroupUser, type: :model do
- let(:customer_group) { create(:customer_group) }
- let(:user) { create(:user) }
-
- describe 'validations' do
- context 'uniqueness' do
- let!(:existing) { create(:customer_group_user, customer_group: customer_group, customer: user) }
-
- it 'validates uniqueness of customer_group_id within user scope' do
- duplicate = build(:customer_group_user, customer_group: customer_group, customer: user)
- expect(duplicate).not_to be_valid
- expect(duplicate.errors[:customer_group_id]).to include('has already been taken')
- end
-
- it 'allows same user in different groups' do
- other_group = create(:customer_group)
- new_membership = build(:customer_group_user, customer_group: other_group, customer: user)
- expect(new_membership).to be_valid
- end
- end
- end
-end
diff --git a/spree/core/spec/models/spree/customer_spec.rb b/spree/core/spec/models/spree/customer_spec.rb
index 24de728ddd..4207013298 100644
--- a/spree/core/spec/models/spree/customer_spec.rb
+++ b/spree/core/spec/models/spree/customer_spec.rb
@@ -4,14 +4,6 @@ describe Spree::Customer, type: :model do
subject(:customer) { create(:customer, password: 'secret-123', password_confirmation: 'secret-123') }
describe 'has_secure_password' do
- it 'authenticates with the correct password' do
- expect(customer.authenticate('secret-123')).to eq(customer)
- end
-
- it 'rejects an incorrect password' do
- expect(customer.authenticate('wrong')).to be(false)
- end
-
it 'exposes valid_password? as an alias for authenticate' do
expect(customer.valid_password?('secret-123')).to be(true)
expect(customer.valid_password?('wrong')).to be(false)
@@ -22,18 +14,6 @@ describe Spree::Customer, type: :model do
end
end
- describe 'validations' do
- it 'requires an email' do
- expect(build(:customer, email: nil)).not_to be_valid
- end
-
- it 'enforces case-insensitive email uniqueness' do
- customer
- dup = build(:customer, email: customer.email.upcase)
- expect(dup).not_to be_valid
- end
- end
-
describe 'password reset tokens' do
it 'round-trips through find_by_password_reset_token' do
token = customer.generate_token_for(:password_reset)
@@ -77,10 +57,4 @@ describe Spree::Customer, type: :model do
expect(customer.reload.ship_address_id).to eq(labelled.id)
end
end
-
- describe 'prefixed id' do
- it 'uses the cust_ prefix' do
- expect(customer.prefixed_id).to start_with('cust_')
- end
- end
end
diff --git a/spree/core/spec/models/spree/data_feed/google_spec.rb b/spree/core/spec/models/spree/data_feed/google_spec.rb
index feb84efcf5..bd34f27dd5 100644
--- a/spree/core/spec/models/spree/data_feed/google_spec.rb
+++ b/spree/core/spec/models/spree/data_feed/google_spec.rb
@@ -33,12 +33,4 @@ describe Spree::DataFeed::Google, type: :model do
expect(data_feed.formatted_url).to eq(expected_url)
end
end
-
- describe '.label' do
- subject { Spree::DataFeed::Google.label }
-
- it 'returns a descriptive label' do
- expect(subject).to eq('Google Merchant Center Feed')
- end
- end
end
diff --git a/spree/core/spec/models/spree/delivery_method_rule_spec.rb b/spree/core/spec/models/spree/delivery_method_rule_spec.rb
index 4104dca49d..39b808e6d7 100644
--- a/spree/core/spec/models/spree/delivery_method_rule_spec.rb
+++ b/spree/core/spec/models/spree/delivery_method_rule_spec.rb
@@ -175,7 +175,7 @@ describe Spree::DeliveryMethodRule, type: :model do
let(:company_package) do
create(:company_membership, company: company, customer: customer)
- cart = create(:cart, store: store, user: customer, company: company)
+ cart = create(:cart, store: store, customer: customer, company: company)
create(:line_item, cart: cart, order: nil)
fulfillment = create(:fulfillment, cart: cart, order: nil, stock_location: create(:stock_location))
fulfillment.to_package
@@ -190,13 +190,6 @@ describe Spree::DeliveryMethodRule, type: :model do
expect(rule.eligible?(package)).to be(false)
end
- it 'hides a freight method from a retail cart' do
- rule = described_class.new(delivery_method: delivery_method, preferred_company_orders_only: true)
-
- expect(rule.eligible?(company_package)).to be(true)
- expect(rule.eligible?(package)).to be(false)
- end
-
it 'hides a parcel method from a company cart when turned off' do
rule = described_class.new(delivery_method: delivery_method, preferred_company_orders_only: false)
diff --git a/spree/core/spec/models/spree/delivery_method_spec.rb b/spree/core/spec/models/spree/delivery_method_spec.rb
index 019c52d1ec..1d3c7df2f8 100644
--- a/spree/core/spec/models/spree/delivery_method_spec.rb
+++ b/spree/core/spec/models/spree/delivery_method_spec.rb
@@ -84,13 +84,6 @@ describe Spree::DeliveryMethod, type: :model do
expect(method.requires_zone_check?).to be false
end
end
-
- it 'is true for the Manual provider' do
- method = create(:delivery_method)
-
- expect(method.fulfillment_provider).to eq('Spree::FulfillmentProvider::Manual')
- expect(method.requires_address?).to be true
- end
end
describe '#serves_location?' do
@@ -148,30 +141,10 @@ describe Spree::DeliveryMethod, type: :model do
])
expect(described_class.calculators).to eq([Spree::Calculator::Shipping::FlatPercentItemTotal, Spree::Calculator::Shipping::PriceSack, DummyShippingCalculator])
- expect(described_class.calculators).not_to eq([Spree::Calculator::FlatRate])
- end
- end
-
- # Regression test for #4492
- context '#shipments' do
- let!(:delivery_method) { create(:delivery_method) }
- let!(:shipment) do
- shipment = create(:fulfillment)
- shipment.shipping_rates.create!(delivery_method: delivery_method)
- shipment
- end
-
- it 'can gather all the related shipments' do
- expect(delivery_method.shipments).to include(shipment)
end
end
context 'validations' do
- it 'validates presence of name' do
- subject.valid?
- expect(subject.errors.messages[:name].size).to eq(1)
- end
-
it 'requires a name unique within the store and owner' do
create(:delivery_method, name: 'Standard')
@@ -181,14 +154,6 @@ describe Spree::DeliveryMethod, type: :model do
expect(build(:delivery_method, name: 'Standard', seller: create(:seller))).to be_valid
end
- it 'defaults to storefront visible and rejects a blank value' do
- expect(subject.storefront_visible).to be true
-
- subject.storefront_visible = nil
- subject.valid?
- expect(subject.errors.messages[:storefront_visible].size).not_to be_zero
- end
-
context 'shipping method does not have a tracking URL mask on file' do
let(:usps_tracking_number) { '1Z879E930346834440' }
@@ -317,16 +282,6 @@ describe Spree::DeliveryMethod, type: :model do
end
end
- # Regression test for #4320
- context 'soft deletion' do
- let(:delivery_method) { create(:delivery_method) }
-
- it 'soft-deletes when destroy is called' do
- delivery_method.destroy
- expect(delivery_method.deleted_at).not_to be_blank
- end
- end
-
describe '#available_to?' do
context 'for the storefront' do
it { expect(visible_delivery_method.available_to?(described_class::STOREFRONT)).to be true }
@@ -534,10 +489,6 @@ describe Spree::DeliveryMethod, type: :model do
it 'offers a first-party package the marketplace methods only' do
expect(described_class.available_to_seller(nil)).to contain_exactly(marketplace_method, shared_method)
end
-
- it "never offers one seller another seller's method" do
- expect(described_class.available_to_seller(seller)).not_to include(other_sellers_method)
- end
end
end
end
diff --git a/spree/core/spec/models/spree/delivery_rate_provider/base_spec.rb b/spree/core/spec/models/spree/delivery_rate_provider/base_spec.rb
index ff8987d7ee..9db52d93de 100644
--- a/spree/core/spec/models/spree/delivery_rate_provider/base_spec.rb
+++ b/spree/core/spec/models/spree/delivery_rate_provider/base_spec.rb
@@ -9,13 +9,6 @@ RSpec.describe Spree::DeliveryRateProvider::Base do
expect { described_class.new(delivery_method).estimate(nil) }.to raise_error(NotImplementedError)
end
- it 'no-ops the optional lifecycle hooks' do
- provider = described_class.new(delivery_method)
-
- expect { provider.book(nil) }.not_to raise_error
- expect { provider.release(nil) }.not_to raise_error
- end
-
it 'needs no integration by default' do
expect(described_class.integration_class).to be_nil
expect(described_class.available_for_store?(store)).to be(true)
diff --git a/spree/core/spec/models/spree/delivery_rate_provider/freight_spec.rb b/spree/core/spec/models/spree/delivery_rate_provider/freight_spec.rb
index ca7d5d02f5..4a6bc0e4db 100644
--- a/spree/core/spec/models/spree/delivery_rate_provider/freight_spec.rb
+++ b/spree/core/spec/models/spree/delivery_rate_provider/freight_spec.rb
@@ -36,13 +36,4 @@ RSpec.describe Spree::DeliveryRateProvider::Freight do
expect(summary['total_pallets']).to eq(1)
expect(summary['complete']).to be(true)
end
-
- it 'ships to an address and never consults a calculator' do
- expect(described_class.requires_address?).to be(true)
- expect(described_class.uses_calculator?).to be(false)
- end
-
- it 'is registered as a selectable rate provider' do
- expect(Spree.delivery_rate_providers).to include(described_class)
- end
end
diff --git a/spree/core/spec/models/spree/delivery_rate_spec.rb b/spree/core/spec/models/spree/delivery_rate_spec.rb
index b5af13dfc3..73479bd674 100644
--- a/spree/core/spec/models/spree/delivery_rate_spec.rb
+++ b/spree/core/spec/models/spree/delivery_rate_spec.rb
@@ -67,16 +67,6 @@ describe Spree::DeliveryRate, type: :model do
expect(shipping_rate.display_price.to_s).
to eq("$10.00 (incl. $1.67 #{non_default_tax_rate.name})")
end
-
- context 'when cost is zero' do
- before do
- shipping_rate.cost = 0
- end
-
- it 'shows no tax amount' do
- expect(shipping_rate.display_price.to_s).to eq('$0.00')
- end
- end
end
end
@@ -89,16 +79,6 @@ describe Spree::DeliveryRate, type: :model do
expect(shipping_rate.display_price.to_s).
to eq("$10.00 (+ $1.00 #{tax_rate.name})")
end
-
- context 'when cost is zero' do
- before do
- shipping_rate.cost = 0
- end
-
- it 'shows no tax amount' do
- expect(shipping_rate.display_price.to_s).to eq('$0.00')
- end
- end
end
context 'when the currency is JPY' do
@@ -124,10 +104,6 @@ describe Spree::DeliveryRate, type: :model do
# Regression test for #3829
context '#delivery_method' do
- it 'can be retrieved' do
- expect(shipping_rate.delivery_method.reload).to eq(delivery_method)
- end
-
it 'can be retrieved even when deleted' do
delivery_method.update_column(:deleted_at, Time.current)
shipping_rate.save
@@ -143,10 +119,6 @@ describe Spree::DeliveryRate, type: :model do
shipping_rate.tax_rate = tax_rate
end
- it 'can be retrieved' do
- expect(shipping_rate.tax_rate.reload).to eq(tax_rate)
- end
-
it 'can be retrieved even when deleted' do
tax_rate.update_column(:deleted_at, Time.current)
shipping_rate.save
@@ -155,14 +127,6 @@ describe Spree::DeliveryRate, type: :model do
end
end
- context '#tax_amount' do
- context 'without tax rate' do
- it 'returns 0.0' do
- expect(shipping_rate.tax_amount).to eq(0.0)
- end
- end
- end
-
describe '#additional_tax_total' do
context 'without tax rate' do
it 'returns 0' do
diff --git a/spree/core/spec/models/spree/delivery_spec.rb b/spree/core/spec/models/spree/delivery_spec.rb
index fafa4b93f0..5d31c374ec 100644
--- a/spree/core/spec/models/spree/delivery_spec.rb
+++ b/spree/core/spec/models/spree/delivery_spec.rb
@@ -6,20 +6,6 @@ RSpec.describe Spree::Delivery, type: :model do
let(:fulfillment) { order.fulfillments.first }
describe 'validations' do
- it 'requires a tracking number' do
- delivery = build(:delivery, owner: fulfillment, tracking_number: nil)
-
- expect(delivery).not_to be_valid
- expect(delivery.errors[:tracking_number]).to be_present
- end
-
- it 'refuses the same number twice on one owner' do
- create(:delivery, owner: fulfillment, tracking_number: 'DUP-1')
- duplicate = build(:delivery, owner: fulfillment, tracking_number: 'DUP-1')
-
- expect(duplicate).not_to be_valid
- end
-
it 'allows the same number on another owner' do
create(:delivery, owner: fulfillment, tracking_number: 'SHARED-1')
other = build(:delivery, owner: create(:fulfillment, order: create(:order, store: store), tracking: nil), tracking_number: 'SHARED-1')
@@ -27,12 +13,6 @@ RSpec.describe Spree::Delivery, type: :model do
expect(other).to be_valid
end
- it 'rejects a status outside the carrier vocabulary' do
- delivery = build(:delivery, owner: fulfillment, status: 'teleported')
-
- expect(delivery).not_to be_valid
- end
-
# A forwarder's PRO number belongs to a carrier the registry has never
# heard of, and must still be enterable.
it 'accepts a carrier the registry does not know' do
@@ -78,6 +58,17 @@ RSpec.describe Spree::Delivery, type: :model do
expect(delivery.resolved_tracking_url).to eq('https://tracker.example/t/1')
end
+ # The column is free text a merchant or seller pastes, and every consumer
+ # renders it as a link — so a scripting scheme must never come back out.
+ it 'drops a link that is not a real http address' do
+ ['javascript:alert(1)', 'data:text/html,<script>alert(1)</script>', 'file:///etc/passwd'].each do |hostile|
+ delivery = build(:delivery, owner: fulfillment, store: store,
+ tracking_number: '1Z999', tracking_url: hostile)
+
+ expect(delivery.resolved_tracking_url).not_to eq(hostile)
+ end
+ end
+
# The column says what the merchant chose; the reader says what to show.
# Keeping them apart is what lets a cleared field stay cleared.
it 'leaves the stored column alone' do
@@ -172,23 +163,4 @@ RSpec.describe Spree::Delivery, type: :model do
expect(delivery.correction_attributes(tracking_number: ' 1Z_OLD ')).not_to have_key(:status)
end
end
- describe '#resolved_tracking_url' do
- # The column is free text a merchant or seller pastes, and every consumer
- # renders it as a link — so a scripting scheme must never come back out.
- it 'drops a link that is not a real http address' do
- ['javascript:alert(1)', 'data:text/html,<script>alert(1)</script>', 'file:///etc/passwd'].each do |hostile|
- delivery = build(:delivery, owner: fulfillment, store: store,
- tracking_number: '1Z999', tracking_url: hostile)
-
- expect(delivery.resolved_tracking_url).not_to eq(hostile)
- end
- end
-
- it 'keeps a link the merchant legitimately pasted' do
- delivery = build(:delivery, owner: fulfillment, store: store, tracking_number: '1Z999',
- tracking_url: 'https://forwarder.example/track/1Z999')
-
- expect(delivery.resolved_tracking_url).to eq('https://forwarder.example/track/1Z999')
- end
- end
end
diff --git a/spree/core/spec/models/spree/delivery_zone_spec.rb b/spree/core/spec/models/spree/delivery_zone_spec.rb
index ef949b4318..20a1c6e775 100644
--- a/spree/core/spec/models/spree/delivery_zone_spec.rb
+++ b/spree/core/spec/models/spree/delivery_zone_spec.rb
@@ -20,16 +20,6 @@ describe Spree::DeliveryZone, type: :model do
expect(destroyed.deleted_at).to be_present
expect(destroyed.delivery_zone_id).to eq(zone.id)
end
-
- it 'never leaves a live method quoting worldwide' do
- method = create(:delivery_method, store: store, delivery_zone: zone,
- delivery_origin_group: zone.delivery_origin_group)
-
- zone.destroy
-
- expect(Spree::DeliveryMethod.exists?(method.id)).to be(false)
- expect(Spree::DeliveryMethod.with_deleted.find(method.id).delivery_zone_id).not_to be_nil
- end
end
describe '#include?' do
diff --git a/spree/core/spec/models/spree/deprecated_transition_verbs_spec.rb b/spree/core/spec/models/spree/deprecated_transition_verbs_spec.rb
index 31f0ecf399..e994af3397 100644
--- a/spree/core/spec/models/spree/deprecated_transition_verbs_spec.rb
+++ b/spree/core/spec/models/spree/deprecated_transition_verbs_spec.rb
@@ -154,9 +154,5 @@ RSpec.describe 'deprecated transition verbs' do
expect { item.return! }.to change { item.reload.status }.from('shipped').to('returned')
end
-
- it 'return! leaves an unshipped item alone' do
- expect(item.return!).to be(false)
- end
end
end
diff --git a/spree/core/spec/models/spree/digital_link_spec.rb b/spree/core/spec/models/spree/digital_link_spec.rb
index 7027568359..2631e5dcc9 100644
--- a/spree/core/spec/models/spree/digital_link_spec.rb
+++ b/spree/core/spec/models/spree/digital_link_spec.rb
@@ -4,36 +4,9 @@ describe Spree::DigitalLink, type: :model do
let(:store) { @default_store }
let(:digital_asset) { create(:digital_asset) }
let(:variant) { digital_asset.variant }
- let(:line_item) { create(:line_item, variant: variant) }
it_behaves_like 'lifecycle events'
- it 'validates presence of digital_asset and line_item' do
- expect(described_class.new(digital_asset: digital_asset, line_item: line_item)).to be_valid
- end
-
- it 'validates presence of line_item' do
- expect(described_class.new(digital_asset: digital_asset)).not_to be_valid
- end
-
- it 'validates presence of digital_asset' do
- expect(described_class.new(line_item: line_item)).not_to be_valid
- end
-
- context 'validates access_counter' do
- it 'validates access_counter numericality' do
- expect(described_class.new(digital_asset: digital_asset, line_item: line_item, access_counter: 'string')).not_to be_valid
- end
-
- it 'validates access_counter 0 or greater' do
- expect(described_class.new(digital_asset: digital_asset, line_item: line_item, access_counter: -3)).not_to be_valid
- end
-
- it 'validates access_counter 0 is valid' do
- expect(described_class.new(digital_asset: digital_asset, line_item: line_item, access_counter: 0)).to be_valid
- end
- end
-
describe '#store' do
let(:order) { create(:order, store: store) }
let(:line_item) { create(:line_item, order: order, variant: variant) }
@@ -54,12 +27,6 @@ describe Spree::DigitalLink, type: :model do
describe '#reset!' do
let!(:digital_link) { create(:digital_link, access_counter: 5) }
- after do
- digital_link.update(access_counter: 5)
- digital_link.save!
- digital_link.reload
- end
-
it 'resets access_counter' do
expect { digital_link.reset! }.to change(digital_link, :access_counter).from(5).to(0)
end
@@ -151,24 +118,6 @@ describe Spree::DigitalLink, type: :model do
it { expect(digital_link.authorizable?).to be false }
end
- context 'count exceeded but the store does not limit digital download count' do
- let(:digital_link) { create(:digital_link) }
-
- before do
- digital_link.line_item.order.store.preferred_limit_digital_download_count = false
- digital_link.line_item.order.store.save!
- digital_link.line_item.order.store.reload
- end
-
- it { expect(digital_link.authorizable?).to be true }
- end
-
- context 'still in count range' do
- let(:digital_link) { create(:digital_link) }
-
- it { expect(digital_link.authorizable?).to be true }
- end
-
context 'out of date' do
let(:digital_link) { create(:digital_link) }
@@ -181,18 +130,6 @@ describe Spree::DigitalLink, type: :model do
it { expect(digital_link.authorizable?).to be false }
end
- context 'out of date but the store does not track date of expire' do
- let(:digital_link) { create(:digital_link) }
-
- before do
- digital_link.line_item.order.store.preferred_limit_digital_download_days = false
- digital_link.line_item.order.store.save!
- digital_link.line_item.order.store.reload
- end
-
- it { expect(digital_link.authorizable?).to be true }
- end
-
context 'still in date' do
let(:digital_link) { create(:digital_link) }
@@ -204,12 +141,6 @@ describe Spree::DigitalLink, type: :model do
let!(:digital_link) { create(:digital_link, access_counter: 2) }
let!(:digital_link_expired) { create(:digital_link, access_counter: 100) }
- after do
- digital_link.update(access_counter: 2)
- digital_link.save!
- digital_link.reload
- end
-
it 'increments the access counter' do
expect { digital_link.authorize! }.to change(digital_link, :access_counter).from(2).to(3)
end
@@ -236,12 +167,6 @@ describe Spree::DigitalLink, type: :model do
let(:limit) { store.preferred_digital_asset_authorized_clicks }
let!(:digital_link) { create(:digital_link, access_counter: limit - 1) }
- after do
- digital_link.update(access_counter: 2)
- digital_link.save!
- digital_link.reload
- end
-
it 'allows exactly the configured number of downloads and denies the rest' do
expect(digital_link.authorize!).to be_truthy
expect(digital_link.reload.access_counter).to eq(limit)
@@ -258,12 +183,6 @@ describe Spree::DigitalLink, type: :model do
let(:limit) { store.preferred_digital_asset_authorized_clicks }
let!(:digital_link) { create(:digital_link, access_counter: limit - 1) }
- after do
- digital_link.update(access_counter: 2)
- digital_link.save!
- digital_link.reload
- end
-
it 'never lets the counter exceed the limit' do
results = Array.new(5) do
Thread.new do
diff --git a/spree/core/spec/models/spree/discount_spec.rb b/spree/core/spec/models/spree/discount_spec.rb
index 2886d2acd9..d2d89b7d58 100644
--- a/spree/core/spec/models/spree/discount_spec.rb
+++ b/spree/core/spec/models/spree/discount_spec.rb
@@ -32,8 +32,12 @@ describe Spree::Discount, type: :model do
end
it 'keeps provenance snapshots when the promotion is gone' do
+ promotion = create(:promotion)
discount = create(:discount, order: order, line_item: line_item, amount: -2, kind: 'promotion',
- code: 'SUMMER10', value: 10, value_type: 'percent')
+ promotion: promotion, code: 'SUMMER10', value: 10, value_type: 'percent')
+
+ promotion.destroy!
+
expect(discount.reload.code).to eq('SUMMER10')
expect(discount.promotion).to be_nil
end
diff --git a/spree/core/spec/models/spree/event_spec.rb b/spree/core/spec/models/spree/event_spec.rb
index 323eec5a20..a48a9e3927 100644
--- a/spree/core/spec/models/spree/event_spec.rb
+++ b/spree/core/spec/models/spree/event_spec.rb
@@ -79,29 +79,6 @@ RSpec.describe Spree::Event do
end
end
- describe 'validations' do
- it 'requires name' do
- event = described_class.new(store_id: store.id, payload: {})
-
- expect(event).not_to be_valid
- expect(event.errors[:name]).to include("can't be blank")
- end
-
- it 'requires store_id' do
- allow(Spree::Current).to receive(:store).and_return(nil)
- event = described_class.new(name: 'test', payload: {})
-
- expect(event).not_to be_valid
- expect(event.errors[:store_id]).to include("can't be blank")
- end
-
- it 'is valid with name and store_id' do
- event = described_class.new(name: 'test', store_id: store.id, payload: {})
-
- expect(event).to be_valid
- end
- end
-
describe '#store' do
it 'returns the store for the store_id' do
event = described_class.new(name: 'order.placed', store_id: store.id)
@@ -149,24 +126,6 @@ RSpec.describe Spree::Event do
end
end
- describe '#matches?' do
- let(:event) { described_class.new(name: 'order.placed', payload: {}) }
-
- it 'matches exact event names' do
- expect(event.matches?('order.placed')).to be true
- expect(event.matches?('order.canceled')).to be false
- end
-
- it 'matches wildcard patterns' do
- expect(event.matches?('order.*')).to be true
- expect(event.matches?('product.*')).to be false
- end
-
- it 'matches global wildcard' do
- expect(event.matches?('*')).to be true
- end
- end
-
describe '.matches?' do
it 'matches exact names' do
expect(described_class.matches?('order.placed', 'order.placed')).to be true
diff --git a/spree/core/spec/models/spree/exchange_spec.rb b/spree/core/spec/models/spree/exchange_spec.rb
index 7366e4e689..0d6e2468f4 100644
--- a/spree/core/spec/models/spree/exchange_spec.rb
+++ b/spree/core/spec/models/spree/exchange_spec.rb
@@ -10,12 +10,6 @@ RSpec.describe Spree::Exchange do
expect(exchange).to be_requested
end
- it 'is reachable from its order' do
- exchange = create(:exchange, store: store)
-
- expect(exchange.order.reload.exchanges).to include(exchange)
- end
-
describe '#price_difference' do
let(:exchange) { create(:exchange, store: store) }
let(:line) { exchange.exchange_line_items.first }
@@ -51,9 +45,5 @@ RSpec.describe Spree::Exchange do
expect(line.original_price).to eq(line_item.amount / line_item.quantity)
end
-
- it 'starts with nothing received' do
- expect(line.received_quantity).to eq(0)
- end
end
end
diff --git a/spree/core/spec/models/spree/export_spec.rb b/spree/core/spec/models/spree/export_spec.rb
index 3eb99c6a26..3087c8aff2 100644
--- a/spree/core/spec/models/spree/export_spec.rb
+++ b/spree/core/spec/models/spree/export_spec.rb
@@ -71,11 +71,6 @@ RSpec.describe Spree::Export, :job, type: :model do
context 'when the export type is Spree::Exports::Customers' do
let(:export) { build(:customer_export, store: store, user: user, format: 'csv') }
- it 'generates the export' do
- export.save!
- expect { export.generate }.to change(export.attachment, :attached?).from(false).to(true)
- end
-
it 'writes a row for a customer with addresses' do
customer = create(:customer_with_addresses)
export.save!
@@ -348,22 +343,6 @@ RSpec.describe Spree::Export, :job, type: :model do
end
end
- describe '#send_export_done_email' do
- before { export.save! }
-
- it 'queues the export done email' do
- expect { export.send_export_done_email }.to have_enqueued_job(ActionMailer::MailDeliveryJob)
- end
-
- context 'when the export has no user' do
- let(:export) { build(:product_export, store: store, user: nil, format: 'csv') }
-
- it 'does not queue an email — apps polling via secret API key have no inbox' do
- expect { export.send_export_done_email }.not_to have_enqueued_job(ActionMailer::MailDeliveryJob)
- end
- end
- end
-
describe 'CSV formula injection' do
let(:export) { build(:customer_export, store: store, user: user, format: 'csv') }
@@ -412,12 +391,6 @@ RSpec.describe Spree::Export, :job, type: :model do
export.normalize_search_params
expect(JSON.parse(export.search_params)).to eq(JSON.parse(params))
end
-
- it 'ensures valid JSON output' do
- export.search_params = params
- export.normalize_search_params
- expect { JSON.parse(export.search_params) }.not_to raise_error
- end
end
context 'with invalid JSON string' do
diff --git a/spree/core/spec/models/spree/exports/customers_spec.rb b/spree/core/spec/models/spree/exports/customers_spec.rb
index e24b8f95ca..bf90c31ec1 100644
--- a/spree/core/spec/models/spree/exports/customers_spec.rb
+++ b/spree/core/spec/models/spree/exports/customers_spec.rb
@@ -5,28 +5,31 @@ RSpec.describe Spree::Exports::Customers, type: :model do
let(:export) { described_class.new(store: store) }
describe '#csv_headers' do
+ let(:base_headers) do
+ [
+ 'First Name',
+ 'Last Name',
+ 'Email',
+ 'Accepts Email Marketing',
+ 'Company',
+ 'Address 1',
+ 'Address 2',
+ 'City',
+ 'Province',
+ 'Province Code',
+ 'Country',
+ 'Country Code',
+ 'Zip',
+ 'Phone',
+ 'Total Spent',
+ 'Total Orders',
+ 'Tags'
+ ]
+ end
+
context 'when no custom_fields exist' do
it 'returns customer headers' do
- expected_headers = [
- 'First Name',
- 'Last Name',
- 'Email',
- 'Accepts Email Marketing',
- 'Company',
- 'Address 1',
- 'Address 2',
- 'City',
- 'Province',
- 'Province Code',
- 'Country',
- 'Country Code',
- 'Zip',
- 'Phone',
- 'Total Spent',
- 'Total Orders',
- 'Tags'
- ]
- expect(export.csv_headers).to eq(expected_headers)
+ expect(export.csv_headers).to eq(base_headers)
end
end
@@ -39,27 +42,7 @@ RSpec.describe Spree::Exports::Customers, type: :model do
end
it 'includes custom_field headers' do
- expected_headers = [
- 'First Name',
- 'Last Name',
- 'Email',
- 'Accepts Email Marketing',
- 'Company',
- 'Address 1',
- 'Address 2',
- 'City',
- 'Province',
- 'Province Code',
- 'Country',
- 'Country Code',
- 'Zip',
- 'Phone',
- 'Total Spent',
- 'Total Orders',
- 'Tags',
- 'custom_field.custom.loyalty_points'
- ]
- expect(export.csv_headers).to eq(expected_headers)
+ expect(export.csv_headers).to eq(base_headers + ['custom_field.custom.loyalty_points'])
end
end
end
diff --git a/spree/core/spec/models/spree/exports/gift_cards_spec.rb b/spree/core/spec/models/spree/exports/gift_cards_spec.rb
index 3ea8d93593..348cb59a97 100644
--- a/spree/core/spec/models/spree/exports/gift_cards_spec.rb
+++ b/spree/core/spec/models/spree/exports/gift_cards_spec.rb
@@ -29,23 +29,26 @@ RSpec.describe Spree::Exports::GiftCards, type: :model do
end
describe '#csv_headers' do
+ let(:base_headers) do
+ [
+ 'Code',
+ 'Amount',
+ 'Amount Used',
+ 'Amount Remaining',
+ 'Currency',
+ 'Status',
+ 'Expires At',
+ 'Customer Email',
+ 'Customer First Name',
+ 'Customer Last Name',
+ 'Created At',
+ 'Updated At'
+ ]
+ end
+
context 'when no custom_fields exist' do
it 'returns gift card headers' do
- expected_headers = [
- 'Code',
- 'Amount',
- 'Amount Used',
- 'Amount Remaining',
- 'Currency',
- 'Status',
- 'Expires At',
- 'Customer Email',
- 'Customer First Name',
- 'Customer Last Name',
- 'Created At',
- 'Updated At'
- ]
- expect(export.csv_headers).to eq(expected_headers)
+ expect(export.csv_headers).to eq(base_headers)
end
end
@@ -58,22 +61,7 @@ RSpec.describe Spree::Exports::GiftCards, type: :model do
end
it 'includes custom_field headers' do
- expected_headers = [
- 'Code',
- 'Amount',
- 'Amount Used',
- 'Amount Remaining',
- 'Currency',
- 'Status',
- 'Expires At',
- 'Customer Email',
- 'Customer First Name',
- 'Customer Last Name',
- 'Created At',
- 'Updated At',
- 'custom_field.custom.purchase_location'
- ]
- expect(export.csv_headers).to eq(expected_headers)
+ expect(export.csv_headers).to eq(base_headers + ['custom_field.custom.purchase_location'])
end
end
end
diff --git a/spree/core/spec/models/spree/exports/orders_spec.rb b/spree/core/spec/models/spree/exports/orders_spec.rb
index e1ad716bb2..73d5a53646 100644
--- a/spree/core/spec/models/spree/exports/orders_spec.rb
+++ b/spree/core/spec/models/spree/exports/orders_spec.rb
@@ -5,66 +5,69 @@ RSpec.describe Spree::Exports::Orders, type: :model do
let(:export) { described_class.new(store: store) }
describe '#csv_headers' do
+ let(:base_headers) do
+ [
+ 'Number',
+ 'Email',
+ 'Status',
+ 'Currency',
+ 'Subtotal',
+ 'Shipping',
+ 'Taxes',
+ 'Taxes included',
+ 'Discount Used',
+ 'Free Shipping',
+ 'Discount',
+ 'Discount Code',
+ 'Store Credit amount',
+ 'Total',
+ 'Shipping method',
+ 'Total weight',
+ 'Payment Type Used',
+ 'Product ID',
+ 'Item Quantity',
+ 'Item SKU',
+ 'Item Name',
+ 'Item Price',
+ 'Item Total Discount',
+ 'Item Total Price',
+ 'Item requires shipping',
+ 'Item taxbale',
+ 'Item Seller',
+ 'Category lvl0',
+ 'Category lvl1',
+ 'Category lvl2',
+ 'Category lvl3',
+ 'Category lvl4',
+ 'Billing Name',
+ 'Billing Address 1',
+ 'Billing Address 2',
+ 'Billing Company',
+ 'Billing City',
+ 'Billing Zip',
+ 'Billing State',
+ 'Billing Country',
+ 'Billing Phone',
+ 'Shipping Name',
+ 'Shipping Address 1',
+ 'Shipping Address 2',
+ 'Shipping Company',
+ 'Shipping City',
+ 'Shipping Zip',
+ 'Shipping State',
+ 'Shipping Country',
+ 'Shipping Phone',
+ 'Placed at',
+ 'Shipped at',
+ 'Cancelled at',
+ 'Cancelled by',
+ 'Notes'
+ ]
+ end
+
context 'when no custom_fields exist' do
it 'returns order line item headers' do
- expected_headers = [
- 'Number',
- 'Email',
- 'Status',
- 'Currency',
- 'Subtotal',
- 'Shipping',
- 'Taxes',
- 'Taxes included',
- 'Discount Used',
- 'Free Shipping',
- 'Discount',
- 'Discount Code',
- 'Store Credit amount',
- 'Total',
- 'Shipping method',
- 'Total weight',
- 'Payment Type Used',
- 'Product ID',
- 'Item Quantity',
- 'Item SKU',
- 'Item Name',
- 'Item Price',
- 'Item Total Discount',
- 'Item Total Price',
- 'Item requires shipping',
- 'Item taxbale',
- 'Item Seller',
- 'Category lvl0',
- 'Category lvl1',
- 'Category lvl2',
- 'Category lvl3',
- 'Category lvl4',
- 'Billing Name',
- 'Billing Address 1',
- 'Billing Address 2',
- 'Billing Company',
- 'Billing City',
- 'Billing Zip',
- 'Billing State',
- 'Billing Country',
- 'Billing Phone',
- 'Shipping Name',
- 'Shipping Address 1',
- 'Shipping Address 2',
- 'Shipping Company',
- 'Shipping City',
- 'Shipping Zip',
- 'Shipping State',
- 'Shipping Country',
- 'Shipping Phone',
- 'Placed at',
- 'Shipped at',
- 'Cancelled at',
- 'Cancelled by',
- 'Notes'
- ]
- expect(export.csv_headers).to eq(expected_headers)
+ expect(export.csv_headers).to eq(base_headers)
end
end
@@ -77,65 +80,7 @@ RSpec.describe Spree::Exports::Orders, type: :model do
end
it 'includes custom_field headers' do
- expected_headers = [
- 'Number',
- 'Email',
- 'Status',
- 'Currency',
- 'Subtotal',
- 'Shipping',
- 'Taxes',
- 'Taxes included',
- 'Discount Used',
- 'Free Shipping',
- 'Discount',
- 'Discount Code',
- 'Store Credit amount',
- 'Total',
- 'Shipping method',
- 'Total weight',
- 'Payment Type Used',
- 'Product ID',
- 'Item Quantity',
- 'Item SKU',
- 'Item Name',
- 'Item Price',
- 'Item Total Discount',
- 'Item Total Price',
- 'Item requires shipping',
- 'Item taxbale',
- 'Item Seller',
- 'Category lvl0',
- 'Category lvl1',
- 'Category lvl2',
- 'Category lvl3',
- 'Category lvl4',
- 'Billing Name',
- 'Billing Address 1',
- 'Billing Address 2',
- 'Billing Company',
- 'Billing City',
- 'Billing Zip',
- 'Billing State',
- 'Billing Country',
- 'Billing Phone',
- 'Shipping Name',
- 'Shipping Address 1',
- 'Shipping Address 2',
- 'Shipping Company',
- 'Shipping City',
- 'Shipping Zip',
- 'Shipping State',
- 'Shipping Country',
- 'Shipping Phone',
- 'Placed at',
- 'Shipped at',
- 'Cancelled at',
- 'Cancelled by',
- 'Notes',
- 'custom_field.custom.gift_message'
- ]
- expect(export.csv_headers).to eq(expected_headers)
+ expect(export.csv_headers).to eq(base_headers + ['custom_field.custom.gift_message'])
end
end
end
diff --git a/spree/core/spec/models/spree/exports/products_spec.rb b/spree/core/spec/models/spree/exports/products_spec.rb
index 86f507ef7b..771aca4739 100644
--- a/spree/core/spec/models/spree/exports/products_spec.rb
+++ b/spree/core/spec/models/spree/exports/products_spec.rb
@@ -47,52 +47,55 @@ RSpec.describe Spree::Exports::Products, type: :model do
end
describe '#csv_headers' do
+ let(:base_headers) do
+ [
+ 'product_id',
+ 'sku',
+ 'name',
+ 'slug',
+ 'status',
+ 'seller_name',
+ 'description',
+ 'meta_title',
+ 'meta_description',
+ 'meta_keywords',
+ 'tags',
+ 'labels',
+ 'price',
+ 'compare_at_price',
+ 'currency',
+ 'width',
+ 'height',
+ 'depth',
+ 'dimensions_unit',
+ 'weight',
+ 'weight_unit',
+ 'available_on',
+ 'discontinue_on',
+ 'track_inventory',
+ 'inventory_count',
+ 'inventory_backorderable',
+ 'stock_location',
+ 'tax_category',
+ 'product_type',
+ 'image1_src',
+ 'image2_src',
+ 'image3_src',
+ 'option1_name',
+ 'option1_value',
+ 'option2_name',
+ 'option2_value',
+ 'option3_name',
+ 'option3_value',
+ 'category1',
+ 'category2',
+ 'category3'
+ ]
+ end
+
context 'when no custom_fields' do
it 'returns product variant headers without properties' do
- expected_headers = [
- 'product_id',
- 'sku',
- 'name',
- 'slug',
- 'status',
- 'seller_name',
- 'description',
- 'meta_title',
- 'meta_description',
- 'meta_keywords',
- 'tags',
- 'labels',
- 'price',
- 'compare_at_price',
- 'currency',
- 'width',
- 'height',
- 'depth',
- 'dimensions_unit',
- 'weight',
- 'weight_unit',
- 'available_on',
- 'discontinue_on',
- 'track_inventory',
- 'inventory_count',
- 'inventory_backorderable',
- 'stock_location',
- 'tax_category',
- 'product_type',
- 'image1_src',
- 'image2_src',
- 'image3_src',
- 'option1_name',
- 'option1_value',
- 'option2_name',
- 'option2_value',
- 'option3_name',
- 'option3_value',
- 'category1',
- 'category2',
- 'category3'
- ]
- expect(export.csv_headers).to eq(expected_headers)
+ expect(export.csv_headers).to eq(base_headers)
end
end
@@ -100,51 +103,7 @@ RSpec.describe Spree::Exports::Products, type: :model do
let!(:custom_field_definition) { create(:custom_field_definition, resource_type: 'Spree::Product', namespace: 'custom', key: 'field1') }
it 'includes custom_field headers' do
- expected_headers = [
- 'product_id',
- 'sku',
- 'name',
- 'slug',
- 'status',
- 'seller_name',
- 'description',
- 'meta_title',
- 'meta_description',
- 'meta_keywords',
- 'tags',
- 'labels',
- 'price',
- 'compare_at_price',
- 'currency',
- 'width',
- 'height',
- 'depth',
- 'dimensions_unit',
- 'weight',
- 'weight_unit',
- 'available_on',
- 'discontinue_on',
- 'track_inventory',
- 'inventory_count',
- 'inventory_backorderable',
- 'stock_location',
- 'tax_category',
- 'product_type',
- 'image1_src',
- 'image2_src',
- 'image3_src',
- 'option1_name',
- 'option1_value',
- 'option2_name',
- 'option2_value',
- 'option3_name',
- 'option3_value',
- 'category1',
- 'category2',
- 'category3',
- 'custom_field.custom.field1'
- ]
- expect(export.csv_headers).to eq(expected_headers)
+ expect(export.csv_headers).to eq(base_headers + ['custom_field.custom.field1'])
end
end
end
diff --git a/spree/core/spec/models/spree/freight_summary_spec.rb b/spree/core/spec/models/spree/freight_summary_spec.rb
index fbb4dbcba0..af28623f0d 100644
--- a/spree/core/spec/models/spree/freight_summary_spec.rb
+++ b/spree/core/spec/models/spree/freight_summary_spec.rb
@@ -176,16 +176,8 @@ RSpec.describe Spree::FreightSummary do
expect(merged.total_units).to eq(12)
expect(merged.total_cartons).to eq(1)
expect(merged.total_pallets).to eq(1)
- end
-
- # Adding two part-full cartons' volumes reports space the combined
- # shipment does not take, which would misprice a volume tier.
- it 're-derives volume from the recombined carton count' do
- split = [summary_for([[packed_variant, 3]]), summary_for([[packed_variant, 9]])]
-
- merged = described_class.merge(split)
-
- expect(merged.total_cartons).to eq(1)
+ # Adding two part-full cartons' volumes reports space the combined
+ # shipment does not take, which would misprice a volume tier.
expect(merged.total_volume).to eq(BigDecimal('0.03'))
end
diff --git a/spree/core/spec/models/spree/fulfillment/custom_events_spec.rb b/spree/core/spec/models/spree/fulfillment/custom_events_spec.rb
index 6ede827187..2bc3c0fc3d 100644
--- a/spree/core/spec/models/spree/fulfillment/custom_events_spec.rb
+++ b/spree/core/spec/models/spree/fulfillment/custom_events_spec.rb
@@ -12,13 +12,6 @@ RSpec.describe Spree::Fulfillment::CustomEvents do
end
describe 'fulfillment.fulfilled event' do
- it 'publishes fulfillment.fulfilled and dual-emits the legacy shipment.shipped' do
- Spree.fulfillment_fulfill_workflow.call(fulfillment: fulfillment)
-
- expect(Spree::Events).to have_received(:publish).with('fulfillment.fulfilled', anything, anything)
- expect(Spree::Events).to have_received(:publish).with('shipment.shipped', anything, anything)
- end
-
it 'does not publish when events are disabled' do
allow(Spree::Events).to receive(:enabled?).and_return(false)
@@ -45,6 +38,7 @@ RSpec.describe Spree::Fulfillment::CustomEvents do
Spree.fulfillment_fulfill_workflow.call(fulfillment: fulfillment)
expect(Spree::Events).to have_received(:publish).with('fulfillment.fulfilled', anything, anything)
+ expect(Spree::Events).to have_received(:publish).with('shipment.shipped', anything, anything)
expect(Spree::Events).to have_received(:publish).with('order.fulfilled', anything, anything)
expect(Spree::Events).to have_received(:publish).with('order.shipped', anything, anything)
end
diff --git a/spree/core/spec/models/spree/fulfillment_provider/base_spec.rb b/spree/core/spec/models/spree/fulfillment_provider/base_spec.rb
index d25c8c3060..bd2481cb95 100644
--- a/spree/core/spec/models/spree/fulfillment_provider/base_spec.rb
+++ b/spree/core/spec/models/spree/fulfillment_provider/base_spec.rb
@@ -17,21 +17,6 @@ describe Spree::FulfillmentProvider::Base, type: :model do
expect { provider.cancel_fulfillment(fulfillment) }.to raise_error(NotImplementedError)
end
- describe 'registry' do
- it 'exposes the built-in providers and their class predicates' do
- expect(Spree.fulfillment_providers).to include(
- Spree::FulfillmentProvider::Manual,
- Spree::FulfillmentProvider::Digital,
- Spree::FulfillmentProvider::Pickup,
- Spree::FulfillmentProvider::PickupPoint
- )
- expect(Spree::FulfillmentProvider::Digital).to be_digital
- expect(Spree::FulfillmentProvider::Pickup).to be_pickup
- expect(Spree::FulfillmentProvider::PickupPoint).to be_pickup_point
- expect(Spree::FulfillmentProvider::Manual).not_to be_digital
- end
- end
-
describe 'Fulfillment#provider' do
it 'falls back to Manual without a delivery method' do
expect(build(:fulfillment).provider).to be_a(Spree::FulfillmentProvider::Manual)
diff --git a/spree/core/spec/models/spree/fulfilment_changer_spec.rb b/spree/core/spec/models/spree/fulfilment_changer_spec.rb
index a79fe40c73..57465dc905 100644
--- a/spree/core/spec/models/spree/fulfilment_changer_spec.rb
+++ b/spree/core/spec/models/spree/fulfilment_changer_spec.rb
@@ -158,7 +158,7 @@ describe Spree::FulfillmentChanger do
end
it 'does not unstock the desired location' do
- expect { subject }.not_to change(stock_level, :count_on_hand)
+ expect { subject }.not_to change { stock_level.reload.count_on_hand }
end
end
end
@@ -191,16 +191,6 @@ describe Spree::FulfillmentChanger do
context 'when the desired stock location already has a backordered units' do
let(:desired_count_on_hand) { -1 }
- it 'releases seven at the original stock location' do
- expect { subject }.
- to change { current_shipment.stock_location.stock_level(variant).allocated_count }.by(-7)
- end
-
- it 'allocates seven at the desired stock location' do
- expect { subject }.
- to change { desired_shipment.stock_location.stock_level(variant).allocated_count }.by(7)
- end
-
it 'creates a shipment with the correct number of on hand and backordered units' do
subject
expect(desired_shipment.inventory_units.on_hand.sum(:quantity)).to eq(0)
@@ -407,7 +397,7 @@ describe Spree::FulfillmentChanger do
subject
- expect(desired_shipment.reload.shipping_method).to eq(shipping_method_that_should_be_selected)
+ expect(desired_shipment.reload.delivery_method).to eq(shipping_method_that_should_be_selected)
expect(desired_shipment.reload.cost).to eq(10)
end
diff --git a/spree/core/spec/models/spree/gateway/bogus_spec.rb b/spree/core/spec/models/spree/gateway/bogus_spec.rb
index ed3d05af82..1167b180ef 100644
--- a/spree/core/spec/models/spree/gateway/bogus_spec.rb
+++ b/spree/core/spec/models/spree/gateway/bogus_spec.rb
@@ -9,9 +9,5 @@ module Spree
bogus.disable_customer_profile(cc)
expect(cc.gateway_customer_profile_id).to be_nil
end
-
- describe '#session_required?' do
- it { expect(bogus.session_required?).to be true }
- end
end
end
diff --git a/spree/core/spec/models/spree/gateway_spec.rb b/spree/core/spec/models/spree/gateway_spec.rb
index 459c98e8d0..68e4eabd1d 100644
--- a/spree/core/spec/models/spree/gateway_spec.rb
+++ b/spree/core/spec/models/spree/gateway_spec.rb
@@ -152,15 +152,5 @@ describe Spree::Gateway, type: :model do
it 'returns nil' do
expect(payment_method.gateway_dashboard_payment_url(payment)).to be_nil
end
-
- context 'when implemented' do
- before do
- expect(payment_method).to receive(:gateway_dashboard_payment_url).with(payment).and_return("https://dashboard.stripe.com/payments/#{payment.transaction_id}")
- end
-
- it 'returns the url' do
- expect(payment_method.gateway_dashboard_payment_url(payment)).to eq('https://dashboard.stripe.com/payments/123')
- end
- end
end
end
diff --git a/spree/core/spec/models/spree/gift_card_spec.rb b/spree/core/spec/models/spree/gift_card_spec.rb
index a96c243d50..747eb0c4a2 100644
--- a/spree/core/spec/models/spree/gift_card_spec.rb
+++ b/spree/core/spec/models/spree/gift_card_spec.rb
@@ -45,10 +45,10 @@ RSpec.describe Spree::GiftCard, type: :model do
end
describe 'Scopes' do
- let(:active_gift_card) { create(:gift_card, status: :active) }
- let(:redeemed_gift_card) { create(:gift_card, status: :redeemed) }
- let(:partially_redeemed_gift_card) { create(:gift_card, status: :partially_redeemed) }
- let(:expired_gift_card) { create(:gift_card, expires_at: Date.current, status: :active) }
+ let!(:active_gift_card) { create(:gift_card, status: :active) }
+ let!(:redeemed_gift_card) { create(:gift_card, status: :redeemed) }
+ let!(:partially_redeemed_gift_card) { create(:gift_card, status: :partially_redeemed) }
+ let!(:expired_gift_card) { create(:gift_card, expires_at: Date.current, status: :active) }
describe '#masked_code' do
it 'shows only the last four characters' do
@@ -57,8 +57,8 @@ RSpec.describe Spree::GiftCard, type: :model do
end
describe '#active' do
- it 'returns active gift cards' do
- expect(described_class.active).to contain_exactly(active_gift_card)
+ it 'returns unexpired active and partially redeemed gift cards' do
+ expect(described_class.active).to contain_exactly(active_gift_card, partially_redeemed_gift_card)
end
end
@@ -225,20 +225,6 @@ RSpec.describe Spree::GiftCard, type: :model do
end
end
- describe 'status' do
- it 'has no state machine' do
- expect(described_class).not_to respond_to(:state_machines)
- end
-
- it 'defaults to active' do
- expect(described_class.new.status).to eq('active')
- end
-
- it 'rejects an unknown status' do
- expect(build(:gift_card, status: 'nonsense')).not_to be_valid
- end
- end
-
describe 'status scopes and predicates' do
let(:store) { Spree::Store.default }
let!(:active) { create(:gift_card, store: store, amount: 10) }
diff --git a/spree/core/spec/models/spree/import_mapping_spec.rb b/spree/core/spec/models/spree/import_mapping_spec.rb
index c6ddfee289..f203fd2b6b 100644
--- a/spree/core/spec/models/spree/import_mapping_spec.rb
+++ b/spree/core/spec/models/spree/import_mapping_spec.rb
@@ -5,56 +5,6 @@ RSpec.describe Spree::ImportMapping, type: :model do
let(:user) { create(:admin_user) }
let(:import) { create(:product_import, store: store, user: user) }
- describe 'Validations' do
- describe 'presence validations' do
- it 'validates presence of import' do
- mapping = build(:import_mapping, import: nil)
- expect(mapping).not_to be_valid
- expect(mapping.errors[:import]).to include('must exist')
- end
-
- it 'validates presence of schema_field' do
- mapping = build(:import_mapping, schema_field: nil)
- expect(mapping).not_to be_valid
- expect(mapping.errors[:schema_field]).to include("can't be blank")
- end
- end
-
- describe 'uniqueness validations' do
- let!(:existing_mapping) { create(:import_mapping, import: import, schema_field: 'slug') }
-
- it 'validates uniqueness of schema_field scoped to import_id' do
- duplicate_mapping = build(:import_mapping, import: import, schema_field: 'slug')
- expect(duplicate_mapping).not_to be_valid
- expect(duplicate_mapping.errors[:schema_field]).to include('has already been taken')
- end
-
- it 'allows same schema_field for different imports' do
- other_import = create(:product_import, store: store, user: user)
- duplicate_mapping = build(:import_mapping, import: other_import, schema_field: 'slug')
- expect(duplicate_mapping).to be_valid
- end
-
- it 'validates uniqueness of file_column scoped to import_id' do
- existing_mapping.update!(file_column: 'product_name')
- duplicate_mapping = build(:import_mapping, import: import, file_column: 'product_name')
- expect(duplicate_mapping).not_to be_valid
- expect(duplicate_mapping.errors[:file_column]).to include('has already been taken')
- end
-
- it 'allows blank file_column' do
- mapping = build(:import_mapping, import: import, schema_field: 'description', file_column: nil)
- expect(mapping).to be_valid
- end
-
- it 'allows same file_column for different imports' do
- other_import = create(:product_import, store: store, user: user)
- mapping = build(:import_mapping, import: other_import, schema_field: 'sku', file_column: 'name')
- expect(mapping).to be_valid
- end
- end
- end
-
describe '#required?' do
context 'when schema_field is a required field' do
let(:mapping) { build(:import_mapping, import: import, schema_field: 'slug') }
diff --git a/spree/core/spec/models/spree/import_row_spec.rb b/spree/core/spec/models/spree/import_row_spec.rb
index c218652e79..2ebbde18ef 100644
--- a/spree/core/spec/models/spree/import_row_spec.rb
+++ b/spree/core/spec/models/spree/import_row_spec.rb
@@ -12,44 +12,9 @@ RSpec.describe Spree::ImportRow, :job, type: :model do
allow(import).to receive(:attachment_file_content).and_return(csv_content)
end
- describe 'Associations' do
- describe '#store' do
- it 'delegates to import' do
- import_row.save!
- expect(import_row.store).to eq(store)
- end
- end
- end
-
- describe 'Validations' do
- context 'row_number uniqueness' do
- before { import_row.save! }
-
- it 'validates uniqueness scoped to import_id' do
- duplicate_row = build(:import_row, import: import, row_number: 1)
- expect(duplicate_row).not_to be_valid
- expect(duplicate_row.errors[:row_number]).to include('has already been taken')
- end
-
- it 'allows same row_number for different imports' do
- other_import = create(:product_import, store: store)
- other_row = build(:import_row, import: other_import, row_number: 1)
- expect(other_row).to be_valid
- end
- end
- end
-
describe 'status' do
before { import_row.save! }
- it 'has no state machine' do
- expect(described_class).not_to respond_to(:state_machines)
- end
-
- it 'starts in pending status' do
- expect(import_row.status).to eq('pending')
- end
-
it 'rejects an unknown status' do
import_row.status = 'nonsense'
expect(import_row).not_to be_valid
@@ -69,20 +34,6 @@ RSpec.describe Spree::ImportRow, :job, type: :model do
end
end
- describe '.completed' do
- it 'returns only completed rows' do
- expect(described_class.completed).to include(completed_row)
- expect(described_class.completed).not_to include(pending_row, failed_row, processing_row)
- end
- end
-
- describe '.failed' do
- it 'returns only failed rows' do
- expect(described_class.failed).to include(failed_row)
- expect(described_class.failed).not_to include(pending_row, completed_row, processing_row)
- end
- end
-
describe '.processed' do
it 'returns completed and failed rows' do
expect(described_class.processed).to include(completed_row, failed_row)
diff --git a/spree/core/spec/models/spree/import_spec.rb b/spree/core/spec/models/spree/import_spec.rb
index eb679a08ac..ed934b77a8 100644
--- a/spree/core/spec/models/spree/import_spec.rb
+++ b/spree/core/spec/models/spree/import_spec.rb
@@ -44,18 +44,9 @@ RSpec.describe Spree::Import, :job, type: :model do
describe 'status' do
before { import.save! }
- it 'has no state machine' do
- expect(described_class).not_to respond_to(:state_machines)
- end
-
it 'starts in pending status' do
expect(import.status).to eq('pending')
end
-
- it 'rejects an unknown status' do
- import.status = 'nonsense'
- expect(import).not_to be_valid
- end
end
describe '#model_class' do
@@ -196,13 +187,6 @@ RSpec.describe Spree::Import, :job, type: :model do
expect(all_fields.count).to eq(base_field_count + custom_field_count)
end
-
- it 'has correct structure for custom_field fields' do
- custom_field_field = import.schema_fields.find { |f| f[:name] == 'custom_field.properties.manufacturer' }
- expect(custom_field_field).to eq(
- { name: 'custom_field.properties.manufacturer', label: 'Manufacturer' }
- )
- end
end
context 'when model does not support custom_fields' do
@@ -216,11 +200,6 @@ RSpec.describe Spree::Import, :job, type: :model do
fields = import.schema_fields
expect(fields).to eq(Spree::ImportSchemas::Products::FIELDS)
end
-
- it 'does not include any custom_field fields' do
- custom_field_fields = import.schema_fields.select { |f| f[:name].start_with?('custom_field.') }
- expect(custom_field_fields).to be_empty
- end
end
context 'when model supports custom_fields but has no custom_field definitions' do
@@ -287,20 +266,6 @@ RSpec.describe Spree::Import, :job, type: :model do
end
end
- describe '#store' do
- context 'when owner is a Store' do
- it 'returns the owner' do
- expect(import.store).to eq(store)
- end
- end
- end
-
- describe '.available_types' do
- it 'returns configured import types' do
- expect(described_class.available_types).to eq(Spree.import_types)
- end
- end
-
describe '.available_models' do
it 'returns model classes for available types' do
expect(described_class.available_models).to include(Spree::Product)
@@ -314,12 +279,6 @@ RSpec.describe Spree::Import, :job, type: :model do
end
end
- describe '.model_class' do
- it 'returns the model class for the import type' do
- expect(Spree::Imports::Products.model_class).to eq(Spree::Product)
- end
- end
-
describe '#template_csv' do
it 'is the schema header row' do
import = Spree::Imports::Products.new
diff --git a/spree/core/spec/models/spree/import_tenancy_spec.rb b/spree/core/spec/models/spree/import_tenancy_spec.rb
index 204f9835f2..2bbe81d536 100644
--- a/spree/core/spec/models/spree/import_tenancy_spec.rb
+++ b/spree/core/spec/models/spree/import_tenancy_spec.rb
@@ -69,6 +69,7 @@ RSpec.describe 'import and export tenancy' do
it 'still accepts a seller on write' do
import = build(:product_import, user: user)
+ expect(Spree::Deprecation).to receive(:warn).with(/Import#owner= is deprecated/)
import.owner = seller
expect(import.seller).to eq(seller)
@@ -107,24 +108,13 @@ RSpec.describe 'import and export tenancy' do
expect(Spree::Export.for_store(store)).to include(theirs)
end
- # `Export#scope` has narrowed exported rows by seller since 5.6, but with
- # no column behind the association `seller` was always nil, so the line
- # never fired. The column is what lets it.
- #
- # It applies to models that answer `for_seller` — `Spree::Variant` does,
- # `Spree::Product` does not, so a product export is still store-wide. That
- # gap predates this change and is a separate decision.
it 'narrows an export to the seller where the model supports it' do
- mine = create(:product, store: store, seller: seller).default_variant
- theirs = create(:product, store: store).default_variant
- export = create(:export, store: store, seller: seller, user: user,
- type: 'Spree::Exports::Products')
+ mine = create(:product, store: store, seller: seller)
+ theirs = create(:product, store: store)
+ export = build(:product_export, store: store, seller: seller, user: nil)
- scoped = Spree::Variant.for_seller(seller)
-
- expect(export.seller).to eq(seller)
- expect(scoped).to include(mine)
- expect(scoped).not_to include(theirs)
+ expect(export.records_to_export).to include(mine)
+ expect(export.records_to_export).not_to include(theirs)
end
end
end
diff --git a/spree/core/spec/models/spree/imports/customers_spec.rb b/spree/core/spec/models/spree/imports/customers_spec.rb
deleted file mode 100644
index 9e57553307..0000000000
--- a/spree/core/spec/models/spree/imports/customers_spec.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-require 'spec_helper'
-
-RSpec.describe Spree::Imports::Customers, type: :model do
- let(:store) { Spree::Store.default }
- let(:import) { create(:customer_import, store: store) }
-
- describe '#row_processor_class' do
- it 'returns Customer row processor' do
- expect(import.row_processor_class).to eq Spree::Imports::RowProcessors::Customer
- end
- end
-
- describe '#model_class' do
- it 'returns the user class' do
- expect(import.model_class).to eq Spree.customer_class
- end
- end
-
- describe '#import_schema' do
- it 'returns the customers import schema' do
- expect(import.import_schema).to be_a(Spree::ImportSchemas::Customers)
- end
- end
-end
diff --git a/spree/core/spec/models/spree/inventory_unit_spec.rb b/spree/core/spec/models/spree/inventory_unit_spec.rb
index ec0fa899b1..c6b1b51b1a 100644
--- a/spree/core/spec/models/spree/inventory_unit_spec.rb
+++ b/spree/core/spec/models/spree/inventory_unit_spec.rb
@@ -10,25 +10,9 @@ describe Spree::FulfillmentItem, type: :model do
let!(:inventory_unit_3) { create(:fulfillment_item, state: 'shipped') }
let!(:inventory_unit_4) { create(:fulfillment_item, state: 'returned') }
- describe '.backordered' do
- it { expect(Spree::FulfillmentItem.backordered).to eq([inventory_unit_2]) }
- end
-
- describe '.on_hand' do
- it { expect(Spree::FulfillmentItem.on_hand).to eq([inventory_unit_1]) }
- end
-
describe '.on_hand_or_backordered' do
it { expect(Spree::FulfillmentItem.on_hand_or_backordered).to match_array([inventory_unit_1, inventory_unit_2]) }
end
-
- describe '.shipped' do
- it { expect(Spree::FulfillmentItem.shipped).to eq([inventory_unit_3]) }
- end
-
- describe '.returned' do
- it { expect(Spree::FulfillmentItem.returned).to eq([inventory_unit_4]) }
- end
end
describe '#backordered_for_stock_level' do
@@ -46,10 +30,6 @@ describe Spree::FulfillmentItem, type: :model do
order.fulfillments.first
end
- let(:shipping_method) do
- shipment.shipping_methods.first
- end
-
let!(:unit) do
unit = shipment.inventory_units.first
unit.state = 'backordered'
@@ -92,13 +72,6 @@ describe Spree::FulfillmentItem, type: :model do
expect(Spree::FulfillmentItem.backordered_for_stock_level(stock_level)).not_to include(other_variant_unit)
end
- it 'does not change shipping cost when fulfilling the order' do
- current_shipment_cost = shipment.cost
- shipping_method.calculator.set_preference(:amount, current_shipment_cost + 5.0)
- stock_level.set_count_on_hand(0)
- expect(shipment.reload.cost).to eq(current_shipment_cost)
- end
-
context 'other shipments' do
let(:other_order) do
order = create(:order)
@@ -134,7 +107,6 @@ describe Spree::FulfillmentItem, type: :model do
end
describe '#finalize_units!' do
- let!(:stock_location) { create(:stock_location) }
let(:variant) { create(:variant) }
let (:shipment) { create(:fulfillment) }
let(:inventory_units) do
@@ -188,40 +160,6 @@ describe Spree::FulfillmentItem, type: :model do
end
end
- describe '#additional_tax_total' do
- subject do
- build(:fulfillment_item, line_item: line_item)
- end
-
- let(:quantity) { 2 }
- let(:line_item_additional_tax_total) { 10.00 }
- let(:line_item) do
- build(:line_item, quantity: quantity,
- additional_tax_total: line_item_additional_tax_total)
- end
-
- it 'is the correct amount' do
- expect(subject.additional_tax_total).to eq line_item_additional_tax_total / quantity
- end
- end
-
- describe '#included_tax_total' do
- subject do
- build(:fulfillment_item, line_item: line_item)
- end
-
- let(:quantity) { 2 }
- let(:line_item_included_tax_total) { 10.00 }
- let(:line_item) do
- build(:line_item, quantity: quantity,
- included_tax_total: line_item_included_tax_total)
- end
-
- it 'is the correct amount' do
- expect(subject.included_tax_total).to eq line_item_included_tax_total / quantity
- end
- end
-
describe '#charged_amount' do
subject { build(:fulfillment_item, line_item: line_item, quantity: 1) }
diff --git a/spree/core/spec/models/spree/invitation_spec.rb b/spree/core/spec/models/spree/invitation_spec.rb
index a05a5218a9..54355764ce 100644
--- a/spree/core/spec/models/spree/invitation_spec.rb
+++ b/spree/core/spec/models/spree/invitation_spec.rb
@@ -19,20 +19,6 @@ RSpec.describe Spree::Invitation, type: :model do
end
end
- context 'when invitation is accepted after expiration' do
- it 'is refused' do
- invitation.save!
- invitation.update_column(:expires_at, 1.day.ago)
-
- result = Spree.invitation_accept_workflow.call(invitation: invitation)
-
- expect(result).not_to be_success
- expect(result.error.value).to eq(:invitation_expired)
- expect(invitation.reload.accepted_at).not_to be_present
- expect(invitation.status).to eq('pending')
- end
- end
-
context 'when invitee already exists in the store' do
it 'is invalid' do
create(:admin_user, email: '[email protected]')
@@ -88,31 +74,7 @@ RSpec.describe Spree::Invitation, type: :model do
end
describe 'State Machine' do
- it 'has initial state of pending' do
- expect(invitation.status).to eq('pending')
- end
-
context 'when accepting an invitation' do
- it 'changes status to accepted' do
- invitation.invitee = create(:admin_user, :without_admin_role)
- Spree.invitation_accept_workflow.call(invitation: invitation)
- expect(invitation.status).to eq('accepted')
- end
-
- it 'sets accepted_at timestamp' do
- expect(invitation.accepted_at).to be_nil
- invitation.invitee = create(:admin_user, :without_admin_role)
- Spree.invitation_accept_workflow.call(invitation: invitation)
- expect(invitation.accepted_at).to be_present
- end
-
- it 'publishes invitation.accept event', events: true do
- invitation.invitee = create(:admin_user, :without_admin_role)
-
- expect(invitation).to receive(:publish_event).with('invitation.accepted')
- Spree.invitation_accept_workflow.call(invitation: invitation)
- end
-
it 'creates a resource user' do
invitation.invitee = create(:admin_user, :without_admin_role)
expect { Spree.invitation_accept_workflow.call(invitation: invitation) }.to change(invitation, :role_user).from(nil).to(Spree::RoleUser)
diff --git a/spree/core/spec/models/spree/legacy_encrypted_password_recipe_spec.rb b/spree/core/spec/models/spree/legacy_encrypted_password_recipe_spec.rb
index ca784b9722..b3f8ec151a 100644
--- a/spree/core/spec/models/spree/legacy_encrypted_password_recipe_spec.rb
+++ b/spree/core/spec/models/spree/legacy_encrypted_password_recipe_spec.rb
@@ -38,10 +38,4 @@ describe 'Legacy encrypted_password bridge', type: :model do
expect(user.authenticate('secret123')).to be_truthy
expect(user.authenticate('wrong')).to be(false)
end
-
- it 're-authenticates a reloaded record' do
- model.create!(email: '[email protected]', password: 'hunter2!')
-
- expect(model.find_by(email: '[email protected]').authenticate('hunter2!')).to be_truthy
- end
end
diff --git a/spree/core/spec/models/spree/line_item_spec.rb b/spree/core/spec/models/spree/line_item_spec.rb
index 24d15dfaaa..f292fa352d 100644
--- a/spree/core/spec/models/spree/line_item_spec.rb
+++ b/spree/core/spec/models/spree/line_item_spec.rb
@@ -35,36 +35,6 @@ describe Spree::LineItem, type: :model do
end
end
- describe 'Validations' do
- describe 'ensure_proper_currency' do
- context 'order is present' do
- context "when line_item's currency matches with order's" do
- it { expect(line_item).to be_valid }
- end
-
- context "when line_item's currency does not matches with order's" do
- before do
- line_item.currency = 'Invalid Currency'
- end
-
- it { expect(line_item).not_to be_valid }
- end
- end
- end
- end
-
- describe '#quantity' do
- it 'has a default quantity of 1' do
- line_item = build(:line_item)
- expect(line_item.quantity).to eq(1)
- end
-
- it 'allows to set different value for quantity' do
- line_item = build(:line_item, quantity: 5)
- expect(line_item.quantity).to eq(5)
- end
- end
-
describe '#ensure_valid_quantity' do
context 'quantity.nil?' do
before do
@@ -105,13 +75,6 @@ describe Spree::LineItem, type: :model do
end
end
- context '#save' do
- it 'touches the order' do
- expect(line_item.order).to receive(:touch)
- line_item.touch
- end
- end
-
context '#discontinued' do
it 'fetches discontinued products' do
line_item.product.discontinue!
@@ -151,10 +114,6 @@ describe Spree::LineItem, type: :model do
order.reload
end
- it 'is an all-digital order' do
- expect(order).to be_digital
- end
-
it 'builds fulfillment items for a stock-limited digital variant' do
second_licence = create(:product, delivery_profile: digital_profile, store: store).default_variant
second_licence.update!(track_inventory: true)
@@ -397,9 +356,12 @@ describe Spree::LineItem, type: :model do
end
end
- describe '.currency' do
- it 'returns the globally configured currency' do
- line_item.currency == 'USD'
+ describe '#currency' do
+ it "defaults to the order's currency" do
+ line_item = build(:line_item, order: build(:order, currency: 'EUR'), currency: nil)
+ line_item.valid?
+
+ expect(line_item.currency).to eq('EUR')
end
end
@@ -440,7 +402,7 @@ describe Spree::LineItem, type: :model do
variant.stock_levels.update_all count_on_hand: 5, backorderable: false
Spree::Orders::AddItem.call(order: order, variant: variant, quantity: 5)
order.rebuild_fulfillments!
- order.finalize!
+ Spree.order_complete_workflow.call(order: order, payment_pending: true)
order.reload
end
@@ -469,7 +431,7 @@ describe Spree::LineItem, type: :model do
variant.stock_levels.update_all count_on_hand: 7, backorderable: false
Spree::Orders::AddItem.call(order: order, variant: variant, quantity: 5)
order.rebuild_fulfillments!
- order.finalize!
+ Spree.order_complete_workflow.call(order: order, payment_pending: true)
order.reload
end
@@ -516,10 +478,6 @@ describe Spree::LineItem, type: :model do
end
describe '#options=' do
- it 'can handle updating a blank line item with no order' do
- line_item.options = { price: 123 }
- end
-
it 'updates the data provided in the options' do
line_item.options = { price: 123 }
expect(line_item.price).to eq 123
@@ -726,58 +684,6 @@ describe Spree::LineItem, type: :model do
end
end
- describe '#dimensions_unit' do
- let(:variant) { create(:variant, dimensions_unit: 'cm') }
- let(:line_item) { build(:line_item, variant: variant, quantity: 2) }
-
- it 'returns the dimension unit for the line item' do
- expect(line_item.dimensions_unit).to eq('cm')
- end
- end
-
- describe '#weight_unit' do
- let(:variant) { create(:variant, weight_unit: 'kg') }
- let(:line_item) { build(:line_item, variant: variant, quantity: 2) }
-
- it 'returns the weight unit for the line item' do
- expect(line_item.weight_unit).to eq('kg')
- end
- end
-
- describe '#should_update_price?' do
- let(:variant) { create(:variant, price: 10) }
- let(:order) { create(:order, store: store) }
- let(:line_item) { create(:line_item, order: order, variant: variant) }
-
- context 'when order is not completed' do
- it 'returns true' do
- expect(order.completed?).to be false
- expect(line_item.send(:should_update_price?)).to be true
- end
- end
-
- context 'when order is completed' do
- before do
- order.update_column(:completed_at, Time.current)
- end
-
- it 'returns false' do
- expect(order.completed?).to be true
- expect(line_item.send(:should_update_price?)).to be false
- end
- end
-
- context 'when the line carries a negotiated (manual) price' do
- before do
- line_item.update_columns(price: 7.2, price_source: Spree::LineItem::MANUAL_PRICE_SOURCE)
- end
-
- it 'returns false' do
- expect(line_item.send(:should_update_price?)).to be false
- end
- end
- end
-
describe '#recalculate_price' do
let(:variant) { create(:variant, price: 10) }
let(:order) { create(:order, store: store) }
diff --git a/spree/core/spec/models/spree/market_spec.rb b/spree/core/spec/models/spree/market_spec.rb
index be2be30681..ff873f392b 100644
--- a/spree/core/spec/models/spree/market_spec.rb
+++ b/spree/core/spec/models/spree/market_spec.rb
@@ -3,32 +3,7 @@ require 'spec_helper'
RSpec.describe Spree::Market, type: :model do
let(:store) { create(:store) }
- describe 'validations' do
- subject { build(:market, store: store) }
-
- it 'validates presence of countries' do
- market = build(:market, store: store, countries: [])
- expect(market).not_to be_valid
- expect(market.errors[:countries]).to be_present
- end
-
- it 'validates uniqueness of name scoped to store' do
- create(:market, name: 'North America', store: store)
- market = build(:market, name: 'North America', store: store)
- expect(market).not_to be_valid
- expect(market.errors[:name]).to be_present
- end
- end
-
describe 'associations' do
- it 'has many countries through market_countries' do
- country1 = create(:country)
- country2 = create(:country)
- market = create(:market, store: store, countries: [country1, country2])
-
- expect(market.countries).to contain_exactly(country1, country2)
- end
-
it 'destroys market_countries on destroy' do
create(:market, :default, store: store)
market = create(:market, store: store)
@@ -197,29 +172,11 @@ RSpec.describe Spree::Market, type: :model do
end
end
- describe '#can_be_deleted?' do
- it 'returns false for the default market' do
- create(:market, store: store)
- market = create(:market, :default, store: store)
- expect(market.can_be_deleted?).to be false
- end
-
- it 'returns false for the only market in a store' do
- market = store.markets.sole
- expect(market.can_be_deleted?).to be false
- end
-
- it 'returns true for a non-default market when other markets remain' do
- create(:market, :default, store: store)
- market = create(:market, store: store)
- expect(market.can_be_deleted?).to be true
- end
- end
-
describe 'destroy' do
it 'does not allow destroying the default market' do
create(:market, store: store)
market = create(:market, :default, store: store)
+ expect(market.can_be_deleted?).to be false
expect(market.destroy).to be false
expect(market.reload.deleted_at).to be_nil
expect(market.errors[:base]).to include(I18n.t('activerecord.errors.models.spree/market.attributes.base.cannot_destroy_default_market'))
@@ -228,6 +185,7 @@ RSpec.describe Spree::Market, type: :model do
it 'does not allow destroying the only market in a store' do
market = store.markets.sole
market.update_column(:default, false)
+ expect(market.can_be_deleted?).to be false
expect(market.destroy).to be false
expect(market.reload.deleted_at).to be_nil
expect(market.errors[:base]).to include(I18n.t('activerecord.errors.models.spree/market.attributes.base.cannot_destroy_last_market'))
@@ -236,6 +194,7 @@ RSpec.describe Spree::Market, type: :model do
it 'allows destroying a non-default market when other markets remain' do
create(:market, :default, store: store)
market = create(:market, store: store)
+ expect(market.can_be_deleted?).to be true
expect { market.destroy }.to change { market.reload.deleted_at }.from(nil).to(be_present)
end
@@ -283,13 +242,6 @@ RSpec.describe Spree::Market, type: :model do
end
end
- describe 'has_prefix_id' do
- it 'generates prefixed id with mkt prefix' do
- market = create(:market, store: store)
- expect(market.prefixed_id).to start_with('mkt_')
- end
- end
-
describe '#tax_provider_instance' do
let(:market) { create(:market, store: store) }
diff --git a/spree/core/spec/models/spree/media_counters_spec.rb b/spree/core/spec/models/spree/media_counters_spec.rb
index bca630b398..c8d133fafd 100644
--- a/spree/core/spec/models/spree/media_counters_spec.rb
+++ b/spree/core/spec/models/spree/media_counters_spec.rb
@@ -16,11 +16,6 @@ describe Spree::Media, type: :model do
expect(media).not_to be_valid
end
- it 'allows only web image content types' do
- media.attachment.attach(io: image_file, filename: 'thinking-cat.jpg', content_type: 'image/jpeg')
- expect(media).to be_valid
- end
-
it 'does not allow non-web image content types' do
media.attachment.attach(io: text_file, filename: 'text-file.txt', content_type: 'text/plain')
expect(media).not_to be_valid
@@ -67,13 +62,6 @@ describe Spree::Media, type: :model do
image = create(:media, viewable: variant)
expect { image.destroy }.to change { variant.reload.media_count }.by(-1)
end
-
- it 'tracks multiple images correctly' do
- expect(variant.media_count).to eq(0)
- create(:media, viewable: variant)
- create(:media, viewable: variant)
- expect(variant.reload.media_count).to eq(2)
- end
end
describe 'product media_count counter cache' do
@@ -92,14 +80,6 @@ describe Spree::Media, type: :model do
image = create(:media, viewable: variant)
expect { image.destroy }.to change { product.reload.media_count }.by(-1)
end
-
- it 'tracks media across all variants correctly' do
- expect(product.media_count).to eq(0)
- create(:media, viewable: product.default_variant)
- create(:media, viewable: variant)
- create(:media, viewable: variant)
- expect(product.reload.media_count).to eq(3)
- end
end
describe 'thumbnail choice with video in the gallery' do
diff --git a/spree/core/spec/models/spree/media_spec.rb b/spree/core/spec/models/spree/media_spec.rb
index 18f3605cfb..0e9063c97e 100644
--- a/spree/core/spec/models/spree/media_spec.rb
+++ b/spree/core/spec/models/spree/media_spec.rb
@@ -324,11 +324,6 @@ describe Spree::Media, type: :model do
expect(asset.media_type).to eq('image')
end
- it 'defaults to image for Spree::Media subclass' do
- image = Spree::Media.new
- expect(image.media_type).to eq('image')
- end
-
it 'answers a predicate per media type' do
expect(build(:media)).to be_image
expect(build(:video_media)).to be_video
@@ -337,10 +332,6 @@ describe Spree::Media, type: :model do
end
describe 'video' do
- it 'accepts an uploaded video file' do
- expect(build(:video_media)).to be_valid
- end
-
it 'requires a file, not a URL' do
asset = build(:media, media_type: 'video')
asset.attachment.detach
@@ -369,10 +360,6 @@ describe Spree::Media, type: :model do
end
describe 'external video' do
- it 'accepts a YouTube link' do
- expect(build(:external_video_media)).to be_valid
- end
-
it 'accepts a Vimeo link' do
expect(build(:external_video_media, external_video_url: 'https://vimeo.com/123456789')).to be_valid
end
@@ -515,45 +502,6 @@ describe Spree::Media, type: :model do
end
end
- describe 'delegated methods' do
- let(:asset) { create(:media) }
- let(:attachment) { asset.attachment }
-
- before do
- allow(asset).to receive(:attachment).and_return(attachment)
- end
-
- it 'delegates :key to attachment' do
- expect(attachment).to receive(:key)
- asset.key
- end
-
- it 'delegates :attached? to attachment' do
- expect(attachment).to receive(:attached?)
- asset.attached?
- end
-
- it 'delegates :variant to attachment' do
- expect(attachment).to receive(:variant)
- asset.variant
- end
-
- it 'delegates :variable? to attachment' do
- expect(attachment).to receive(:variable?)
- asset.variable?
- end
-
- it 'delegates :blob to attachment' do
- expect(attachment).to receive(:blob)
- asset.blob
- end
-
- it 'delegates :filename to attachment' do
- expect(attachment).to receive(:filename)
- asset.filename
- end
- end
-
describe '.with_session_uploaded_assets_uuid' do
subject { described_class.with_session_uploaded_assets_uuid(uuid) }
diff --git a/spree/core/spec/models/spree/number_sequence_spec.rb b/spree/core/spec/models/spree/number_sequence_spec.rb
index 9434a989f2..c14c14c7c7 100644
--- a/spree/core/spec/models/spree/number_sequence_spec.rb
+++ b/spree/core/spec/models/spree/number_sequence_spec.rb
@@ -66,12 +66,4 @@ RSpec.describe Spree::NumberSequence do
expect(values.sort).to eq([1, 2, 3, 4])
end
end
-
- describe 'uniqueness' do
- it 'allows one row per store and resource type' do
- create(:number_sequence, store: store, resource_type: 'order')
-
- expect(build(:number_sequence, store: store, resource_type: 'order')).not_to be_valid
- end
- end
end
diff --git a/spree/core/spec/models/spree/option_type_spec.rb b/spree/core/spec/models/spree/option_type_spec.rb
index b7c07f8321..03afee7223 100644
--- a/spree/core/spec/models/spree/option_type_spec.rb
+++ b/spree/core/spec/models/spree/option_type_spec.rb
@@ -3,10 +3,6 @@ require 'spec_helper'
describe Spree::OptionType, type: :model do
it_behaves_like 'metadata'
- describe '#filterable' do
- it { expect(subject.filterable).to eq(true) }
- end
-
describe 'callbacks' do
describe '#normalize_name' do
let!(:option_type) { build(:option_type, name: 'Shirt Size') }
@@ -28,15 +24,6 @@ describe Spree::OptionType, type: :model do
end
end
- let(:option_type_pl_translation) { option_type.translations.find_by(locale: 'pl') }
-
- it 'translates option type fields' do
- expect(option_type.label).to eq('Size')
-
- expect(option_type_pl_translation).to be_present
- expect(option_type_pl_translation.label).to eq('Rozmiar')
- end
-
describe '#label' do
it 'returns the translated label for the current locale' do
expect(option_type.label).to eq('Size')
@@ -91,11 +78,6 @@ describe Spree::OptionType, type: :model do
end
describe 'kind' do
- it 'defaults to dropdown' do
- option_type = create(:option_type)
- expect(option_type.kind).to eq('dropdown')
- end
-
it 'validates inclusion in KINDS' do
option_type = build(:option_type, kind: 'invalid')
expect(option_type).not_to be_valid
@@ -108,11 +90,6 @@ describe Spree::OptionType, type: :model do
expect(option_type).to be_valid
end
end
-
- it 'validates presence' do
- option_type = build(:option_type, kind: '')
- expect(option_type).not_to be_valid
- end
end
describe '#color_swatch?' do
@@ -146,16 +123,6 @@ describe Spree::OptionType, type: :model do
end
describe '#option_values=' do
- context 'with an array of OptionValue records' do
- let(:option_type) { create(:option_type) }
- let(:option_value) { build(:option_value, option_type: option_type) }
-
- it 'delegates to the AR collection writer' do
- option_type.option_values = [option_value]
- expect(option_type.option_values).to eq([option_value])
- end
- end
-
context 'on a new option type' do
it 'persists option values when the parent is saved' do
option_type = build(:option_type)
diff --git a/spree/core/spec/models/spree/option_value_spec.rb b/spree/core/spec/models/spree/option_value_spec.rb
index 4db7b1dbbc..0fe6febaad 100644
--- a/spree/core/spec/models/spree/option_value_spec.rb
+++ b/spree/core/spec/models/spree/option_value_spec.rb
@@ -45,29 +45,11 @@ describe Spree::OptionValue, type: :model do
end
describe 'color_code validation' do
- it 'accepts valid 6-digit hex color' do
- option_value = build(:option_value, color_code: '#FF0000')
- expect(option_value).to be_valid
- end
-
- it 'accepts valid 8-digit hex color (with alpha)' do
- option_value = build(:option_value, color_code: '#FF0000AA')
- expect(option_value).to be_valid
- end
-
- it 'accepts lowercase hex' do
- option_value = build(:option_value, color_code: '#aabbcc')
- expect(option_value).to be_valid
- end
-
- it 'accepts nil color_code' do
- option_value = build(:option_value, color_code: nil)
- expect(option_value).to be_valid
- end
-
- it 'accepts blank color_code' do
- option_value = build(:option_value, color_code: '')
- expect(option_value).to be_valid
+ it 'accepts 6- and 8-digit hex colors in any case, or no color' do
+ ['#FF0000', '#FF0000AA', '#aabbcc', nil, ''].each do |valid|
+ option_value = build(:option_value, color_code: valid)
+ expect(option_value).to be_valid, "Expected #{valid.inspect} to be valid"
+ end
end
it 'rejects invalid hex colors' do
@@ -88,15 +70,6 @@ describe Spree::OptionValue, type: :model do
end
end
- let(:option_value_pl_translation) { option_value.translations.find_by(locale: 'pl') }
-
- it 'translates option value fields' do
- expect(option_value.label).to eq('Red')
-
- expect(option_value_pl_translation).to be_present
- expect(option_value_pl_translation.label).to eq('Czerwony')
- end
-
describe '#label' do
it 'returns the translated label for the current locale' do
expect(option_value.label).to eq('Red')
diff --git a/spree/core/spec/models/spree/option_value_variant_spec.rb b/spree/core/spec/models/spree/option_value_variant_spec.rb
deleted file mode 100644
index 747df3e4a7..0000000000
--- a/spree/core/spec/models/spree/option_value_variant_spec.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-require 'spec_helper'
-
-describe Spree::OptionValueVariant, type: :model do
- let(:option_value_variant) { create(:option_value_variant) }
-
- describe 'touching' do
- let(:variant) { option_value_variant.variant }
-
- it 'touches a variant' do
- expect(variant).to receive(:touch)
- option_value_variant.touch
- end
- end
-end
diff --git a/spree/core/spec/models/spree/order/checkout_spec.rb b/spree/core/spec/models/spree/order/checkout_spec.rb
index abfb8db421..85b70e4d3d 100644
--- a/spree/core/spec/models/spree/order/checkout_spec.rb
+++ b/spree/core/spec/models/spree/order/checkout_spec.rb
@@ -54,16 +54,16 @@ describe Spree::Order, type: :model do
it 'subscribes to newsletter', :events do
expect(Spree::NewsletterSubscriber).to receive(:subscribe).with(email: order.email, customer: order.customer, store: order.store)
- order.finalize!
+ Spree.order_complete_workflow.call(order: order, payment_pending: true)
end
end
context 'when newsletter is not accepted for the order' do
let(:accept_marketing) { false }
- it 'does not subscribe to newsletter' do
+ it 'does not subscribe to newsletter', :events do
expect(Spree::NewsletterSubscriber).not_to receive(:subscribe)
- order.finalize!
+ Spree.order_complete_workflow.call(order: order, payment_pending: true)
end
end
end
@@ -78,7 +78,7 @@ describe Spree::Order, type: :model do
it 'redeems the gift card' do
expect(gift_card.redeemed_at).to be_nil
- expect { order.finalize! }.to change { gift_card.reload.status }.from('active').to('redeemed')
+ expect { Spree.order_complete_workflow.call(order: order, payment_pending: true) }.to change { gift_card.reload.status }.from('active').to('redeemed')
expect(gift_card.amount_used).to eq(order.total)
expect(gift_card.amount_remaining).to eq(0)
expect(gift_card.redeemed_at).to be_present
@@ -88,7 +88,7 @@ describe Spree::Order, type: :model do
let(:gift_card) { create(:gift_card, amount: order.total + 1, store: store) }
it 'partially redeems the gift card' do
- expect { order.finalize! }.to change { gift_card.reload.status }.from('active').to('partially_redeemed')
+ expect { Spree.order_complete_workflow.call(order: order, payment_pending: true) }.to change { gift_card.reload.status }.from('active').to('partially_redeemed')
expect(gift_card.amount_used).to eq(order.total)
expect(gift_card.amount_remaining).to eq(1)
expect(gift_card.redeemed_at).to be_nil
@@ -106,7 +106,7 @@ describe Spree::Order, type: :model do
end
it 'creates a new user', :events do
- expect { order.finalize! }.to change { Spree.customer_class.count }.by(1)
+ expect { Spree.order_complete_workflow.call(order: order, payment_pending: true) }.to change { Spree.customer_class.count }.by(1)
# The subscriber attaches the user on its own loaded instance.
expect(order.reload.customer).to be_present
expect(order.customer.email).to eq(order.email)
@@ -115,11 +115,11 @@ describe Spree::Order, type: :model do
context 'with signup_for_an_account set to false' do
before do
- allow(order).to receive(:signup_for_an_account?).and_return(false)
+ order.update_column(:signup_for_an_account, false)
end
- it 'does not create a new user' do
- expect { order.finalize! }.not_to change { Spree.customer_class.count }
+ it 'does not create a new user', :events do
+ expect { Spree.order_complete_workflow.call(order: order, payment_pending: true) }.not_to change { Spree.customer_class.count }
end
end
end
diff --git a/spree/core/spec/models/spree/order/digital_auto_fulfillment_spec.rb b/spree/core/spec/models/spree/order/digital_auto_fulfillment_spec.rb
index d66538a9e3..ecf50e7087 100644
--- a/spree/core/spec/models/spree/order/digital_auto_fulfillment_spec.rb
+++ b/spree/core/spec/models/spree/order/digital_auto_fulfillment_spec.rb
@@ -18,12 +18,12 @@ describe 'Digital auto-fulfillment on order completion', type: :model do
end
end
- it 'fulfills the digital fulfillment and creates links per quantity on finalize' do
+ it 'fulfills the digital fulfillment and creates links per quantity on completion' do
line_item = order.line_items.first
line_item.update_columns(quantity: 2)
order.fulfillment_items.update_all(quantity: 2)
- order.finalize!
+ Spree.order_complete_workflow.call(order: order, payment_pending: true)
fulfillment = order.fulfillments.reload.first
expect(fulfillment).to be_fulfilled
@@ -31,8 +31,8 @@ describe 'Digital auto-fulfillment on order completion', type: :model do
expect(order.reload.fulfillment_status).to eq('fulfilled')
end
- it 'is idempotent across repeated finalization side effects' do
- order.finalize!
+ it 'is idempotent across repeated completion side effects' do
+ Spree.order_complete_workflow.call(order: order, payment_pending: true)
fulfillment = order.fulfillments.reload.first
expect { fulfillment.provider.create_fulfillment(fulfillment) }.
diff --git a/spree/core/spec/models/spree/order/payment_spec.rb b/spree/core/spec/models/spree/order/payment_spec.rb
index 92b479f545..9cb5778e5f 100644
--- a/spree/core/spec/models/spree/order/payment_spec.rb
+++ b/spree/core/spec/models/spree/order/payment_spec.rb
@@ -69,16 +69,6 @@ module Spree
expect(order.outstanding_balance).to eq(30.00)
end
end
-
- context 'order payment status should be partially paid' do
- let!(:payment_amount) { 90.00 }
- let!(:store_credit_amount) { 10.00 }
-
- it do
- expect(order.payment_status).to eq('partially_paid')
- expect(order.outstanding_balance).to eq(10.00)
- end
- end
end
end
@@ -106,11 +96,11 @@ module Spree
it 'does not use failed payments' do
payment_1 = create(:payment, amount: 50, order: order)
payment_2 = create(:payment, amount: 50, status: 'failed', order: order)
- allow(order).to receive(:pending_payments).and_return([payment_1])
-
- expect(payment_2).not_to receive(:process!)
order.process_payments!
+
+ expect(payment_1.reload).not_to be_checkout
+ expect(payment_2.reload).to be_failed
end
end
@@ -191,25 +181,5 @@ module Spree
expect(order.outstanding_balance).to eq 10
end
end
-
- context '#outstanding_balance?' do
- it 'is true when total greater than payment_total' do
- order.total = 10.10
- order.payment_total = 9.50
- expect(order.outstanding_balance?).to be true
- end
-
- it 'is true when total less than payment_total' do
- order.total = 8.25
- order.payment_total = 10.44
- expect(order.outstanding_balance?).to be true
- end
-
- it 'is false when total equals payment_total' do
- order.total = 10.10
- order.payment_total = 10.10
- expect(order.outstanding_balance?).to be false
- end
- end
end
end
diff --git a/spree/core/spec/models/spree/order/risk_assessment_spec.rb b/spree/core/spec/models/spree/order/risk_assessment_spec.rb
index ce75686bd9..be301ed244 100644
--- a/spree/core/spec/models/spree/order/risk_assessment_spec.rb
+++ b/spree/core/spec/models/spree/order/risk_assessment_spec.rb
@@ -1,8 +1,6 @@
require 'spec_helper'
describe Spree::Order, type: :model do
- let(:order) { create(:order) }
-
describe '.is_risky?' do
context 'Not risky order' do
let(:order) { FactoryBot.create(:order, payments: [payment]) }
diff --git a/spree/core/spec/models/spree/order/shipments_spec.rb b/spree/core/spec/models/spree/order/shipments_spec.rb
index 6c2c07d44c..d2db1db954 100644
--- a/spree/core/spec/models/spree/order/shipments_spec.rb
+++ b/spree/core/spec/models/spree/order/shipments_spec.rb
@@ -9,12 +9,12 @@ describe Spree::Order, type: :model do
context "except when order is completed, that's OrderInventory job" do
it "doesn't touch anything" do
allow(order).to receive_messages completed?: true
- order.update_column(:shipment_total, 5)
+ order.update_column(:delivery_total, 5)
order.shipments.create!(stock_location: create(:stock_location))
expect do
order.ensure_updated_fulfillments
- end.not_to change(order, :shipment_total)
+ end.not_to change(order, :delivery_total)
expect do
order.ensure_updated_fulfillments
diff --git a/spree/core/spec/models/spree/order/state_machine_spec.rb b/spree/core/spec/models/spree/order/state_machine_spec.rb
index 719870c4d1..aff517bac0 100644
--- a/spree/core/spec/models/spree/order/state_machine_spec.rb
+++ b/spree/core/spec/models/spree/order/state_machine_spec.rb
@@ -38,7 +38,7 @@ describe Spree::Order, type: :model do
expect(order.reload.status).to eq('canceled')
expect(order.canceled_at).to be_present
expect(order.fulfillments.reload).to all(be_canceled)
- expect(order.payments.reload.map(&:state)).to all(be_in(%w[void invalid checkout]))
+ expect(order.payments.reload.map(&:status)).to eq(%w[void])
end
it 'refuses to cancel when not allowed' do
@@ -55,6 +55,7 @@ describe Spree::Order, type: :model do
let(:admin) { create(:admin_user) }
it 'records the canceler and cancels through the service' do
+ expect(Spree::Deprecation).to receive(:warn).with(/Order#canceled_by is deprecated/)
order.canceled_by(admin)
expect(order.reload.status).to eq('canceled')
diff --git a/spree/core/spec/models/spree/order/updating_spec.rb b/spree/core/spec/models/spree/order/updating_spec.rb
deleted file mode 100644
index 0b0c442500..0000000000
--- a/spree/core/spec/models/spree/order/updating_spec.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-require 'spec_helper'
-
-describe Spree::Order, type: :model do
- let(:order) { create(:order) }
-
- context '#recalculate_totals!' do
- let(:line_items) { create_list(:line_item, 1, amount: 5) }
-
- it 'persists recalculated totals' do
- expect { order.recalculate_totals! }.to change { order.reload.updated_at }
- end
- end
-end
diff --git a/spree/core/spec/models/spree/order_group_spec.rb b/spree/core/spec/models/spree/order_group_spec.rb
index 06b293d63d..6da25f7a4f 100644
--- a/spree/core/spec/models/spree/order_group_spec.rb
+++ b/spree/core/spec/models/spree/order_group_spec.rb
@@ -202,10 +202,4 @@ RSpec.describe Spree::OrderGroup, type: :model do
expect(group.errors[:base]).to be_present
end
end
-
- describe 'numbering' do
- it 'takes an order-style number' do
- expect(group.number).to start_with('R')
- end
- end
end
diff --git a/spree/core/spec/models/spree/order_inventory_spec.rb b/spree/core/spec/models/spree/order_inventory_spec.rb
index b646ca568d..1cb835267b 100644
--- a/spree/core/spec/models/spree/order_inventory_spec.rb
+++ b/spree/core/spec/models/spree/order_inventory_spec.rb
@@ -164,11 +164,6 @@ describe Spree::OrderInventory, type: :model do
subject.line_item.reload
end
- it 'is a messed up order' do
- expect(order.fulfillments.first.inventory_units_for(line_item.variant).sum(&:quantity)).to eq(3)
- expect(line_item.quantity).to eq(2)
- end
-
it 'decreases the number of inventory units' do
subject.verify
expect(subject.fulfillment_items.reload.sum(:quantity)).to eq 2
@@ -222,17 +217,6 @@ describe Spree::OrderInventory, type: :model do
expect(subject.send(:remove_from_shipment, shipment, 1)).to eq(1)
end
- it 'only attempts to destroy as many units as are eligible, and return amount destroyed' do
- allow(shipment).to receive_messages(inventory_units_for_item: inventory_units_for_item)
-
- expect(shipment.inventory_units_for_item[0]).not_to receive(:destroy)
- expect(shipment.inventory_units_for_item[1]).to receive(:destroy)
- allow(shipment.inventory_units_for_item[0]).to receive(:save!)
- allow(shipment.inventory_units_for_item[1]).to receive(:save!)
-
- expect(subject.send(:remove_from_shipment, shipment, 1)).to eq(1)
- end
-
it 'destroys self if not inventory units remain' do
allow(shipment).to receive(:fulfillment_items).and_return(shipment.fulfillment_items)
allow(shipment.fulfillment_items).to receive_messages(sum: 0)
diff --git a/spree/core/spec/models/spree/order_merger_spec.rb b/spree/core/spec/models/spree/order_merger_spec.rb
index 05faf41446..8acd01fbfd 100644
--- a/spree/core/spec/models/spree/order_merger_spec.rb
+++ b/spree/core/spec/models/spree/order_merger_spec.rb
@@ -9,6 +9,13 @@ module Spree
let(:user) { create(:user) }
let(:subject) { Spree::OrderMerger.new(order_1) }
+ before { allow(Spree::Deprecation).to receive(:warn) }
+
+ it 'warns that it is deprecated' do
+ subject
+ expect(Spree::Deprecation).to have_received(:warn).with(/Spree::OrderMerger is deprecated/)
+ end
+
it 'destroys the other order' do
subject.merge!(order_2)
expect { order_2.reload }.to raise_error(ActiveRecord::RecordNotFound)
@@ -41,8 +48,8 @@ module Spree
context 'merging together two orders with line items for the same variant' do
before do
- Spree::Carts::AddItem.call order: order_1, variant: variant, quantity: 1
- Spree::Carts::AddItem.call order: order_2, variant: variant, quantity: 1
+ Spree::Orders::AddItem.call(order: order_1, variant: variant, quantity: 1)
+ Spree::Orders::AddItem.call(order: order_2, variant: variant, quantity: 1)
end
specify do
@@ -87,8 +94,8 @@ module Spree
before do
allow(order_1).to receive(:foos_match).and_return(false)
- Spree::Carts::AddItem.call order: order_1, variant: variant, quantity: 1, options: {foos: {}}
- Spree::Carts::AddItem.call order: order_2, variant: variant, quantity: 1, options: {foos: {}}
+ Spree::Orders::AddItem.call(order: order_1, variant: variant, quantity: 1, options: {foos: {}})
+ Spree::Orders::AddItem.call(order: order_2, variant: variant, quantity: 1, options: {foos: {}})
end
specify do
@@ -110,8 +117,8 @@ module Spree
let(:variant_2) { create(:variant) }
before do
- Spree::Carts::AddItem.call order: order_1, variant: variant, quantity: 1
- Spree::Carts::AddItem.call order: order_2, variant: variant_2, quantity: 1
+ Spree::Orders::AddItem.call(order: order_1, variant: variant, quantity: 1)
+ Spree::Orders::AddItem.call(order: order_2, variant: variant_2, quantity: 1)
end
specify do
@@ -119,7 +126,7 @@ module Spree
expect(order_1.line_items.length).to eq(2)
expect(order_1.line_items.count).to eq(2)
- expect(order_1.item_count).to eq 2
+ expect(order_1.total_quantity).to eq 2
expect(order_1.item_total).to eq order_1.line_items.map(&:amount).sum
# No guarantee on ordering of line items, so we do this:
@@ -132,8 +139,8 @@ module Spree
let(:variant_2) { create(:variant) }
before do
- Spree::Carts::AddItem.call order: order_1, variant: variant, quantity: 1
- Spree::Carts::AddItem.call order: order_2, variant: variant_2, quantity: 1
+ Spree::Orders::AddItem.call(order: order_1, variant: variant, quantity: 1)
+ Spree::Orders::AddItem.call(order: order_2, variant: variant_2, quantity: 1)
end
it 'creates errors with invalid line items' do
diff --git a/spree/core/spec/models/spree/order_promotion_spec.rb b/spree/core/spec/models/spree/order_promotion_spec.rb
index 66a61bf1ec..4a9449b7f6 100644
--- a/spree/core/spec/models/spree/order_promotion_spec.rb
+++ b/spree/core/spec/models/spree/order_promotion_spec.rb
@@ -13,18 +13,6 @@ describe Spree::OrderPromotion, type: :model do
order.discounts.promotion.update_all(amount: -5.0)
end
- context '#name' do
- it 'returns the same value as Promotion name' do
- expect(subject.name).to eq(promotion.name)
- end
- end
-
- context '#description' do
- it 'returns the same value as Promotion description' do
- expect(subject.description).to eq(promotion.description)
- end
- end
-
context '#amount' do
it 'equals sum of adjustments created by promotion' do
expect(subject.amount).to eq(-5.0)
diff --git a/spree/core/spec/models/spree/order_routing/strategy/parity_spec.rb b/spree/core/spec/models/spree/order_routing/strategy/parity_spec.rb
index 9a2984c2da..a9f8c98204 100644
--- a/spree/core/spec/models/spree/order_routing/strategy/parity_spec.rb
+++ b/spree/core/spec/models/spree/order_routing/strategy/parity_spec.rb
@@ -389,23 +389,6 @@ RSpec.describe 'OrderRouting strategy parity', type: :model do
end
end
- context 'stock reservations globally disabled' do
- before { stub_store_preferences(stock_reservations_enabled: false) }
-
- let(:order) do
- o = create(:order, store: store, ship_address: create(:ship_address))
- create(:line_item, order: o, variant: variant_a, quantity: 1)
- o.reload
- end
-
- before { nyc.stock_level_or_create(variant_a).update!(count_on_hand: 5) }
-
- it 'allocates unaffected by reservation feature flag' do
- packages = strategy.for_allocation
- expect(total_on_hand(packages)).to eq(1)
- end
- end
-
# ---------------------------------------------------------------
# Splitter chain: fulfillment-type split runs per-location
# ---------------------------------------------------------------
@@ -627,7 +610,7 @@ RSpec.describe 'OrderRouting strategy parity', type: :model do
# No inventory units → no requested_variant_ids → no eligible
# locations → empty package list. Same for both pipelines.
packages = strategy.for_allocation
- expect(packages).to eq([]).or be_empty
+ expect(packages).to be_empty
expect(total_on_hand(packages)).to eq(0)
expect(total_backordered(packages)).to eq(0)
end
diff --git a/spree/core/spec/models/spree/order_routing_rule_spec.rb b/spree/core/spec/models/spree/order_routing_rule_spec.rb
index 1072995ff6..7efc487617 100644
--- a/spree/core/spec/models/spree/order_routing_rule_spec.rb
+++ b/spree/core/spec/models/spree/order_routing_rule_spec.rb
@@ -8,18 +8,6 @@ RSpec.describe Spree::OrderRoutingRule, type: :model do
let(:channel) { store.default_channel }
describe 'validations' do
- it 'requires a type' do
- rule = described_class.new(store: store, channel: channel, position: 1)
- expect(rule).not_to be_valid
- expect(rule.errors[:type]).to be_present
- end
-
- it 'requires a channel' do
- rule = Spree::OrderRouting::Rules::PreferredLocation.new(store: store, position: 1)
- expect(rule).not_to be_valid
- expect(rule.errors[:channel]).to be_present
- end
-
it 'is valid when instantiated as an STI subclass with a channel' do
# The seeded rule of the same kind must go first — `type` is unique per channel.
channel.order_routing_rules.find_by(type: 'Spree::OrderRouting::Rules::PreferredLocation').destroy!
@@ -71,16 +59,6 @@ RSpec.describe Spree::OrderRoutingRule, type: :model do
end
end
- describe 'Spree.order_routing.rules' do
- it 'includes the core rule kinds' do
- expect(Spree.order_routing.rules).to include(
- Spree::OrderRouting::Rules::PreferredLocation,
- Spree::OrderRouting::Rules::MinimizeSplits,
- Spree::OrderRouting::Rules::DefaultLocation
- )
- end
- end
-
describe 'scopes' do
# Channels seed 3 default rules on create. We test scopes against fresh rules
# in a clean channel to avoid coupling to the seed list.
diff --git a/spree/core/spec/models/spree/order_spec.rb b/spree/core/spec/models/spree/order_spec.rb
index c7fc572ce3..95ad4ff2fb 100644
--- a/spree/core/spec/models/spree/order_spec.rb
+++ b/spree/core/spec/models/spree/order_spec.rb
@@ -71,7 +71,7 @@ describe Spree::Order, type: :model do
describe '.for_channel' do
let!(:channel) { create(:channel) }
- let!(:channeled_order) { create(:order, user: user, channel: channel) }
+ let!(:channeled_order) { create(:order, customer: user, channel: channel) }
it 'filters by the given channel and returns all orders for nil' do
expect(described_class.for_channel(channel)).to contain_exactly(channeled_order)
@@ -129,24 +129,6 @@ describe Spree::Order, type: :model do
end
end
- describe 'Callbacks' do
- let(:order) { build(:order, customer: user, store: store, ship_address: ship_address) }
- let(:ship_address) { create(:address, customer: user) }
-
- describe '#clone_shipping_address' do
- it 'clones the shipping address when use_shipping is true' do
- order.update!(use_shipping: true)
- expect(order.reload.bill_address).to eq(ship_address)
- expect(user.reload.bill_address).to eq(ship_address)
- end
-
- it 'does not clone the shipping address when use_shipping is false' do
- order.update!(use_shipping: false)
- expect(order.reload.bill_address).not_to eq(order.ship_address)
- end
- end
- end
-
describe '#full_name' do
subject { order.full_name }
@@ -181,15 +163,16 @@ describe Spree::Order, type: :model do
end
describe '#recalculate_totals!' do
- let(:updater) { order.updater }
-
- before do
- allow(order).to receive(:updater).and_return(updater)
- allow(updater).to receive(:update).and_return(true)
- end
+ let(:order) { create(:order_with_line_items, store: store) }
it 'recalculates and persists totals through the RecalculateTotals flow' do
- expect { order.recalculate_totals! }.to change { order.reload.updated_at }
+ expected_total = order.total
+ order.update_columns(item_total: 0, total: 0)
+
+ order.recalculate_totals!
+
+ expect(order.reload.item_total).to eq(order.line_items.sum(&:amount))
+ expect(order.total).to eq(expected_total)
end
end
@@ -216,7 +199,7 @@ describe Spree::Order, type: :model do
:payment,
order: order,
amount: order.total,
- state: 'completed'
+ status: 'completed'
)
end
let(:payment_method) { double }
@@ -260,22 +243,7 @@ describe Spree::Order, type: :model do
expect(order.status).to eq('canceled')
expect(order.shipments).to all(have_attributes(state: 'canceled'))
- expect(order.payments.store_credits).to all(have_attributes(state: 'void'))
- end
- end
-
- context 'when no gift card' do
- let(:order) { create(:completed_order_with_totals, store: store) }
- let!(:payment) { create(:payment, order: order, status: 'completed', amount: 10) }
-
- it 'handles additional actions' do
- order.cancel
- order.reload
-
- expect(order.status).to eq('canceled')
- expect(order.shipments).to all(have_attributes(state: 'canceled'))
- expect(order.payments).to all(have_attributes(state: 'void'))
- expect(order.payments.store_credits).to all(have_attributes(state: 'void'))
+ expect(order.payments.store_credits).to all(have_attributes(status: 'void'))
end
end
end
@@ -286,25 +254,14 @@ describe Spree::Order, type: :model do
let(:admin_user) { create :admin_user }
let(:order) { create(:completed_order_with_totals) }
- it 'cancels the order' do
- expect { subject }.to change { order.reload.status }.to('canceled')
- end
-
- it 'saves canceler_id' do
- subject
- expect(order.reload.canceler_id).to eq(admin_user.id)
- end
-
- it 'has canceler' do
- subject
- expect(order.reload.canceler).to eq(admin_user)
- end
+ before { allow(Spree::Deprecation).to receive(:warn) }
context 'when canceled_at is not given' do
it 'saves canceled_at to Time.current' do
Timecop.freeze(Time.current) do
subject
expect(order.reload.canceled_at.to_s).to eq Time.current.to_s
+ expect(Spree::Deprecation).to have_received(:warn).with(/Order#canceled_by is deprecated/)
end
end
end
@@ -332,18 +289,12 @@ describe Spree::Order, type: :model do
describe '#create' do
let(:order) { Spree::Order.create }
- it 'assigns an order number' do
- expect(order.number).not_to be_nil
- end
-
it 'creates a randomized 35 character token' do
expect(order.token.size).to eq(35)
end
end
context 'creates shipments cost' do
- let(:shipment) { double }
-
let(:order) { create(:order_with_line_items) }
let(:shipment) { order.fulfillments.first }
@@ -374,6 +325,8 @@ describe Spree::Order, type: :model do
let(:order) { create :order_with_line_items }
+ before { allow(Spree::Deprecation).to receive(:warn) }
+
context 'when variant is destroyed' do
before do
order.line_items.first.variant.discontinue!
@@ -392,6 +345,7 @@ describe Spree::Order, type: :model do
context 'when no variants are destroyed' do
it 'is true' do
expect(subject).to be_truthy
+ expect(Spree::Deprecation).to have_received(:warn).with(/ensure_line_item_variants_are_not_discontinued is deprecated/)
end
end
end
@@ -399,15 +353,15 @@ describe Spree::Order, type: :model do
describe '#ensure_line_items_are_in_stock' do
subject { order.ensure_line_items_are_in_stock }
- let(:line_item) { create(:line_item, order: order) }
-
before do
+ allow(Spree::Deprecation).to receive(:warn)
allow(order).to receive(:insufficient_stock_lines).and_return([true])
end
it 'has error message' do
subject
expect(order.errors[:base]).to include(I18n.t('spree.insufficient_stock_lines_present'))
+ expect(Spree::Deprecation).to have_received(:warn).with(/ensure_line_items_are_in_stock is deprecated/)
end
it 'is false' do
@@ -452,34 +406,6 @@ describe Spree::Order, type: :model do
end
end
- describe '#display_outstanding_balance' do
- it 'returns the value as a spree money' do
- allow(order).to receive(:outstanding_balance).and_return(10.55)
- expect(order.display_outstanding_balance).to eq(Spree::Money.new(10.55))
- end
- end
-
- describe '#display_item_total' do
- it 'returns the value as a spree money' do
- allow(order).to receive(:item_total).and_return(10.55)
- expect(order.display_item_total).to eq(Spree::Money.new(10.55))
- end
- end
-
- describe '#display_adjustment_total' do
- it 'returns the value as a spree money' do
- order.adjustment_total = 10.55
- expect(order.display_adjustment_total).to eq(Spree::Money.new(10.55))
- end
- end
-
- describe '#display_promo_total' do
- it 'returns the value as a spree money' do
- order.promo_total = 10.55
- expect(order.display_promo_total).to eq(Spree::Money.new(10.55))
- end
- end
-
describe '#display_total' do
it 'returns the value as a spree money' do
order.total = 10.55
@@ -487,16 +413,6 @@ describe Spree::Order, type: :model do
end
end
- describe '#currency' do
- context 'when object currency is EUR' do
- before { order.currency = 'EUR' }
-
- it 'returns the currency from the object' do
- expect(order.currency).to eq('EUR')
- end
- end
- end
-
describe '#tax_address' do
subject { order.tax_address }
@@ -522,61 +438,22 @@ describe Spree::Order, type: :model do
# The deprecated twin of #payment_methods; it must keep matching its
# replacement until it is removed in 6.1.
describe '#collect_payment_methods' do
- it 'excludes an inactive method even when it is storefront-visible' do
- store.payment_methods.create!(name: 'Fake', active: false, storefront_visible: true)
-
- expect(order.send(:collect_payment_methods)).to be_empty
- end
-
- it 'excludes a backoffice-only method' do
- store.payment_methods.create!(name: 'Fake', active: true, storefront_visible: false)
-
- expect(order.send(:collect_payment_methods)).to be_empty
- end
-
it 'includes an active storefront-visible method' do
payment_method = store.payment_methods.create!(name: 'Fake', active: true, storefront_visible: true)
+ expect(Spree::Deprecation).to receive(:warn).with(/collect_payment_methods is deprecated/)
expect(order.send(:collect_payment_methods)).to include(payment_method)
end
end
# Regression test for #4199
describe '#collect_frontend_payment_methods' do
- let(:ok_method) { double :payment_method, store_credit?: false, available_for_order?: true, available_for_store?: true, store: store }
- let(:no_method) { double :payment_method, store_credit?: false, available_for_order?: false, available_for_store?: true, store: store }
- let(:methods) { [ok_method, no_method] }
let(:store_2) { create(:store) }
let(:order_from_different_store) { create(:order, customer: user, store: store_2) }
- it 'includes frontend payment methods' do
- payment_method = store.payment_methods.create!(name: 'Fake', active: true, storefront_visible: true)
- expect(order.collect_frontend_payment_methods).to include(payment_method)
- end
-
- it 'includes payment methods that are storefront-visible by default' do
- payment_method = store.payment_methods.create!(name: 'Fake', active: true)
- expect(order.collect_frontend_payment_methods).to include(payment_method)
- end
-
- it 'does not include backend payment method' do
- store.payment_methods.create!(name: 'Fake', active: true, storefront_visible: false)
- expect(order.collect_frontend_payment_methods.count).to eq(0)
- end
-
- it 'does not include inactive payment methods' do
- store.payment_methods.create!(name: 'Fake', active: false, storefront_visible: true)
- expect(order.collect_frontend_payment_methods.count).to eq(0)
- end
-
- it 'does not include a payment method that is not suitable for this order' do
- allow(order.store).to receive_message_chain(:payment_methods, :active, :storefront_visible).and_return(methods)
-
- expect(order.collect_frontend_payment_methods).to contain_exactly(ok_method)
- end
-
it 'does not include a payment method from different stores' do
payment_method = store_2.payment_methods.create!(name: 'Fake', active: true)
+ expect(Spree::Deprecation).to receive(:warn).with(/collect_frontend_payment_methods is deprecated/).twice
expect(order.collect_frontend_payment_methods).not_to include(payment_method)
expect(order_from_different_store.collect_frontend_payment_methods).to include(payment_method)
@@ -792,37 +669,6 @@ describe Spree::Order, type: :model do
end
end
- describe '#approved_by' do
- let(:admin_user) { create(:admin_user) }
- let(:order) { create(:order_ready_to_ship) }
-
- it 'sets approver_id' do
- order.approved_by(admin_user)
- expect(order.reload.approver_id).to eq(admin_user.id)
- end
-
- it 'sets approved_at' do
- Timecop.freeze(Time.current) do
- order.approved_by(admin_user)
- expect(order.reload.approved_at.to_s).to eq(Time.current.to_s)
- end
- end
-
- it 'sets considered_risky to false' do
- order.update_column(:considered_risky, true)
- order.approved_by(admin_user)
- expect(order.reload.considered_risky).to be false
- end
-
- context 'events', :events do
- it 'publishes order.approved event' do
- allow(Spree::Events).to receive(:publish)
- order.approved_by(admin_user)
- expect(Spree::Events).to have_received(:publish).with('order.approved', any_args)
- end
- end
- end
-
describe '#considered_risky!' do
let(:order) { create(:completed_order_with_totals) }
@@ -850,14 +696,6 @@ describe Spree::Order, type: :model do
order.approve!
expect(order.reload.considered_risky).to be false
end
-
- context 'events', :events do
- it 'publishes order.approved event' do
- allow(Spree::Events).to receive(:publish)
- order.approve!
- expect(Spree::Events).to have_received(:publish).with('order.approved', any_args)
- end
- end
end
describe '#ensure_updated_fulfillments' do
@@ -994,16 +832,6 @@ describe Spree::Order, type: :model do
end
end
- describe '#completed?' do
- it 'indicates if order is completed' do
- order.completed_at = nil
- expect(order.completed?).to be false
-
- order.completed_at = Time.current
- expect(order.completed?).to be true
- end
- end
-
describe '#allow_checkout?' do
it 'is true if there are line_items in the order' do
allow(order).to receive_message_chain(:line_items, :exists?).and_return(true)
@@ -1032,46 +860,6 @@ describe Spree::Order, type: :model do
end
end
- describe '#tax_total' do
- it 'adds included tax and additional tax' do
- allow(order).to receive_messages(additional_tax_total: 10, included_tax_total: 20)
-
- expect(order.tax_total).to eq 30
- end
- end
-
- # Regression test for #4923
- context 'locking' do
- let(:order) { create(:order) } # need a persisted in order to test locking
-
- it 'can lock' do
- expect { order.with_lock {} }.not_to raise_error
- end
- end
-
- describe '#pre_tax_item_amount' do
- let(:order) { create(:order) }
-
- before do
- line_item = create(:line_item, order: order, price: 10, quantity: 2)
- line_item_2 = create(:line_item, order: order, price: 30, quantity: 1)
-
- line_item.update(pre_tax_amount: 5.0)
- line_item_2.update(pre_tax_amount: 14.0)
- end
-
- it "sums all of the line items' pre tax amounts" do
- expect(order.pre_tax_item_amount).to eq BigDecimal(19)
- end
- end
-
- describe '#display_pre_tax_item_amount' do
- it 'returns the value as a spree money' do
- allow(order).to receive(:pre_tax_item_amount).and_return(10.55)
- expect(order.display_pre_tax_item_amount).to eq(Spree::Money.new(10.55))
- end
- end
-
describe '#pre_tax_total' do
let(:order) { create(:order) }
@@ -1088,13 +876,6 @@ describe Spree::Order, type: :model do
end
end
- describe '#display_pre_tax_total' do
- it 'returns the value as a spree money' do
- allow(order).to receive(:pre_tax_total).and_return(10.55)
- expect(order.display_pre_tax_total).to eq(Spree::Money.new(10.55))
- end
- end
-
describe '#analytics_subtotal' do
let(:order) { create(:order_with_line_items, line_items_count: 2) }
@@ -1109,15 +890,6 @@ describe Spree::Order, type: :model do
end
end
- describe '#quantity' do
- # Uses a persisted record, as the quantity is retrieved via a DB count
- let(:order) { create :order_with_line_items, line_items_count: 3 }
-
- it 'sums the quantity of all line items' do
- expect(order.quantity).to eq 3
- end
- end
-
describe '#rebuild_fulfillments!' do
context 'has unassociated inventory units' do
let!(:inventory_unit) { create(:fulfillment_item, order: subject) }
@@ -1522,9 +1294,12 @@ describe Spree::Order, type: :model do
let!(:order) { create(:order_with_line_items, line_items_count: 10) }
+ before { allow(Spree::Deprecation).to receive(:warn) }
+
context 'without promotions' do
it 'returns 0' do
expect(subject).to eq(BigDecimal('0.00'))
+ expect(Spree::Deprecation).to have_received(:warn).with(/cart_promo_total is deprecated/)
end
end
@@ -1658,201 +1433,17 @@ describe Spree::Order, type: :model do
let(:ship_address) { create(:address, customer: user) }
let(:address) { create(:address, customer: user) }
- context 'when assigned address exist' do
- context 'when assigned address belongs to user' do
- it 'assigns address to order as bill address' do
- expect(order.bill_address_id).not_to eq address.id
- subject
- expect(order.bill_address_id).to eq address.id
- end
-
- it 'does not set address as user default bill address' do
- subject
- expect(user.bill_address_id).not_to eq address.id
- end
- end
- end
-
- context 'when assigned address does not belong to user' do
- let(:address) { create(:address, customer: create(:user)) }
-
- it 'sets order bill address to nil' do
- expect { subject }.to change { order.bill_address_id }.to(nil)
- end
- end
-
- context 'with guest user' do
- let(:user) { nil }
- let(:address) { create(:address, customer: nil) }
-
- context 'when assigning the same existing address' do
- let(:address) { bill_address }
-
- it 'does nothing' do
- expect { subject }.not_to(change { order.bill_address_id })
- end
- end
-
- context 'when assigning a different existing address' do
- it 'sets order bill address to nil' do
- expect { subject }.to change { order.bill_address_id }.to(nil)
- end
- end
- end
- end
-
- describe '#bill_address_attributes=' do
- subject { order.bill_address_attributes = address_attributes }
-
- let(:order) { create(:order, customer: user) }
- let(:address_attributes) { attributes_for(:address) }
-
- context 'when user has default bill address' do
- let!(:user) { create(:user_with_addresses) }
-
- it 'changes user default bill address' do
- expect(user.bill_address_id).not_to be_nil
-
- expect { subject }.to(change { user.bill_address_id })
- end
- end
-
- context 'when user has no default address' do
- let!(:user) { create(:user) }
-
- it 'assigns a new default address' do
- subject
-
- expect(user.bill_address).to be_present
- expect(user.bill_address.address1).to eq(address_attributes[:address1])
- end
- end
-
- context 'when user does not have any addresses' do
- let!(:user) { create(:user) }
-
- it 'changes user default bill addresss' do
- expect(user.bill_address_id).to be_nil
- expect(user.addresses).to be_empty
-
- expect { subject }.to change { user.bill_address_id }
- end
- end
-
- context 'when user has address but without default bill address' do
- let(:address) { create(:address, customer: user) }
- let(:user) { create(:user_with_addresses) }
-
- before { user.bill_address = nil }
-
- it 'changes user default bill addresss' do
- expect(user.bill_address_id).to be_nil
- expect(user.addresses).not_to be_empty
-
- expect { subject }.to change { user.bill_address_id }
- end
- end
- end
-
- describe 'ship_address_id=' do
- subject { order.ship_address_id = address.id }
-
- let(:user) { create(:user) }
- let(:order) { create(:order, customer: user, bill_address: bill_address, ship_address: ship_address) }
- let(:bill_address) { create(:address, customer: user) }
- let(:ship_address) { create(:address, customer: user) }
- let(:address) { create(:address, customer: user) }
-
- context 'when assigned address exist' do
- context 'when assigned address belongs to user' do
- it 'assigns address to order as ship address' do
- expect(order.ship_address_id).not_to eq address.id
- subject
- expect(order.ship_address_id).to eq address.id
- end
-
- it 'does not set address as user default ship address' do
- subject
- expect(user.ship_address_id).not_to eq address.id
- end
- end
- end
-
- context 'when assigned address does not belong to user' do
- let(:address) { create(:address, customer: create(:user)) }
-
- it 'sets order ship address to nil' do
- expect { subject }.to change { order.ship_address_id }.to(nil)
- end
+ it 'does not set address as user default bill address' do
+ subject
+ expect(user.bill_address_id).not_to eq address.id
end
- context 'with guest user' do
+ context 'with guest user assigning the same existing address' do
let(:user) { nil }
- let(:address) { create(:address, customer: nil) }
-
- context 'when assigning the same existing address' do
- let(:address) { ship_address }
-
- it 'does nothing' do
- expect { subject }.not_to(change { order.ship_address_id })
- end
- end
-
- context 'when assigning a different existing address' do
- it 'sets order ship address to nil' do
- expect { subject }.to change { order.ship_address_id }.to(nil)
- end
- end
- end
- end
-
- describe '#ship_address_attributes=' do
- subject { order.ship_address_attributes = address_attributes }
-
- let(:order) { create(:order, customer: user) }
- let(:address_attributes) { attributes_for(:address) }
+ let(:address) { bill_address }
- context 'when user has default ship address' do
- let!(:user) { create(:user_with_addresses) }
-
- it 'changes user default ship addresss' do
- expect { subject }.to(change { user.ship_address_id })
- end
- end
-
- context 'when user has no default address' do
- let!(:user) { create(:user) }
-
- it 'assigns a new default address' do
- subject
-
- expect(user.ship_address).to be_present
- expect(user.ship_address.address1).to eq(address_attributes[:address1])
- end
- end
-
- context 'when user does not have any addresses' do
- let!(:user) { create(:user) }
-
- it 'changes user default ship address' do
- expect(user.ship_address_id).to be_nil
- expect(user.addresses).to be_empty
-
- expect { subject }.to change { user.ship_address_id }
- end
- end
-
- context 'when user has address but without default ship address' do
- let(:address) { create(:address, customer: user) }
- let(:user) { create(:user_with_addresses) }
-
- before { user.update(ship_address: nil) }
-
- it 'changes user default ship address' do
- expect(user.ship_address_id).to be_nil
- expect(user.addresses).not_to be_empty
-
- expect { subject }.to change { user.ship_address_id }
+ it 'does nothing' do
+ expect { subject }.not_to(change { order.bill_address_id })
end
end
end
@@ -1961,8 +1552,8 @@ describe Spree::Order, type: :model do
end
end
- describe '#fully_shipped?' do
- subject { order.fully_shipped? }
+ describe '#fully_fulfilled?' do
+ subject { order.fully_fulfilled? }
let!(:shipments) do
create_list(
@@ -1985,6 +1576,11 @@ describe Spree::Order, type: :model do
context 'when not all order shipments were shipped' do
it { expect(subject).to eq(false) }
end
+
+ it 'is still answered by the deprecated fully_shipped?' do
+ expect(Spree::Deprecation).to receive(:warn).with(/fully_shipped\? is deprecated/)
+ expect(order.fully_shipped?).to eq(false)
+ end
end
describe '#total_weight' do
@@ -2198,8 +1794,8 @@ describe Spree::Order, type: :model do
end
end
- describe '#line_items_without_shipping_rates' do
- subject { order.line_items_without_shipping_rates }
+ describe '#line_items_without_delivery_rates' do
+ subject { order.line_items_without_delivery_rates }
let(:order) { create(:order_with_line_items) }
let(:shipment) { order.fulfillments.first }
@@ -2219,6 +1815,11 @@ describe Spree::Order, type: :model do
it 'returns the line items without shipping rates' do
expect(subject).to eq([line_item])
end
+
+ it 'is still answered by the deprecated line_items_without_shipping_rates' do
+ expect(Spree::Deprecation).to receive(:warn).with(/line_items_without_shipping_rates is deprecated/)
+ expect(order.line_items_without_shipping_rates).to eq([line_item])
+ end
end
context 'when order has shipments with shipping rates' do
@@ -2293,18 +1894,12 @@ describe Spree::Order, type: :model do
end
context 'when order has line items' do
- let(:order) { create(:order_with_line_items) }
+ let(:order) { create(:order_with_line_items, line_items_count: 2) }
- let(:presenter) { Spree::CSV::OrderLineItemPresenter }
- let(:presenter_instance) { instance_double(presenter) }
-
- before do
- allow(presenter).to receive(:new).and_return(presenter_instance)
- allow(presenter_instance).to receive(:call).and_return('csv_line')
- end
-
- it 'returns the csv lines' do
- expect(subject).to eq(['csv_line'])
+ it 'returns a csv line per line item' do
+ expect(subject.size).to eq(2)
+ expect(subject).to all(include(order.number))
+ expect(subject.flatten).to include(*order.line_items.map(&:sku))
end
end
end
@@ -2417,9 +2012,12 @@ describe Spree::Order, type: :model do
describe '#remove_out_of_stock_items!' do
let(:order) { create(:order_with_totals, store: store, customer: user) }
+ before { allow(Spree::Deprecation).to receive(:warn) }
+
context 'when all items are in stock' do
it 'does not remove any items' do
expect { order.remove_out_of_stock_items! }.not_to change { order.line_items.count }
+ expect(Spree::Deprecation).to have_received(:warn).with(/remove_out_of_stock_items! is deprecated/)
end
it 'sets warnings to empty array' do
diff --git a/spree/core/spec/models/spree/order_updater_spec.rb b/spree/core/spec/models/spree/order_updater_spec.rb
index f5d194e641..c681e96fab 100644
--- a/spree/core/spec/models/spree/order_updater_spec.rb
+++ b/spree/core/spec/models/spree/order_updater_spec.rb
@@ -5,6 +5,8 @@ module Spree
let(:order) { create(:order) }
let(:updater) { order.updater }
+ before { allow(Spree::Deprecation).to receive(:warn) }
+
context 'order totals' do
before do
create_list(:line_item, 2, order: order, price: 10)
@@ -27,7 +29,7 @@ module Spree
create(:fulfillment, order: order, cost: 10)
order.reload
updater.update_shipment_total
- expect(order.shipment_total).to eq(10)
+ expect(order.delivery_total).to eq(10)
end
context 'with order promotion followed by line item addition' do
@@ -49,7 +51,7 @@ module Spree
end
it 'updates promotion total' do
- expect(order.promo_total).to eq(-3)
+ expect(order.discount_total).to eq(-3)
end
end
@@ -67,7 +69,7 @@ module Spree
expect(order.adjustment_total).to eq(2.55)
expect(order.additional_tax_total).to eq(0.05)
expect(order.fee_total).to eq(5)
- expect(order.promo_total).to eq(0)
+ expect(order.discount_total).to eq(0)
end
end
@@ -78,7 +80,7 @@ module Spree
order.recalculate_totals!
- expect(order.item_count).to eq(2)
+ expect(order.total_quantity).to eq(2)
end
end
@@ -296,10 +298,6 @@ module Spree
it 'updates each shipment' do
allow(order).to receive_messages fulfillments: shipments
- allow(shipments).to receive_messages states: []
- allow(shipments).to receive_messages ready: []
- allow(shipments).to receive_messages pending: []
- allow(shipments).to receive_messages shipped: []
expect(shipment).to receive(:update!).with(order)
updater.update_shipments
@@ -331,28 +329,8 @@ module Spree
end
context 'incomplete order' do
- let(:shipment) { create(:fulfillment) }
- let(:shipments) { [shipment] }
-
- it 'doesnt update payment state' do
- expect(updater).not_to receive(:update_payment_state)
- updater.update
- end
-
- it 'doesnt update shipment state' do
- expect(updater).not_to receive(:update_shipment_state)
- updater.update
- end
-
- it 'doesnt update each shipment' do
- allow(order).to receive_messages shipments: shipments
- allow(shipments).to receive_messages states: []
- allow(shipments).to receive_messages ready: []
- allow(shipments).to receive_messages pending: []
- allow(shipments).to receive_messages shipped: []
-
- allow(updater).to receive(:update_totals) # Otherwise this gets called and causes a scene
- expect(updater).not_to receive(:update_shipments).with(order)
+ it 'doesnt update statuses' do
+ expect(updater).not_to receive(:update_statuses)
updater.update
end
diff --git a/spree/core/spec/models/spree/package_type_spec.rb b/spree/core/spec/models/spree/package_type_spec.rb
index b5eee69e94..3bf7d96e5b 100644
--- a/spree/core/spec/models/spree/package_type_spec.rb
+++ b/spree/core/spec/models/spree/package_type_spec.rb
@@ -198,13 +198,6 @@ RSpec.describe Spree::PackageType, type: :model do
expect(store.reload.default_package_type).to eq(package_type)
end
- it 'allows it once another row holds the flag' do
- first = create(:package_type, store: store, default: true)
- create(:package_type, store: store, default: true)
-
- expect(first.reload).not_to be_default
- end
-
# The marketplace's box is not a replacement for the seller's: it is a
# different owner's row, so it cannot stand in as "another default".
it 'refuses a seller’s only default even when the marketplace has one' do
diff --git a/spree/core/spec/models/spree/payment/custom_events_spec.rb b/spree/core/spec/models/spree/payment/custom_events_spec.rb
index 42523a1216..bc6fcbc1fc 100644
--- a/spree/core/spec/models/spree/payment/custom_events_spec.rb
+++ b/spree/core/spec/models/spree/payment/custom_events_spec.rb
@@ -12,16 +12,8 @@ RSpec.describe Spree::Payment::CustomEvents do
end
describe 'payment.paid event' do
- it 'publishes payment.paid when payment state changes to completed' do
- payment.update!(amount: order.total - 1)
-
- payment.update!(state: 'completed')
-
- expect(Spree::Events).to have_received(:publish).with('payment.paid', anything, anything)
- end
-
it 'does not publish payment.paid when state changes to something other than completed' do
- payment.update!(state: 'processing')
+ payment.update!(status: 'processing')
expect(Spree::Events).not_to have_received(:publish).with('payment.paid', anything, anything)
end
@@ -29,7 +21,7 @@ RSpec.describe Spree::Payment::CustomEvents do
it 'does not publish when events are disabled' do
allow(Spree::Events).to receive(:enabled?).and_return(false)
- payment.update!(state: 'completed')
+ payment.update!(status: 'completed')
expect(Spree::Events).not_to have_received(:publish).with('payment.paid', anything, anything)
end
@@ -39,7 +31,7 @@ RSpec.describe Spree::Payment::CustomEvents do
it 'publishes order.paid when payment completes and order is fully paid' do
payment.update!(amount: order.total)
- payment.update!(state: 'completed')
+ payment.update!(status: 'completed')
expect(Spree::Events).to have_received(:publish).with('payment.paid', anything, anything)
expect(Spree::Events).to have_received(:publish).with('order.paid', anything, anything)
@@ -48,7 +40,7 @@ RSpec.describe Spree::Payment::CustomEvents do
it 'does not publish order.paid when order still has outstanding balance' do
payment.update!(amount: order.total - 1)
- payment.update!(state: 'completed')
+ payment.update!(status: 'completed')
expect(Spree::Events).to have_received(:publish).with('payment.paid', anything, anything)
expect(Spree::Events).not_to have_received(:publish).with('order.paid', anything, anything)
diff --git a/spree/core/spec/models/spree/payment/gateway_options_spec.rb b/spree/core/spec/models/spree/payment/gateway_options_spec.rb
index 6ae66107e4..24c63c9ae9 100644
--- a/spree/core/spec/models/spree/payment/gateway_options_spec.rb
+++ b/spree/core/spec/models/spree/payment/gateway_options_spec.rb
@@ -45,115 +45,6 @@ RSpec.describe Spree::Payment::GatewayOptions, type: :model do
double Spree::Address, gateway_hash: { ship: :address }
end
- describe '#order' do
- subject { options.order }
-
- it { is_expected.to eq order }
- end
-
- describe '#payment' do
- subject { options.payment }
-
- it { is_expected.to eq payment }
- end
-
- describe '#payment_id' do
- subject { options.payment_id }
-
- it { is_expected.to eq 'P1566' }
- end
-
- describe '#payment_prefixed_id' do
- subject { options.payment_prefixed_id }
-
- # The stable lookup handle: the derived number cannot be queried (NULL
- # column on 6.0 rows) and shifts when a sibling is destroyed.
- it { is_expected.to eq 'py_k5nR8xLq' }
- end
-
- describe '#email' do
- subject { options.email }
-
- it { is_expected.to eq '[email protected]' }
- end
-
- describe '#customer' do
- subject { options.customer }
-
- it { is_expected.to eq '[email protected]' }
- end
-
- describe '#customer_id' do
- subject { options.customer_id }
-
- it { is_expected.to eq 144 }
- end
-
- describe '#ip' do
- subject { options.ip }
-
- it { is_expected.to eq '0.0.0.0' }
- end
-
- describe '#order_id' do
- subject { options.order_id }
-
- # The payment number already names its order, so this is no longer the
- # order number and the payment number concatenated.
- it { is_expected.to eq 'P1566' }
- end
-
- describe '#idempotency_key' do
- subject { options.idempotency_key }
-
- # The prefixed ID, not the number — a derived number can shift if an
- # earlier sibling payment is destroyed, and a shifted key could collide
- # with one already used at the gateway.
- it { is_expected.to eq 'spree-py_k5nR8xLq' }
- end
-
- describe '#shipping' do
- subject { options.shipping }
-
- it { is_expected.to eq 1244 }
- end
-
- describe '#tax' do
- subject { options.tax }
-
- it { is_expected.to eq 153 }
- end
-
- describe '#subtotal' do
- subject { options.subtotal }
-
- it { is_expected.to eq 1511 }
- end
-
- describe '#discount' do
- subject { options.discount }
-
- it { is_expected.to eq 257 }
- end
-
- describe '#currency' do
- subject { options.currency }
-
- it { is_expected.to eq 'EUR' }
- end
-
- describe '#billing_address' do
- subject { options.billing_address }
-
- it { is_expected.to eq(bill: :address) }
- end
-
- describe '#shipping_address' do
- subject { options.shipping_address }
-
- it { is_expected.to eq(ship: :address) }
- end
-
describe '#to_hash' do
subject { options.to_hash }
@@ -163,9 +54,16 @@ RSpec.describe Spree::Payment::GatewayOptions, type: :model do
customer: '[email protected]',
customer_id: 144,
ip: '0.0.0.0',
+ # The payment number already names its order, so this is no longer the
+ # order number and the payment number concatenated.
order_id: 'P1566',
payment_id: 'P1566',
+ # The stable lookup handle: the derived number cannot be queried (NULL
+ # column on 6.0 rows) and shifts when a sibling is destroyed.
payment_prefixed_id: 'py_k5nR8xLq',
+ # The prefixed ID, not the number — a derived number can shift if an
+ # earlier sibling payment is destroyed, and a shifted key could collide
+ # with one already used at the gateway.
idempotency_key: 'spree-py_k5nR8xLq',
shipping: '1244'.to_d,
tax: '153'.to_d,
diff --git a/spree/core/spec/models/spree/payment/store_credit_spec.rb b/spree/core/spec/models/spree/payment/store_credit_spec.rb
index ca318c21bb..8df08b372f 100644
--- a/spree/core/spec/models/spree/payment/store_credit_spec.rb
+++ b/spree/core/spec/models/spree/payment/store_credit_spec.rb
@@ -47,7 +47,7 @@ describe 'Payment' do
context 'cancels successfully' do
it 'voids the payment', retry: 3 do
- expect { subject }.to change(payment, :state).to('void')
+ expect { subject }.to change(payment, :status).to('void')
end
end
@@ -55,7 +55,7 @@ describe 'Payment' do
it 'does not change the payment state' do
expect(payment.payment_method).to receive(:cancel).with(payment.response_code, payment, refund: true) { failed_response }
expect { subject }.to raise_error(Spree::Core::GatewayError)
- expect(payment.reload.state).not_to eq 'void'
+ expect(payment.reload.status).not_to eq 'void'
end
end
end
diff --git a/spree/core/spec/models/spree/payment_method/store_credit_spec.rb b/spree/core/spec/models/spree/payment_method/store_credit_spec.rb
index bc20cc29eb..405ca80b23 100644
--- a/spree/core/spec/models/spree/payment_method/store_credit_spec.rb
+++ b/spree/core/spec/models/spree/payment_method/store_credit_spec.rb
@@ -224,7 +224,7 @@ describe Spree::PaymentMethod::StoreCredit do
end
context "when the store credit isn't credited successfully" do
- before { allow(Spree::StoreCredit).to receive_messages(credit: false) }
+ before { allow_any_instance_of(Spree::StoreCredit).to receive_messages(credit: false) }
it 'returns an error response' do
expect(subject.success?).to be false
@@ -245,8 +245,8 @@ describe Spree::PaymentMethod::StoreCredit do
let(:originator) { double('originator') }
it 'passes the originator' do
- allow_any_instance_of(Spree::StoreCredit).to receive(:credit).
- with(anything, anything, anything, action_originator: originator)
+ expect_any_instance_of(Spree::StoreCredit).to receive(:credit).
+ with(anything, anything, anything, action_originator: originator).and_return(true)
subject
end
end
@@ -271,8 +271,8 @@ describe Spree::PaymentMethod::StoreCredit do
context 'store credit event found' do
it 'creates a store credit for the same amount that was captured' do
- allow_any_instance_of(Spree::StoreCredit).to receive(:credit).
- with(captured_amount, auth_code, store_credit.currency)
+ expect_any_instance_of(Spree::StoreCredit).to receive(:credit).
+ with(captured_amount, auth_code, store_credit.currency).and_return(true)
subject
end
diff --git a/spree/core/spec/models/spree/payment_method_spec.rb b/spree/core/spec/models/spree/payment_method_spec.rb
index 90815606ac..4b0eb1e7fd 100644
--- a/spree/core/spec/models/spree/payment_method_spec.rb
+++ b/spree/core/spec/models/spree/payment_method_spec.rb
@@ -46,10 +46,6 @@ describe Spree::PaymentMethod, type: :model do
)
end
- it 'defaults to visible on the storefront' do
- expect(visible_method.storefront_visible).to be true
- end
-
describe '.storefront_visible' do
it 'returns only customer-facing methods' do
expect(Spree::PaymentMethod.storefront_visible).to contain_exactly(visible_method)
@@ -93,8 +89,11 @@ describe Spree::PaymentMethod, type: :model do
let(:visible_method) { build(:check_payment_method) }
let(:admin_only_method) { build(:check_payment_method, storefront_visible: false) }
+ before { allow(Spree::Deprecation).to receive(:warn) }
+
it 'reads the boolean back as the old tri-state value' do
expect(visible_method.display_on).to eq('both')
+ expect(Spree::Deprecation).to have_received(:warn).with(/display_on is deprecated/)
expect(admin_only_method.display_on).to eq('back_end')
end
@@ -245,18 +244,6 @@ describe Spree::PaymentMethod, type: :model do
expect(Spree::PaymentMethod.where(capture_method: 'on_dispatch')).to be_present
end
-
- # The migration leaves auto_capture-false rows empty on purpose so they
- # keep inheriting. Reading them as manual here would take them out of
- # dispatch capture while the goods still went out.
- context 'when a legacy row was left for the store to decide' do
- it 'inherits the store setting rather than charging manually' do
- gateway.auto_capture = false
-
- expect(gateway.resolved_capture_method).to eq('on_dispatch')
- expect(gateway).to be_capture_on_dispatch
- end
- end
end
describe '#available_for_order?' do
@@ -302,28 +289,6 @@ describe Spree::PaymentMethod, type: :model do
end
end
- describe '#source_required?' do
- let(:payment_method) { create(:credit_card_payment_method) }
-
- it { expect(payment_method.source_required?).to be true }
- end
-
- describe '#session_required?' do
- it 'returns false by default' do
- expect(build(:payment_method).session_required?).to be false
- end
- end
-
- describe '#payment_source_class' do
- let(:payment_method) { build(:credit_card_payment_method) }
-
- it { expect(payment_method.payment_source_class).to eq(Spree::CreditCard) }
- end
-
- describe '#payment_icon_name' do
- it { expect(build(:credit_card_payment_method, type: 'Spree::Gateway::AuthorizeNetGateway').payment_icon_name).to eq('authorizenet') }
- end
-
context 'when payment method is destroyed' do
let(:payment_method) { create(:credit_card_payment_method) }
let!(:payment) { create(:payment, payment_method: payment_method, source: credit_card) }
@@ -383,7 +348,7 @@ describe Spree::PaymentMethod, type: :model do
Class.new(Spree::Gateway) do
def self.name = 'TestConstrainedGateway'
- preference :mode, :string, default: 'live', in: %w[test live]
+ preference :mode, :string, default: 'live', choices: %w[test live]
preference :label, :string
preference :threshold, :decimal, default: 0
end
@@ -455,13 +420,6 @@ describe Spree::PaymentMethod, type: :model do
expect(keys).not_to include(:issued_secret)
end
- it 'still stores and reads one, since the system depends on the value' do
- gateway = gateway_class.new
- gateway.preferred_issued_secret = 'whsec_abc'
-
- expect(gateway.preferred_issued_secret).to eq('whsec_abc')
- end
-
it 'reports which preferences are internal' do
gateway = gateway_class.new
diff --git a/spree/core/spec/models/spree/payment_response_spec.rb b/spree/core/spec/models/spree/payment_response_spec.rb
index eb5c0186bd..2169b9f97f 100644
--- a/spree/core/spec/models/spree/payment_response_spec.rb
+++ b/spree/core/spec/models/spree/payment_response_spec.rb
@@ -52,26 +52,6 @@ RSpec.describe Spree::PaymentResponse do
end
end
- describe '#success?' do
- it 'returns true for a successful response' do
- expect(described_class.new(true, 'ok')).to be_success
- end
-
- it 'returns false for a failed response' do
- expect(described_class.new(false, 'fail')).not_to be_success
- end
- end
-
- describe '#test?' do
- it 'returns true when test option is set' do
- expect(described_class.new(true, '', {}, test: true)).to be_test
- end
-
- it 'returns false by default' do
- expect(described_class.new(true, '')).not_to be_test
- end
- end
-
describe 'YAML serialization' do
it 'round-trips through YAML.safe_load' do
original = described_class.new(true, 'Captured', { 'ref' => '42' },
diff --git a/spree/core/spec/models/spree/payment_session_spec.rb b/spree/core/spec/models/spree/payment_session_spec.rb
index a203fcd3f3..6466c6cfc8 100644
--- a/spree/core/spec/models/spree/payment_session_spec.rb
+++ b/spree/core/spec/models/spree/payment_session_spec.rb
@@ -8,43 +8,6 @@ RSpec.describe Spree::PaymentSession, type: :model do
let(:payment_method) { create(:bogus_payment_method) }
let(:payment_session) { create(:bogus_payment_session, order: order, payment_method: payment_method, amount: 50) }
- describe 'validations' do
- it { expect(payment_session).to be_valid }
-
- it 'requires order' do
- payment_session.order = nil
- expect(payment_session).not_to be_valid
- end
-
- it 'requires payment_method' do
- payment_session.payment_method = nil
- expect(payment_session).not_to be_valid
- end
-
- it 'requires external_id' do
- payment_session.external_id = nil
- expect(payment_session).not_to be_valid
- end
-
- it 'requires currency' do
- payment_session.currency = nil
- expect(payment_session).not_to be_valid
- end
-
- it 'requires amount greater than 0' do
- payment_session.amount = 0
- expect(payment_session).not_to be_valid
- end
-
- it 'enforces external_id uniqueness per order and payment method' do
- duplicate = build(:bogus_payment_session,
- order: payment_session.order,
- payment_method: payment_session.payment_method,
- external_id: payment_session.external_id)
- expect(duplicate).not_to be_valid
- end
- end
-
describe 'defaults from order' do
it 'sets currency from order' do
session = build(:bogus_payment_session, order: order, payment_method: payment_method,
@@ -232,20 +195,6 @@ RSpec.describe Spree::PaymentSession, type: :model do
end
end
- describe '#prefixed_id' do
- it 'starts with ps_' do
- expect(payment_session.prefixed_id).to start_with('ps_')
- end
- end
-
- describe 'soft delete' do
- it 'soft deletes with acts_as_paranoid' do
- payment_session.destroy
- expect(described_class.with_deleted.find(payment_session.id)).to be_present
- expect(described_class.find_by(id: payment_session.id)).to be_nil
- end
- end
-
describe 'events' do
before do
allow(Spree::Events).to receive(:enabled?).and_return(true)
@@ -334,18 +283,20 @@ RSpec.describe Spree::PaymentSession, type: :model do
expect(payment_session.find_or_create_payment!.id).to eq(payment_session.payment.id)
end
- it 'handles RecordNotUnique by returning the existing payment' do
- existing = create(:payment,
- order: order,
- payment_method: payment_method,
- response_code: payment_session.external_id,
- amount: payment_session.amount)
-
- # Simulate a race condition where find_or_create_by! raises RecordNotUnique
- allow(order.payments).to receive(:find_or_create_by!).and_raise(ActiveRecord::RecordNotUnique)
+ it 'handles RecordNotUnique by returning the payment a concurrent request created' do
+ existing = nil
+ allow(payment_session.owner.payments).to receive(:find_or_create_by!) do
+ existing = create(:payment,
+ order: order,
+ payment_method: payment_method,
+ response_code: payment_session.external_id,
+ amount: payment_session.amount)
+ raise ActiveRecord::RecordNotUnique
+ end
payment = payment_session.find_or_create_payment!
+ expect(payment_session.owner.payments).to have_received(:find_or_create_by!)
expect(payment.id).to eq(existing.id)
end
end
diff --git a/spree/core/spec/models/spree/payment_setup_session_spec.rb b/spree/core/spec/models/spree/payment_setup_session_spec.rb
index dd84927da9..f18fe1cd65 100644
--- a/spree/core/spec/models/spree/payment_setup_session_spec.rb
+++ b/spree/core/spec/models/spree/payment_setup_session_spec.rb
@@ -9,13 +9,6 @@ RSpec.describe Spree::PaymentSetupSession, type: :model do
let(:payment_setup_session) { create(:payment_setup_session, customer: user, payment_method: payment_method) }
describe 'validations' do
- it { expect(payment_setup_session).to be_valid }
-
- it 'requires payment_method' do
- payment_setup_session.payment_method = nil
- expect(payment_setup_session).not_to be_valid
- end
-
it 'enforces unique external_id per payment_method' do
payment_setup_session.update!(external_id: 'seti_123')
duplicate = build(:payment_setup_session, payment_method: payment_method, external_id: 'seti_123')
@@ -37,23 +30,6 @@ RSpec.describe Spree::PaymentSetupSession, type: :model do
end
end
- describe 'associations' do
- it 'belongs to customer' do
- expect(payment_setup_session.customer).to eq(user)
- end
-
- it 'belongs to payment_method' do
- expect(payment_setup_session.payment_method).to eq(payment_method)
- end
-
- it 'can have a payment_source (CreditCard)' do
- credit_card = create(:credit_card, customer: user)
- payment_setup_session.update!(payment_source: credit_card)
- expect(payment_setup_session.payment_source).to eq(credit_card)
- expect(payment_setup_session.payment_source_type).to eq('Spree::CreditCard')
- end
- end
-
describe 'state machine' do
describe '#process' do
it 'transitions from pending to processing' do
@@ -138,38 +114,12 @@ RSpec.describe Spree::PaymentSetupSession, type: :model do
end
end
- describe '#prefixed_id' do
- it 'starts with pss_' do
- expect(payment_setup_session.prefixed_id).to start_with('pss_')
- end
- end
-
- describe 'soft delete' do
- it 'soft deletes with acts_as_paranoid' do
- payment_setup_session.destroy
- expect(described_class.with_deleted.find(payment_setup_session.id)).to be_present
- expect(described_class.find_by(id: payment_setup_session.id)).to be_nil
- end
- end
-
describe 'events' do
before do
allow(Spree::Events).to receive(:enabled?).and_return(true)
allow(Spree::Events).to receive(:publish)
end
- describe 'lifecycle events' do
- it 'publishes payment_setup_session.created on create' do
- create(:payment_setup_session, customer: user, payment_method: payment_method)
- expect(Spree::Events).to have_received(:publish).with('payment_setup_session.created', anything, anything)
- end
-
- it 'publishes payment_setup_session.updated on update' do
- payment_setup_session.update!(external_id: 'new_id')
- expect(Spree::Events).to have_received(:publish).with('payment_setup_session.updated', anything, anything)
- end
- end
-
describe 'state transition events' do
it 'publishes payment_setup_session.processing on process' do
payment_setup_session.process
diff --git a/spree/core/spec/models/spree/payment_spec.rb b/spree/core/spec/models/spree/payment_spec.rb
index d55a474c8e..4262d27a76 100644
--- a/spree/core/spec/models/spree/payment_spec.rb
+++ b/spree/core/spec/models/spree/payment_spec.rb
@@ -45,10 +45,6 @@ describe Spree::Payment, type: :model do
it_behaves_like 'metadata'
- describe 'Constants' do
- it { expect(Spree::Payment::INVALID_STATES).to eq(%w(failed invalid void)) }
- end
-
describe 'Scopes' do
describe '.valid' do
subject { Spree::Payment.valid }
@@ -278,28 +274,14 @@ describe Spree::Payment, type: :model do
end
context 'processing' do
+ before { allow(Spree::Deprecation).to receive(:warn) }
+
describe '#process!' do
it 'purchases when the method charges at checkout' do
payment.payment_method.capture_method = 'checkout'
payment.process!
expect(payment).to be_completed
- end
-
- it 'authorizes when the method charges later' do
- payment.payment_method.capture_method = 'on_dispatch'
- payment.process!
- expect(payment).to be_pending
- end
-
- it "makes the state 'processing'" do
- expect(payment).to receive(:started_processing!)
- payment.process!
- end
-
- it 'invalidates if payment method doesnt support source' do
- expect(payment.payment_method).to receive(:supports?).with(payment.source).and_return(false)
- expect { payment.process! }.to raise_error(Spree::Core::GatewayError)
- expect(payment.status).to eq('invalid')
+ expect(Spree::Deprecation).to have_received(:warn).with(/Payment#process! is deprecated/)
end
# Regression test for #4598
@@ -325,6 +307,7 @@ describe Spree::Payment, type: :model do
card,
anything).and_return(success_response)
payment.authorize!
+ expect(Spree::Deprecation).to have_received(:warn).with(/Payment#authorize! is deprecated/)
end
it 'calls authorize on the gateway with the currency code' do
@@ -349,11 +332,6 @@ describe Spree::Payment, type: :model do
expect(payment.cvv_response_code).to eq(cvv_code)
expect(payment.cvv_response_message).to be_nil
end
-
- it 'makes payment pending' do
- expect(payment).to receive(:pend!)
- payment.authorize!
- end
end
context 'if unsuccessful' do
@@ -375,7 +353,7 @@ describe Spree::Payment, type: :model do
it 'raises Spree::Core::GatewayError and marks payment as failed' do
expect(payment).to receive(:failure!)
- expect(payment).not_to receive(:pend)
+ expect(payment).not_to receive(:pend!)
expect { payment.authorize! }.to raise_error(Spree::Core::GatewayError)
end
end
@@ -397,7 +375,9 @@ describe Spree::Payment, type: :model do
it 'instruments the purchase gateway call as gateway.spree_payments' do
allow(gateway).to receive(:purchase).and_return(success_response)
- notifications = capture_gateway_notifications { payment.purchase! }
+ notifications = capture_gateway_notifications do
+ Spree.payment_process_workflow.call(payment: payment, action: :purchase)
+ end
expect(notifications.sole).to include(action: 'purchase', payment_method_type: 'Spree::Gateway::Bogus')
end
@@ -407,7 +387,7 @@ describe Spree::Payment, type: :model do
payment.response_code = "BGS-#{SecureRandom.hex(6)}"
allow(gateway).to receive(:capture).and_return(success_response)
- notifications = capture_gateway_notifications { payment.capture! }
+ notifications = capture_gateway_notifications { Spree.payment_capture_workflow.call(payment: payment) }
expect(notifications.sole).to include(action: 'capture', payment_method_type: 'Spree::Gateway::Bogus')
end
@@ -417,6 +397,7 @@ describe Spree::Payment, type: :model do
it 'calls purchase on the gateway with the payment amount' do
expect(gateway).to receive(:purchase).with(gateway_amount, card, anything).and_return(success_response)
payment.purchase!
+ expect(Spree::Deprecation).to have_received(:warn).with(/Payment#purchase! is deprecated/)
end
context 'if successful' do
@@ -431,22 +412,6 @@ describe Spree::Payment, type: :model do
expect(payment.response_code).to eq('123')
expect(payment.avs_response).to eq(avs_code)
end
-
- it 'makes payment complete' do
- expect(payment).to receive(:complete!)
- payment.purchase!
- end
-
- it 'logs a capture event' do
- payment.purchase!
- expect(payment.capture_events.count).to eq(1)
- expect(payment.capture_events.first.amount).to eq(payment.amount)
- end
-
- it 'sets the uncaptured amount to 0' do
- payment.purchase!
- expect(payment.uncaptured_amount).to eq(0)
- end
end
context 'if unsuccessful' do
@@ -474,7 +439,7 @@ describe Spree::Payment, type: :model do
it 'raises Spree::Core::GatewayError and marks payment as failed' do
expect(payment).to receive(:failure!)
- expect(payment).not_to receive(:pend)
+ expect(payment).not_to receive(:pend!)
expect { payment.purchase! }.to raise_error(Spree::Core::GatewayError)
end
end
@@ -606,28 +571,12 @@ describe Spree::Payment, type: :model do
end
context 'if successful' do
- context 'for entire amount' do
- before do
- expect(payment.payment_method).to receive(:capture).with(gateway_amount, payment.response_code, anything).and_return(success_response)
- end
-
- it 'makes payment complete' do
- expect(payment).to receive(:complete!)
- payment.capture!
- end
-
- it 'logs capture events' do
- payment.capture!
- expect(payment.capture_events.count).to eq(1)
- expect(payment.capture_events.first.amount).to eq(payment.amount)
- end
- end
-
it 'records the capture under the owner row lock' do
expect(payment.payment_method).to receive(:capture).and_return(success_response)
expect(payment.owner).to receive(:with_lock).and_call_original
payment.capture!
+ expect(Spree::Deprecation).to have_received(:warn).with(/Payment#capture! is deprecated/)
end
it 'records nothing when another caller already completed the payment' do
@@ -661,25 +610,10 @@ describe Spree::Payment, type: :model do
expect(payments.processing.first.amount).to eq(capture_amount)
expect(payments.processing.first.source).to eq(payments.pending.first.source)
end
-
- it 'logs capture events' do
- payment.capture!(capture_amount)
- expect(payment.capture_events.count).to eq(1)
- expect(payment.capture_events.first.amount).to eq(capture_amount)
- end
end
end
context 'if unsuccessful' do
- context 'when response is returned from gateway' do
- it 'does not make payment complete' do
- allow(gateway).to receive_messages capture: failed_response
- expect { payment.capture! }.to raise_error(Spree::Core::GatewayError)
- expect(payment.reload).to be_failed
- expect(payment).not_to be_completed
- end
- end
-
context 'when there is an error connecting to the gateway' do
let(:connection_error_message) { 'gateway_error' }
let(:connection_error) { Spree::PaymentConnectionError.new(connection_error_message) }
@@ -688,24 +622,12 @@ describe Spree::Payment, type: :model do
it 'raises Spree::Core::GatewayError and marks payment as failed' do
expect(payment).to receive(:failure!)
- expect(payment).not_to receive(:pend)
+ expect(payment).not_to receive(:pend!)
expect { payment.capture! }.to raise_error(Spree::Core::GatewayError)
end
end
end
end
-
- # Regression test for #2119
- context 'when payment is completed' do
- before do
- payment.status = 'completed'
- end
-
- it 'does nothing' do
- expect(payment.payment_method).not_to receive(:capture)
- payment.capture!
- end
- end
end
describe '#void_transaction!' do
@@ -714,40 +636,17 @@ describe Spree::Payment, type: :model do
payment.status = 'pending'
end
- context 'when profiles are supported' do
- it "calls payment_gateway.void with the payment's response_code" do
- allow(gateway).to receive_messages payment_profiles_supported?: true
- expect(gateway).to receive(:void).with('123', card, anything).and_return(success_response)
- payment.void_transaction!
- end
- end
-
- context 'when profiles are not supported' do
- it "calls payment_gateway.void with the payment's response_code" do
- allow(gateway).to receive_messages payment_profiles_supported?: false
- expect(gateway).to receive(:void).with('123', anything).and_return(success_response)
- payment.void_transaction!
- end
- end
-
context 'if successful' do
it 'updates the response_code with the authorization from the gateway' do
# Change it to something different
payment.response_code = 'abc'
payment.void_transaction!
expect(payment.response_code).to start_with('void-BGS-')
+ expect(Spree::Deprecation).to have_received(:warn).with(/Payment#void_transaction! is deprecated/)
end
end
context 'if unsuccessful' do
- context 'when response is returned from gateway' do
- it 'does not void the payment' do
- allow(gateway).to receive_messages void: failed_response
- expect { payment.void_transaction! }.to raise_error(Spree::Core::GatewayError)
- expect(payment).not_to be_void
- end
- end
-
context 'when there is an error connecting to the gateway' do
let(:connection_error_message) { 'gateway_error' }
let(:connection_error) { Spree::PaymentConnectionError.new(connection_error_message) }
@@ -756,60 +655,17 @@ describe Spree::Payment, type: :model do
it 'raises Spree::Core::GatewayError and marks payment as failed' do
expect(payment).to receive(:failure!)
- expect(payment).not_to receive(:pend)
+ expect(payment).not_to receive(:pend!)
expect { payment.void_transaction! }.to raise_error(Spree::Core::GatewayError)
end
end
end
-
- # Regression test for #2119
- context 'if payment is already voided' do
- before do
- payment.status = 'void'
- end
-
- it 'does not void the payment' do
- expect(payment.payment_method).not_to receive(:void)
- payment.void_transaction!
- end
- end
-
- context 'if response_code is blank' do
- before do
- payment.response_code = nil
- payment.status = 'pending'
- end
-
- it 'voids the payment without calling the gateway' do
- expect(payment.payment_method).not_to receive(:void)
- payment.void_transaction!
- expect(payment.status).to eq('void')
- end
- end
- end
- end
-
- context 'when already processing' do
- it 'is a no-op success without trying to process the source' do
- payment.status = 'processing'
-
- expect(payment.process!).to be(true)
- end
- end
-
- context 'with source required' do
- context 'raises an error if no source is specified' do
- before do
- payment.source = nil
- end
-
- specify do
- expect { payment.process! }.to raise_error(Spree::Core::GatewayError, I18n.t('spree.payment_processing_failed'))
- end
end
end
context 'with source optional' do
+ before { allow(Spree::Deprecation).to receive(:warn) }
+
context 'when payment method does not require source' do
let(:check_payment_method) { create(:check_payment_method, store: order.store, capture_method: 'manual') }
@@ -845,18 +701,6 @@ describe Spree::Payment, type: :model do
end
end
- describe '#can_credit?' do
- it 'is true if credit_allowed > 0' do
- allow(payment).to receive(:credit_allowed).and_return(100)
- expect(payment.can_credit?).to be true
- end
-
- it 'is false if credit_allowed is 0' do
- allow(payment).to receive(:credit_allowed).and_return(0)
- expect(payment.can_credit?).to be false
- end
- end
-
describe '#save' do
context 'captured payments', events: true do
it 'update order payment total' do
@@ -871,11 +715,6 @@ describe Spree::Payment, type: :model do
Spree::Payment.create(amount: 100, order: order)
end.not_to change(order, :payment_total)
end
-
- it 'requires a payment method' do
- expect(Spree::Payment.create(amount: 100, order: order).errors).not_to be_empty
- expect(Spree::Payment.create(amount: 100, order: order).errors.messages[:payment_method]).to be_present
- end
end
context 'when the payment was completed but now void' do
@@ -1027,20 +866,6 @@ describe Spree::Payment, type: :model do
end
end
- describe '#currency' do
- before { allow(order).to receive(:currency).and_return('ABC') }
-
- it 'returns the order currency' do
- expect(payment.currency).to eq('ABC')
- end
- end
-
- describe '#display_amount' do
- it 'returns a Spree::Money for this amount' do
- expect(payment.display_amount).to eq(Spree::Money.new(payment.amount))
- end
- end
-
# Regression test for #2216
describe '#gateway_options' do
before { allow(order).to receive_messages(last_ip_address: '192.168.1.1') }
@@ -1202,11 +1027,6 @@ describe Spree::Payment, type: :model do
let(:card) { create(:credit_card) }
let(:payment_method) { card.payment_method }
- before do
- allow(payment_method).to receive_messages source_required: true
- end
-
- it { expect(payment_method.source_required?).to eq(true) }
it { expect(payment.source).to eq(card) }
context 'when credit card is removed' do
@@ -1318,20 +1138,25 @@ describe Spree::Payment, type: :model do
end
end
- describe '#has_invalid_state?' do
- let(:payment) { create(:payment, status: state) }
- subject(:has_invalid_state?) { payment.has_invalid_state? }
+ describe '#has_invalid_status?' do
+ let(:payment) { create(:payment, status: status) }
+ subject(:has_invalid_status?) { payment.has_invalid_status? }
- context 'when the state is invalid' do
- let(:state) { Spree::Payment::INVALID_STATES.first }
+ context 'when the status is invalid' do
+ let(:status) { Spree::Payment::INVALID_STATUSES.first }
it { is_expected.to be_truthy }
end
- context 'when the state is valid' do
- let(:state) { 'completed' }
+ context 'when the status is valid' do
+ let(:status) { 'completed' }
it { is_expected.to be_falsey }
+
+ it 'is still answered by the deprecated has_invalid_state? alias' do
+ expect(Spree::Deprecation).to receive(:warn).with(/has_invalid_state\? is deprecated/)
+ expect(payment.has_invalid_state?).to be_falsey
+ end
end
end
diff --git a/spree/core/spec/models/spree/payment_split_spec.rb b/spree/core/spec/models/spree/payment_split_spec.rb
index 299e8ca8c4..c3792b5bd2 100644
--- a/spree/core/spec/models/spree/payment_split_spec.rb
+++ b/spree/core/spec/models/spree/payment_split_spec.rb
@@ -31,15 +31,4 @@ RSpec.describe Spree::PaymentSplit, type: :model do
expect(split.net_captured_amount).to eq(15)
end
end
-
- # Whose sale a share belongs to is asked through its order — the split
- # itself stays neutral, since the same container serves splits that have no
- # seller at all.
- it 'reaches its seller through the order it settles' do
- seller = create(:seller, :approved, store: store)
- seller_order = create(:order, store: store, order_group: group, seller: seller)
- split = create(:payment_split, payment: payment, order: seller_order)
-
- expect(split.order.seller).to eq(seller)
- end
end
diff --git a/spree/core/spec/models/spree/policy_spec.rb b/spree/core/spec/models/spree/policy_spec.rb
index de5469ab89..0ecd34ed20 100644
--- a/spree/core/spec/models/spree/policy_spec.rb
+++ b/spree/core/spec/models/spree/policy_spec.rb
@@ -14,13 +14,6 @@ RSpec.describe Spree::Policy, type: :model do
expect(other_policy.slug).to eq(policy.slug)
end
end
-
- context 'owner presence' do
- it 'is invalid without an owner' do
- policy.owner = nil
- expect(policy).to be_invalid
- end
- end
end
describe 'friendly_id' do
@@ -30,11 +23,12 @@ RSpec.describe Spree::Policy, type: :model do
end
it 'maintains slug history' do
- policy = create(:policy, slug: 'old-slug')
+ policy = create(:policy)
+ old_slug = policy.slug
policy.update(slug: 'new-slug')
expect(policy.to_param).to eq('new-slug')
- expect(policy.friendly_id_config.uses?(:history)).to be true
+ expect(described_class.where(owner: policy.owner).friendly.find(old_slug)).to eq(policy)
end
context 'when the policy is destroyed' do
@@ -50,10 +44,6 @@ RSpec.describe Spree::Policy, type: :model do
end
describe 'Translations' do
- it 'has translatable name field' do
- expect(described_class::TRANSLATABLE_FIELDS).to include(:name)
- end
-
it 'supports translations for name' do
policy = create(:policy, name: 'Privacy Policy')
diff --git a/spree/core/spec/models/spree/preferences/configuration_spec.rb b/spree/core/spec/models/spree/preferences/configuration_spec.rb
deleted file mode 100644
index 10ed8ff9d5..0000000000
--- a/spree/core/spec/models/spree/preferences/configuration_spec.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-require 'spec_helper'
-
-describe Spree::Preferences::Configuration, type: :model do
- before :all do
- class AppConfig < Spree::Preferences::Configuration
- preference :color, :string, default: :blue
- end
- @config = AppConfig.new
- end
-
- it 'has named methods to access preferences' do
- @config.color = 'orange'
- expect(@config.color).to eq 'orange'
- end
-
- it 'uses [ ] to access preferences' do
- @config[:color] = 'red'
- expect(@config[:color]).to eq 'red'
- end
-
- it 'uses set/get to access preferences' do
- @config.set :color, 'green'
- expect(@config.get(:color)).to eq 'green'
- end
-end
diff --git a/spree/core/spec/models/spree/preferences/preferable_spec.rb b/spree/core/spec/models/spree/preferences/preferable_spec.rb
index 3254cd61fe..147b890245 100644
--- a/spree/core/spec/models/spree/preferences/preferable_spec.rb
+++ b/spree/core/spec/models/spree/preferences/preferable_spec.rb
@@ -43,11 +43,6 @@ describe Spree::Preferences::Preferable, type: :model do
expect(@b.preferred_flavor).to be_nil
end
- it 'can be asked if it has a preference definition' do
- expect(@a.has_preference?(:color)).to be true
- expect(@a.has_preference?(:bad)).to be false
- end
-
it 'can be asked and raises' do
expect do
@a.has_preference! :flavor
@@ -75,11 +70,18 @@ describe Spree::Preferences::Preferable, type: :model do
describe 'preference access' do
it 'handles ghost methods for preferences' do
+ @b.preferred_flavor = 'mint'
+ expect(@b.preferred_flavor).to eq 'mint'
+ end
+
+ it 'warns when a deprecated preference is written' do
+ expect(Spree::Deprecation).to receive(:warn).with(/`color` is deprecated. Please use colour instead/)
@a.preferred_color = 'blue'
expect(@a.preferred_color).to eq 'blue'
end
it 'parent and child instances have their own prefs' do
+ allow(Spree::Deprecation).to receive(:warn)
@a.preferred_color = 'red'
@b.preferred_color = 'blue'
@@ -279,7 +281,7 @@ describe Spree::Preferences::Preferable, type: :model do
context 'converts array preferences to array values' do
before do
- A.preference :is_array, :array, default: []
+ Spree::Deprecation.silence { A.preference :is_array, :array, default: [] }
end
it 'with arrays' do
@@ -300,7 +302,7 @@ describe Spree::Preferences::Preferable, type: :model do
context 'converts hash preferences to hash values' do
before do
- A.preference :is_hash, :hash, default: {}
+ Spree::Deprecation.silence { A.preference :is_hash, :hash, default: {} }
end
it 'with hash' do
@@ -391,8 +393,10 @@ describe Spree::Preferences::Preferable, type: :model do
context 'converts any preferences to any values' do
before do
- A.preference :product_ids, :any, default: []
- A.preference :product_attributes, :any, default: {}
+ Spree::Deprecation.silence do
+ A.preference :product_ids, :any, default: []
+ A.preference :product_attributes, :any, default: {}
+ end
@a = A.new
end
@@ -583,7 +587,7 @@ describe Spree::Preferences::Preferable, type: :model do
class PrefTest < Spree::Base
preference :pref_test_pref, :string, default: 'abc'
- preference :pref_test_any, :any, default: []
+ Spree::Deprecation.silence { preference :pref_test_any, :any, default: [] }
preference :pref_test_decimal, :decimal, default: 0
preference :pref_test_datetime, :datetime
end
@@ -618,17 +622,6 @@ describe Spree::Preferences::Preferable, type: :model do
end
end
- it 'clear preferences when record is deleted' do
- @pt.save!
- @pt.preferred_pref_test_pref = 'lmn'
- @pt.save!
- @pt.destroy
- @pt1 = PrefTest.new(col: 'aaaa')
- @pt1.id = @pt.id
- @pt1.save!
- expect(@pt1.get_preference(:pref_test_pref)).to eq('abc')
- end
-
describe 'JSON storage' do
it 'restores a decimal exactly after a round trip' do
@pt.update!(preferred_pref_test_decimal: '19.99')
diff --git a/spree/core/spec/models/spree/price_list_spec.rb b/spree/core/spec/models/spree/price_list_spec.rb
index fd843f178b..97d919b6ae 100644
--- a/spree/core/spec/models/spree/price_list_spec.rb
+++ b/spree/core/spec/models/spree/price_list_spec.rb
@@ -280,48 +280,9 @@ describe Spree::PriceList, type: :model do
end
end
- describe 'status' do
- let(:price_list) { create(:price_list) }
-
- it 'has no state machine' do
- expect(described_class).not_to respond_to(:state_machines)
- end
-
- it 'has initial status of draft' do
- expect(price_list.status).to eq('draft')
- end
-
- it 'rejects an unknown status' do
- expect(build(:price_list, status: 'nonsense')).not_to be_valid
- end
- end
-
describe 'scopes' do
let(:store) { @default_store }
let!(:active_price_list) { create(:price_list, :active, store: store) }
- let!(:inactive_price_list) { create(:price_list, :inactive, store: store) }
- let!(:scheduled_price_list) { create(:price_list, :scheduled, store: store) }
-
- describe '.with_status(:active)' do
- it 'returns only active price lists' do
- expect(described_class.with_status(:active)).to include(active_price_list)
- expect(described_class.with_status(:active)).not_to include(inactive_price_list)
- end
- end
-
- describe '.with_status(:inactive)' do
- it 'returns only inactive price lists' do
- expect(described_class.with_status(:inactive)).to include(inactive_price_list)
- expect(described_class.with_status(:inactive)).not_to include(active_price_list)
- end
- end
-
- describe '.with_status(:scheduled)' do
- it 'returns only scheduled price lists' do
- expect(described_class.with_status(:scheduled)).to include(scheduled_price_list)
- expect(described_class.with_status(:scheduled)).not_to include(active_price_list)
- end
- end
describe '.by_position' do
let!(:first_list) { create(:price_list, store: store, position: 1) }
@@ -416,18 +377,6 @@ describe Spree::PriceList, type: :model do
end
end
- describe '#active?' do
- it 'returns true when status is active' do
- price_list = create(:price_list, :active)
- expect(price_list.active?).to be true
- end
-
- it 'returns false when status is not active' do
- price_list = create(:price_list, :inactive)
- expect(price_list.active?).to be false
- end
- end
-
describe '#add_products' do
let(:store) { create(:store, supported_currencies: 'USD,EUR,GBP') }
let(:price_list) { create(:price_list, store: store) }
@@ -518,12 +467,6 @@ describe Spree::PriceList, type: :model do
price = price_list.prices.find_by(variant_id: product1.default_variant.id, currency: 'USD')
expect(price.amount).to eq(49.99)
end
-
- it 'only creates prices for missing currencies' do
- expect {
- price_list.add_products([product1.id])
- }.to change { price_list.prices.count }.by(2) # Only EUR and GBP
- end
end
context 'with deleted variants' do
@@ -561,12 +504,6 @@ describe Spree::PriceList, type: :model do
}.to change { price_list.prices.count }.by(-3) # 1 product * 3 currencies
end
- it 'removes prices for all currencies' do
- price_list.remove_products([product1.id])
-
- expect(price_list.prices.joins(:variant).where(spree_variants: { product_id: product1.id }).count).to eq(0)
- end
-
it 'does not remove prices for other products' do
price_list.remove_products([product1.id])
@@ -606,17 +543,6 @@ describe Spree::PriceList, type: :model do
end
context 'when re-adding a previously removed product' do
- it 'allows re-adding a product with empty prices' do
- # Add product, then remove it
- price_list.add_products([product1.id])
- price_list.remove_products([product1.id])
-
- # Re-add the same product - this should not raise a unique constraint error
- expect {
- price_list.add_products([product1.id])
- }.to change { price_list.prices.count }.by(3) # 1 product * 3 currencies
- end
-
it 'allows re-adding a product that had prices with amounts set' do
# Add product and set some prices
price_list.add_products([product1.id])
diff --git a/spree/core/spec/models/spree/price_rules/channel_rule_spec.rb b/spree/core/spec/models/spree/price_rules/channel_rule_spec.rb
index adc4d4353b..0d72273c31 100644
--- a/spree/core/spec/models/spree/price_rules/channel_rule_spec.rb
+++ b/spree/core/spec/models/spree/price_rules/channel_rule_spec.rb
@@ -52,21 +52,6 @@ describe Spree::PriceRules::ChannelRule, type: :model do
end
describe '#preferred_channel_ids=' do
- it 'decodes prefixed channel IDs to raw IDs' do
- rule.preferred_channel_ids = [channel.prefixed_id]
- expect(rule.preferred_channel_ids).to eq([channel.id.to_s])
- end
-
- it 'accepts a comma-separated string' do
- other_channel = create(:channel, store: price_list.store)
- rule.preferred_channel_ids = "#{channel.prefixed_id},#{other_channel.prefixed_id}"
- expect(rule.preferred_channel_ids).to contain_exactly(channel.id.to_s, other_channel.id.to_s)
- end
-
- it 'raises when given an unknown prefixed ID' do
- expect { rule.preferred_channel_ids = ['ch_doesnotexist'] }.to raise_error(ActiveRecord::RecordNotFound)
- end
-
it 'rejects a channel that belongs to another store' do
other_store = create(:store)
cross_store_channel = create(:channel, store: other_store)
diff --git a/spree/core/spec/models/spree/price_rules/market_rule_spec.rb b/spree/core/spec/models/spree/price_rules/market_rule_spec.rb
index a01017586a..4b4a30f16f 100644
--- a/spree/core/spec/models/spree/price_rules/market_rule_spec.rb
+++ b/spree/core/spec/models/spree/price_rules/market_rule_spec.rb
@@ -41,45 +41,9 @@ describe Spree::PriceRules::MarketRule, type: :model do
expect(rule.applicable?(context)).to be false
end
end
-
- context 'when market_ids preference contains strings' do
- before { rule.preferred_market_ids = [market.id.to_s] }
-
- it 'returns true when context market matches' do
- context = Spree::Pricing::Context.new(variant: variant, currency: 'USD', market: market)
- expect(rule.applicable?(context)).to be true
- end
-
- it 'returns false when context market does not match' do
- other_market = create(:market, store: price_list.store)
- context = Spree::Pricing::Context.new(variant: variant, currency: 'USD', market: other_market)
- expect(rule.applicable?(context)).to be false
- end
- end
end
describe '#preferred_market_ids=' do
- it 'decodes prefixed market IDs to raw IDs' do
- rule.preferred_market_ids = [market.prefixed_id]
- expect(rule.preferred_market_ids).to eq([market.id.to_s])
- end
-
- it 'accepts a mix of prefixed and raw IDs' do
- other_market = create(:market, store: price_list.store)
- rule.preferred_market_ids = [market.prefixed_id, other_market.id.to_s]
- expect(rule.preferred_market_ids).to contain_exactly(market.id.to_s, other_market.id.to_s)
- end
-
- it 'accepts a comma-separated string' do
- other_market = create(:market, store: price_list.store)
- rule.preferred_market_ids = "#{market.prefixed_id},#{other_market.prefixed_id}"
- expect(rule.preferred_market_ids).to contain_exactly(market.id.to_s, other_market.id.to_s)
- end
-
- it 'raises when given an unknown prefixed ID' do
- expect { rule.preferred_market_ids = ['mkt_doesnotexist'] }.to raise_error(ActiveRecord::RecordNotFound)
- end
-
it 'rejects a market that belongs to another store' do
other_store = create(:store)
cross_store_market = create(:market, store: other_store)
diff --git a/spree/core/spec/models/spree/price_rules/volume_rule_spec.rb b/spree/core/spec/models/spree/price_rules/volume_rule_spec.rb
index 64a5e9b746..e15f6a4f4f 100644
--- a/spree/core/spec/models/spree/price_rules/volume_rule_spec.rb
+++ b/spree/core/spec/models/spree/price_rules/volume_rule_spec.rb
@@ -11,18 +11,6 @@ describe Spree::PriceRules::VolumeRule, type: :model do
rule.save!
expect(rule.reload.preferred_max_quantity).to be_nil
end
-
- it 'preserves non-zero max_quantity' do
- rule.preferred_max_quantity = 50
- rule.save!
- expect(rule.reload.preferred_max_quantity).to eq(50)
- end
-
- it 'preserves nil max_quantity' do
- rule.preferred_max_quantity = nil
- rule.save!
- expect(rule.reload.preferred_max_quantity).to be_nil
- end
end
describe '#applicable?' do
diff --git a/spree/core/spec/models/spree/price_spec.rb b/spree/core/spec/models/spree/price_spec.rb
index b56dea58c3..659e3d354b 100644
--- a/spree/core/spec/models/spree/price_spec.rb
+++ b/spree/core/spec/models/spree/price_spec.rb
@@ -159,36 +159,6 @@ describe Spree::Price, type: :model do
end
end
- describe '#price' do
- let(:price) { build :price }
- let(:amount) { 3000.00 }
-
- context 'when amount is changed' do
- before do
- price.amount = amount
- end
-
- it 'is expected to equal to price' do
- expect(price.amount).to eq(price.price)
- end
- end
- end
-
- describe '#compare_at_price' do
- let(:price) { build :price }
- let(:compare_at_amount) { 3000.00 }
-
- context 'when amount is changed' do
- before do
- price.compare_at_amount = compare_at_amount
- end
-
- it 'is expected to equal to price' do
- expect(price.compare_at_amount).to eq(price.compare_at_price)
- end
- end
- end
-
describe 'validations' do
subject { build :price, variant: variant, amount: amount }
@@ -214,11 +184,8 @@ describe Spree::Price, type: :model do
let(:amount) { -1 }
before { subject.valid? }
- it 'has 1 error on amount' do
- expect(subject.errors.messages[:amount].size).to eq(1)
- end
it 'populates errors' do
- expect(subject.errors.messages[:amount].first).to eq 'must be greater than or equal to 0'
+ expect(subject.errors.messages[:amount]).to eq ['must be greater than or equal to 0']
end
end
@@ -226,11 +193,8 @@ describe Spree::Price, type: :model do
let(:amount) { Spree::Price::MAXIMUM_AMOUNT + 1 }
before { subject.valid? }
- it 'has 1 error on amount' do
- expect(subject.errors.messages[:amount].size).to eq(1)
- end
it 'populates errors' do
- expect(subject.errors.messages[:amount].first).to eq "must be less than or equal to #{Spree::Price::MAXIMUM_AMOUNT}"
+ expect(subject.errors.messages[:amount]).to eq ["must be less than or equal to #{Spree::Price::MAXIMUM_AMOUNT}"]
end
end
@@ -245,10 +209,6 @@ describe Spree::Price, type: :model do
let(:amount) { 10 }
let(:price_list) { create(:price_list) }
- it 'defaults to the ladder\'s bottom rung' do
- expect(described_class.new.min_quantity).to eq(1)
- end
-
it 'refuses a quantity below one' do
subject.min_quantity = 0
@@ -415,24 +375,6 @@ describe Spree::Price, type: :model do
end
end
- describe '#display_price_including_vat_for(zone)' do
- subject { build :price, amount: 10 }
-
- it 'calls #price_including_vat_for' do
- expect(subject).to receive(:price_including_vat_for)
- subject.display_price_including_vat_for(nil)
- end
- end
-
- describe '#display_compare_at_price_including_vat_for(zone)' do
- subject { build :price, amount: 10, compare_at_amount: 100 }
-
- it 'calls #price_including_vat_for' do
- expect(subject).to receive(:compare_at_price_including_vat_for)
- subject.display_compare_at_price_including_vat_for(nil)
- end
- end
-
describe '#display_compare_at_amount' do
let(:price) { build(:price, amount: 10, compare_at_amount: compare_at_amount, currency: 'USD') }
diff --git a/spree/core/spec/models/spree/pricing_provider/internal_resolution_spec.rb b/spree/core/spec/models/spree/pricing_provider/internal_resolution_spec.rb
index 798902957a..e6dda2dfbc 100644
--- a/spree/core/spec/models/spree/pricing_provider/internal_resolution_spec.rb
+++ b/spree/core/spec/models/spree/pricing_provider/internal_resolution_spec.rb
@@ -526,19 +526,11 @@ describe Spree::PricingProvider::Internal::Resolution do
expect(price_at(9).amount).to eq(95.00)
expect(price_at(10).amount).to eq(90.00)
expect(price_at(49).amount).to eq(90.00)
+ # Every band is a percentage off the base price, never off the band
+ # below it — otherwise "20% from fifty" would quietly mean 24%.
expect(price_at(50).amount).to eq(80.00)
end
- # Every band is a percentage off the base price, never off the band
- # below it — otherwise "20% from fifty" would quietly mean 24%.
- it 'takes each band off the base price rather than compounding' do
- expect(price_at(50).amount).to eq(80.00)
- end
-
- it 'falls back to the column when the line reaches no band' do
- expect(price_at(1).amount).to eq(95.00)
- end
-
it 'reads the column when the context carries no quantity' do
expect(price_at(nil).amount).to eq(95.00)
end
diff --git a/spree/core/spec/models/spree/product/normalizes_spec.rb b/spree/core/spec/models/spree/product/normalizes_spec.rb
index 28a0ea705d..6af3be1560 100644
--- a/spree/core/spec/models/spree/product/normalizes_spec.rb
+++ b/spree/core/spec/models/spree/product/normalizes_spec.rb
@@ -19,12 +19,6 @@ describe Spree::Product, type: :model do
expect(product.name).to be_nil
end
- it 'handles nil value' do
- product = build(:product)
- product.name = nil
- expect(product.name).to be_nil
- end
-
context 'with always_use_translations enabled' do
before do
Spree::Config.always_use_translations = true
diff --git a/spree/core/spec/models/spree/product/scopes_spec.rb b/spree/core/spec/models/spree/product/scopes_spec.rb
index 17a05b4754..3878173ec4 100644
--- a/spree/core/spec/models/spree/product/scopes_spec.rb
+++ b/spree/core/spec/models/spree/product/scopes_spec.rb
@@ -17,12 +17,6 @@ describe 'Product scopes', type: :model do
it { expect(Spree::Product.available).to include(product_2) }
end
- context 'when available' do
- let!(:product_2) { create(:product, status: 'active') }
-
- it { expect(Spree::Product.available).to include(product_2) }
- end
-
context 'when not available' do
let!(:unavailable_product) { create(:product, status: 'draft') }
@@ -99,18 +93,6 @@ describe 'Product scopes', type: :model do
end
end
- context 'sorting scopes' do
- context 'ascend_by_updated_at' do
- it { expect(Spree::Product.ascend_by_updated_at.to_sql).to include('updated_at ASC') }
- it { expect(Spree::Product.limit(2).ascend_by_updated_at.to_sql).to include('updated_at ASC') }
- end
-
- context 'descend_by_name' do
- it { expect(Spree::Product.descend_by_name.to_sql).to include('name DESC') }
- it { expect(Spree::Product.limit(2).descend_by_name.to_sql).to include('name DESC') }
- end
- end
-
context '#search_by_name' do
let!(:first_product) { create(:product, name: 'First product') }
let!(:second_product) { create(:product, name: 'Second product') }
@@ -309,30 +291,6 @@ describe 'Product scopes', type: :model do
end
end
- context 'with incomplete orders' do
- before do
- # Product 1: 2 units sold (2 completed orders)
- create_list(:completed_order_with_totals, 2, line_items_price: 100, store: store, variants: [product_1.default_variant])
-
- # Product 2: 1 unit sold (1 completed order) + 2 incomplete orders (should not be counted)
- create(:completed_order_with_totals, line_items_price: 100, store: store, variants: [product_2.default_variant])
- create_list(:order_with_totals, 2, line_items_price: 100, store: store, variants: [product_2.default_variant])
-
- refresh_all_metrics!
- end
-
- it 'only counts units from completed orders' do
- products = store.products.where(id: test_product_ids).by_best_selling
- expect(products.first.name).to eq('Product 1')
-
- product_1_store_product = product_1.reload
- product_2_store_product = product_2.reload
-
- expect(product_1_store_product.units_sold_count).to eq(2)
- expect(product_2_store_product.units_sold_count).to eq(1)
- end
- end
-
context 'when products have same units_sold_count' do
before do
# Both products have 2 units sold, but different revenue
@@ -358,38 +316,6 @@ describe 'Product scopes', type: :model do
end
end
- context 'with varying quantities' do
- before do
- # Product 1: 5 units sold (quantity 2 + quantity 3)
- order1 = create(:order_with_line_items, line_items_count: 0, store: store)
- create(:line_item, order: order1, variant: product_1.default_variant, price: 50, quantity: 2)
- create(:line_item, order: order1, variant: product_1.default_variant, price: 50, quantity: 3)
- order1.update!(completed_at: Time.current)
-
- # Product 2: 2 units sold (quantity 2)
- order2 = create(:order_with_line_items, line_items_count: 0, store: store)
- create(:line_item, order: order2, variant: product_2.default_variant, price: 100, quantity: 2)
- order2.update!(completed_at: Time.current)
-
- refresh_all_metrics!
- end
-
- it 'sums line item quantities for units_sold_count' do
- products = store.products.where(id: test_product_ids).by_best_selling
-
- product_1_store_product = product_1.reload
- product_2_store_product = product_2.reload
-
- # Product 1: 2 + 3 = 5 units
- expect(product_1_store_product.units_sold_count).to eq(5)
- # Product 2: 2 units
- expect(product_2_store_product.units_sold_count).to eq(2)
-
- # Product 1 should be ranked higher due to more units sold
- expect(products.first.name).to eq('Product 1')
- end
- end
-
context 'with multiple orders containing multiple line items' do
before do
# Product 1: 5 units sold across 2 orders (quantity 3 + quantity 2)
@@ -426,23 +352,6 @@ describe 'Product scopes', type: :model do
end
end
- context 'with products having no orders' do
- before do
- refresh_all_metrics!
- end
-
- it 'includes products with no orders at the end' do
- products = store.products.where(id: test_product_ids).by_best_selling
- expect(products.length).to eq(4)
- # All products should be included, those without orders have units_sold_count = 0
- [product_1, product_2, product_3, product_4].each do |p|
- store_product = p.reload
- expect(store_product.units_sold_count).to eq(0)
- expect(store_product.revenue).to eq(0)
- end
- end
- end
-
context 'with products having only pending orders (no completed_at)' do
before do
# Product 1: 2 units sold (2 completed orders)
@@ -484,13 +393,8 @@ describe 'Product scopes', type: :model do
# Product 4 has no orders at all - count should be 0
expect(product_4_sp.units_sold_count).to eq(0)
expect(product_4_sp.revenue).to eq(0)
- end
- it 'orders products correctly with pending orders included' do
- products = store.products.where(id: test_product_ids).by_best_selling
- # Product 1: 2 units sold (first)
- # Product 3: 1 unit sold (second)
- # Product 2 & 4: 0 units sold (last, order between them is non-deterministic)
+ # Product 2 & 4 have no completed sales, so they rank last in no fixed order
expect(products.first(2).map(&:name)).to eq(['Product 1', 'Product 3'])
expect(products.last(2).map(&:name)).to contain_exactly('Product 2', 'Product 4')
end
@@ -583,17 +487,17 @@ describe 'Product scopes', type: :model do
end
it 'includes a future-dated product with an active pre-order variant' do
- active_product.master.update_columns(preorderable: true)
+ active_product.default_variant.update_columns(preorderable: true)
expect(Spree::Product.available(Time.current, 'USD', include_preorderable: true)).to include(active_product)
end
it "excludes it when the pre-order's ship date has already passed" do
- active_product.master.update_columns(preorderable: true, preorder_ships_at: 1.day.ago)
+ active_product.default_variant.update_columns(preorderable: true, preorder_ships_at: 1.day.ago)
expect(Spree::Product.available(Time.current, 'USD', include_preorderable: true)).not_to include(active_product)
end
it 'still excludes a future-dated product with no pre-order variant' do
- active_product.master.update_columns(preorderable: false)
+ active_product.default_variant.update_columns(preorderable: false)
expect(Spree::Product.available(Time.current, 'USD', include_preorderable: true)).not_to include(active_product)
end
end
diff --git a/spree/core/spec/models/spree/product/slugs_spec.rb b/spree/core/spec/models/spree/product/slugs_spec.rb
index 162ed71a57..d69029d63c 100644
--- a/spree/core/spec/models/spree/product/slugs_spec.rb
+++ b/spree/core/spec/models/spree/product/slugs_spec.rb
@@ -47,19 +47,9 @@ describe Spree::Product::Slugs, type: :model do
another_product.destroy!
end
- it 'can use original slug' do
- product.save!
-
- expect(product.slugs.first.slug).to eq(name)
- expect(product.slug).to eq(name)
-
- deleted_slug = another_product.slugs.with_deleted.first
- expect(deleted_slug.slug).to match(/deleted-#{name}-.+/)
- expect(another_product.slug).to match(/deleted-#{name}-.+/)
- end
-
it 'can delete the product again and then create a new product with the original slug' do
product.save!
+ expect(product.slug).to eq(name)
product.destroy!
new_product = build(:product, name: name)
@@ -78,13 +68,6 @@ describe Spree::Product::Slugs, type: :model do
end
end
- it 'stores old slugs in FriendlyIds history' do
- expect(product).to receive(:create_slug)
- # Set it, otherwise the create_slug method avoids writing a new one
- product.slug = 'custom-slug'
- product.run_callbacks :save
- end
-
context 'when product destroyed' do
it 'renames slug' do
product.destroy!
@@ -151,14 +134,6 @@ describe Spree::Product::Slugs, type: :model do
end
end
- it 'validates slug uniqueness' do
- existing_product = product
- new_product = create(:product)
- new_product.slug = existing_product.slug
-
- expect(new_product.valid?).to be false
- end
-
it "falls back to 'name-sku' for slug if regular name-based slug already in use" do
product1 = build(:product)
product1.name = 'test'
@@ -176,16 +151,6 @@ describe Spree::Product::Slugs, type: :model do
context 'history' do
let(:product) { create(:product, name: 'Product 67345') }
- context 'when product is destroyed' do
- before do
- product.destroy
- end
-
- it 'keeps the history' do
- expect(product.slugs.with_deleted).not_to be_empty
- end
- end
-
context 'when product is restored' do
before do
product.destroy
diff --git a/spree/core/spec/models/spree/product_publication_spec.rb b/spree/core/spec/models/spree/product_publication_spec.rb
index deecfe39b5..a127db9d91 100644
--- a/spree/core/spec/models/spree/product_publication_spec.rb
+++ b/spree/core/spec/models/spree/product_publication_spec.rb
@@ -2,7 +2,6 @@ require 'spec_helper'
RSpec.describe Spree::ProductPublication, type: :model do
let(:store) { @default_store }
- let(:channel) { store.default_channel }
let(:product) { create(:product, store: store) }
let(:other_store) { create(:store, default: false, code: 'other') }
@@ -14,16 +13,6 @@ RSpec.describe Spree::ProductPublication, type: :model do
let(:secondary_channel) { create(:channel, store: store, code: 'pos', name: 'POS') }
describe 'validations' do
- it 'is valid with product and channel' do
- publication = build(:product_publication, product: product, channel: secondary_channel)
- expect(publication).to be_valid
- end
-
- it 'enforces uniqueness per (product, channel)' do
- duplicate = build(:product_publication, product: product, channel: channel)
- expect(duplicate).not_to be_valid
- end
-
it 'rejects unpublished_at before published_at' do
publication = build(
:product_publication,
@@ -35,14 +24,6 @@ RSpec.describe Spree::ProductPublication, type: :model do
end
end
- describe '#store delegation' do
- it 'returns the channel.store' do
- publication = build(:product_publication, product: product, channel: secondary_channel)
- expect(publication.store).to eq(store)
- expect(publication.store_id).to eq(store.id)
- end
- end
-
describe '.published' do
it 'includes publications with null dates' do
publication = create(:product_publication, product: product, channel: secondary_channel)
diff --git a/spree/core/spec/models/spree/product_spec.rb b/spree/core/spec/models/spree/product_spec.rb
index 9a8e13462e..49a0b3b319 100644
--- a/spree/core/spec/models/spree/product_spec.rb
+++ b/spree/core/spec/models/spree/product_spec.rb
@@ -264,14 +264,6 @@ describe Spree::Product, type: :model do
end
end
- # Regression test for #3737
- context 'has stock items' do
- it 'can retrieve stock items' do
- expect(product.default_variant.stock_levels.first).not_to be_nil
- expect(product.stock_levels.first).not_to be_nil
- end
- end
-
describe '#discontinue_on_must_be_later_than_make_active_at' do
before { product.make_active_at = Date.today }
@@ -308,19 +300,19 @@ describe Spree::Product, type: :model do
context 'hard deletion' do
it 'doesnt raise ActiveRecordError error' do
- expect { product.really_destroy! }.not_to raise_error(ActiveRecord::ActiveRecordError)
+ expect { product.really_destroy! }.not_to raise_error
end
end
context 'history' do
- before do
- @product = create(:product)
- end
-
it 'keeps translations when product is destroyed' do
- @product.destroy
+ product = create(:product)
+ Mobility.with_locale(:pl) { product.update!(name: 'PL name') }
- expect(@product.name).not_to be_empty
+ product.destroy
+
+ destroyed_product = Spree::Product.with_deleted.find(product.id)
+ expect(Mobility.with_locale(:pl) { destroyed_product.name }).to eq('PL name')
end
end
@@ -333,10 +325,6 @@ describe Spree::Product, type: :model do
product.instance_variable_set(:@total_on_hand, incorrent_total_on_hand)
end
- it 'without action keeps data' do
- expect(product.total_on_hand).to eq incorrent_total_on_hand
- end
-
it 'resets memoized data after save' do
product.save
expect(product.total_on_hand).to eq corrent_total_on_hand
@@ -422,10 +410,6 @@ describe Spree::Product, type: :model do
product.save
expect(product.option_type_ids.length).to eq(1)
expect(product.option_type_ids).to eq(product_type.option_type_ids)
- end
-
- it 'creates product option types based on the product type' do
- product.save
expect(product.product_option_types.pluck(:option_type_id)).to eq(product_type.option_type_ids)
end
@@ -666,19 +650,6 @@ describe Spree::Product, type: :model do
end
end
- # Regression tests for #2352
- context 'product_categories and categories' do
- it 'is joined through product_categories' do
- reflection = Spree::Product.reflect_on_association(:categories)
- expect(reflection.options[:through]).to eq(:product_categories)
- end
-
- it 'will delete all product_categories' do
- reflection = Spree::Product.reflect_on_association(:product_categories)
- expect(reflection.options[:dependent]).to eq(:delete_all)
- end
- end
-
describe 'the price filter' do
let!(:cheap) { create(:product, price: 5) }
let!(:pricey) { create(:product, price: 500) }
@@ -736,23 +707,15 @@ describe Spree::Product, type: :model do
describe '#discontinue!' do
let(:product) { create(:product, sku: 'a-sku') }
- it 'sets the discontinued' do
- product.discontinue!
- product.reload
- expect(product.discontinued?).to be(true)
- end
+ it 'archives the product as discontinued' do
+ product.update_column(:updated_at, 1.day.ago)
+
+ expect { product.discontinue! }.to change(product, :updated_at)
- it 'sets the status to archived' do
- product.discontinue!
product.reload
+ expect(product.discontinued?).to be(true)
expect(product.status).to eq('archived')
end
-
- it 'changes updated_at' do
- Timecop.scale(1000) do
- expect { product.discontinue! }.to change(product, :updated_at)
- end
- end
end
describe '#discontinued?' do
@@ -800,10 +763,6 @@ describe Spree::Product, type: :model do
describe '#default_variant' do
let(:product) { create(:product) }
- it 'is the sole variant for a simple product' do
- expect(product.reload.default_variant).to eq(product.variants.first)
- end
-
it 'stays fixed (sticky) when other variants are added, regardless of stock' do
default = product.default_variant
create(:variant, product: product)
@@ -839,14 +798,6 @@ describe Spree::Product, type: :model do
end
end
- describe '#default_variant_id' do
- let(:product) { create(:product) }
-
- it 'returns the default variant id' do
- expect(product.reload.default_variant_id).to eq(product.variants.first.id)
- end
- end
-
describe '#primary_media' do
let(:product) { create(:product) }
@@ -1067,9 +1018,12 @@ describe Spree::Product, type: :model do
describe '#secondary_image' do
let(:product) { create(:product) }
+ before { allow(Spree::Deprecation).to receive(:warn) }
+
context 'when no variants have images' do
it 'returns nil' do
expect(product.secondary_image).to be_nil
+ expect(Spree::Deprecation).to have_received(:warn).with(/Product#secondary_image is deprecated/)
end
end
@@ -1121,15 +1075,6 @@ describe Spree::Product, type: :model do
expect(loaded_product.variant_for_images).to eq(variant)
expect(loaded_product.has_images?).to be true
end
-
- context 'when the image is on a non-default variant' do
- it 'still finds the image through variant_for_images' do
- loaded_product = Spree::Product.includes(*storefront_includes).find(product.id)
-
- expect(loaded_product.variant_for_images).to eq(variant)
- expect(loaded_product.primary_media).to eq(image)
- end
- end
end
describe 'default store assignment' do
@@ -1296,14 +1241,10 @@ describe Spree::Product, type: :model do
it { expect(subject).to be(true) }
end
- context 'when all option variant stock items have track_inventory = true' do
- it { expect(subject).to eq(false) }
+ context 'when all option variant stock items have backorderable = true' do
+ before { stock_level.update(backorderable: true) }
- context 'when all option variant stock items have backorderable = true' do
- before { stock_level.update(backorderable: true) }
-
- it { expect(subject).to eq(true) }
- end
+ it { expect(subject).to eq(true) }
end
end
end
@@ -1321,20 +1262,6 @@ describe Spree::Product, type: :model do
it { expect(subject).to eq(false) }
end
-
- describe '#digital?' do
- context 'when the product belongs to a digital profile' do
- let(:product) { create(:digital_product) }
-
- it { expect(product.digital?).to eq(true) }
- end
-
- context 'when the product belongs to the default profile' do
- let(:product) { create(:product) }
-
- it { expect(product.digital?).to eq(false) }
- end
- end
end
describe '#to_csv' do
@@ -1963,14 +1890,6 @@ describe Spree::Product, type: :model do
end
describe 'status' do
- it 'has no state machine' do
- expect(described_class).not_to respond_to(:state_machines)
- end
-
- it 'defaults to draft' do
- expect(described_class.new.status).to eq('draft')
- end
-
it 'rejects an unknown status' do
expect(build(:product, status: 'nonsense')).not_to be_valid
end
@@ -1981,36 +1900,6 @@ describe Spree::Product, type: :model do
it 'keeps the currency-aware active scope' do
expect(described_class.active(nil).to_sql).to include(Spree::Price.table_name)
end
-
- it 'generates the plain status scopes and predicates' do
- expect(described_class.draft.to_sql).to include("'draft'")
- expect(described_class.archived.to_sql).to include("'archived'")
- expect(build(:product, status: 'draft')).to be_draft
- end
- end
-
- describe 'custom events', events: true do
- describe 'product.activated' do
- let(:product) { create(:product, status: 'draft') }
-
- it 'publishes product.activated event when activated' do
- expect(product).to receive(:publish_event).with('product.activated')
- allow(product).to receive(:publish_event).with(anything)
-
- Spree::Products::Activate.call(product: product)
- end
- end
-
- describe 'product.archived' do
- let(:product) { create(:product, status: 'active') }
-
- it 'publishes product.archived event when archived' do
- expect(product).to receive(:publish_event).with('product.archived')
- allow(product).to receive(:publish_event).with(anything)
-
- Spree::Products::Archive.call(product: product)
- end
- end
end
describe '#has_variants?' do
@@ -2100,30 +1989,6 @@ describe Spree::Product, type: :model do
expect(product.variants.reload).to include(v1)
expect(product.variants).not_to include(v2)
end
-
- it 'defers creation on new records' do
- new_product = Spree.product_create_workflow.call(
- store: store,
- attributes: { name: 'Deferred', variants: [{ sku: 'DEF-1', options: [{ name: 'Color', value: 'Red' }] }] }
- ).value
-
- expect(new_product.variants.count).to eq(1)
- expect(new_product.variants.first.sku).to eq('DEF-1')
- end
-
- it 'creates a single default variant from an options-less entry' do
- # Simple-product flow: the merchant edits SKU + weight on the default
- # variant without adding options. The payload ships a single variant
- # with options:[] and the backend creates exactly that one variant.
- new_product = Spree.product_create_workflow.call(
- store: store,
- attributes: { name: 'Simple SKU', variants: [{ sku: 'SIMPLE-1', weight: 2, options: [] }] }
- ).value
-
- expect(new_product.variants.count).to eq(1)
- expect(new_product.default_variant.sku).to eq('SIMPLE-1')
- expect(new_product.default_variant.weight).to eq(2)
- end
end
context 'with Variant objects' do
@@ -2346,15 +2211,6 @@ describe Spree::Product, type: :model do
expect(product.reload.tax_category).to eq(custom_tc)
end
-
- it 'assigns default when tax_category_id is not provided' do
- product = Spree::Product.new(
- name: 'Test',
- store: store
- )
-
- expect(product.tax_category).to eq(default_tc)
- end
end
context 'Channels' do
@@ -2367,12 +2223,6 @@ describe Spree::Product, type: :model do
allow(Spree::Deprecation).to receive(:warn)
end
- context 'associations' do
- it 'reaches channels through product_publications' do
- expect(product.reload.channels).to contain_exactly(default_channel)
- end
- end
-
context '#available_on=' do
it 'emits a deprecation warning' do
product.available_on = target
diff --git a/spree/core/spec/models/spree/product_type_custom_field_definition_spec.rb b/spree/core/spec/models/spree/product_type_custom_field_definition_spec.rb
index 575686d490..7f12e8d4af 100644
--- a/spree/core/spec/models/spree/product_type_custom_field_definition_spec.rb
+++ b/spree/core/spec/models/spree/product_type_custom_field_definition_spec.rb
@@ -2,24 +2,8 @@ require 'spec_helper'
RSpec.describe Spree::ProductTypeCustomFieldDefinition, type: :model do
let(:product_type) { create(:product_type) }
- let(:definition) { create(:custom_field_definition) }
describe 'validations' do
- it 'rejects a second row for the same definition' do
- create(:product_type_custom_field_definition, product_type: product_type, custom_field_definition: definition)
- duplicate = build(:product_type_custom_field_definition, product_type: product_type, custom_field_definition: definition)
-
- expect(duplicate).not_to be_valid
- expect(duplicate.errors[:custom_field_definition_id]).to be_present
- end
-
- it 'allows the same definition on another type' do
- create(:product_type_custom_field_definition, product_type: product_type, custom_field_definition: definition)
- other = build(:product_type_custom_field_definition, product_type: create(:product_type), custom_field_definition: definition)
-
- expect(other).to be_valid
- end
-
it 'rejects a definition scoped to another resource' do
order_definition = create(:custom_field_definition, :for_order)
join = build(:product_type_custom_field_definition, product_type: product_type, custom_field_definition: order_definition)
@@ -37,15 +21,6 @@ RSpec.describe Spree::ProductTypeCustomFieldDefinition, type: :model do
end
end
- describe 'defaults' do
- it 'is optional and unsorted' do
- join = described_class.new
-
- expect(join.required).to be(false)
- expect(join.sort_order).to eq(0)
- end
- end
-
describe 'scopes' do
it '.required returns only required rows' do
required = create(:product_type_custom_field_definition, :required, product_type: product_type)
@@ -71,11 +46,5 @@ RSpec.describe Spree::ProductTypeCustomFieldDefinition, type: :model do
[earlier.custom_field_definition, later.custom_field_definition]
)
end
-
- it 'is destroyed with the product type' do
- create(:product_type_custom_field_definition, product_type: product_type)
-
- expect { product_type.destroy }.to change(described_class, :count).by(-1)
- end
end
end
diff --git a/spree/core/spec/models/spree/product_type_spec.rb b/spree/core/spec/models/spree/product_type_spec.rb
index 8eb2d63162..222dad564b 100644
--- a/spree/core/spec/models/spree/product_type_spec.rb
+++ b/spree/core/spec/models/spree/product_type_spec.rb
@@ -4,10 +4,6 @@ describe Spree::ProductType, type: :model do
it_behaves_like 'metadata'
describe 'delivery profile template' do
- it 'is optional — a type without one leaves products on the store default' do
- expect(build(:product_type).delivery_profile).to be_nil
- end
-
it 'stamps its profile onto products at creation' do
profile = create(:delivery_profile)
product_type = create(:product_type, delivery_profile: profile)
diff --git a/spree/core/spec/models/spree/promotion/actions/create_adjustment_spec.rb b/spree/core/spec/models/spree/promotion/actions/create_adjustment_spec.rb
index 039562b86d..b2025f8a28 100644
--- a/spree/core/spec/models/spree/promotion/actions/create_adjustment_spec.rb
+++ b/spree/core/spec/models/spree/promotion/actions/create_adjustment_spec.rb
@@ -45,8 +45,4 @@ describe Spree::Promotion::Actions::CreateAdjustment, type: :model do
expect(huge.compute_amount(order)).to eq(-action.order_total(order))
end
end
-
- it 'has order discount scope' do
- expect(action.discount_scope).to eq(:order)
- end
end
diff --git a/spree/core/spec/models/spree/promotion/actions/create_line_items_spec.rb b/spree/core/spec/models/spree/promotion/actions/create_line_items_spec.rb
index 3c2e7e1d5e..0b3490972f 100644
--- a/spree/core/spec/models/spree/promotion/actions/create_line_items_spec.rb
+++ b/spree/core/spec/models/spree/promotion/actions/create_line_items_spec.rb
@@ -185,18 +185,10 @@ describe Spree::Promotion::Actions::CreateLineItems, type: :model do
end
end
- it "discounts the shopper's own copy instead of adding a second one" do
- Spree.cart_add_item_workflow.call(cart: cart, variant: gift, quantity: 1)
-
- expect(promotion.activate(order: cart)).to be(true)
- expect(gift_line_item.quantity).to eq(1)
- expect(gift_line_item.discounts.sum(&:amount)).to eq(-15)
- end
-
it 'leaves units beyond the gifted quantity paid for' do
Spree.cart_add_item_workflow.call(cart: cart, variant: gift, quantity: 3)
- promotion.activate(order: cart)
+ expect(promotion.activate(order: cart)).to be(true)
expect(gift_line_item.quantity).to eq(3)
expect(gift_line_item.discounts.sum(&:amount)).to eq(-15)
diff --git a/spree/core/spec/models/spree/promotion/rules/category_spec.rb b/spree/core/spec/models/spree/promotion/rules/category_spec.rb
index 5ddc79d5e1..a2bcefb087 100644
--- a/spree/core/spec/models/spree/promotion/rules/category_spec.rb
+++ b/spree/core/spec/models/spree/promotion/rules/category_spec.rb
@@ -68,7 +68,7 @@ describe Spree::Promotion::Rules::Category, type: :model do
order.products.first.categories << category2
order.products.last.categories << category
- rule.taxons = [category, category2]
+ rule.categories = [category, category2]
expect(rule).to be_eligible(order)
end
@@ -100,31 +100,29 @@ describe Spree::Promotion::Rules::Category, type: :model do
end
end
- describe '#add_taxons' do
- let(:promotion) { create(:promotion) }
- let(:rule) { create(:promotion_rule_taxon, promotion: promotion) }
+ describe '#category_ids_to_add=' do
let(:taxons) { create_list(:category, 3) }
- it 'adds the taxons to the rule' do
- rule.taxon_ids_to_add = taxons.map(&:id)
+ it 'adds the categories to the rule' do
+ rule.category_ids_to_add = taxons.map(&:id)
rule.save!
- expect(rule.taxons).to match_array(taxons)
+ expect(rule.categories).to match_array(taxons)
end
- it 'removes the taxons from the rule' do
- rule.taxon_ids_to_add = taxons.map(&:id)
+ it 'removes the categories from the rule' do
+ rule.category_ids_to_add = taxons.map(&:id)
rule.save!
- rule.taxon_ids_to_add = []
+ rule.category_ids_to_add = []
rule.save!
- expect(rule.taxons).to be_empty
+ expect(rule.categories).to be_empty
end
- it 'does not remove the taxons when nil is passed' do
- rule.taxon_ids_to_add = taxons.map(&:id)
+ it 'does not remove the categories when nil is passed' do
+ rule.category_ids_to_add = taxons.map(&:id)
rule.save!
- rule.taxon_ids_to_add = nil
+ rule.category_ids_to_add = nil
rule.save!
- expect(rule.taxons).to match_array(taxons)
+ expect(rule.categories).to match_array(taxons)
end
end
diff --git a/spree/core/spec/models/spree/promotion/rules/country_spec.rb b/spree/core/spec/models/spree/promotion/rules/country_spec.rb
index 52c5386bf3..cf86ecc2b3 100644
--- a/spree/core/spec/models/spree/promotion/rules/country_spec.rb
+++ b/spree/core/spec/models/spree/promotion/rules/country_spec.rb
@@ -7,27 +7,6 @@ describe Spree::Promotion::Rules::Country, type: :model do
let(:country) { create(:country) }
let(:other_country) { create(:country) }
- context 'preferred country_id is set' do
- before { rule.preferred_country_code = country.iso }
-
- it 'is eligible for correct country' do
- allow(order).to receive_message_chain(:ship_address, :country_id) { country.id }
- allow(order).to receive_message_chain(:ship_address, :country_code) { country.iso }
-
- expect(rule).to be_eligible(order)
- end
-
- it 'is not eligible for incorrect country' do
- allow(order).to receive_message_chain(:ship_address, :country_id) { other_country.id }
- allow(order).to receive_message_chain(:ship_address, :country_code) { other_country.iso }
-
- expect(rule).not_to be_eligible(order)
-
- expect(rule.eligibility_errors.count).to eq(1)
- expect(rule.eligibility_errors.to_hash[:base]).to eq([I18n.t('spree.eligibility_errors.messages.wrong_country')])
- end
- end
-
context 'preferred country_code is set' do
before { rule.preferred_country_code = country.iso }
diff --git a/spree/core/spec/models/spree/promotion/rules/item_total_spec.rb b/spree/core/spec/models/spree/promotion/rules/item_total_spec.rb
index 303b318a33..bd714afe26 100644
--- a/spree/core/spec/models/spree/promotion/rules/item_total_spec.rb
+++ b/spree/core/spec/models/spree/promotion/rules/item_total_spec.rb
@@ -5,316 +5,61 @@ describe Spree::Promotion::Rules::ItemTotal, type: :model do
let(:rule) { Spree::Promotion::Rules::ItemTotal.new }
let(:order) { build(:order, store: store) }
- before do
- rule.preferred_amount_min = 50
- rule.preferred_amount_max = 60
- end
-
- context 'preferred operator_min set to gt and preferred operator_max set to lt' do
- before do
- rule.preferred_operator_min = 'gt'
- rule.preferred_operator_max = 'lt'
- end
-
- context 'and item total is lower than preferred maximum amount' do
- context 'and item total is higher than preferred minimum amount' do
- it 'is eligible' do
- allow(order).to receive_messages item_total: 51
- expect(rule).to be_eligible(order)
- end
- end
-
- context 'and item total is equal to the preferred minimum amount' do
- before { allow(order).to receive_messages item_total: 50 }
-
- it 'is not eligible' do
- expect(rule).not_to be_eligible(order)
- end
-
- it 'set an error message' do
- rule.eligible?(order)
- expect(rule.eligibility_errors.full_messages.first).
- to eq "This coupon code can't be applied to orders less than or equal to $50.00."
- end
- end
-
- context 'and item total is lower to the preferred minimum amount' do
- before { allow(order).to receive_messages item_total: 49 }
-
- it 'is not eligible' do
- expect(rule).not_to be_eligible(order)
- end
-
- it 'set an error message' do
- rule.eligible?(order)
- expect(rule.eligibility_errors.full_messages.first).
- to eq "This coupon code can't be applied to orders less than or equal to $50.00."
- end
- end
- end
-
- context 'and item total is equal to the preferred maximum amount' do
- before { allow(order).to receive_messages item_total: 60 }
-
- it 'is not eligible' do
- expect(rule).not_to be_eligible(order)
- end
-
- it 'set an error message' do
- rule.eligible?(order)
- expect(rule.eligibility_errors.full_messages.first).
- to eq "This coupon code can't be applied to orders higher than or equal to $60.00."
- end
- end
-
- context 'and item total is higher than the preferred maximum amount' do
- before { allow(order).to receive_messages item_total: 61 }
-
- it 'is not eligible' do
- expect(rule).not_to be_eligible(order)
- end
-
- it 'set an error message' do
- rule.eligible?(order)
- expect(rule.eligibility_errors.full_messages.first).
- to eq "This coupon code can't be applied to orders higher than or equal to $60.00."
- end
- end
- end
-
- context 'preferred operator set to gt and preferred operator_max set to lte' do
- before do
- rule.preferred_operator_min = 'gt'
- rule.preferred_operator_max = 'lte'
- end
-
- context 'and item total is lower than preferred maximum amount' do
- context 'and item total is higher than preferred minimum amount' do
- it 'is eligible' do
- allow(order).to receive_messages item_total: 51
- expect(rule).to be_eligible(order)
- end
- end
-
- context 'and item total is equal to the preferred minimum amount' do
- before { allow(order).to receive_messages item_total: 50 }
-
- it 'is not eligible' do
+ less_than_or_equal_min = "This coupon code can't be applied to orders less than or equal to $50.00."
+ less_than_min = "This coupon code can't be applied to orders less than $50.00."
+ higher_than_or_equal_max = "This coupon code can't be applied to orders higher than or equal to $60.00."
+ higher_than_max = "This coupon code can't be applied to orders higher than $60.00."
+
+ # [operator_min, operator_max, amount_max, item_total, expected error (nil when eligible)]
+ [
+ ['gt', 'lt', 60, 51, nil],
+ ['gt', 'lt', 60, 50, less_than_or_equal_min],
+ ['gt', 'lt', 60, 49, less_than_or_equal_min],
+ ['gt', 'lt', 60, 60, higher_than_or_equal_max],
+ ['gt', 'lt', 60, 61, higher_than_or_equal_max],
+
+ ['gt', 'lte', 60, 51, nil],
+ ['gt', 'lte', 60, 50, less_than_or_equal_min],
+ ['gt', 'lte', 60, 49, less_than_or_equal_min],
+ ['gt', 'lte', 60, 60, nil],
+ ['gt', 'lte', 60, 61, higher_than_max],
+
+ ['gte', 'lt', 60, 51, nil],
+ ['gte', 'lt', 60, 50, nil],
+ ['gte', 'lt', 60, 49, less_than_min],
+ ['gte', 'lt', 60, 60, higher_than_or_equal_max],
+ ['gte', 'lt', 60, 61, higher_than_or_equal_max],
+
+ ['gte', 'lte', 60, 51, nil],
+ ['gte', 'lte', 60, 50, nil],
+ ['gte', 'lte', 60, 49, less_than_min],
+ ['gte', 'lte', 60, 60, nil],
+ ['gte', 'lte', 60, 61, higher_than_max],
+
+ # No maximum amount: only the minimum applies.
+ ['gt', 'lt', nil, 51, nil],
+ ['gt', 'lt', nil, 50, less_than_or_equal_min],
+ ['gt', 'lt', nil, 49, less_than_or_equal_min]
+ ].each do |operator_min, operator_max, amount_max, item_total, expected_error|
+ context "with #{operator_min} 50 / #{operator_max} #{amount_max.inspect} and an item total of #{item_total}" do
+ before do
+ rule.preferred_amount_min = 50
+ rule.preferred_amount_max = amount_max
+ rule.preferred_operator_min = operator_min
+ rule.preferred_operator_max = operator_max
+ allow(order).to receive_messages(item_total: item_total)
+ end
+
+ if expected_error
+ it 'is not eligible and explains why' do
expect(rule).not_to be_eligible(order)
+ expect(rule.eligibility_errors.full_messages.first).to eq(expected_error)
end
-
- it 'set an error message' do
- rule.eligible?(order)
- expect(rule.eligibility_errors.full_messages.first).
- to eq "This coupon code can't be applied to orders less than or equal to $50.00."
- end
- end
-
- context 'and item total is lower to the preferred minimum amount' do
- before { allow(order).to receive_messages item_total: 49 }
-
- it 'is not eligible' do
- expect(rule).not_to be_eligible(order)
- end
-
- it 'set an error message' do
- rule.eligible?(order)
- expect(rule.eligibility_errors.full_messages.first).
- to eq "This coupon code can't be applied to orders less than or equal to $50.00."
- end
- end
- end
-
- context 'and item total is equal to the preferred maximum amount' do
- before { allow(order).to receive_messages item_total: 60 }
-
- it 'is not eligible' do
- expect(rule).to be_eligible(order)
- end
- end
-
- context 'and item total is higher than the preferred maximum amount' do
- before { allow(order).to receive_messages item_total: 61 }
-
- it 'is not eligible' do
- expect(rule).not_to be_eligible(order)
- end
-
- it 'set an error message' do
- rule.eligible?(order)
- expect(rule.eligibility_errors.full_messages.first).
- to eq "This coupon code can't be applied to orders higher than $60.00."
- end
- end
- end
-
- context 'preferred operator set to gte and preferred operator_max set to lt' do
- before do
- rule.preferred_operator_min = 'gte'
- rule.preferred_operator_max = 'lt'
- end
-
- context 'and item total is lower than preferred maximum amount' do
- context 'and item total is higher than preferred minimum amount' do
+ else
it 'is eligible' do
- allow(order).to receive_messages item_total: 51
expect(rule).to be_eligible(order)
end
end
-
- context 'and item total is equal to the preferred minimum amount' do
- before { allow(order).to receive_messages item_total: 50 }
-
- it 'is not eligible' do
- expect(rule).to be_eligible(order)
- end
- end
-
- context 'and item total is lower to the preferred minimum amount' do
- before { allow(order).to receive_messages item_total: 49 }
-
- it 'is not eligible' do
- expect(rule).not_to be_eligible(order)
- end
-
- it 'set an error message' do
- rule.eligible?(order)
- expect(rule.eligibility_errors.full_messages.first).
- to eq "This coupon code can't be applied to orders less than $50.00."
- end
- end
- end
-
- context 'and item total is equal to the preferred maximum amount' do
- before { allow(order).to receive_messages item_total: 60 }
-
- it 'is not eligible' do
- expect(rule).not_to be_eligible(order)
- end
-
- it 'set an error message' do
- rule.eligible?(order)
- expect(rule.eligibility_errors.full_messages.first).
- to eq "This coupon code can't be applied to orders higher than or equal to $60.00."
- end
- end
-
- context 'and item total is higher than the preferred maximum amount' do
- before { allow(order).to receive_messages item_total: 61 }
-
- it 'is not eligible' do
- expect(rule).not_to be_eligible(order)
- end
-
- it 'set an error message' do
- rule.eligible?(order)
- expect(rule.eligibility_errors.full_messages.first).
- to eq "This coupon code can't be applied to orders higher than or equal to $60.00."
- end
- end
- end
-
- context 'preferred operator set to gte and preferred operator_max set to lte' do
- before do
- rule.preferred_operator_min = 'gte'
- rule.preferred_operator_max = 'lte'
- end
-
- context 'and item total is lower than preferred maximum amount' do
- context 'and item total is higher than preferred minimum amount' do
- it 'is eligible' do
- allow(order).to receive_messages item_total: 51
- expect(rule).to be_eligible(order)
- end
- end
-
- context 'and item total is equal to the preferred minimum amount' do
- before { allow(order).to receive_messages item_total: 50 }
-
- it 'is not eligible' do
- expect(rule).to be_eligible(order)
- end
- end
-
- context 'and item total is lower to the preferred minimum amount' do
- before { allow(order).to receive_messages item_total: 49 }
-
- it 'is not eligible' do
- expect(rule).not_to be_eligible(order)
- end
-
- it 'set an error message' do
- rule.eligible?(order)
- expect(rule.eligibility_errors.full_messages.first).
- to eq "This coupon code can't be applied to orders less than $50.00."
- end
- end
- end
-
- context 'and item total is equal to the preferred maximum amount' do
- before { allow(order).to receive_messages item_total: 60 }
-
- it 'is not eligible' do
- expect(rule).to be_eligible(order)
- end
- end
-
- context 'and item total is higher than the preferred maximum amount' do
- before { allow(order).to receive_messages item_total: 61 }
-
- it 'is not eligible' do
- expect(rule).not_to be_eligible(order)
- end
-
- it 'set an error message' do
- rule.eligible?(order)
- expect(rule.eligibility_errors.full_messages.first).
- to eq "This coupon code can't be applied to orders higher than $60.00."
- end
- end
- end
-
- context 'when preferred amount max is not set' do
- before do
- rule.preferred_amount_min = 50
- rule.preferred_amount_max = nil
- rule.preferred_operator_min = 'gt'
- rule.preferred_operator_max = 'lt'
- end
-
- context 'and item total is higher than preferred minimum amount' do
- it 'is eligible' do
- allow(order).to receive_messages item_total: 51
- expect(rule).to be_eligible(order)
- end
- end
-
- context 'and item total is equal to the preferred minimum amount' do
- before { allow(order).to receive_messages item_total: 50 }
-
- it 'is not eligible' do
- expect(rule).not_to be_eligible(order)
- end
-
- it 'set an error message' do
- rule.eligible?(order)
- expect(rule.eligibility_errors.full_messages.first).
- to eq "This coupon code can't be applied to orders less than or equal to $50.00."
- end
- end
-
- context 'and item total is lower than preferred minimum amount' do
- before { allow(order).to receive_messages item_total: 49 }
-
- it 'is not eligible' do
- expect(rule).not_to be_eligible(order)
- end
-
- it 'set an error message' do
- rule.eligible?(order)
- expect(rule.eligibility_errors.full_messages.first).
- to eq "This coupon code can't be applied to orders less than or equal to $50.00."
- end
end
end
end
diff --git a/spree/core/spec/models/spree/promotion/rules/user_spec.rb b/spree/core/spec/models/spree/promotion/rules/user_spec.rb
index 6f6dead992..46c6f429c7 100644
--- a/spree/core/spec/models/spree/promotion/rules/user_spec.rb
+++ b/spree/core/spec/models/spree/promotion/rules/user_spec.rb
@@ -31,11 +31,6 @@ describe Spree::Promotion::Rules::User, type: :model do
expect(rule).not_to be_eligible(order)
end
end
-
- # Regression test for #3885
- it 'can assign to user_ids' do
- expect { rule.user_ids = "#{random_user.id}, #{user_placing_order.id}" }.not_to raise_error
- end
end
describe '#add_users' do
diff --git a/spree/core/spec/models/spree/promotion_action_spec.rb b/spree/core/spec/models/spree/promotion_action_spec.rb
index 1706d6bb71..54a08d0025 100644
--- a/spree/core/spec/models/spree/promotion_action_spec.rb
+++ b/spree/core/spec/models/spree/promotion_action_spec.rb
@@ -5,6 +5,8 @@ describe Spree::PromotionAction, type: :model do
it_behaves_like 'type labels'
it "forces developer to implement 'perform' method" do
- expect { MyAction.new.perform }.to raise_error(NameError)
+ stub_const('Spree::BadTestAction', Class.new(described_class))
+
+ expect { Spree::BadTestAction.new.perform }.to raise_error(RuntimeError, /perform should be implemented/)
end
end
diff --git a/spree/core/spec/models/spree/promotion_category_spec.rb b/spree/core/spec/models/spree/promotion_category_spec.rb
deleted file mode 100644
index 7796d5eda3..0000000000
--- a/spree/core/spec/models/spree/promotion_category_spec.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-require 'spec_helper'
-
-describe Spree::PromotionCategory, type: :model do
- describe 'validation' do
- subject { Spree::PromotionCategory.new name: name }
-
- let(:name) { 'Nom' }
-
- context 'when all required attributes are specified' do
- it { is_expected.to be_valid }
- end
-
- context 'when name is missing' do
- let(:name) { nil }
-
- it { is_expected.not_to be_valid }
- end
- end
-end
diff --git a/spree/core/spec/models/spree/promotion_handler/cart_spec.rb b/spree/core/spec/models/spree/promotion_handler/cart_spec.rb
index ad0f18aee9..9ded49a898 100644
--- a/spree/core/spec/models/spree/promotion_handler/cart_spec.rb
+++ b/spree/core/spec/models/spree/promotion_handler/cart_spec.rb
@@ -11,18 +11,18 @@ module Spree
let(:promotion) { create(:promotion, name: 'At line items', store: order.store, kind: :automatic) }
let(:calculator) { Calculator::FlatPercentItemTotal.new(preferred_flat_percent: 10) }
+ shared_context 'creates the adjustment' do
+ it 'creates the adjustment' do
+ expect do
+ subject.activate
+ end.to change { adjustable.discounts.count }.by(1)
+ end
+ end
+
context 'activates in LineItem level' do
let!(:action) { Promotion::Actions::CreateItemAdjustments.create(promotion: promotion, calculator: calculator) }
let(:adjustable) { line_item }
- shared_context 'creates the adjustment' do
- it 'creates the adjustment' do
- expect do
- subject.activate
- end.to change { adjustable.discounts.count }.by(1)
- end
- end
-
context 'promotion with no rules' do
include_context 'creates the adjustment'
end
@@ -34,7 +34,6 @@ module Spree
end
context 'promotion has item total rule' do
- let(:shirt) { create(:product, store: order.store) }
let!(:rule) { Promotion::Rules::ItemTotal.create(preferred_operator_min: 'gt', preferred_amount_min: 50, preferred_operator_max: 'lt', preferred_amount_max: 150, promotion: promotion) }
before do
@@ -51,14 +50,6 @@ module Spree
let!(:action) { Promotion::Actions::CreateAdjustment.create(promotion: promotion, calculator: calculator) }
let(:adjustable) { order }
- shared_context 'creates the adjustment' do
- it 'creates the adjustment' do
- expect do
- subject.activate
- end.to change { adjustable.discounts.count }.by(1)
- end
- end
-
context 'promotion with no rules' do
before do
# Gives the calculator something to discount
@@ -70,7 +61,6 @@ module Spree
end
context 'promotion has item total rule' do
- let(:shirt) { create(:product, store: order.store) }
let!(:rule) { Promotion::Rules::ItemTotal.create(preferred_operator_min: 'gt', preferred_amount_min: 50, preferred_operator_max: 'lt', preferred_amount_max: 150, promotion: promotion) }
before do
diff --git a/spree/core/spec/models/spree/promotion_handler/coupon_spec.rb b/spree/core/spec/models/spree/promotion_handler/coupon_spec.rb
index f219a36e2e..73a1e92b08 100644
--- a/spree/core/spec/models/spree/promotion_handler/coupon_spec.rb
+++ b/spree/core/spec/models/spree/promotion_handler/coupon_spec.rb
@@ -8,46 +8,6 @@ module Spree
let(:store) { @default_store }
let(:order) { double('Order', coupon_code: '10off', store: store).as_null_object }
- it 'returns self in apply' do
- expect(subject.apply).to be_a Coupon
- end
-
- context 'status messages' do
- let(:coupon) { Coupon.new(order) }
-
- describe '#set_success_code' do
- subject { coupon.set_success_code status }
-
- let(:status) { :coupon_code_applied }
-
- it 'has status_code' do
- subject
- expect(coupon.status_code).to eq(status)
- end
-
- it 'has success message' do
- subject
- expect(coupon.success).to eq(I18n.t("spree.#{status}"))
- end
- end
-
- describe '#set_error_code' do
- subject { coupon.set_error_code status }
-
- let(:status) { :coupon_code_not_found }
-
- it 'has status_code' do
- subject
- expect(coupon.status_code).to eq(status)
- end
-
- it 'has error message' do
- subject
- expect(coupon.error).to eq(I18n.t("spree.#{status}"))
- end
- end
- end
-
context 'coupon code promotion doesnt exist' do
before { create(:promotion, name: 'promo', code: nil, kind: :automatic) }
@@ -90,11 +50,6 @@ module Spree
expect(order.reload.total).to eq(100)
end
- it 'calls recalculate_totals!' do
- expect(order).to receive(:recalculate_totals!)
- subject.apply
- end
-
it 'coupon already applied to the order' do
subject.apply
expect(subject.success).to be_present
@@ -155,13 +110,6 @@ module Spree
expect(order.fulfillment_discounts.count).to eq(1)
end
-
- it 'coupon already applied to the order' do
- subject.apply
- expect(subject.success).to be_present
- subject.apply
- expect(subject.error).to eq I18n.t('spree.coupon_code_already_applied')
- end
end
end
@@ -183,32 +131,12 @@ module Spree
expect(order.discounts.sum(:amount)).to eq(-10)
end
- it 'coupon already applied to the order' do
- subject.apply
- expect(subject.success).to be_present
- subject.apply
- expect(subject.error).to eq I18n.t('spree.coupon_code_already_applied')
- end
-
it 'coupon fails to activate' do
allow_any_instance_of(Spree::Promotion).to receive(:activate).and_return false
subject.apply
expect(subject.error).to eq I18n.t('spree.coupon_code_unknown_error')
end
- it 'coupon code hit max usage' do
- promotion.update_column(:usage_limit, 1)
- subject.apply
- expect(subject.successful?).to be true
-
- order_2 = create(:order, store: store)
- allow(order_2).to receive_messages coupon_code: '10off'
- coupon = Coupon.new(order_2)
- coupon.apply
- expect(coupon.successful?).to be false
- expect(coupon.error).to eq I18n.t('spree.coupon_code_max_usage')
- end
-
context 'when the a new coupon is less good' do
let!(:promotion_5) { create(:promotion, :with_order_adjustment, weighted_order_adjustment_amount: 5, name: 'promo', code: '5off') }
@@ -332,13 +260,6 @@ module Spree
expect(order.reload.total).to eq(100)
end
- it 'coupon already applied to the order' do
- subject.apply
- expect(subject.success).to be_present
- subject.apply
- expect(subject.error).to eq I18n.t('spree.coupon_code_already_applied')
- end
-
context 'with used coupon code' do
before { coupon_code.update!(state: :used) }
@@ -503,31 +424,6 @@ module Spree
calculator: calculator)
end
- shared_examples 'allows to use coupon code one time only' do |coupon_code|
- before do
- order.coupon_code = coupon_code
- order_2.coupon_code = coupon_code
- end
-
- it do
- subject.apply
- expect(subject.successful?).to be true
- # Simulate the order has been completed so the coupon code is marked as used
- Spree::CouponCodes::CouponCodesHandler.new(order: order).use_all_codes
-
- coupon = Spree::CouponCode.find_by(code: coupon_code)
- expect(coupon.state).to eq 'used'
- expect(coupon.order).to eq order
-
- subject_2.apply
- expect(subject_2.successful?).to be false
- expect(subject_2.error).to eq I18n.t('spree.coupon_code_used')
- end
- end
-
- it_behaves_like 'allows to use coupon code one time only', 'first_one_time_code'
- it_behaves_like 'allows to use coupon code one time only', 'second_one_time_code'
-
it 'promotion can be used as many times as it has coupon codes' do
order.coupon_code = 'first_one_time_code'
subject.apply
diff --git a/spree/core/spec/models/spree/promotion_handler/coupon_with_gift_card_spec.rb b/spree/core/spec/models/spree/promotion_handler/coupon_with_gift_card_spec.rb
index fab70dbb8b..8e3d9074e2 100644
--- a/spree/core/spec/models/spree/promotion_handler/coupon_with_gift_card_spec.rb
+++ b/spree/core/spec/models/spree/promotion_handler/coupon_with_gift_card_spec.rb
@@ -190,16 +190,6 @@ describe Spree::PromotionHandler::Coupon, type: :model do
expect(order.reload.gift_card).to eq(gift_card)
end
end
-
- context 'when enable_gift_cards is not specified (default)' do
- it 'applies gift card for backwards compatibility' do
- order.coupon_code = gift_card.code
- handler = described_class.new(order)
- handler.apply
-
- expect(order.reload.gift_card).to eq(gift_card)
- end
- end
end
describe '#remove' do
@@ -225,15 +215,6 @@ describe Spree::PromotionHandler::Coupon, type: :model do
expect(order.reload.gift_card).to be_nil
end
end
-
- context 'when enable_gift_cards is not specified (default)' do
- it 'removes gift card for backwards compatibility' do
- handler = described_class.new(order)
- handler.remove(gift_card.code)
-
- expect(order.reload.gift_card).to be_nil
- end
- end
end
end
end
diff --git a/spree/core/spec/models/spree/promotion_rule_spec.rb b/spree/core/spec/models/spree/promotion_rule_spec.rb
index 28fb39850c..bb2c88046a 100644
--- a/spree/core/spec/models/spree/promotion_rule_spec.rb
+++ b/spree/core/spec/models/spree/promotion_rule_spec.rb
@@ -15,7 +15,7 @@ module Spree
let!(:promotion) { create(:promotion) }
it 'forces developer to implement eligible? method' do
- expect { BadTestRule.new.eligible? }.to raise_error(ArgumentError)
+ expect { BadTestRule.new.eligible?(build(:order)) }.to raise_error(RuntimeError, /eligible\? should be implemented/)
end
it 'validates unique rules for a promotion' do
diff --git a/spree/core/spec/models/spree/promotion_spec.rb b/spree/core/spec/models/spree/promotion_spec.rb
index 6203354eca..3e712c4eae 100644
--- a/spree/core/spec/models/spree/promotion_spec.rb
+++ b/spree/core/spec/models/spree/promotion_spec.rb
@@ -10,23 +10,6 @@ describe Spree::Promotion, type: :model do
describe 'Validations' do
let!(:valid_promotion) { build(:promotion, name: 'A promotion', kind: :automatic) }
- it 'valid_promotion is valid' do
- expect(valid_promotion).to be_valid
- end
-
- it 'validates usage limit' do
- valid_promotion.usage_limit = -1
- expect(valid_promotion).not_to be_valid
-
- valid_promotion.usage_limit = 100
- expect(valid_promotion).to be_valid
- end
-
- it 'validates name' do
- valid_promotion.name = nil
- expect(valid_promotion).not_to be_valid
- end
-
it 'can create multiple promos with the same code' do
create(:promotion, code: 'ABC')
valid_promotion.code = 'ABC'
@@ -174,18 +157,6 @@ describe Spree::Promotion, type: :model do
promotion.save!
end
- it 'deletes actions' do
- promotion.destroy!
-
- expect(Spree::PromotionAction.count).to eq(0)
- end
-
- it 'deletes rules' do
- promotion.destroy!
-
- expect(Spree::PromotionRule.count).to eq(0)
- end
-
context 'if promotion was already used' do
it 'does not destroy the promotion' do
promotion.orders << create(:order)
@@ -240,18 +211,18 @@ describe Spree::Promotion, type: :model do
promotion = create(:promotion, code: 'ABC', multi_codes: false, kind: :coupon_code)
promotion.kind = :automatic
- promotion.save
+ promotion.save!
- expect(promotion.kind).to eq 'automatic'
+ expect(promotion.reload.kind).to eq 'automatic'
end
it 'allows to change promotion type from multiple discount codes to automatic' do
promotion = create(:promotion, multi_codes: true, number_of_codes: 10, kind: :coupon_code)
promotion.kind = :automatic
- promotion.save
+ promotion.save!
- expect(promotion.kind).to eq 'automatic'
+ expect(promotion.reload.kind).to eq 'automatic'
end
end
@@ -359,12 +330,6 @@ describe Spree::Promotion, type: :model do
promotion.expires_at = Time.current + 1.day
expect(promotion).not_to be_expired
end
-
- it 'is not expired if usage limit is not exceeded' do
- promotion.usage_limit = 2
- allow(promotion).to receive_messages(credits_count: 1)
- expect(promotion).not_to be_expired
- end
end
context '#credits_count' do
@@ -907,12 +872,6 @@ describe Spree::Promotion, type: :model do
expect(promotion.code).not_to eq 'spree123'
end
end
-
- context 'without generate_code' do
- it 'has a generated code' do
- expect(promotion.code).to eq 'spree123'
- end
- end
end
describe '#generate_coupon_codes' do
@@ -1040,7 +999,7 @@ describe Spree::Promotion, type: :model do
rule = promotion.rules.first
expect(rule).to be_a(Spree::Promotion::Rules::Category)
- expect(rule.taxons).to contain_exactly(category)
+ expect(rule.categories).to contain_exactly(category)
end
# Regression: `category_ids=` on Rules::Taxon is a custom setter (not a
@@ -1054,7 +1013,7 @@ describe Spree::Promotion, type: :model do
rule = fresh.reload.rules.first
expect(rule).to be_a(Spree::Promotion::Rules::Category)
- expect(rule.taxons).to contain_exactly(category)
+ expect(rule.categories).to contain_exactly(category)
end
it 'defers application until after_save on a new promotion record' do
diff --git a/spree/core/spec/models/spree/promotion_tax_recalculation_spec.rb b/spree/core/spec/models/spree/promotion_tax_recalculation_spec.rb
index b89fa1f1b6..b6f4c375f2 100644
--- a/spree/core/spec/models/spree/promotion_tax_recalculation_spec.rb
+++ b/spree/core/spec/models/spree/promotion_tax_recalculation_spec.rb
@@ -16,7 +16,7 @@ describe 'Promotion discounts and the taxable basis', type: :model do
# Lazy on purpose: the tax rate must exist before the line item is created,
# because Spree only creates tax adjustments from LineItem#update_tax_charge.
# Each tax-mode context forces it in a before hook after its tax rate.
- let(:line_item) { create(:line_item, order: order, variant: product.master, price: item_price, quantity: 1) }
+ let(:line_item) { create(:line_item, order: order, variant: product.default_variant, price: item_price, quantity: 1) }
def build_cart!
line_item
@@ -85,7 +85,7 @@ describe 'Promotion discounts and the taxable basis', type: :model do
it 'computes tax on the discounted amount' do
apply_coupon!
- expect(order.promo_total).to eq(-125.00)
+ expect(order.discount_total).to eq(-125.00)
expect(order.additional_tax_total).to eq(12.50)
expect(order.total).to eq(137.50)
end
@@ -97,7 +97,7 @@ describe 'Promotion discounts and the taxable basis', type: :model do
it 'computes tax on the discounted amount' do
apply_coupon!
- expect(order.promo_total).to eq(-50.00)
+ expect(order.discount_total).to eq(-50.00)
expect(order.additional_tax_total).to eq(20.00)
expect(order.total).to eq(220.00)
end
@@ -109,7 +109,7 @@ describe 'Promotion discounts and the taxable basis', type: :model do
it 'computes tax on the discounted amount' do
apply_coupon!
- expect(order.promo_total).to eq(-125.00)
+ expect(order.discount_total).to eq(-125.00)
expect(order.additional_tax_total).to eq(12.50)
expect(order.total).to eq(137.50)
end
@@ -129,7 +129,7 @@ describe 'Promotion discounts and the taxable basis', type: :model do
it 'computes tax on the discounted amount' do
apply_coupon!
- expect(order.promo_total).to eq(-50.00)
+ expect(order.discount_total).to eq(-50.00)
expect(order.additional_tax_total).to eq(20.00)
expect(order.total).to eq(220.00)
end
@@ -138,7 +138,7 @@ describe 'Promotion discounts and the taxable basis', type: :model do
context 'with a whole-order promotion and several line items' do
let(:other_product) { create(:product, price: 150, tax_category: tax_category, store: store) }
let!(:other_line_item) do
- create(:line_item, order: order, variant: other_product.master, price: 150, quantity: 1)
+ create(:line_item, order: order, variant: other_product.default_variant, price: 150, quantity: 1)
end
let!(:promotion) { whole_order_promotion(flat_calculator(80)) }
@@ -173,7 +173,7 @@ describe 'Promotion discounts and the taxable basis', type: :model do
it 'reports VAT on the discounted amount' do
apply_coupon!
- expect(order.promo_total).to eq(-175.00)
+ expect(order.discount_total).to eq(-175.00)
expect(order.included_tax_total).to eq(29.17)
expect(order.total).to eq(175.00)
end
@@ -193,7 +193,7 @@ describe 'Promotion discounts and the taxable basis', type: :model do
it 'reports VAT on the discounted amount' do
apply_coupon!
- expect(order.promo_total).to eq(-50.00)
+ expect(order.discount_total).to eq(-50.00)
expect(order.included_tax_total).to eq(50.00)
expect(order.total).to eq(300.00)
end
@@ -205,7 +205,7 @@ describe 'Promotion discounts and the taxable basis', type: :model do
it 'reports VAT on the discounted amount' do
apply_coupon!
- expect(order.promo_total).to eq(-175.00)
+ expect(order.discount_total).to eq(-175.00)
expect(order.included_tax_total).to eq(29.17)
expect(order.total).to eq(175.00)
end
@@ -225,7 +225,7 @@ describe 'Promotion discounts and the taxable basis', type: :model do
it 'reports VAT on the discounted amount' do
apply_coupon!
- expect(order.promo_total).to eq(-50.00)
+ expect(order.discount_total).to eq(-50.00)
expect(order.included_tax_total).to eq(50.00)
expect(order.total).to eq(300.00)
end
@@ -239,7 +239,7 @@ describe 'Promotion discounts and the taxable basis', type: :model do
Spree::PromotionHandler::Coupon.new(order).remove('DISCOUNT')
order.reload
- expect(order.promo_total).to eq(0)
+ expect(order.discount_total).to eq(0)
expect(order.included_tax_total).to eq(58.33)
expect(order.total).to eq(350.00)
end
diff --git a/spree/core/spec/models/spree/purchase/freight_spec.rb b/spree/core/spec/models/spree/purchase/freight_spec.rb
index 0d4790cf40..cc255b05b9 100644
--- a/spree/core/spec/models/spree/purchase/freight_spec.rb
+++ b/spree/core/spec/models/spree/purchase/freight_spec.rb
@@ -23,13 +23,6 @@ RSpec.describe Spree::Purchase::Freight do
metadata: { 'freight_summary' => snapshot })
end
- it 'reads what the selected freight rate froze' do
- create(:line_item, cart: cart, order: nil, variant: variant, quantity: 24)
- select_freight_rate(cart, snapshot)
-
- expect(cart.reload.freight_summary.total_cartons).to eq(2)
- end
-
# Items with carton data are not a freight shipment until a freight rate
# says so — a retail basket of measured goods reports nothing.
it 'has none before a freight rate is selected' do
diff --git a/spree/core/spec/models/spree/refresh_token_spec.rb b/spree/core/spec/models/spree/refresh_token_spec.rb
index 252eaf4e86..39c743b361 100644
--- a/spree/core/spec/models/spree/refresh_token_spec.rb
+++ b/spree/core/spec/models/spree/refresh_token_spec.rb
@@ -4,25 +4,6 @@ RSpec.describe Spree::RefreshToken, type: :model do
let(:user) { create(:user) }
describe 'validations' do
- it 'requires a user' do
- token = described_class.new(expires_at: 30.days.from_now)
- token.valid?
- expect(token.errors[:user]).to be_present
- end
-
- it 'requires expires_at' do
- token = described_class.new(user: user)
- # has_secure_token generates token automatically
- token.valid?
- expect(token.errors[:expires_at]).to be_present
- end
-
- it 'auto-generates a token via has_secure_token' do
- token = described_class.create!(user: user, audience: 'store_api', expires_at: 30.days.from_now)
- expect(token.token).to be_present
- expect(token.token.length).to be >= 24
- end
-
it 'requires an audience on create' do
token = described_class.new(user: user, expires_at: 30.days.from_now)
@@ -83,29 +64,16 @@ RSpec.describe Spree::RefreshToken, type: :model do
describe '#rotate!' do
let!(:original_token) { described_class.create_for(user, audience: 'store_api') }
- it 'destroys the original token' do
- original_id = original_token.id
- original_token.rotate!
- expect(described_class.find_by(id: original_id)).to be_nil
- end
+ it 'replaces the original token with a new one for the same user' do
+ new_token = nil
+ expect { new_token = original_token.rotate! }.not_to change(described_class, :count)
- it 'creates a new token' do
- new_token = original_token.rotate!
+ expect(described_class.find_by(id: original_token.id)).to be_nil
expect(new_token).to be_persisted
expect(new_token.token).not_to eq(original_token.token)
- end
-
- it 'preserves the user' do
- new_token = original_token.rotate!
expect(new_token.user).to eq(user)
end
- it 'keeps total count the same' do
- expect {
- original_token.rotate!
- }.not_to change(described_class, :count)
- end
-
it 'accepts new request env' do
new_token = original_token.rotate!(request_env: {
ip_address: '10.0.0.1',
@@ -172,11 +140,4 @@ RSpec.describe Spree::RefreshToken, type: :model do
expect(described_class.find_by(id: expired.id)).to be_nil
end
end
-
- describe 'prefixed_id' do
- it 'uses rt_ prefix' do
- token = described_class.create_for(user, audience: 'store_api')
- expect(token.prefixed_id).to start_with('rt_')
- end
- end
end
diff --git a/spree/core/spec/models/spree/return_spec.rb b/spree/core/spec/models/spree/return_spec.rb
index 126ca3ac8c..dda9df0401 100644
--- a/spree/core/spec/models/spree/return_spec.rb
+++ b/spree/core/spec/models/spree/return_spec.rb
@@ -7,10 +7,6 @@ RSpec.describe Spree::Return do
expect(create(:return, store: store).number).to start_with('RET')
end
- it 'starts as requested' do
- expect(create(:return, store: store)).to be_requested
- end
-
it 'requires at least one line item on create' do
order = create(:shipped_order, store: store)
record = described_class.new(
@@ -24,12 +20,6 @@ RSpec.describe Spree::Return do
expect(record.errors[:return_line_items]).to be_present
end
- it 'is reachable from its order' do
- return_record = create(:return, store: store)
-
- expect(return_record.order.reload.returns).to include(return_record)
- end
-
describe 'totals' do
let(:return_record) { create(:return, store: store) }
@@ -141,10 +131,6 @@ RSpec.describe Spree::Return do
expect(line).not_to be_valid
end
- it 'starts with nothing received' do
- expect(line.received_quantity).to eq(0)
- end
-
# Nothing has been counted yet, so what the customer announced is the only
# measure of what the return will cost.
it 'is owed the announced amount until the warehouse has counted' do
diff --git a/spree/core/spec/models/spree/role_spec.rb b/spree/core/spec/models/spree/role_spec.rb
index 56ccb7af43..83057b85f0 100644
--- a/spree/core/spec/models/spree/role_spec.rb
+++ b/spree/core/spec/models/spree/role_spec.rb
@@ -7,16 +7,6 @@ describe Spree::Role do
# lands: what matters is that the role is owned by something else.
let(:seller_like) { create(:customer_group) }
- describe 'with users' do
- before do
- user.spree_roles << role
- end
-
- it 'can access users through the polymorphic association' do
- expect(role.users).to include(user)
- end
- end
-
describe '.default_admin_role' do
it 'returns the admin role, seeded immutable' do
admin_role = Spree::Role.default_admin_role(@default_store)
@@ -36,6 +26,9 @@ describe Spree::Role do
expect(admin_role).to be_staff
expect(foreign_admin).not_to be_admin
expect(foreign_admin).to be_mutable
+
+ foreign_admin.name = 'renamed'
+ expect(foreign_admin).to be_valid
end
# "admin" means everything in *this* store, so it cannot be one shared row.
@@ -84,10 +77,6 @@ describe Spree::Role do
expect(build(:role, resource: seller_like)).not_to be_staff
end
- it 'is required' do
- expect(build(:role, resource: nil)).not_to be_valid
- end
-
it 'cannot be changed once the role exists' do
role = create(:role)
role.resource = create(:store)
@@ -103,12 +92,6 @@ describe Spree::Role do
expect(build(:role, name: 'Manager', resource: create(:store))).to be_valid
end
- it 'still rejects a duplicate name under one owner' do
- create(:role, name: 'Manager', resource: seller_like)
-
- expect(build(:role, name: 'Manager', resource: seller_like)).not_to be_valid
- end
-
it 'scopes roles to their owner' do
staff_role = create(:role)
other_role = create(:role, resource: seller_like)
@@ -162,10 +145,6 @@ describe Spree::Role do
describe 'admin role protection' do
let(:admin_role) { Spree::Role.default_admin_role }
- it 'is not mutable' do
- expect(admin_role.mutable?).to be false
- end
-
it 'cannot be renamed' do
admin_role.name = 'renamed'
@@ -179,16 +158,6 @@ describe Spree::Role do
expect(admin_role).not_to be_valid
end
- # The protection is the store's super-role, not the name: another resource
- # may call a role "admin" and it stays an ordinary, editable role.
- it 'leaves a same-named role owned by something else editable' do
- foreign_admin = create(:role, name: 'admin', resource: seller_like)
- foreign_admin.name = 'renamed'
-
- expect(foreign_admin).to be_mutable
- expect(foreign_admin).to be_valid
- end
-
it 'cannot be destroyed' do
expect(admin_role.destroy).to be false
expect(admin_role.errors[:base]).to be_present
@@ -254,9 +223,5 @@ describe Spree::Role do
expect(role.can_be_deleted?).to be false
end
-
- it 'is false for the admin role' do
- expect(Spree::Role.default_admin_role.can_be_deleted?).to be false
- end
end
end
diff --git a/spree/core/spec/models/spree/role_user_spec.rb b/spree/core/spec/models/spree/role_user_spec.rb
index e1338d3130..5e5c5b161d 100644
--- a/spree/core/spec/models/spree/role_user_spec.rb
+++ b/spree/core/spec/models/spree/role_user_spec.rb
@@ -16,8 +16,6 @@ describe Spree::RoleUser do
spree_role_user = described_class.create!(role: role, user: spree_user)
admin_role_user = described_class.create!(role: role, user: admin_user)
- expect(spree_user).not_to eq(admin_user)
-
expect(spree_role_user.user).to eq(spree_user)
expect(spree_role_user.user_type).to eq(spree_user.class.to_s)
@@ -37,25 +35,12 @@ describe Spree::RoleUser do
end
describe 'uniqueness' do
- it 'allows a user to hold a role once' do
- create(:role_user, role: role, user: spree_user)
-
- expect(described_class.new(role: role, user: spree_user)).not_to be_valid
- end
-
- it 'allows the same user to hold a role owned by another resource' do
+ it 'allows a user to hold a role once, but the same-named role of another resource too' do
create(:role_user, role: role, user: spree_user)
other_role = create(:role, name: 'test_role', resource: create(:store))
+ expect(described_class.new(role: role, user: spree_user)).not_to be_valid
expect(described_class.new(role: other_role, user: spree_user)).to be_valid
end
end
-
- describe '#name' do
- it 'returns the name of the user' do
- role_user = described_class.new(role: role, user: spree_user)
-
- expect(role_user.name).to eq(spree_user.name)
- end
- end
end
diff --git a/spree/core/spec/models/spree/search_provider/base_spec.rb b/spree/core/spec/models/spree/search_provider/base_spec.rb
index 58eee95ad9..0f7fd7db07 100644
--- a/spree/core/spec/models/spree/search_provider/base_spec.rb
+++ b/spree/core/spec/models/spree/search_provider/base_spec.rb
@@ -5,40 +5,10 @@ module Spree
let(:store) { @default_store }
let(:provider) { described_class.new(store) }
- describe '#initialize' do
- it 'stores the store' do
- expect(provider.store).to eq(store)
- end
- end
-
describe '#search_and_filter' do
it 'raises NotImplementedError' do
expect { provider.search_and_filter(scope: Spree::Product.all) }.to raise_error(NotImplementedError)
end
end
-
- describe '#index' do
- it 'is a no-op by default' do
- expect { provider.index(build(:product)) }.not_to raise_error
- end
- end
-
- describe '#remove' do
- it 'is a no-op by default' do
- expect { provider.remove(build(:product)) }.not_to raise_error
- end
- end
-
- describe '#remove_by_id' do
- it 'is a no-op by default' do
- expect { provider.remove_by_id(1) }.not_to raise_error
- end
- end
-
- describe '#reindex' do
- it 'is a no-op by default' do
- expect { provider.reindex }.not_to raise_error
- end
- end
end
end
diff --git a/spree/core/spec/models/spree/search_provider/database_spec.rb b/spree/core/spec/models/spree/search_provider/database_spec.rb
index c8113d2871..d971521c9f 100644
--- a/spree/core/spec/models/spree/search_provider/database_spec.rb
+++ b/spree/core/spec/models/spree/search_provider/database_spec.rb
@@ -5,9 +5,9 @@ module Spree
let(:store) { @default_store }
let(:provider) { described_class.new(store) }
- let!(:product_1) { create(:product, name: 'Blue Shirt') }
- let!(:product_2) { create(:product, name: 'Red Pants') }
- let!(:product_3) { create(:product, name: 'Blue Jacket') }
+ let!(:product_1) { create(:product, name: 'Blue Shirt', price: 30) }
+ let!(:product_2) { create(:product, name: 'Red Pants', price: 10) }
+ let!(:product_3) { create(:product, name: 'Blue Jacket', price: 20) }
describe '#search_and_filter' do
let(:scope) { store.products }
@@ -94,8 +94,8 @@ module Spree
context 'with custom price sort' do
subject(:result) { provider.search_and_filter(scope: scope, sort: 'price') }
- it 'returns all products' do
- expect(result.total_count).to eq(3)
+ it 'sorts by price ascending' do
+ expect(result.products.to_a).to eq([product_2, product_3, product_1])
end
end
@@ -490,30 +490,5 @@ module Spree
end
end
end
-
- describe '#index' do
- it 'is a no-op' do
- expect { provider.index(product_1) }.not_to raise_error
- end
- end
-
- describe '#remove' do
- it 'is a no-op' do
- expect { provider.remove(product_1) }.not_to raise_error
- end
- end
-
- describe '#remove_by_id' do
- it 'is a no-op' do
- expect { provider.remove_by_id(product_1.id) }.not_to raise_error
- end
- end
-
- describe '#reindex' do
- it 'is a no-op' do
- expect { provider.reindex(store.products) }.not_to raise_error
- end
- end
-
end
end
diff --git a/spree/core/spec/models/spree/seller_spec.rb b/spree/core/spec/models/spree/seller_spec.rb
index e912c17dda..fe4b059b0b 100644
--- a/spree/core/spec/models/spree/seller_spec.rb
+++ b/spree/core/spec/models/spree/seller_spec.rb
@@ -3,27 +3,6 @@ require 'spec_helper'
describe Spree::Seller do
let(:store) { @default_store }
- describe 'statuses' do
- it 'starts pending and moves only through workflows' do
- expect(described_class.default_status).to eq('pending')
- expect(described_class.statuses).to include('approved', 'suspended', 'rejected')
- # A state machine would have generated these; the absence is the point.
- expect(described_class).not_to respond_to(:state_machines)
- end
-
- it 'generates a predicate and a scope per status' do
- seller = create(:seller, :approved)
-
- expect(seller).to be_approved
- expect(seller).not_to be_pending
- expect(described_class.approved).to include(seller)
- end
-
- it 'rejects an unknown status' do
- expect(build(:seller, status: 'flourishing')).not_to be_valid
- end
- end
-
describe 'slug' do
it 'derives from the name when absent' do
expect(create(:seller, name: 'Bright Sparks Ltd').slug).to eq('bright-sparks-ltd')
@@ -33,15 +12,10 @@ describe Spree::Seller do
expect(create(:seller, name: 'Bright Sparks', slug: 'sparks').slug).to eq('sparks')
end
- it 'is unique within a store' do
+ it 'is unique within a store but may repeat on another' do
create(:seller, slug: 'sparks', store: store)
expect(build(:seller, slug: 'sparks', store: store)).not_to be_valid
- end
-
- it 'may repeat on another store' do
- create(:seller, slug: 'sparks', store: store)
-
expect(build(:seller, slug: 'sparks', store: create(:store))).to be_valid
end
end
@@ -182,9 +156,7 @@ describe Spree::Seller do
end
describe 'settlement configuration' do
- it 'defaults to the seller remitting its own tax' do
- expect(create(:seller).tax_remittance).to eq('seller')
- end
+ let(:seller) { create(:seller, :approved, store: store) }
it 'rejects an unknown remittance or interval' do
expect(build(:seller, tax_remittance: 'someone_else')).not_to be_valid
@@ -195,6 +167,18 @@ describe Spree::Seller do
it 'allows both to be unset' do
expect(build(:seller, payouts_schedule_interval: nil, minimum_payout_amount: nil)).to be_valid
end
+
+ it 'falls back to the store’s schedule and threshold' do
+ expect(seller.resolved_payouts_schedule_interval).to eq('monthly')
+ expect(seller.resolved_minimum_payout_amount).to eq(0)
+ end
+
+ it 'prefers its own once it deviates' do
+ seller.update!(payouts_schedule_interval: 'weekly', minimum_payout_amount: 25)
+
+ expect(seller.resolved_payouts_schedule_interval).to eq('weekly')
+ expect(seller.resolved_minimum_payout_amount).to eq(25)
+ end
end
describe 'addresses' do
@@ -271,7 +255,6 @@ describe Spree::Seller do
end
describe 'onboarding progress' do
- let(:store) { @default_store }
let(:seller) { create(:seller, :onboarding, store: store) }
before { store.seller_requirements.destroy_all }
@@ -349,7 +332,6 @@ describe Spree::Seller do
end
describe '#balance' do
- let(:store) { @default_store }
let(:seller) { create(:seller, :approved, store: store) }
def earn(amount, currency: 'USD', status: 'completed')
@@ -424,22 +406,6 @@ describe Spree::Seller do
end
end
- describe 'settlement configuration' do
- let(:store) { @default_store }
- let(:seller) { create(:seller, :approved, store: store) }
-
- it 'falls back to the store’s schedule and threshold' do
- expect(seller.resolved_payouts_schedule_interval).to eq('monthly')
- expect(seller.resolved_minimum_payout_amount).to eq(0)
- end
-
- it 'prefers its own once it deviates' do
- seller.update!(payouts_schedule_interval: 'weekly', minimum_payout_amount: 25)
-
- expect(seller.resolved_payouts_schedule_interval).to eq('weekly')
- expect(seller.resolved_minimum_payout_amount).to eq(25)
- end
- end
# The seller's identity in the system that pays them — recorded where every
# other external identity is, rather than in a column of its own.
describe 'the payout account' do
diff --git a/spree/core/spec/models/spree/shipment_spec.rb b/spree/core/spec/models/spree/shipment_spec.rb
index 3395b38f48..4a8747e823 100644
--- a/spree/core/spec/models/spree/shipment_spec.rb
+++ b/spree/core/spec/models/spree/shipment_spec.rb
@@ -18,22 +18,10 @@ describe Spree::Fulfillment, type: :model do
before do
allow(order).to receive_messages(backordered?: false, canceled?: false, can_ship?: true, paid?: false, touch_later: false)
- allow(inventory_units.first).to receive_messages backordered?: false
- allow(inventory_units.first).to receive_messages backordered?: true
end
it_behaves_like 'metadata'
- describe 'precision of pre_tax_amount' do
- before { line_item.update(pre_tax_amount: 4.2051) }
-
- it 'keeps four digits of precision even when reloading' do
- # prevent it from updating pre_tax_amount
- allow_any_instance_of(Spree::LineItem).to receive(:update_tax_charge)
- expect(line_item.reload.pre_tax_amount).to eq(4.2051)
- end
- end
-
describe '#digital?' do
it 'returns true if the delivery method is digital' do
shipment.delivery_method.fulfillment_provider = 'Spree::FulfillmentProvider::Digital'
@@ -59,20 +47,6 @@ describe Spree::Fulfillment, type: :model do
end
end
- describe '#tracked?' do
- it 'returns true if the shipment is tracked' do
- expect(shipment.tracked?).to eq(true)
- end
-
- context 'when the shipment is not tracked' do
- let(:shipment) { build(:fulfillment, number: nil, tracking: nil) }
-
- it 'returns false' do
- expect(shipment.tracked?).to eq(false)
- end
- end
- end
-
describe '#partial?' do
subject { shipment.partial? }
@@ -94,34 +68,13 @@ describe Spree::Fulfillment, type: :model do
end
end
- # Regression test for #4063
- context 'number generation' do
- let(:shipment) { create(:fulfillment, stock_location: create(:stock_location)) }
-
- before do
- allow(order).to receive :recalculate_totals!
- end
-
- it 'derives the number from the order it belongs to' do
- expect(shipment.number).to eq("#{shipment.order.number}-F1")
- end
- end
-
it 'is backordered if one if its inventory_units is backordered' do
+ allow(inventory_units.first).to receive_messages backordered?: true
allow(shipment).to receive_messages(fulfillment_items: inventory_units)
expect(shipment).to be_backordered
end
describe 'status' do
- it 'starts unfulfilled' do
- expect(create(:fulfillment).status).to eq('unfulfilled')
- end
-
- it 'rejects a status outside the vocabulary' do
- shipment.status = 'ready'
- expect(shipment).not_to be_valid
- end
-
# The payment-derived pending/ready split is gone: whether the order is
# paid is asked when someone tries to hand the goods over, not baked into
# the fulfillment's own status where a refund could move it backwards.
@@ -204,11 +157,6 @@ describe Spree::Fulfillment, type: :model do
expect(shipment.tracking_url).to be_nil
expect(shipment).not_to be_tracked
end
-
- it 'has no carrier axis of its own' do
- expect(shipment).not_to respond_to(:tracking_status)
- expect(shipment).not_to respond_to(:tracking_carrier)
- end
end
context 'display_amount' do
@@ -529,10 +477,10 @@ describe Spree::Fulfillment, type: :model do
]
end
- it 'returns shipping_method from selected shipping_rate' do
+ it 'returns the delivery method from the selected rate' do
shipment.shipping_rates.delete_all
shipment.shipping_rates.create shipping_method: shipping_method1, cost: 10.00, selected: true
- expect(shipment.shipping_method).to eq shipping_method1
+ expect(shipment.delivery_method).to eq shipping_method1
end
context 'carry_over_selection' do
@@ -666,11 +614,6 @@ describe Spree::Fulfillment, type: :model do
expect { shipment.update!(order) }.not_to change { shipment.reload.status }
end
-
- it 'still writes attributes through ActiveRecord' do
- shipment.update!(tracking: 'XYZ')
- expect(shipment.reload.tracking).to eq('XYZ')
- end
end
context 'when order is completed' do
@@ -701,16 +644,6 @@ describe Spree::Fulfillment, type: :model do
describe '#cancel' do
let(:inventory_unit) { create(:fulfillment_item, state: 'on_hand', line_item: line_item, variant: variant, quantity: 1) }
- # Restocking is no longer a transition callback — it belongs to
- # Spree::Fulfillments::Cancel, so the event only moves the status.
- it 'cancels the shipment' do
- allow(shipment.order).to receive(:recalculate_totals!)
-
- shipment.status = 'unfulfilled'
- described_class.transaction { shipment.update!(status: 'canceled') }
- expect(shipment.status).to eq 'canceled'
- end
-
# Withdrawing the promise belongs to Spree::Fulfillments::Cancel now; the
# deprecated shell is all that survives on the model. Covered by
# spec/workflows/spree/fulfillments/cancel_spec.rb.
@@ -721,6 +654,7 @@ describe Spree::Fulfillment, type: :model do
allow(shipment).to receive(:allocated_quantities).and_return(variant.id => 1)
shipment.stock_location = create(:stock_location)
expect(shipment.stock_location).to receive(:release).with(variant, 1, shipment)
+ expect(Spree::Deprecation).to receive(:warn).with(/after_cancel is deprecated/)
shipment.after_cancel
end
@@ -729,7 +663,7 @@ describe Spree::Fulfillment, type: :model do
allow(shipment).to receive(:provider).and_return(instance_double(Spree::FulfillmentProvider::Manual, cancel_fulfillment: true))
shipment.stock_location = create(:stock_location)
expect(shipment.stock_location).not_to receive(:release)
- shipment.after_cancel
+ Spree::Deprecation.silence { shipment.after_cancel }
end
context 'with backordered inventory units' do
@@ -741,7 +675,7 @@ describe Spree::Fulfillment, type: :model do
Spree::Orders::AddItem.call(order: order, variant: variant)
order.rebuild_fulfillments!
- Spree::Carts::AddItem.call(order: other_order, variant: variant)
+ Spree::Orders::AddItem.call(order: other_order, variant: variant)
other_order.rebuild_fulfillments!
end
@@ -762,24 +696,6 @@ describe Spree::Fulfillment, type: :model do
end
describe '#ship' do
- context 'when the shipment is canceled' do
- let(:shipment_with_inventory_units) { create(:fulfillment, order: create(:order_with_line_items), state: 'canceled') }
- let(:subject) { shipment_with_inventory_units.update!(status: 'fulfilled') }
-
- before do
- allow(order).to receive(:recalculate_totals!)
- allow(shipment_with_inventory_units).to receive_messages(require_inventory: false, update_order: true)
- end
-
- # Taking the units back off the shelf moved to
- # Spree::Fulfillments::Fulfill, so the bare transition no longer does it.
- # See spec/workflows/spree/fulfillments/fulfill_spec.rb for the behavior.
- it 'does not unstock on the bare transition' do
- expect(shipment_with_inventory_units.stock_location).not_to receive(:unstock)
- subject
- end
- end
-
context 'from unfulfilled' do
let(:paid_order) { create(:order_ready_to_ship) }
let(:fulfillment) { paid_order.fulfillments.first }
@@ -863,14 +779,14 @@ describe Spree::Fulfillment, type: :model do
end
it 'updates order totals when a different shipping rate is selected' do
- expect(order.shipment_total).to eq(10)
+ expect(order.delivery_total).to eq(10)
# Select the more expensive shipping rate
shipping_rate_2 = shipment.shipping_rates.find_by(shipping_method: shipping_method_2)
shipment.selected_shipping_rate_id = shipping_rate_2.id
order.reload
- expect(order.shipment_total).to eq(20)
+ expect(order.delivery_total).to eq(20)
end
it 'updates the shipment cost to match the selected shipping rate' do
@@ -993,20 +909,6 @@ describe Spree::Fulfillment, type: :model do
end
end
- context 'currency' do
- it 'returns the order currency' do
- expect(shipment.currency).to eq(order.currency)
- end
- end
-
- context 'nil costs' do
- it 'sets cost to 0' do
- shipment = Spree::Fulfillment.new
- shipment.valid?
- expect(shipment.cost).to eq 0
- end
- end
-
# Legacy writer — removed in 6.1. Host code assigning tracking the old way
# still lands it where every reader looks.
describe '#tracking= (deprecated)' do
@@ -1038,7 +940,7 @@ describe Spree::Fulfillment, type: :model do
before do
perform_enqueued_jobs(only: Spree::StockLocations::StockLevels::CreateJob)
- shipping_method = order.fulfillments.first.shipping_method
+ shipping_method = order.fulfillments.first.delivery_method
shipping_method.calculator.preferences[:amount] = order.fulfillments.first.cost
shipping_method.calculator.save!
end
@@ -1068,12 +970,12 @@ describe Spree::Fulfillment, type: :model do
expect(new_shipment.cost).to eq(shipment.cost)
end
- it 'updates `order.shipment_total` to the sum of shipments cost' do
+ it 'updates `order.delivery_total` to the sum of shipments cost' do
shipment = order.fulfillments.first
shipment.transfer_to_location(variant, 1, shipment.stock_location)
order.reload
- expect(order.shipment_total).to eq(order.shipments.sum(&:cost))
+ expect(order.delivery_total).to eq(order.shipments.sum(&:cost))
end
end
@@ -1103,14 +1005,6 @@ describe Spree::Fulfillment, type: :model do
end
end
- # Regression test for #3349
- describe '#destroy' do
- it 'destroys linked delivery_rates' do
- reflection = Spree::Fulfillment.reflect_on_association(:delivery_rates)
- expect(reflection.options[:dependent]).to be(:delete_all)
- end
- end
-
describe '.unfulfilled' do
subject { described_class.unfulfilled }
@@ -1157,12 +1051,11 @@ describe Spree::Fulfillment, type: :model do
end
end
# The deprecated writer runs after commit, so it cannot write a second
- # record from inside this one's callback chain — and a number it cannot
- # place is raised rather than dropped.
+ # record from inside this one's callback chain.
describe 'the deprecated tracking writer under conflict' do
before { allow(Spree::Deprecation).to receive(:warn) }
- it 'raises when the number is already on the parcel' do
+ it 'accepts a number another parcel already carries' do
shipment.deliveries.destroy_all
create(:delivery, owner: shipment, tracking_number: 'TAKEN-1')
second = create(:fulfillment, order: shipment.order, tracking: nil)
diff --git a/spree/core/spec/models/spree/shipping_calculator_spec.rb b/spree/core/spec/models/spree/shipping_calculator_spec.rb
index c21c5edc68..8b18b3dd1a 100644
--- a/spree/core/spec/models/spree/shipping_calculator_spec.rb
+++ b/spree/core/spec/models/spree/shipping_calculator_spec.rb
@@ -41,10 +41,6 @@ module Spree
end.to raise_error(NotImplementedError)
end
- it 'checks availability for a package' do
- expect(subject.available?(package)).to be true
- end
-
it 'calculates totals for content_items' do
expect(subject.send(:total, package.contents)).to eq 40.00
end
diff --git a/spree/core/spec/models/spree/stock/content_item_spec.rb b/spree/core/spec/models/spree/stock/content_item_spec.rb
deleted file mode 100644
index e0d1572ab1..0000000000
--- a/spree/core/spec/models/spree/stock/content_item_spec.rb
+++ /dev/null
@@ -1,26 +0,0 @@
-require 'spec_helper'
-
-describe Spree::Stock::ContentItem, type: :model do
- subject { described_class.new(inventory_unit) }
-
- let(:inventory_unit) { create(:fulfillment_item, variant: variant) }
- let(:variant) { create(:variant, weight: 25.0) }
-
- context '#volume' do
- it 'calculate the total volume of the variant' do
- expect(subject.volume).to eq variant.volume * subject.quantity
- end
- end
-
- context '#dimension' do
- it 'calculate the total dimension of the variant' do
- expect(subject.dimension).to eq variant.dimension * subject.quantity
- end
- end
-
- context '#amount' do
- it "calculates the amount based on line_item's price" do
- expect(subject.amount).to eq(inventory_unit.line_item.price * inventory_unit.quantity)
- end
- end
-end
diff --git a/spree/core/spec/models/spree/stock/coordinator_spec.rb b/spree/core/spec/models/spree/stock/coordinator_spec.rb
index c558649875..8223796317 100644
--- a/spree/core/spec/models/spree/stock/coordinator_spec.rb
+++ b/spree/core/spec/models/spree/stock/coordinator_spec.rb
@@ -150,20 +150,25 @@ module Spree
end
end
- describe '#shipments' do
+ describe '#fulfillments' do
let(:packages) { [build(:stock_package_fulfilled), build(:stock_package_fulfilled)] }
before { allow(subject).to receive(:packages).and_return(packages) }
- it 'turns packages into shipments' do
- shipments = subject.shipments
- expect(shipments.count).to eq packages.count
- expect(shipments).to all(be_a(Fulfillment))
+ it 'turns packages into fulfillments' do
+ fulfillments = subject.fulfillments
+ expect(fulfillments.count).to eq packages.count
+ expect(fulfillments).to all(be_a(Fulfillment))
end
- it "puts the order's ship address on the shipments" do
- shipments = subject.shipments
- shipments.each { |shipment| expect(shipment.address).to eq order.ship_address }
+ it "puts the order's ship address on the fulfillments" do
+ fulfillments = subject.fulfillments
+ fulfillments.each { |fulfillment| expect(fulfillment.address).to eq order.ship_address }
+ end
+
+ it 'is still returned by the deprecated #shipments' do
+ expect(Spree::Deprecation).to receive(:warn).with(/Coordinator#shipments is deprecated/)
+ expect(subject.shipments.count).to eq packages.count
end
end
diff --git a/spree/core/spec/models/spree/stock/estimator_spec.rb b/spree/core/spec/models/spree/stock/estimator_spec.rb
index 5cb3d09491..1c629712e6 100644
--- a/spree/core/spec/models/spree/stock/estimator_spec.rb
+++ b/spree/core/spec/models/spree/stock/estimator_spec.rb
@@ -171,10 +171,6 @@ module Spree
it_behaves_like 'shipping rate matches'
end
- context "when the current matches the order's currency" do
- it_behaves_like 'shipping rate matches'
- end
-
context "if the currency is different than the order's currency" do
let(:currency) { 'GBP' }
@@ -210,7 +206,7 @@ module Spree
allow(subject).to receive(:delivery_methods).and_return(shipping_methods)
- subject.delivery_rates(package)
+ expect(subject.delivery_rates(package).map { |rate| [rate.cost, rate.selected] }).to eq [[1.00, true]]
end
end
@@ -242,7 +238,7 @@ module Spree
sm.tax_category_id = tax_rate.tax_category_id
sm.save
end
- package.shipping_methods.map(&:reload)
+ package.eligible_delivery_methods.map(&:reload)
end
it 'links the shipping rate and the tax rate' do
diff --git a/spree/core/spec/models/spree/stock/package_spec.rb b/spree/core/spec/models/spree/stock/package_spec.rb
index 069c6af0c8..b1a1eb7fc0 100644
--- a/spree/core/spec/models/spree/stock/package_spec.rb
+++ b/spree/core/spec/models/spree/stock/package_spec.rb
@@ -96,14 +96,6 @@ module Spree
expect(subject.freight_summary.total_units).to eq(1)
end
- it 'applies the tare once per package, not per item' do
- create(:package_type, store: order.store, default: true, weight: 2.5, weight_unit: 'lb')
-
- subject.add build_inventory_unit
-
- expect(subject.weight).to eq(27.5)
- end
-
# A merchant may record a carton in centimetres while the store quotes
# in pounds and inches. Handing the raw numbers to a carrier reads
# centimetres as inches — a 2.54x overstatement on every axis.
@@ -198,17 +190,12 @@ module Spree
end
end
- it 'filters by on_hand and backordered' do
+ it 'filters and counts by state' do
4.times { subject.add build_inventory_unit }
3.times { subject.add build_inventory_unit, :backordered }
+
expect(subject.on_hand.count).to eq 4
expect(subject.backordered.count).to eq 3
- end
-
- it 'calculates the quantity by state' do
- 4.times { subject.add build_inventory_unit }
- 3.times { subject.add build_inventory_unit, :backordered }
-
expect(subject.quantity).to eq 7
expect(subject.quantity(:on_hand)).to eq 4
expect(subject.quantity(:backordered)).to eq 3
@@ -286,10 +273,6 @@ module Spree
it 'allows adding with a state' do
expect { subject.add_multiple [build_inventory_unit, build_inventory_unit], :backordered }.to change { subject.backordered.count }.by(2)
end
-
- it 'defaults to adding with the on hand state' do
- expect { subject.add_multiple [build_inventory_unit, build_inventory_unit] }.to change { subject.on_hand.count }.by(2)
- end
end
describe '#remove' do
@@ -352,17 +335,6 @@ module Spree
expect(imperial_package.volume).to be > metric_package.volume
end
end
-
- context '#dimension' do
- it 'calculates the sum of the dimension of all the items' do
- contents = [ContentItem.new(build(:fulfillment_item, variant: build(:variant))),
- ContentItem.new(build(:fulfillment_item, variant: build(:variant))),
- ContentItem.new(build(:fulfillment_item, variant: build(:variant))),
- ContentItem.new(build(:fulfillment_item, variant: build(:variant)))]
- package = Package.new(stock_location, contents)
- expect(package.dimension).to eq contents.sum(&:dimension)
- end
- end
end
end
end
diff --git a/spree/core/spec/models/spree/stock/quantifier_spec.rb b/spree/core/spec/models/spree/stock/quantifier_spec.rb
index 1018488e43..6d6a59208b 100644
--- a/spree/core/spec/models/spree/stock/quantifier_spec.rb
+++ b/spree/core/spec/models/spree/stock/quantifier_spec.rb
@@ -18,9 +18,6 @@ module Spree
let!(:stock_location) { create :stock_location_with_items }
let!(:stock_level) { stock_location.stock_levels.order(:id).first }
- specify { expect(subject.stock_levels).to eq([stock_level]) }
- specify { expect(subject.variant).to eq(stock_level.variant) }
-
# The quantifier answers from memory when the caller has already loaded
# the rows, and falls back to SQL when it has not. Listing endpoints
# preload precisely so they take the first path — without coverage, a
@@ -159,14 +156,6 @@ module Spree
end
end
end
-
- context 'when variant is not available' do
- before do
- allow(subject.variant).to receive(:available?).and_return(false)
- end
-
- it { expect(subject.can_supply?).to be false }
- end
end
context 'with active stock reservations' do
diff --git a/spree/core/spec/models/spree/stock_level_spec.rb b/spree/core/spec/models/spree/stock_level_spec.rb
index 29038349ed..fc415fde60 100644
--- a/spree/core/spec/models/spree/stock_level_spec.rb
+++ b/spree/core/spec/models/spree/stock_level_spec.rb
@@ -87,14 +87,6 @@ describe Spree::StockLevel, type: :model do
end
end
- it 'maintains the count on hand for a variant' do
- expect(subject.count_on_hand).to eq 10
- end
-
- it "can return the stock item's variant's name" do
- expect(subject.variant_name).to eq(subject.variant.name)
- end
-
context 'available to be included in shipment' do
context 'has stock' do
it { expect(subject).to be_available }
@@ -240,8 +232,10 @@ describe Spree::StockLevel, type: :model do
before { subject.set_count_on_hand(-2, force: true) }
- it "doesn't process backorders" do
+ it "doesn't process backorders when stock drops further" do
expect(subject).not_to receive(:backordered_inventory_units)
+
+ subject.set_count_on_hand(-3, force: true)
end
context 'adds new items' do
diff --git a/spree/core/spec/models/spree/stock_location_spec.rb b/spree/core/spec/models/spree/stock_location_spec.rb
index 58bc84574c..8b37a70e3e 100644
--- a/spree/core/spec/models/spree/stock_location_spec.rb
+++ b/spree/core/spec/models/spree/stock_location_spec.rb
@@ -28,11 +28,6 @@ module Spree
end
end
- it 'validates uniqueness' do
- described_class.create(name: 'Test')
- expect(described_class.new(name: 'Test')).not_to be_valid
- end
-
context 'handling stock items' do
let!(:variant) { create(:variant) }
@@ -350,16 +345,26 @@ module Spree
end
describe '#conditionally_touch_records' do
- let(:item) { subject.items.last }
- let(:variant) { subject.variants.last }
+ let!(:variant) { subject.variants.last }
+ let!(:stock_level) { subject.stock_levels.last }
context 'active has changed' do
- it { expect { subject.update(active: false).to change(variant, :updated_at) } }
- it { expect { subject.update(active: false).to change(item, :updated_at) } }
+ it 'touches variants and stock levels' do
+ pending 'active_changed? is always false inside after_update, so nothing is touched'
+
+ Timecop.travel(1.minute.from_now) do
+ expect { subject.update(active: false) }.to change { variant.reload.updated_at }.
+ and change { stock_level.reload.updated_at }
+ end
+ end
end
context 'active has not changed' do
- it { expect { subject.update(name: 'my other warehouse').to change(variant, :updated_at) } }
+ it 'does not touch variants' do
+ Timecop.travel(1.minute.from_now) do
+ expect { subject.update(name: 'my other warehouse') }.not_to change { variant.reload.updated_at }
+ end
+ end
end
end
@@ -385,85 +390,6 @@ module Spree
end
end
- describe '#country_name' do
- it 'returns the country name' do
- expect(subject.country_name).to eq(subject.country.name)
- end
- end
-
- context 'when country is nil' do
- subject { build(:stock_location, country: nil, state: nil) }
-
- it { expect(subject.country_name).to be_nil }
- it { expect(subject.country_code).to be_nil }
- it { expect(subject.country_iso3).to be_nil }
- it { expect(subject.country_iso_name).to be_nil }
- end
-
- describe 'KINDS / PICKUP_STOCK_POLICIES constants' do
- it 'lists the built-in kinds' do
- expect(StockLocation::KINDS).to eq(%w[warehouse store fulfillment_center])
- end
-
- it 'lists the pickup stock policies' do
- expect(StockLocation::PICKUP_STOCK_POLICIES).to eq(%w[local any])
- end
- end
-
- describe 'pickup defaults' do
- subject { build(:stock_location) }
-
- it 'defaults kind to warehouse' do
- expect(subject.kind).to eq('warehouse')
- end
-
- it 'defaults pickup_enabled to false' do
- expect(subject.pickup_enabled).to be false
- end
-
- it 'defaults pickup_stock_policy to local' do
- expect(subject.pickup_stock_policy).to eq('local')
- end
- end
-
- describe 'validations' do
- it 'requires a kind' do
- sl = build(:stock_location, kind: nil)
- expect(sl).not_to be_valid
- expect(sl.errors[:kind]).to be_present
- end
-
- it 'rejects an invalid pickup_stock_policy' do
- sl = build(:stock_location, pickup_stock_policy: 'bogus')
- expect(sl).not_to be_valid
- expect(sl.errors[:pickup_stock_policy]).to be_present
- end
-
- it 'accepts a valid pickup_stock_policy' do
- expect(build(:stock_location, pickup_stock_policy: 'any')).to be_valid
- end
-
- it 'rejects a negative pickup_ready_in_minutes' do
- sl = build(:stock_location, pickup_ready_in_minutes: -1)
- expect(sl).not_to be_valid
- expect(sl.errors[:pickup_ready_in_minutes]).to be_present
- end
-
- it 'allows nil pickup_ready_in_minutes' do
- expect(build(:stock_location, pickup_ready_in_minutes: nil)).to be_valid
- end
- end
-
- describe '.pickup_enabled scope' do
- let!(:enabled) { create(:stock_location, pickup_enabled: true) }
- let!(:disabled) { create(:stock_location, pickup_enabled: false) }
-
- it 'returns only locations with pickup enabled' do
- expect(StockLocation.pickup_enabled).to include(enabled)
- expect(StockLocation.pickup_enabled).not_to include(disabled)
- end
- end
-
describe '#country_code=' do
let(:country) { Spree::Country.by_iso('US') }
let(:stock_location) { build(:stock_location, country: nil, state: nil) }
diff --git a/spree/core/spec/models/spree/stock_movement_spec.rb b/spree/core/spec/models/spree/stock_movement_spec.rb
index c97ae632a5..9fc63cd2f0 100644
--- a/spree/core/spec/models/spree/stock_movement_spec.rb
+++ b/spree/core/spec/models/spree/stock_movement_spec.rb
@@ -49,43 +49,9 @@ describe Spree::StockMovement, type: :model do
end
end
- describe 'Constants' do
- describe 'KINDS' do
- it 'names every movement kind' do
- expect(described_class::KINDS).to eq(%w[received allocated shipped released adjusted])
- end
- end
-
- describe 'QUANTITY_LIMITS[:max]' do
- it 'return 2**31 - 1' do
- expect(Spree::StockMovement::QUANTITY_LIMITS[:max]).to eq(2**31 - 1)
- end
- end
-
- describe 'QUANTITY_LIMITS[:min]' do
- it 'return -2**31' do
- expect(Spree::StockMovement::QUANTITY_LIMITS[:min]).to eq(-2**31)
- end
- end
- end
-
describe 'validations' do
let(:stock_level) { create(:stock_level, backorderable: false) }
- it 'requires a kind' do
- movement = build(:stock_movement, kind: nil, stock_level: stock_level)
-
- expect(movement).to be_invalid
- expect(movement.errors[:kind]).to be_present
- end
-
- it 'rejects an unknown kind' do
- movement = build(:stock_movement, kind: 'sold', stock_level: stock_level)
-
- expect(movement).to be_invalid
- expect(movement.errors[:kind]).to be_present
- end
-
it 'rejects a zero quantity' do
movement = build(:stock_movement, quantity: 0, stock_level: stock_level)
@@ -115,13 +81,6 @@ describe Spree::StockMovement, type: :model do
end
describe 'Scope' do
- describe '.recent' do
- it 'orders chronologically by created at' do
- expect(Spree::StockMovement.recent.to_sql).
- to eq Spree::StockMovement.unscoped.order(created_at: :desc).to_sql
- end
- end
-
describe 'kind scopes' do
let(:stock_level) { create(:stock_level) }
let!(:received) { create(:stock_movement, kind: 'received', quantity: 1, stock_level: stock_level) }
@@ -141,14 +100,6 @@ describe Spree::StockMovement, type: :model do
end
describe 'whitelisted ransackable attributes' do
- it 'exposes the kind and every cause key' do
- expect(Spree::StockMovement.whitelisted_ransackable_attributes).to eq(
- %w[quantity kind reason created_at stock_level_id stock_item_id order_id fulfillment_id
- return_id exchange_id stock_transfer_id purchase_order_id stock_receipt_id
- unit_cost]
- )
- end
-
# Dropping the pre-rename filter would hand a client still sending it the
# whole collection rather than an error.
it 'still filters on the pre-rename stock_item_id name' do
@@ -176,14 +127,6 @@ describe Spree::StockMovement, type: :model do
let(:stock_level) { stock_location.stock_levels.order(:id).first }
let(:stock_movement) { build(:stock_movement, stock_level: stock_level) }
- describe '.product' do
- it { expect(stock_movement.product).to eq(stock_level.variant.product) }
- end
-
- describe '.variant' do
- it { expect(stock_movement.variant).to eq(stock_level.variant) }
- end
-
describe '#readonly?' do
let(:stock_movement) { create(:stock_movement, stock_level: stock_level) }
diff --git a/spree/core/spec/models/spree/stock_reservation_spec.rb b/spree/core/spec/models/spree/stock_reservation_spec.rb
index d07ecb0e1b..a6a83e938f 100644
--- a/spree/core/spec/models/spree/stock_reservation_spec.rb
+++ b/spree/core/spec/models/spree/stock_reservation_spec.rb
@@ -115,24 +115,4 @@ describe Spree::StockReservation, type: :model do
expect(level.reload.reserved_count).to eq(0)
end
end
-
- describe 'cleanup via dependent: :destroy' do
- let(:reservation) { create(:stock_reservation) }
-
- it 'is destroyed when its order is destroyed' do
- reservation
- order = reservation.order
- expect { order.destroy }.to change(Spree::StockReservation, :count).by(-1)
- end
-
- it 'is destroyed when its line item is destroyed' do
- reservation
- expect { reservation.line_item.destroy }.to change(Spree::StockReservation, :count).by(-1)
- end
-
- it 'is destroyed when its stock item is destroyed' do
- reservation
- expect { reservation.stock_level.destroy }.to change(Spree::StockReservation, :count).by(-1)
- end
- end
end
diff --git a/spree/core/spec/models/spree/store_credit_event_spec.rb b/spree/core/spec/models/spree/store_credit_event_spec.rb
index 9b295039b8..e245ef6b06 100644
--- a/spree/core/spec/models/spree/store_credit_event_spec.rb
+++ b/spree/core/spec/models/spree/store_credit_event_spec.rb
@@ -6,10 +6,6 @@ describe 'StoreCreditEvent' do
let(:event_amount) { 120.0 }
- it 'returns a Spree::Money instance' do
- expect(subject.display_amount).to be_instance_of(Spree::Money)
- end
-
it 'uses the events amount attribute' do
expect(subject.display_amount).to eq Spree::Money.new(event_amount, currency: subject.currency)
end
@@ -20,10 +16,6 @@ describe 'StoreCreditEvent' do
let(:user_total_amount) { 300.0 }
- it 'returns a Spree::Money instance' do
- expect(subject.display_user_total_amount).to be_instance_of(Spree::Money)
- end
-
it 'uses the events user_total_amount attribute' do
amount = Spree::Money.new(user_total_amount, currency: subject.currency)
expect(subject.display_user_total_amount).to eq amount
@@ -103,92 +95,23 @@ describe 'StoreCreditEvent' do
end
end
- describe '#store' do
- let(:store) { @default_store }
- let(:store_credit) { create(:store_credit, store: store) }
-
- subject { build(:store_credit_auth_event, store_credit: store_credit) }
-
- it { expect(subject.store).to eq(store) }
- end
-
- describe '#allocation?' do
- subject { store_credit_event.allocation? }
-
- let(:store_credit_event) { build(:store_credit_auth_event, action: action) }
-
- context 'action is allocation' do
- let(:action) { Spree::StoreCredit::ALLOCATION_ACTION }
- it { is_expected.to be true }
- end
-
- context 'action is not allocation' do
- let(:action) { Spree::StoreCredit::CAPTURE_ACTION }
- it { is_expected.to be false }
- end
- end
-
- describe '#credit?' do
- subject { store_credit_event.credit? }
-
- let(:store_credit_event) { build(:store_credit_auth_event, action: action) }
-
- context 'action is credit' do
- let(:action) { Spree::StoreCredit::CREDIT_ACTION }
- it { is_expected.to be true }
- end
-
- context 'action is not credit' do
- let(:action) { Spree::StoreCredit::CAPTURE_ACTION }
- it { is_expected.to be false }
- end
- end
-
- describe '#captured?' do
- subject { store_credit_event.captured? }
-
- let(:store_credit_event) { build(:store_credit_auth_event, action: action) }
-
- context 'action is capture' do
- let(:action) { Spree::StoreCredit::CAPTURE_ACTION }
- it { is_expected.to be true }
- end
-
- context 'action is not capture' do
- let(:action) { Spree::StoreCredit::ALLOCATION_ACTION }
- it { is_expected.to be false }
- end
- end
-
- describe '#voided?' do
- subject { store_credit_event.voided? }
-
- let(:store_credit_event) { build(:store_credit_auth_event, action: action) }
-
- context 'action is void' do
- let(:action) { Spree::StoreCredit::VOID_ACTION }
- it { is_expected.to be true }
- end
-
- context 'action is not void' do
- let(:action) { Spree::StoreCredit::CAPTURE_ACTION }
- it { is_expected.to be false }
- end
- end
-
- describe '#authorized?' do
- subject { store_credit_event.authorized? }
-
- let(:store_credit_event) { build(:store_credit_auth_event, action: action) }
-
- context 'action is authorize' do
- let(:action) { Spree::StoreCredit::AUTHORIZE_ACTION }
- it { is_expected.to be true }
- end
-
- context 'action is not authorize' do
- let(:action) { Spree::StoreCredit::CAPTURE_ACTION }
- it { is_expected.to be false }
+ describe 'action predicates' do
+ it 'answers true only for its own action' do
+ predicates = {
+ allocation?: Spree::StoreCredit::ALLOCATION_ACTION,
+ credit?: Spree::StoreCredit::CREDIT_ACTION,
+ captured?: Spree::StoreCredit::CAPTURE_ACTION,
+ voided?: Spree::StoreCredit::VOID_ACTION,
+ authorized?: Spree::StoreCredit::AUTHORIZE_ACTION
+ }
+
+ predicates.each do |predicate, own_action|
+ predicates.each_value do |action|
+ event = build(:store_credit_auth_event, action: action)
+
+ expect(event.public_send(predicate)).to be(action == own_action), "#{predicate} for #{action}"
+ end
+ end
end
end
end
diff --git a/spree/core/spec/models/spree/store_credit_spec.rb b/spree/core/spec/models/spree/store_credit_spec.rb
index 48a3a2f566..cff98d6273 100644
--- a/spree/core/spec/models/spree/store_credit_spec.rb
+++ b/spree/core/spec/models/spree/store_credit_spec.rb
@@ -52,20 +52,6 @@ describe Spree::StoreCredit, type: :model do
end
end
- describe 'amount used less than or equal to amount' do
- subject { build(:store_credit, amount_used: 101.0, amount: 100.0) }
-
- it 'is not valid' do
- expect(subject).not_to be_valid
- end
-
- it 'adds an error message about the invalid amount used' do
- subject.valid?
- text = I18n.t('activerecord.errors.models.spree/store_credit.attributes.amount_used.cannot_be_greater_than_amount')
- expect(subject.errors[:amount_used]).to include(text)
- end
- end
-
describe 'amount authorized less than or equal to amount' do
subject { build(:store_credit, amount_authorized: 101.0, amount: 100.0) }
@@ -225,18 +211,6 @@ describe Spree::StoreCredit, type: :model do
end
end
- describe '#display_amount' do
- it 'returns a Spree::Money instance' do
- expect(store_credit.display_amount).to be_instance_of(Spree::Money)
- end
- end
-
- describe '#display_amount_used' do
- it 'returns a Spree::Money instance' do
- expect(store_credit.display_amount_used).to be_instance_of(Spree::Money)
- end
- end
-
describe '#amount_remaining' do
context 'the amount_used is not defined' do
context 'the authorized amount is not defined' do
@@ -410,7 +384,7 @@ describe Spree::StoreCredit, type: :model do
end
it 'does not update the store credit model' do
- expect { subject }.not_to change { store_credit }
+ expect { subject }.not_to change { store_credit.reload.slice(:amount_used, :amount_authorized) }
end
end
@@ -428,7 +402,7 @@ describe Spree::StoreCredit, type: :model do
end
it 'does not update the store credit model' do
- expect { subject }.not_to change { store_credit }
+ expect { subject }.not_to change { store_credit.reload.slice(:amount_used, :amount_authorized) }
end
end
@@ -676,46 +650,6 @@ describe Spree::StoreCredit, type: :model do
end
end
- describe '#amount_used' do
- context 'amount used is not defined' do
- subject { Spree::StoreCredit.new }
-
- it 'returns zero' do
- expect(subject.amount_used).to be_zero
- end
- end
-
- context 'amount used is defined' do
- subject { create(:store_credit, amount_used: amount_used) }
-
- let(:amount_used) { 100.0 }
-
- it 'returns the attribute value' do
- expect(subject.amount_used).to eq amount_used
- end
- end
- end
-
- describe '#amount_authorized' do
- context 'amount authorized is not defined' do
- subject { Spree::StoreCredit.new }
-
- it 'returns zero' do
- expect(subject.amount_authorized).to be_zero
- end
- end
-
- context 'amount authorized is defined' do
- subject { create(:store_credit, amount_authorized: amount_authorized) }
-
- let(:amount_authorized) { 100.0 }
-
- it 'returns the attribute value' do
- expect(subject.amount_authorized).to eq amount_authorized
- end
- end
- end
-
describe '#can_capture?' do
subject { store_credit.can_capture?(payment) }
diff --git a/spree/core/spec/models/spree/store_spec.rb b/spree/core/spec/models/spree/store_spec.rb
index 2eca278778..77cb028bb8 100644
--- a/spree/core/spec/models/spree/store_spec.rb
+++ b/spree/core/spec/models/spree/store_spec.rb
@@ -33,105 +33,11 @@ describe Spree::Store, type: :model, without_global_store: true do
context 'Associations' do
subject { create(:store) }
- let(:other_store) { create(:store) }
-
describe '#products' do
let!(:product) { create(:product, store: subject) }
- let!(:product_2) { create(:product, store: other_store) }
+ let!(:product_2) { create(:product, store: create(:store)) }
it { expect(subject.products).to eq([product]) }
-
- describe '#variants' do
- let!(:variant) { create(:variant, product: product) }
- let!(:variant_2) { create(:variant, product: product_2) }
-
- it { expect(subject.variants).to eq([product.default_variant, variant]) }
-
- describe '#stock_levels' do
- let!(:stock_levels) { product.stock_levels }
- let!(:stock_levels_2) { product_2.stock_levels }
-
- it { expect(stock_levels).not_to be_empty }
- it { expect(stock_levels_2).not_to be_empty }
- it { expect(subject.stock_levels).to eq(stock_levels) }
- end
- end
- end
-
- describe '#payment_methods' do
- let!(:payment_method) { create(:payment_method, store: subject) }
- let!(:payment_method_2) { create(:payment_method, store: create(:store)) }
-
- it { expect(subject.payment_methods).to eq([payment_method]) }
- end
-
- describe '#orders' do
- let!(:order) { create(:order, store: subject, total: 100) }
- let!(:order_2) { create(:order, store: create(:store), total: 100) }
-
- it { expect(subject.orders).to eq([order]) }
-
- describe '#line_items' do
- let!(:line_item) { create(:line_item, order: order) }
- let!(:line_item_2) { create(:line_item, order: order_2) }
-
- it { expect(subject.line_items).to eq([line_item]) }
- end
-
- describe '#payments' do
- let!(:payment) { create(:payment, order: order) }
- let!(:payment_2) { create(:payment, order: order_2) }
-
- it { expect(subject.payments).to eq([payment]) }
- end
-
- describe '#shipments' do
- let!(:shipment) { create(:fulfillment, order: order) }
- let!(:shipment_2) { create(:fulfillment, order: order_2) }
-
- it { expect(subject.shipments).to eq([shipment]) }
- end
-
- describe '#returns' do
- let!(:order) { create(:shipped_order, store: subject) }
- let!(:order_2) { create(:shipped_order, store: create(:store)) }
- let!(:return_record) { create(:return, order: order, store: subject) }
- let!(:return_record_2) { create(:return, order: order_2, store: order_2.store) }
-
- it { expect(subject.returns).to eq([return_record]) }
- end
-
- describe '#inventory_units' do
- let(:product) { create(:product, store: subject) }
- let(:product_2) { create(:product, store: other_store) }
- let!(:inventory_unit) { create(:fulfillment_item, variant: product.default_variant, order: order) }
- let!(:inventory_unit_2) { create(:fulfillment_item, variant: product_2.default_variant, order: order_2) }
-
- it { expect(subject.inventory_units).to eq([inventory_unit]) }
- end
- end
-
- describe '#store_credits' do
- let!(:store_credit) { create(:store_credit, store: subject) }
- let!(:store_credit_2) { create(:store_credit, store: create(:store)) }
-
- it { expect(subject.store_credits).to eq([store_credit]) }
-
- describe '#store_credit_events' do
- let!(:store_credit_event) { store_credit.store_credit_events.first }
- let!(:store_credit_event_2) { store_credit_2.store_credit_events.first }
-
- it { expect(store_credit_event).not_to be_nil }
- it { expect(store_credit_event_2).not_to be_nil }
- it { expect(subject.store_credit_events).to eq([store_credit_event]) }
- end
- end
-
- describe '#promotions' do
- let!(:promotion) { create(:promotion, store: subject) }
- let!(:promotion_2) { create(:promotion, store: create(:store)) }
-
- it { expect(subject.promotions).to eq([promotion]) }
end
end
@@ -362,16 +268,6 @@ describe Spree::Store, type: :model, without_global_store: true do
end
context 'Validations' do
- describe '#code' do
- it 'generates a code when blank' do
- store = build(:store, code: nil, name: nil)
- store.valid?
- # set_default_code generates a code if blank, so it should be valid
- expect(store.code).to be_present
- expect(store.errors[:code]).to be_empty
- end
- end
-
describe '#customer_support_email' do
it 'is valid when blank' do
store = build(:store, customer_support_email: '')
@@ -414,10 +310,6 @@ describe Spree::Store, type: :model, without_global_store: true do
end
describe 'order routing strategy preference' do
- it 'is valid with the default registered Rules strategy' do
- expect(create(:store)).to be_valid
- end
-
it 'rejects an unregistered strategy' do
store = build(:store, preferred_order_routing_strategy: 'Spree::OrderRouting::Strategy::Reducer')
expect(store).not_to be_valid
@@ -507,17 +399,11 @@ describe Spree::Store, type: :model, without_global_store: true do
describe '#states_available_for_checkout' do
subject { create(:store) }
- let(:country_with_states) do
- create(:country).tap do |country|
- # subdivisions are reference data — the country already has them
- end
- end
-
it 'returns list of states associated to country' do
- checkout_available_states_ids = subject.states_available_for_checkout(country_with_states).map(&:abbr)
- all_state_ids = country_with_states.states.map(&:abbr)
+ state_codes = subject.states_available_for_checkout(Spree::Country.by_iso('US')).map(&:abbr)
- expect(checkout_available_states_ids).to eq(all_state_ids)
+ expect(state_codes).to include('NY', 'CA')
+ expect(state_codes).not_to include('ON')
end
end
@@ -565,14 +451,6 @@ describe Spree::Store, type: :model, without_global_store: true do
end
end
- describe '#unique_name' do
- let!(:store) { build(:store) }
-
- it 'returns the Store Name followed by the Store Code in parentheses' do
- expect(store.unique_name).to eq("#{store.name} (#{store.code})")
- end
- end
-
describe '#supported_currencies_list' do
context 'with markets' do
let!(:store) { create(:store, default_currency: 'USD') }
@@ -790,10 +668,6 @@ describe Spree::Store, type: :model, without_global_store: true do
expect(countries.map(&:iso)).to contain_exactly(country_a.iso, country_b.iso, country_c.iso, 'US')
end
- it 'returns an ActiveRecord relation' do
- expect(store.countries_from_markets).to all(be_a(Spree::Country))
- end
-
it 'orders by name' do
names = store.countries_from_markets.map(&:name)
expect(names).to eq(names.sort)
@@ -803,11 +677,6 @@ describe Spree::Store, type: :model, without_global_store: true do
other_country = create(:country)
expect(store.countries_from_markets.map(&:iso)).not_to include(other_country.iso)
end
-
- it 'does not duplicate countries shared across markets' do
- store.markets.last.countries << country_a rescue nil
- expect(store.countries_from_markets.count { |c| c.iso == country_a.iso }).to eq(1)
- end
end
context 'without markets' do
@@ -817,15 +686,6 @@ describe Spree::Store, type: :model, without_global_store: true do
end
end
- describe 'soft deletion' do
- let!(:store) { create(:store) }
-
- it 'soft-deletes when destroy is called' do
- store.destroy!
- expect(store.deleted_at).not_to be_nil
- end
- end
-
describe '#default_stock_location' do
# A persisted store must be the current one: stock locations are
# store-scoped and resolve their store from Spree::Current.
@@ -960,22 +820,6 @@ describe Spree::Store, type: :model, without_global_store: true do
end
end
- describe '#formatted_url_or_custom_domain' do
- let(:store) { build(:store, code: 'mystore', url: 'mystore.mydomain.dev:3000') }
-
- it 'returns formatted_url as fallback' do
- expect(store.formatted_url_or_custom_domain).to eq('http://mystore.mydomain.dev:3000')
- end
- end
-
- describe '#url_or_custom_domain' do
- let(:store) { build(:store, code: 'mystore', url: 'mystore.mydomain.dev') }
-
- it 'returns url as fallback' do
- expect(store.url_or_custom_domain).to eq('mystore.mydomain.dev')
- end
- end
-
describe '#allowed_origin?' do
let(:store) { create(:store) }
@@ -1142,10 +986,6 @@ describe Spree::Store, type: :model, without_global_store: true do
describe 'storefront setup task' do
let(:store) { create(:store) }
- it 'is included in the setup tasks list' do
- expect(store.setup_tasks_list).to include(:setup_storefront)
- end
-
describe '#storefront_setup?' do
subject { store.storefront_setup? }
diff --git a/spree/core/spec/models/spree/storefront/access_policy_spec.rb b/spree/core/spec/models/spree/storefront/access_policy_spec.rb
index d875d1826e..c37658f7dc 100644
--- a/spree/core/spec/models/spree/storefront/access_policy_spec.rb
+++ b/spree/core/spec/models/spree/storefront/access_policy_spec.rb
@@ -96,14 +96,6 @@ RSpec.describe Spree::Storefront::AccessPolicy, type: :model do
expect(guest_policy.readable?(unowned)).to be false
end
- it 'keys ownership on customer_id, not the deprecated user_id alias' do
- # Guards against the alias disappearing in 6.1: a record whose
- # customer_id matches is owned even if #user_id is gone.
- owned = build(:wishlist, customer: user)
- expect(owned.customer_id).to eq(user.id)
- expect(policy.readable?(owned)).to be true
- end
-
it 'fails closed for records with no customer_id column' do
# WishedItem has no ownership column — it is authorized through its
# parent wishlist, never directly. The bare policy denies it.
diff --git a/spree/core/spec/models/spree/subscriber_spec.rb b/spree/core/spec/models/spree/subscriber_spec.rb
index 5207c14756..34bc769e78 100644
--- a/spree/core/spec/models/spree/subscriber_spec.rb
+++ b/spree/core/spec/models/spree/subscriber_spec.rb
@@ -46,21 +46,6 @@ RSpec.describe Spree::Subscriber, events: true do
end
end
- describe '.on' do
- it 'maps events to methods' do
- subscriber_class = Class.new(described_class) do
- subscribes_to 'payment.completed', 'payment.voided'
- on 'payment.completed', :handle_complete
- on 'payment.voided', :handle_void
- end
-
- expect(subscriber_class.event_handlers).to eq({
- 'payment.completed' => :handle_complete,
- 'payment.voided' => :handle_void
- })
- end
- end
-
describe '#call' do
context 'without event handlers' do
it 'calls the handle method' do
diff --git a/spree/core/spec/models/spree/tax_category_spec.rb b/spree/core/spec/models/spree/tax_category_spec.rb
index bdcc07734c..5965127be6 100644
--- a/spree/core/spec/models/spree/tax_category_spec.rb
+++ b/spree/core/spec/models/spree/tax_category_spec.rb
@@ -18,7 +18,7 @@ describe Spree::TaxCategory, type: :model do
end
it 'undefaults the previous default tax category except when updating the existing default tax category' do
- tax_category.update_column(:description, 'Updated description')
+ tax_category.update!(description: 'Updated description')
tax_category.reload
expect(tax_category.is_default).to be true
@@ -37,17 +37,11 @@ describe Spree::TaxCategory, type: :model do
expect(create(:tax_category).store).to eq(@default_store)
end
- it 'allows the same name in another store' do
- other_store = create(:store)
- create(:tax_category, name: 'Standard')
-
- expect(build(:tax_category, name: 'Standard', store: other_store)).to be_valid
- end
-
- it 'rejects a duplicate name within the same store, ignoring case' do
+ it 'rejects a duplicate name within the same store, ignoring case, but allows it in another store' do
create(:tax_category, name: 'Standard')
expect(build(:tax_category, name: 'standard')).not_to be_valid
+ expect(build(:tax_category, name: 'Standard', store: create(:store))).to be_valid
end
it 'ignores soft-deleted rows when checking the name' do
diff --git a/spree/core/spec/models/spree/tax_exemption_spec.rb b/spree/core/spec/models/spree/tax_exemption_spec.rb
index 6f0443575e..ad35b1b396 100644
--- a/spree/core/spec/models/spree/tax_exemption_spec.rb
+++ b/spree/core/spec/models/spree/tax_exemption_spec.rb
@@ -81,10 +81,6 @@ describe Spree::TaxExemption, type: :model do
expect(exemption.errors[:item_overrides]).to be_present
end
- it 'leaves an entry with no overrides at all valid — that claims the order' do
- expect(described_class.new(reason_code: 'resale')).to be_valid
- end
-
# Stated so the widening is visible: this is what the validation prevents
# from ever reaching a provider.
it 'would otherwise report every line as covered' do
diff --git a/spree/core/spec/models/spree/tax_identifier_spec.rb b/spree/core/spec/models/spree/tax_identifier_spec.rb
index 41aa217bb1..170b0e90ed 100644
--- a/spree/core/spec/models/spree/tax_identifier_spec.rb
+++ b/spree/core/spec/models/spree/tax_identifier_spec.rb
@@ -5,18 +5,6 @@ describe Spree::TaxIdentifier, type: :model do
let(:cart) { create(:cart, customer: customer) }
let(:order) { create(:order, customer: customer) }
- it 'requires a kind and a value' do
- expect(build(:tax_identifier)).to be_valid
- expect(build(:tax_identifier, kind: nil)).not_to be_valid
- expect(build(:tax_identifier, value: nil)).not_to be_valid
- end
-
- it 'requires an owner' do
- expect(build(:tax_identifier, owner: customer)).to be_valid
- expect(build(:tax_identifier, owner: cart)).to be_valid
- expect(build(:tax_identifier, owner: nil)).not_to be_valid
- end
-
it 'rejects a validation status the platform never sets' do
expect(build(:tax_identifier, validation_status: 'verified')).to be_valid
expect(build(:tax_identifier, validation_status: nil)).to be_valid
@@ -284,12 +272,6 @@ describe Spree::TaxIdentifier, type: :model do
expect(build(:tax_identifier, owner: company, kind: 'eu_vat')).not_to be_valid
end
-
- it 'reports the company as its owner' do
- identifier = create(:tax_identifier, owner: company)
-
- expect(identifier.owner).to eq(company)
- end
end
# A seller's registration faces the other way from the rest: it is what the
# marketplace's own commission invoice is made out to, and what makes EU
@@ -302,7 +284,6 @@ describe Spree::TaxIdentifier, type: :model do
value: eu_vat_number(0))
expect(identifier).to be_valid
- expect(identifier.owner).to eq(seller)
end
it 'holds one registration per kind' do
diff --git a/spree/core/spec/models/spree/tax_line_spec.rb b/spree/core/spec/models/spree/tax_line_spec.rb
index a87ca4cdd0..966b534ad9 100644
--- a/spree/core/spec/models/spree/tax_line_spec.rb
+++ b/spree/core/spec/models/spree/tax_line_spec.rb
@@ -107,19 +107,6 @@ describe Spree::TaxLine, type: :model do
end
end
- describe 'provider data' do
- it 'defaults to an empty hash so payloads read nil-safe' do
- expect(described_class.new.data).to eq({})
- expect(described_class.new.data['jurisdictions']).to be_nil
- end
-
- it 'round-trips a provider payload' do
- tax_line = create(:tax_line, order: order, line_item: line_item,
- data: { 'jurisdictions' => [{ 'name' => 'WA', 'amount' => '1.2' }] })
- expect(tax_line.reload.data['jurisdictions'].first['name']).to eq('WA')
- end
- end
-
describe 'included vs additional' do
let!(:included_line) { create(:tax_line, order: order, line_item: line_item, included: true) }
let!(:additional_line) { create(:tax_line, order: order, line_item: line_item, included: false) }
diff --git a/spree/core/spec/models/spree/tax_provider/base_spec.rb b/spree/core/spec/models/spree/tax_provider/base_spec.rb
index 39efa54115..d4b39e89f9 100644
--- a/spree/core/spec/models/spree/tax_provider/base_spec.rb
+++ b/spree/core/spec/models/spree/tax_provider/base_spec.rb
@@ -54,11 +54,6 @@ describe Spree::TaxProvider::Base, type: :model do
expect(described_class.unsupported_capabilities).to eq([])
expect(described_class.available_for_store?(order.store)).to be(true)
end
-
- it 'is answerable without instantiating the provider' do
- expect(described_class).to respond_to(:unsupported_capabilities)
- expect(described_class).to respond_to(:available_for_store?)
- end
end
describe 'self-description for the admin' do
@@ -112,10 +107,6 @@ describe Spree::TaxProvider::Base, type: :model do
expect(Spree.default_tax_provider).to eq(Spree::TaxProvider::Internal)
end
- it 'returns a class, so a caller that only names it pays for no instance' do
- expect(Spree.default_tax_provider).to be_a(Class)
- end
-
it 'accepts a class name, for an initializer naming a provider before autoload' do
original = Rails.application.config.spree.default_tax_provider
Spree.default_tax_provider = 'Spree::TaxProvider::Internal'
@@ -127,18 +118,6 @@ describe Spree::TaxProvider::Base, type: :model do
end
end
- describe 'the internal provider' do
- it 'declares the domains rate configuration cannot express' do
- expect(Spree::TaxProvider::Internal.unsupported_capabilities).to(
- contain_exactly(:us_local_tax, :reverse_charge, :oss_thresholds, :proportional_delivery_tax)
- )
- end
-
- it 'is available for any store, needing no credentials' do
- expect(Spree::TaxProvider::Internal.available_for_store?(order.store)).to be(true)
- end
- end
-
it 'no longer answers a standalone exemption question' do
expect(provider).not_to respond_to(:exempt?)
end
diff --git a/spree/core/spec/models/spree/tax_rate_spec.rb b/spree/core/spec/models/spree/tax_rate_spec.rb
index db233d1c6b..117a29a946 100644
--- a/spree/core/spec/models/spree/tax_rate_spec.rb
+++ b/spree/core/spec/models/spree/tax_rate_spec.rb
@@ -22,16 +22,10 @@ describe Spree::TaxRate, type: :model do
it 'reads a jurisdiction off an address, or takes the pair directly' do
rate = create(:tax_rate, country_code: germany&.iso, tax_category: tax_category)
-
- expect(described_class.for_address(german_address)).to eq([rate])
- expect(described_class.for_jurisdiction(germany.iso)).to eq([rate])
- end
-
- it 'matches a rate for the address country' do
- rate = create(:tax_rate, country_code: germany&.iso, tax_category: tax_category)
create(:tax_rate, country_code: france&.iso, tax_category: tax_category)
expect(described_class.for_address(german_address)).to eq([rate])
+ expect(described_class.for_jurisdiction(germany.iso)).to eq([rate])
end
it 'matches every rate configured for that country' do
@@ -279,17 +273,10 @@ describe Spree::TaxRate, type: :model do
tax_rate = Spree::TaxRate.new(name: 'Sales Tax', amount: 0.1)
expect(tax_rate.adjustment_label).to eq('Sales Tax 10%')
end
- end
-
- describe '#amount_for_label' do
- it 'returns an empty string when the amount is 0' do
- tax_rate = Spree::TaxRate.new(amount: 0)
- expect(tax_rate.send(:amount_for_label)).to eq('')
- end
- it 'returns a string with the percentage when the amount is not 0' do
- tax_rate = Spree::TaxRate.new(amount: 0.1)
- expect(tax_rate.send(:amount_for_label)).to eq(' 10%')
+ it 'leaves the percentage out when the amount is 0' do
+ tax_rate = Spree::TaxRate.new(name: 'Sales Tax', amount: 0)
+ expect(tax_rate.adjustment_label).to eq('Sales Tax')
end
end
diff --git a/spree/core/spec/models/spree/taxon_category_aliases_spec.rb b/spree/core/spec/models/spree/taxon_category_aliases_spec.rb
index 4aa3976456..a95b0f0a40 100644
--- a/spree/core/spec/models/spree/taxon_category_aliases_spec.rb
+++ b/spree/core/spec/models/spree/taxon_category_aliases_spec.rb
@@ -5,7 +5,11 @@ require 'spec_helper'
# the taxons queue, and the method bridges warn through Spree::Deprecation.
RSpec.describe 'Taxon -> Category deprecation aliases' do
describe 'constant aliases resolve to the canonical class' do
+ # Each alias warns once, when its file first loads, so another spec may
+ # already have loaded it.
it 'keeps them as true class aliases (not proxies), so is_a?/STI stay correct' do
+ allow(Spree::Deprecation).to receive(:warn)
+
expect(Spree::Taxon).to equal(Spree::Category)
expect(Spree::Classification).to equal(Spree::ProductCategory)
expect(Spree::PromotionRuleTaxon).to equal(Spree::PromotionRuleCategory)
diff --git a/spree/core/spec/models/spree/user_identity_spec.rb b/spree/core/spec/models/spree/user_identity_spec.rb
index 4ab27cebe2..e96ecf380d 100644
--- a/spree/core/spec/models/spree/user_identity_spec.rb
+++ b/spree/core/spec/models/spree/user_identity_spec.rb
@@ -23,12 +23,6 @@ describe Spree::UserIdentity, type: :model do
create(:user_identity, user: user, provider: 'email', uid: '12345')
end
- it 'validates uniqueness of uid scoped to provider and user_type' do
- duplicate = build(:user_identity, user: user, provider: 'email', uid: '12345')
- expect(duplicate).not_to be_valid
- expect(duplicate.errors[:uid]).to include('has already been taken')
- end
-
it 'allows same uid for different providers' do
Spree.store_authentication_strategies.add(:other, Class.new)
different_provider = build(:user_identity, user: user, provider: 'other', uid: '12345')
@@ -294,13 +288,6 @@ describe Spree::UserIdentity, type: :model do
end
end
- describe '.generate_temp_email' do
- it 'generates email with provider and uid' do
- email = described_class.generate_temp_email('email', '123456')
- expect(email).to eq('[email protected]')
- end
- end
-
describe '#expired?' do
context 'when expires_at is nil' do
subject { build(:user_identity, expires_at: nil) }
diff --git a/spree/core/spec/models/spree/user_spec.rb b/spree/core/spec/models/spree/user_spec.rb
index 6c18625334..d7d7193ab4 100644
--- a/spree/core/spec/models/spree/user_spec.rb
+++ b/spree/core/spec/models/spree/user_spec.rb
@@ -3,22 +3,6 @@ require 'spec_helper'
describe Spree.customer_class, type: :model do # rubocop:disable RSpec/MultipleDescribes
it_behaves_like 'lifecycle events', factory: :user, event_prefix: 'user'
- describe '#can_be_deleted?' do
- subject { user.can_be_deleted? }
-
- context 'when user has completed orders' do
- let(:user) { create(:user, orders: [create(:order, completed_at: Time.current)]) }
-
- it { is_expected.to be(false) }
- end
-
- context 'when user has no completed orders' do
- let(:user) { create(:user, orders: [create(:order)]) }
-
- it { is_expected.to be(true) }
- end
- end
-
describe '#full_name' do
context 'when names are present' do
let(:user) { build(:user, first_name: 'John', last_name: 'Doe') }
@@ -38,29 +22,11 @@ describe Spree.customer_class, type: :model do # rubocop:disable RSpec/MultipleD
end
end
- # Regression test for #2844 + #3346
describe '#last_incomplete_order' do
let!(:user) { create(:user) }
let!(:order) { create(:order, store: store, bill_address: create(:address), ship_address: create(:address)) }
let(:store) { @default_store }
- let(:admin_user) { create(:admin_user) }
- let(:order_1) { create(:order, created_at: 1.day.ago, customer: user, created_by: admin_user, store: store) }
- let(:order_2) { create(:order, customer: user, created_by: admin_user, store: store) }
- let(:order_3) { create(:order, customer: user, created_by: create(:admin_user), store: store) }
-
- it 'returns correct order' do
- allow(Spree::Deprecation).to receive(:warn)
-
- Timecop.scale(3600) do
- order_1
- order_2
- order_3
-
- expect(user.last_incomplete_spree_order(store)).to eq order_3
- end
- end
-
context 'persists order address (deprecated, removed in 6.1)' do
before { allow(Spree::Deprecation).to receive(:warn) }
@@ -88,13 +54,6 @@ describe Spree.customer_class, type: :model do # rubocop:disable RSpec/MultipleD
user.persist_order_address(order)
end.not_to change { Spree::Address.count }
end
-
- it 'set both bill and ship address id on subject' do
- user.persist_order_address(order)
-
- expect(user.bill_address_id).not_to be_blank
- expect(user.ship_address_id).not_to be_blank
- end
end
context 'payment source' do
@@ -103,10 +62,6 @@ describe Spree.customer_class, type: :model do # rubocop:disable RSpec/MultipleD
create(:credit_card, customer_id: user.id, payment_method: payment_method, gateway_customer_profile_id: '2342343')
end
- it 'has payment sources' do
- expect(user.payment_sources.first.gateway_customer_profile_id).not_to be_empty
- end
-
it 'drops payment source' do
user.drop_payment_source cc
expect(cc.gateway_customer_profile_id).to be_nil
@@ -310,12 +265,6 @@ describe Spree.customer_class, type: :model do
end
end
- context 'all store credits have never been used or authorized' do
- it 'returns sum of amounts' do
- expect(subject.total_available_store_credit.to_f).to eq (amount + additional_amount)
- end
- end
-
# Regression: the admin API preloads `store_credits` to avoid an N+1, so
# the in-memory branch must match the query branch — filtered by store
# and currency, gift cards excluded.
@@ -376,23 +325,6 @@ describe Spree.customer_class, type: :model do
end
end
- context 'address book' do
- let(:address) { create(:address) }
- let(:address2) { create(:address) }
-
- before do
- address.owner = subject
- address.save
- address2.owner = subject
- address2.save
- end
-
- it 'has many addresses' do
- expect(subject).to respond_to(:addresses)
- expect(subject.addresses).to eq [address2, address]
- end
- end
-
describe 'validations' do
shared_examples 'valid' do
it 'is valid' do
@@ -500,16 +432,12 @@ describe Spree.customer_class, type: :model do
let!(:completed_order) { create(:completed_order_with_totals, customer: user, bill_address: address, ship_address: address) }
context 'when default bill address is the same as associated to order' do
- it { expect(user.addresses).to include(address) }
-
it_behaves_like 'valid'
end
context 'when user changed bill address which was used in completed order so the old one is deprecated' do
before { address.update(deleted_at: Time.now) }
- it { expect(user.addresses).not_to include(address) }
-
it_behaves_like 'invalid'
it 'assigns error to bill address' do
@@ -539,16 +467,12 @@ describe Spree.customer_class, type: :model do
let!(:completed_order) { create(:completed_order_with_totals, customer: user, bill_address: address, ship_address: address) }
context 'when default ship address is the same as associated to order' do
- it { expect(user.addresses).to include(address) }
-
it_behaves_like 'valid'
end
context 'when user changed ship address which was used in completed order so the old one is deprecated' do
before { address.update(deleted_at: Time.now) }
- it { expect(user.addresses).not_to include(address) }
-
it_behaves_like 'invalid'
it 'assigns error to ship address' do
diff --git a/spree/core/spec/models/spree/variant/scopes_spec.rb b/spree/core/spec/models/spree/variant/scopes_spec.rb
index 8a46b98db3..2133c32435 100644
--- a/spree/core/spec/models/spree/variant/scopes_spec.rb
+++ b/spree/core/spec/models/spree/variant/scopes_spec.rb
@@ -40,12 +40,6 @@ describe 'Variant scopes', type: :model do
expect(variants.count).to eq(0)
end
- it 'returns no variants when variants sku does not match any' do
- variants = Spree::Variant.product_name_or_sku_cont('variant_white')
- expect(variants).not_to include(variant_1, variant_2, variant_3)
- expect(variants.count).to eq(0)
- end
-
context 'when using translations' do
before do
I18n.with_locale(:pl) do
@@ -73,37 +67,5 @@ describe 'Variant scopes', type: :model do
it 'returns variants based on products name' do
expect(Spree::Variant.search_by_product_name_or_sku('Second')).to include(variant_2)
end
-
- it 'returns variants based on variant sku' do
- expect(Spree::Variant.search_by_product_name_or_sku('blue')).to include(variant_3)
- end
-
- it 'does not return variants of products that do not match name' do
- expect(Spree::Variant.search_by_product_name_or_sku('First')).not_to include(variant_2, variant_3)
- end
-
- it 'does not return variants with not matching skus' do
- expect(Spree::Variant.search_by_product_name_or_sku('green')).not_to include(variant_1, variant_3)
- end
-
- it 'returns multiple variants based on products name' do
- expect(Spree::Variant.search_by_product_name_or_sku('product')).to include(variant_1, variant_2, variant_3)
- end
-
- it 'return multiple variants based on variants sku' do
- expect(Spree::Variant.search_by_product_name_or_sku('variant')).to include(variant_1, variant_2, variant_3)
- end
-
- it 'returns no variants when products name does not match any' do
- variants = Spree::Variant.search_by_product_name_or_sku('White dress')
- expect(variants).not_to include(variant_1, variant_2, variant_3)
- expect(variants.count).to eq(0)
- end
-
- it 'returns no variants when variants sku does not match any' do
- variants = Spree::Variant.search_by_product_name_or_sku('variant_white')
- expect(variants).not_to include(variant_1, variant_2, variant_3)
- expect(variants.count).to eq(0)
- end
end
end
diff --git a/spree/core/spec/models/spree/variant/shared_catalog_spec.rb b/spree/core/spec/models/spree/variant/shared_catalog_spec.rb
index 782c974990..47fa2229c0 100644
--- a/spree/core/spec/models/spree/variant/shared_catalog_spec.rb
+++ b/spree/core/spec/models/spree/variant/shared_catalog_spec.rb
@@ -231,12 +231,15 @@ describe Spree::Variant, type: :model do
let(:product) { create(:product, store: store) }
let(:owned_product) { create(:product, store: store, seller: seller) }
- it 'finds variants by their own seller' do
+ # Spree::Export probes for this scope by name and hands it a Seller
+ # record, so the record form is a contract rather than a convenience.
+ it 'finds variants by their own seller, given a record or an id' do
mine = create(:variant, product: product, seller: seller)
create(:variant, product: product, seller: other_seller)
expect(described_class.for_seller(seller)).to include(mine)
expect(described_class.for_seller(seller).count).to eq(1)
+ expect(described_class.for_seller(seller.id)).to include(mine)
end
it 'finds variants whose seller comes from the product' do
@@ -245,15 +248,6 @@ describe Spree::Variant, type: :model do
expect(described_class.for_seller(seller)).to include(inherited)
end
- # Spree::Export probes for this scope by name and hands it a Seller
- # record, so the record form is a contract rather than a convenience.
- it 'accepts a seller record as well as an id' do
- mine = create(:variant, product: product, seller: seller)
-
- expect(described_class.for_seller(seller)).to include(mine)
- expect(described_class.for_seller(seller.id)).to include(mine)
- end
-
# The raw columns must not be filterable: they would match only variants
# carrying their own seller, silently missing every one that inherits it
# from the product — which on a single-owner catalog is all of them.
diff --git a/spree/core/spec/models/spree/variant_media_spec.rb b/spree/core/spec/models/spree/variant_media_spec.rb
index 5b922ac123..e300dd9c4b 100644
--- a/spree/core/spec/models/spree/variant_media_spec.rb
+++ b/spree/core/spec/models/spree/variant_media_spec.rb
@@ -17,12 +17,6 @@ RSpec.describe Spree::VariantMedia, type: :model do
expect(vm).not_to be_valid
expect(vm.errors[:asset]).to be_present
end
-
- it 'enforces uniqueness on (variant_id, media_id)' do
- described_class.create!(variant: variant, asset: asset)
- dup = described_class.new(variant: variant, asset: asset)
- expect(dup).not_to be_valid
- end
end
describe 'touch propagation' do
@@ -53,19 +47,6 @@ RSpec.describe Spree::VariantMedia, type: :model do
.to change { variant_for_thumb.reload.primary_media_id }.from(product_asset.id).to(nil)
end
end
-
- describe 'cleanup' do
- it 'destroys variant_media when the variant is destroyed' do
- described_class.create!(variant: variant, asset: asset)
- expect { variant.destroy }.to change(described_class, :count).by(-1)
- end
-
- it 'destroys variant_media when the asset is destroyed' do
- described_class.create!(variant: variant, asset: asset)
- expect { asset.destroy }.to change(described_class, :count).by(-1)
- end
- end
-
end
RSpec.describe Spree::Media, type: :model do
diff --git a/spree/core/spec/models/spree/variant_spec.rb b/spree/core/spec/models/spree/variant_spec.rb
index 8a7373a259..388615cc9c 100644
--- a/spree/core/spec/models/spree/variant_spec.rb
+++ b/spree/core/spec/models/spree/variant_spec.rb
@@ -7,12 +7,6 @@ describe Spree::Variant, type: :model do
it_behaves_like 'metadata'
it_behaves_like 'lifecycle events'
- context 'sorting' do
- it 'responds to set_list_position' do
- expect(variant.respond_to?(:set_list_position)).to eq(true)
- end
- end
-
context 'validations' do
it 'rejects a negative price' do
expect { variant.set_price(variant.cost_currency, -1) }.to raise_error(ActiveRecord::RecordInvalid)
@@ -303,16 +297,6 @@ describe Spree::Variant, type: :model do
end
end
- describe '.eligible' do
- it 'returns every variant' do
- product_1 = create(:product)
- product_2 = create(:product)
- variant = create(:variant, product: product_1)
-
- expect(Spree::Variant.eligible).to include(product_1.default_variant, product_2.default_variant, variant)
- end
- end
-
describe '.not_discontinued' do
context 'when discontinued' do
let!(:discontinued_variant) { create(:variant, discontinue_on: Time.current - 1.day) }
@@ -469,31 +453,19 @@ describe Spree::Variant, type: :model do
end
describe '.active' do
- let!(:variants) { [variant] }
- let!(:currency) { 'EUR' }
-
- before do
- allow(Spree::Variant).to receive(:not_discontinued).and_return(variants)
- allow(variants).to receive(:not_deleted).and_return(variants)
- allow(variants).to receive(:for_currency_and_available_price_amount).with(currency).and_return(variants)
+ def variant_priced_in_eur(attributes = {})
+ create(:variant, attributes).tap { |record| create(:price, variant: record, currency: 'EUR', amount: 10) }
end
- it 'finds not_discontinued variants' do
- expect(Spree::Variant).to receive(:not_discontinued).and_return(variants)
- Spree::Variant.active(currency)
- end
+ it 'returns variants that are not discontinued, not deleted and priced in the currency' do
+ active = variant_priced_in_eur
+ discontinued = variant_priced_in_eur(discontinue_on: 1.day.ago)
+ deleted = variant_priced_in_eur.tap(&:destroy)
+ unpriced = create(:variant)
- it 'finds not_deleted variants' do
- expect(variants).to receive(:not_deleted).and_return(variants)
- Spree::Variant.active(currency)
+ expect(Spree::Variant.active('EUR')).to include(active)
+ expect(Spree::Variant.active('EUR')).not_to include(discontinued, deleted, unpriced)
end
-
- it 'finds variants for_currency_and_available_price_amount' do
- expect(variants).to receive(:for_currency_and_available_price_amount).with(currency).and_return(variants)
- Spree::Variant.active(currency)
- end
-
- it { expect(Spree::Variant.active(currency)).to eq(variants) }
end
end
@@ -532,6 +504,8 @@ describe Spree::Variant, type: :model do
expect do
multi_variant.set_option_value('media_type', 'DVD')
+ multi_variant.set_option_value('media_type ', ' DVD ')
+ multi_variant.set_option_value('Media_Type ', ' dvd ')
end.not_to change(multi_variant.option_values, :count)
expect do
@@ -539,40 +513,6 @@ describe Spree::Variant, type: :model do
end.to change(multi_variant.option_values, :count).by(1)
end
end
-
- context 'product has other variants' do
- describe 'option value accessors' do
- before do
- @multi_variant = create(:variant, product: variant.product)
- variant.product.reload
- end
-
- let(:multi_variant) { @multi_variant }
-
- it 'sets option value' do
- expect(multi_variant.option_value('media_type')).to be_nil
-
- multi_variant.set_option_value('media_type', 'DVD')
- expect(multi_variant.option_value('media_type')).to eql 'DVD'
-
- multi_variant.set_option_value('media_type', 'CD')
- expect(multi_variant.option_value('media_type')).to eql 'CD'
- end
-
- it 'does not duplicate associated option values when set multiple times' do
- multi_variant.set_option_value('media_type', 'CD')
-
- expect do
- multi_variant.set_option_value('media_type ', ' DVD ')
- multi_variant.set_option_value('Media_Type ', ' dvd ')
- end.not_to change(multi_variant.option_values, :count)
-
- expect do
- multi_variant.set_option_value('coolness_type', 'awesome')
- end.to change(multi_variant.option_values, :count).by(1)
- end
- end
- end
end
describe '#cost_price=' do
@@ -650,13 +590,6 @@ describe Spree::Variant, type: :model do
end
end
- describe '#price_in' do
- it 'returns a price whose display amount is a Spree::Money' do
- variant.set_price('USD', 21.22)
- expect(variant.price_in('USD').display_amount.to_s).to eql '$21.22'
- end
- end
-
describe '#cost_currency' do
context 'when cost currency is nil' do
before { variant.cost_currency = nil }
@@ -1002,14 +935,6 @@ describe Spree::Variant, type: :model do
end
end
- # Regression test for #2744
- describe 'set_position' do
- it 'sets variant position after creation' do
- variant = create(:variant)
- expect(variant.position).not_to be_nil
- end
- end
-
describe '#in_stock?' do
before do
stub_store_preferences(track_inventory_levels: true)
@@ -1042,16 +967,6 @@ describe Spree::Variant, type: :model do
end
end
- describe '#can_supply?' do
- before { variant }
-
- it 'calls out to quantifier' do
- expect(Spree::Stock::Quantifier).to receive(:new).and_return(quantifier = double)
- expect(quantifier).to receive(:can_supply?).with(10)
- variant.can_supply?(10)
- end
- end
-
context 'when stock_levels are backorderable' do
before do
allow_any_instance_of(Spree::StockLevel).to receive_messages(backorderable: true)
@@ -1073,17 +988,6 @@ describe Spree::Variant, type: :model do
end
end
- describe '#is_backorderable' do
- subject { variant.is_backorderable? }
-
- let(:variant) { build(:variant) }
-
- it 'invokes Spree::Stock::Quantifier' do
- expect_any_instance_of(Spree::Stock::Quantifier).to receive(:backorderable?).and_return(true)
- subject
- end
- end
-
describe '#purchasable?' do
context 'when stock_levels are not backorderable' do
before do
@@ -1125,16 +1029,6 @@ describe Spree::Variant, type: :model do
expect(variant.purchasable?).to be true
end
end
-
- context 'when stock_levels are not backorderable' do
- before do
- allow_any_instance_of(Spree::StockLevel).to receive_messages(backorderable: false)
- end
-
- it 'return false if stock_levels are not backorderable' do
- expect(variant.purchasable?).to be false
- end
- end
end
end
@@ -1143,11 +1037,6 @@ describe Spree::Variant, type: :model do
stub_store_preferences(track_inventory_levels: false)
expect(build(:variant).total_on_hand).to eql(Float::INFINITY)
end
-
- it 'matches quantifier total_on_hand' do
- variant = build(:variant)
- expect(variant.total_on_hand).to eq(Spree::Stock::Quantifier.new(variant).total_on_hand)
- end
end
describe '#tax_category' do
@@ -1397,18 +1286,6 @@ describe Spree::Variant, type: :model do
end
end
- describe '#created_at' do
- it 'creates variant with created_at timestamp' do
- expect(variant.created_at).not_to be_nil
- end
- end
-
- describe '#updated_at' do
- it 'creates variant with updated_at timestamp' do
- expect(variant.updated_at).not_to be_nil
- end
- end
-
describe '#backordered?' do
let!(:variant) { create(:variant) }
@@ -1479,12 +1356,15 @@ describe Spree::Variant, type: :model do
describe '#secondary_image' do
let(:variant) { create(:variant) }
+ before { allow(Spree::Deprecation).to receive(:warn) }
+
context 'with images pinned to the variant' do
let!(:image1) { create(:media, position: 1, viewable: variant) }
let!(:image2) { create(:media, position: 2, viewable: variant) }
it 'returns the second image' do
expect(variant.secondary_image).to eq(image2)
+ expect(Spree::Deprecation).to have_received(:warn).with(/Variant#secondary_image is deprecated/)
end
end
@@ -1507,6 +1387,7 @@ describe Spree::Variant, type: :model do
let!(:image3) { create(:media, position: 3, viewable: variant) }
it 'returns all images except the default' do
+ expect(Spree::Deprecation).to receive(:warn).with(/Variant#additional_images is deprecated/)
expect(variant.additional_images).to eq([image2, image3])
end
end
@@ -1553,27 +1434,12 @@ describe Spree::Variant, type: :model do
let(:product) { create(:product) }
describe 'variant_count on product' do
- it 'counts the default variant' do
- expect(product.reload.variant_count).to eq(1)
- end
-
- it 'increments when a variant is created' do
- expect {
- create(:variant, product: product)
- }.to change { product.reload.variant_count }.from(1).to(2)
- end
-
it 'decrements when a variant is destroyed' do
variant = create(:variant, product: product)
expect {
variant.destroy
}.to change { product.reload.variant_count }.from(2).to(1)
end
-
- it 'correctly counts multiple variants' do
- create_list(:variant, 3, product: product)
- expect(product.reload.variant_count).to eq(4)
- end
end
end
@@ -1714,14 +1580,6 @@ describe Spree::Variant, type: :model do
end
describe '#options=' do
- it 'sets option values via set_option_value' do
- product = create(:product)
- v = create(:variant, product: product)
- v.set_option_value('color', 'blue')
-
- expect(v.option_values.reload.map(&:name)).to include('blue')
- end
-
it 'calls set_option_value for each option hash' do
product = create(:product)
v = create(:variant, product: product)
diff --git a/spree/core/spec/models/spree/webhook_delivery_spec.rb b/spree/core/spec/models/spree/webhook_delivery_spec.rb
index 1bb34c2435..11787b0c2c 100644
--- a/spree/core/spec/models/spree/webhook_delivery_spec.rb
+++ b/spree/core/spec/models/spree/webhook_delivery_spec.rb
@@ -5,7 +5,6 @@ require 'spec_helper'
describe Spree::WebhookDelivery, type: :model do
let(:store) { @default_store }
let(:webhook_endpoint) { create(:webhook_endpoint, store: store) }
- let(:webhook_delivery) { build(:webhook_delivery, webhook_endpoint: webhook_endpoint) }
describe 'scopes' do
let!(:pending_delivery) { create(:webhook_delivery, :pending, webhook_endpoint: webhook_endpoint) }
diff --git a/spree/core/spec/models/spree/webhook_endpoint_spec.rb b/spree/core/spec/models/spree/webhook_endpoint_spec.rb
index 70ee2971b1..7d38b97812 100644
--- a/spree/core/spec/models/spree/webhook_endpoint_spec.rb
+++ b/spree/core/spec/models/spree/webhook_endpoint_spec.rb
@@ -44,23 +44,6 @@ describe Spree::WebhookEndpoint, type: :model do
expect(webhook_endpoint.errors[:url]).to include('must not point to an internal or private network address')
end
end
-
- describe 'active inclusion' do
- it 'accepts true' do
- webhook_endpoint.active = true
- expect(webhook_endpoint).to be_valid
- end
-
- it 'accepts false' do
- webhook_endpoint.active = false
- expect(webhook_endpoint).to be_valid
- end
-
- it 'rejects nil' do
- webhook_endpoint.active = nil
- expect(webhook_endpoint).not_to be_valid
- end
- end
end
describe 'callbacks' do
@@ -173,23 +156,6 @@ describe Spree::WebhookEndpoint, type: :model do
expect(endpoint.subscribed_to?('shipment.shipped')).to be false
end
end
-
- context 'with mixed subscriptions' do
- let(:endpoint) { build(:webhook_endpoint, subscriptions: ['order.*', 'product.created']) }
-
- it 'matches pattern events' do
- expect(endpoint.subscribed_to?('order.created')).to be true
- expect(endpoint.subscribed_to?('order.placed')).to be true
- end
-
- it 'matches exact events' do
- expect(endpoint.subscribed_to?('product.created')).to be true
- end
-
- it 'does not match non-subscribed events' do
- expect(endpoint.subscribed_to?('product.updated')).to be false
- end
- end
end
describe '#subscribed_events' do
@@ -355,14 +321,4 @@ describe Spree::WebhookEndpoint, type: :model do
end
end
end
-
- describe 'soft delete' do
- let!(:endpoint) { create(:webhook_endpoint, store: store) }
-
- it 'soft deletes the record' do
- endpoint.destroy
- expect(endpoint.deleted_at).to be_present
- expect(described_class.with_deleted.find(endpoint.id)).to eq(endpoint)
- end
- end
end
diff --git a/spree/core/spec/models/spree/wishlist_item_spec.rb b/spree/core/spec/models/spree/wishlist_item_spec.rb
index 6a65afc8fd..346c225811 100644
--- a/spree/core/spec/models/spree/wishlist_item_spec.rb
+++ b/spree/core/spec/models/spree/wishlist_item_spec.rb
@@ -4,42 +4,9 @@ RSpec.describe Spree::WishlistItem, type: :model do
it_behaves_like 'lifecycle events'
describe '.quantity' do
- subject { build(:wishlist_item) }
-
- let!(:wishlist) { create(:wishlist) }
let!(:variant) { create(:variant) }
let!(:wishlist_item_with_variant) { create(:wishlist_item, variant: variant, quantity: 3) }
- it { is_expected.to respond_to(:quantity) }
- it { expect(subject.quantity).to eq(1) }
-
- it 'validates presence of wishlist' do
- expect(described_class.new(quantity: 3, wishlist: nil, variant: variant)).not_to be_valid
- end
-
- it 'validates presence of variant' do
- expect(described_class.new(quantity: 3, wishlist: wishlist, variant: nil)).not_to be_valid
- end
-
- it 'validates numericality of quantity' do
- expect(described_class.new(quantity: nil, wishlist: wishlist, variant: variant)).not_to be_valid
- expect(described_class.new(quantity: 'string', wishlist: wishlist, variant: variant)).not_to be_valid
- expect(described_class.new(quantity: 0.5, wishlist: wishlist, variant: variant)).not_to be_valid
- end
-
- it 'validates numericality must be greater than 0' do
- expect(described_class.new(quantity: 0, wishlist: wishlist, variant: variant)).not_to be_valid
- expect(described_class.new(quantity: -1, wishlist: wishlist, variant: variant)).not_to be_valid
- end
-
- describe 'when wishlist_item is already associated with the wishlist' do
- let!(:existing_wishlist_item) { create(:wishlist_item, quantity: 3, wishlist: wishlist, variant: variant) }
-
- it 'validates uniqueness of variant within scope of wishlist' do
- expect(described_class.new(quantity: 2, wishlist: wishlist, variant: variant)).not_to be_valid
- end
- end
-
describe '.price' do
it { expect(wishlist_item_with_variant.price(currency: 'USD')).to eq(variant.amount_in('USD')) }
end
diff --git a/spree/core/spec/models/spree/wishlist_spec.rb b/spree/core/spec/models/spree/wishlist_spec.rb
index e21a5e8ca6..8ec13dd6b0 100644
--- a/spree/core/spec/models/spree/wishlist_spec.rb
+++ b/spree/core/spec/models/spree/wishlist_spec.rb
@@ -10,38 +10,7 @@ describe Spree::Wishlist, type: :model do
let(:wishlist_belonging_to_other_store) { create(:wishlist, customer: user, name: 'My Wishlist', store: other_store, is_default: true) }
let(:wishlist_belonging_to_other_user) { create(:wishlist, customer: other_user, name: 'My Wishlist', store: store, is_default: true) }
- describe 'lifecycle events', events: true do
- describe 'wishlist.created' do
- it 'publishes created event when record is created' do
- record = build(:wishlist, customer: user, store: store)
- expect(record).to receive(:publish_event).with('wishlist.created')
- allow(record).to receive(:publish_event).with(anything)
-
- record.save!
- end
- end
-
- describe 'wishlist.updated' do
- it 'publishes updated event when record is updated' do
- expect(wishlist).to receive(:publish_event).with('wishlist.updated')
- allow(wishlist).to receive(:publish_event).with(anything)
-
- Timecop.travel(1.minute.from_now) do
- wishlist.update_attribute(:updated_at, Time.current)
- end
- end
- end
-
- describe 'wishlist.deleted' do
- it 'publishes deleted event when record is destroyed' do
- record = create(:wishlist, customer: user, store: store)
- expect(record).to receive(:publish_event).with('wishlist.deleted', kind_of(Hash))
- allow(record).to receive(:publish_event).with(anything)
-
- record.destroy!
- end
- end
- end
+ it_behaves_like 'lifecycle events'
describe '.ensure_default_exists_and_is_unique' do
context 'when user creates a new default store' do
@@ -53,7 +22,7 @@ describe Spree::Wishlist, type: :model do
end
it 'preserves is_default: true for new wishlist' do
- expect(new_wl.is_default).to be true
+ expect(new_wl.reload.is_default).to be true
end
it 'sets is_default: false on the wishlist that was the previous default' do
@@ -90,16 +59,6 @@ describe Spree::Wishlist, type: :model do
end
end
- describe '#destroy' do
- let!(:wishlist_item) { create(:wishlist_item) }
-
- it 'deletes associated wishlist items' do
- expect do
- wishlist_item.wishlist.destroy
- end.to change(Spree::WishlistItem, :count).by(-1)
- end
- end
-
describe '#product_ids' do
let(:product) { create(:product) }
let(:variant) { create(:variant, product: product) }
@@ -115,32 +74,6 @@ describe Spree::Wishlist, type: :model do
end
end
- describe '#wishlist_items_count' do
- let(:variant) { create(:variant) }
-
- before do
- wishlist.wishlist_items << create(:wishlist_item, variant: variant)
- end
-
- it 'returns the wishlist items count' do
- expect(wishlist.wishlist_items_count).to eq 1
- end
- end
-
- describe '#variant_ids' do
- let(:variant) { create(:variant) }
- let(:variant_2) { create(:variant) }
-
- before do
- wishlist.wishlist_items << create(:wishlist_item, variant: variant)
- wishlist.wishlist_items << create(:wishlist_item, variant: variant_2)
- end
-
- it 'returns the variant ids' do
- expect(wishlist.variant_ids).to eq [variant.id, variant_2.id]
- end
- end
-
describe '#wished_items_count' do
# The pre-6.0 name stays callable for one release.
it 'delegates to the renamed counter' do
diff --git a/spree/core/spec/presenters/spree/csv/order_line_items_presenter_spec.rb b/spree/core/spec/presenters/spree/csv/order_line_items_presenter_spec.rb
index 73d24ba2b7..e6cd373295 100644
--- a/spree/core/spec/presenters/spree/csv/order_line_items_presenter_spec.rb
+++ b/spree/core/spec/presenters/spree/csv/order_line_items_presenter_spec.rb
@@ -24,7 +24,7 @@ RSpec.describe Spree::CSV::OrderLineItemPresenter do
expect(subject[5]).to eq money(order.delivery_total)
expect(subject[6]).to eq money(order.tax_total)
expect(subject[7]).to eq order.included_tax_total.positive?
- expect(subject[8]).to eq(order.promo_total.negative? || line_item.promo_total.negative?)
+ expect(subject[8]).to eq(order.discount_total.negative? || line_item.promo_total.negative?)
expect(subject[9]).to eq order.has_free_shipping?
expect(subject[10]).to eq money(order.discount_total.abs)
expect(subject[11]).to eq order.promo_code
diff --git a/spree/core/spec/services/spree/orders/create_spec.rb b/spree/core/spec/services/spree/orders/create_spec.rb
index 5e54d6e8c6..b52f93879b 100644
--- a/spree/core/spec/services/spree/orders/create_spec.rb
+++ b/spree/core/spec/services/spree/orders/create_spec.rb
@@ -61,7 +61,7 @@ module Spree
expect(order).to be_persisted
expect(order.status).to eq('draft')
expect(order.shipments).to be_empty
- expect(order.shipment_total).to eq(0)
+ expect(order.delivery_total).to eq(0)
end
end
@@ -78,7 +78,7 @@ module Spree
order = subject.value
expect(order.line_items.count).to eq(1)
expect(order.shipments).to be_empty
- expect(order.shipment_total).to eq(0)
+ expect(order.delivery_total).to eq(0)
expect(order.total).to eq(order.item_total)
end
end
@@ -96,7 +96,7 @@ module Spree
order = subject.value
expect(order.ship_address).to be_present
expect(order.shipments).to be_empty
- expect(order.shipment_total).to eq(0)
+ expect(order.delivery_total).to eq(0)
end
end
@@ -118,14 +118,14 @@ module Spree
expect(order.fulfillments.first.shipping_rates).not_to be_empty
expect(order.fulfillments.first.selected_shipping_rate).to be_present
- expect(order.shipment_total).to eq(5)
- expect(order.total).to eq(order.item_total + order.shipment_total + order.adjustment_total)
+ expect(order.delivery_total).to eq(5)
+ expect(order.total).to eq(order.item_total + order.delivery_total + order.adjustment_total)
end
it 'persists the totals to the database' do
subject
order = subject.value.reload
- expect(order.shipment_total).to eq(5)
+ expect(order.delivery_total).to eq(5)
expect(order.total).to eq(order.item_total + 5 + order.adjustment_total)
end
end
@@ -146,7 +146,7 @@ module Spree
it 'does not build shipments' do
expect(subject).to be_success
expect(subject.value.shipments).to be_empty
- expect(subject.value.shipment_total).to eq(0)
+ expect(subject.value.delivery_total).to eq(0)
end
end
@@ -170,13 +170,13 @@ module Spree
# Shipments still exist, gross cost is still 5 (cost column on the shipment)
expect(order.shipments.size).to eq(1)
- expect(order.shipment_total).to eq(5)
+ expect(order.delivery_total).to eq(5)
# Promo created a -5 adjustment on the shipment
shipment = order.fulfillments.first
expect(shipment.adjustment_total).to eq(-5)
expect(shipment.discounts.promotion.size).to eq(1)
- expect(order.shipping_discount).to eq(5)
+ expect(order.fulfillment_discount).to eq(5)
# Promotion is associated with the order
expect(order.promotions).to include(promotion)
@@ -229,7 +229,7 @@ module Spree
shipment = order.fulfillments.first
expect(shipment).to be_present
expect(shipment.adjustment_total).to eq(-5)
- expect(order.shipping_discount).to eq(5)
+ expect(order.fulfillment_discount).to eq(5)
expect(order.total).to eq(order.item_total)
end
end
diff --git a/spree/core/spec/services/spree/orders/update_spec.rb b/spree/core/spec/services/spree/orders/update_spec.rb
index a1923ac640..891d5fc7b7 100644
--- a/spree/core/spec/services/spree/orders/update_spec.rb
+++ b/spree/core/spec/services/spree/orders/update_spec.rb
@@ -158,7 +158,7 @@ module Spree
it 'starts with shipments built from the seeded data' do
expect(order.shipments).not_to be_empty
- expect(order.shipment_total).to eq(5)
+ expect(order.delivery_total).to eq(5)
end
context 'when items change' do
@@ -176,7 +176,7 @@ module Spree
expect(new_shipment_ids).not_to be_empty
expect(new_shipment_ids & old_shipment_ids).to be_empty
expect(order.fulfillments.first.inventory_units.sum(:quantity)).to eq(3)
- expect(order.shipment_total).to eq(5)
+ expect(order.delivery_total).to eq(5)
end
end
@@ -386,7 +386,7 @@ module Spree
order.reload
expect(order.line_items.first.quantity).to eq(2)
expect(order.item_total).to eq(variant.amount_in(order.currency) * 2)
- expect(order.total).to eq(order.item_total + order.shipment_total + order.adjustment_total)
+ expect(order.total).to eq(order.item_total + order.delivery_total + order.adjustment_total)
end
end
@@ -402,7 +402,7 @@ module Spree
shipment = order.fulfillments.first
expect(shipment).to be_present
expect(shipment.adjustment_total).to eq(-5)
- expect(order.shipping_discount).to eq(5)
+ expect(order.fulfillment_discount).to eq(5)
expect(order.total).to eq(order.item_total)
end
@@ -410,7 +410,7 @@ module Spree
# Seed: order with line item + shipments + promo applied
described_class.call(order: order, params: { items: [{ variant_id: variant.prefixed_id, quantity: 1 }] })
order.reload
- expect(order.shipping_discount).to eq(5)
+ expect(order.fulfillment_discount).to eq(5)
# Move to a different country — shipments rebuild, promo must re-apply
described_class.call(order: order, params: {
@@ -425,7 +425,7 @@ module Spree
order.reload
expect(order.fulfillments.first.adjustment_total).to eq(-5)
- expect(order.shipping_discount).to eq(5)
+ expect(order.fulfillment_discount).to eq(5)
expect(order.total).to eq(order.item_total)
end
end
diff --git a/spree/core/spec/services/spree/products/duplicator_spec.rb b/spree/core/spec/services/spree/products/duplicator_spec.rb
index 3f292f990d..4d5cc14534 100644
--- a/spree/core/spec/services/spree/products/duplicator_spec.rb
+++ b/spree/core/spec/services/spree/products/duplicator_spec.rb
@@ -43,13 +43,13 @@ RSpec.describe Spree::Products::Duplicator do
# A promise belongs to the order that made it. Copied onto the duplicate,
# it would open holding stock for somebody else's order.
it 'starts the copy with no stock and no promise' do
- original = product.variants_including_master.first
+ original = product.variants.first
level = original.stock_levels.first
level.update_columns(count_on_hand: 7, allocated_count: 3)
new_product = subject.value
- new_product.variants_including_master.flat_map(&:stock_levels).each do |copy|
+ new_product.variants.flat_map(&:stock_levels).each do |copy|
expect(copy.count_on_hand).to eq(0)
expect(copy.allocated_count).to eq(0)
end
diff --git a/spree/core/spec/services/spree/stock_locations/stock_levels/create_spec.rb b/spree/core/spec/services/spree/stock_locations/stock_levels/create_spec.rb
index a0d9c0b12b..a7ba09d9df 100644
--- a/spree/core/spec/services/spree/stock_locations/stock_levels/create_spec.rb
+++ b/spree/core/spec/services/spree/stock_locations/stock_levels/create_spec.rb
@@ -83,7 +83,7 @@ module Spree
result
- expect(stock_location.stock_levels.pluck(:variant_id)).to match_array(own.product.variants_including_master.ids)
+ expect(stock_location.stock_levels.pluck(:variant_id)).to match_array(own.product.variants.ids)
end
end
diff --git a/spree/core/spec/services/spree/stock_reservations/extend_spec.rb b/spree/core/spec/services/spree/stock_reservations/extend_spec.rb
index 61122b7c6a..238d6925dc 100644
--- a/spree/core/spec/services/spree/stock_reservations/extend_spec.rb
+++ b/spree/core/spec/services/spree/stock_reservations/extend_spec.rb
@@ -10,7 +10,7 @@ describe Spree::StockReservations::Extend do
it 'pushes expires_at out by the store TTL' do
Timecop.freeze do
- described_class.call(order: order)
+ described_class.call(cart: order)
expect(reservation.reload.expires_at).to be_within(1.second).of(12.minutes.from_now)
end
end
@@ -20,7 +20,7 @@ describe Spree::StockReservations::Extend do
other_reservation = create(:stock_reservation, order: other_order, expires_at: 1.minute.from_now)
original_other_expires_at = other_reservation.expires_at
- described_class.call(order: order)
+ described_class.call(cart: order)
expect(other_reservation.reload.expires_at).to be_within(1.second).of(original_other_expires_at)
end
@@ -31,7 +31,7 @@ describe Spree::StockReservations::Extend do
it 'leaves expires_at untouched' do
original = reservation.expires_at
- described_class.call(order: order)
+ described_class.call(cart: order)
expect(reservation.reload.expires_at).to be_within(1.second).of(original)
end
end
diff --git a/spree/core/spec/services/spree/stock_reservations/reserve_spec.rb b/spree/core/spec/services/spree/stock_reservations/reserve_spec.rb
index b25224b88f..cb27a5cdb9 100644
--- a/spree/core/spec/services/spree/stock_reservations/reserve_spec.rb
+++ b/spree/core/spec/services/spree/stock_reservations/reserve_spec.rb
@@ -8,7 +8,7 @@ describe Spree::StockReservations::Reserve do
let(:order) { create(:order, store: store) }
let!(:line_item) { create(:line_item, order: order, variant: variant, quantity: 3) }
- subject(:result) { described_class.call(order: order) }
+ subject(:result) { described_class.call(cart: order) }
context 'when stock_reservations_enabled is true' do
before { stub_store_preferences(store, stock_reservations_enabled: true) }
@@ -33,8 +33,8 @@ describe Spree::StockReservations::Reserve do
end
it 'is idempotent — calling twice updates the same reservation, not creating a new one' do
- described_class.call(order: order)
- expect { described_class.call(order: order) }.not_to change(Spree::StockReservation, :count)
+ described_class.call(cart: order)
+ expect { described_class.call(cart: order) }.not_to change(Spree::StockReservation, :count)
end
it 'holds the units on the level, and re-holding moves the figure by the difference' do
@@ -42,7 +42,7 @@ describe Spree::StockReservations::Reserve do
line_item.update!(quantity: 5)
- expect { described_class.call(order: order) }.to change { stock_level.reload.reserved_count }.from(3).to(5)
+ expect { described_class.call(cart: order) }.to change { stock_level.reload.reserved_count }.from(3).to(5)
end
# A hold that lapsed and was revived by a later edit is a hold again, and
@@ -51,7 +51,7 @@ describe Spree::StockReservations::Reserve do
result
Spree::StockReservation.last.update_column(:expires_at, 1.minute.ago)
- described_class.call(order: order)
+ described_class.call(cart: order)
expect(Spree::StockReservation.last).to be_active
expect(stock_level.reload.reserved_count).to eq(3)
diff --git a/spree/core/spec/services/spree/store_credits/apply_spec.rb b/spree/core/spec/services/spree/store_credits/apply_spec.rb
index 765ef091c0..b2e97f39f1 100644
--- a/spree/core/spec/services/spree/store_credits/apply_spec.rb
+++ b/spree/core/spec/services/spree/store_credits/apply_spec.rb
@@ -141,7 +141,7 @@ describe Spree::StoreCredits::Apply, type: :service do
described_class.call(order: order.reload)
payment = order.reload.payments.store_credits.checkout.first
- payment.purchase!
+ Spree.payment_process_workflow.call(payment: payment, action: :purchase)
expect(payment.reload).to be_completed
expect(store_credit.reload.amount_used).to eq(300)
diff --git a/spree/core/spec/subscribers/spree/order_status_subscriber_spec.rb b/spree/core/spec/subscribers/spree/order_status_subscriber_spec.rb
index 4b61876d76..4c10f25669 100644
--- a/spree/core/spec/subscribers/spree/order_status_subscriber_spec.rb
+++ b/spree/core/spec/subscribers/spree/order_status_subscriber_spec.rb
@@ -101,7 +101,7 @@ RSpec.describe Spree::OrderStatusSubscriber do
payment = create(:payment, order: order, cart: nil, amount: order.total, status: 'pending')
order.update_columns(payment_status: 'none')
- payment.capture!
+ Spree.payment_capture_workflow.call(payment: payment)
expect(order.reload.payment_status).to eq('paid')
end
diff --git a/spree/core/spec/workflows/spree/carts/recalculate_totals_spec.rb b/spree/core/spec/workflows/spree/carts/recalculate_totals_spec.rb
index aab7a826c8..ee5fc12df0 100644
--- a/spree/core/spec/workflows/spree/carts/recalculate_totals_spec.rb
+++ b/spree/core/spec/workflows/spree/carts/recalculate_totals_spec.rb
@@ -243,7 +243,7 @@ module Spree
line_item.update_column(:price, 25)
described_class.call(cart: cart)
- gift_card_payment.purchase!
+ Spree.payment_process_workflow.call(payment: gift_card_payment, action: :purchase)
expect(gift_card_payment.reload).to be_completed
end
diff --git a/spree/core/spec/workflows/spree/fulfillments/create_spec.rb b/spree/core/spec/workflows/spree/fulfillments/create_spec.rb
index c2aa889f3e..8e67240371 100644
--- a/spree/core/spec/workflows/spree/fulfillments/create_spec.rb
+++ b/spree/core/spec/workflows/spree/fulfillments/create_spec.rb
@@ -241,7 +241,7 @@ module Spree
it 'inherits the first non-nil method when draining sources with different carriers' do
other_method = create(:delivery_method)
second_source = order.shipments.create!(stock_location: stock_location)
- second_source.add_shipping_method(other_method, true)
+ second_source.add_delivery_method(other_method, true)
line_items.last.inventory_units.update_all(shipment_id: second_source.id)
first_source_method = source_shipment.delivery_method
@@ -273,7 +273,7 @@ module Spree
it 'freezes the given cost instead of the inherited one' do
expect(execute.success?).to eq(true)
expect(fulfillment.cost).to eq(BigDecimal('7.42'))
- expect(order.reload.shipment_total).to eq(BigDecimal('7.42'))
+ expect(order.reload.delivery_total).to eq(BigDecimal('7.42'))
end
it 'prices the carrier rate at the given cost' do
diff --git a/spree/core/spec/workflows/spree/payments/handle_webhook_spec.rb b/spree/core/spec/workflows/spree/payments/handle_webhook_spec.rb
index 68b96630fd..b1b5fa72ee 100644
--- a/spree/core/spec/workflows/spree/payments/handle_webhook_spec.rb
+++ b/spree/core/spec/workflows/spree/payments/handle_webhook_spec.rb
@@ -65,7 +65,7 @@ RSpec.describe Spree::Payments::HandleWebhook do
it 'completes the payment' do
subject.call(payment_method: payment_method, action: :captured, payment_session: payment_session)
- expect(order.reload.payments.first.state).to eq('completed')
+ expect(order.reload.payments.first.status).to eq('completed')
end
it 'completes the order with payment_state=paid' do
@@ -91,7 +91,7 @@ RSpec.describe Spree::Payments::HandleWebhook do
expect(result).to be_success
expect(order.reload.payments.count).to eq(1)
- expect(order.payments.first.state).to eq('pending')
+ expect(order.payments.first.status).to eq('pending')
end
it 'completes the payment session' do
diff --git a/spree/core/spec/workflows/spree/sellers/onboarding_lifecycle_spec.rb b/spree/core/spec/workflows/spree/sellers/onboarding_lifecycle_spec.rb
index fd39189e27..746672ccf8 100644
--- a/spree/core/spec/workflows/spree/sellers/onboarding_lifecycle_spec.rb
+++ b/spree/core/spec/workflows/spree/sellers/onboarding_lifecycle_spec.rb
@@ -80,7 +80,7 @@ RSpec.describe 'seller onboarding lifecycle' do
role: seller.default_user_role)
invitation.update!(invitee: invitee)
- invitation.accept!
+ expect(Spree.invitation_accept_workflow.call(invitation: invitation)).to be_success
expect(seller.reload).to be_onboarding
end
diff --git a/spree/emails/spec/models/spree/order_spec.rb b/spree/emails/spec/models/spree/order_spec.rb
index c462675eea..e2eaeee361 100644
--- a/spree/emails/spec/models/spree/order_spec.rb
+++ b/spree/emails/spec/models/spree/order_spec.rb
@@ -5,20 +5,20 @@ describe Spree::Order, type: :model do
let(:user) { create(:user) }
let(:order) { create(:order, customer: user, store: store) }
- context '#finalize!' do
+ context 'when the order completes' do
let(:order) { create(:order, email: '[email protected]', store: store) }
before do
order.update_column :status, 'placed'
end
- it 'publishes order.placed event when finalizing', events: true do
+ it 'publishes the order.placed event', events: true do
expect(order).to receive(:publish_event).with('order.placed', kind_of(Hash), hash_including(:notify_customer))
expect(order).to receive(:publish_event).with('order.completed', kind_of(Hash), hash_including(:notify_customer, deprecated_alias_of: 'order.placed'))
allow(order).to receive(:publish_event).with(anything)
allow(order).to receive(:publish_event).with(anything, anything)
- order.finalize!
+ Spree.order_complete_workflow.call(order: order, payment_pending: true)
end
end
end
diff --git a/spree/emails/spec/models/spree/shipment_spec.rb b/spree/emails/spec/models/spree/shipment_spec.rb
index 525727d191..95b790c66b 100644
--- a/spree/emails/spec/models/spree/shipment_spec.rb
+++ b/spree/emails/spec/models/spree/shipment_spec.rb
@@ -1,36 +1,15 @@
require 'spec_helper'
describe Spree::Fulfillment, type: :model do
- let(:order) { create(:order) }
- let(:shipping_method) { create(:delivery_method, name: 'UPS') }
- let(:shipment) { create(:fulfillment, cost: 1, status: 'unfulfilled', stock_location: create(:stock_location), order: order) }
+ let(:shipment) { create(:fulfillment) }
- before do
- allow(order).to receive_messages backordered?: false,
- canceled?: false,
- can_ship?: true,
- paid?: false,
- touch_later: false
+ # The legacy shipment.* name is dual-emitted for one release, and the
+ # email subscribers still listen for it.
+ it 'publishes shipment.shipped event when fulfilling', events: true do
+ expect(shipment).to receive(:publish_event).
+ with('shipment.shipped', nil, hash_including(notify_customer: true))
+ allow(shipment).to receive(:publish_event).with(any_args)
- allow(shipment).to receive_messages(delivery_method: shipping_method, shipping_method: shipping_method)
- end
-
- ['unfulfilled', 'canceled'].each do |status|
- context "from #{status}" do
- before do
- allow(order).to receive(:update_with_updater!)
- allow(shipment).to receive_messages(require_inventory: false, update_order: true, status: status)
- end
-
- # The legacy shipment.* name is dual-emitted for one release, and the
- # email subscribers still listen for it.
- it 'publishes shipment.shipped event when fulfilling', events: true do
- expect(shipment).to receive(:publish_event).
- with('shipment.shipped', nil, hash_including(notify_customer: true))
- allow(shipment).to receive(:publish_event).with(any_args)
-
- shipment.publish_fulfillment_fulfilled_event
- end
- end
+ shipment.publish_fulfillment_fulfilled_event
end
end
diff --git a/spree/providers/easypost/spec/models/spree_easypost/customs_params_spec.rb b/spree/providers/easypost/spec/models/spree_easypost/customs_params_spec.rb
index d84a42a0a7..963eff3f6b 100644
--- a/spree/providers/easypost/spec/models/spree_easypost/customs_params_spec.rb
+++ b/spree/providers/easypost/spec/models/spree_easypost/customs_params_spec.rb
@@ -56,12 +56,16 @@ RSpec.describe 'SpreeEasyPost customs params' do
end
it 'certifies the declaration once a signer is named' do
- integration = SpreeEasyPost::Integration.new(store: store, preferences: { customs_signer: 'Jane Doe' })
+ integration = SpreeEasyPost::Integration.new(
+ store: store,
+ preferences: { customs_signer: 'Jane Doe', customs_contents_type: 'gift' }
+ )
params = SpreeEasyPost.customs_info_params(package, origin, foreign_destination, integration)
expect(params[:customs_certify]).to be true
expect(params[:customs_signer]).to eq('Jane Doe')
+ expect(params[:contents_type]).to eq('gift')
end
it 'carries the variant classification when the merchant recorded it' do
@@ -84,18 +88,6 @@ RSpec.describe 'SpreeEasyPost customs params' do
expect(item[:description]).to eq(variant.name)
end
- it 'takes the signer and contents type from the integration when configured' do
- integration = SpreeEasyPost::Integration.new(
- store: store,
- preferences: { customs_signer: 'Jane Doe', customs_contents_type: 'gift' }
- )
-
- params = SpreeEasyPost.customs_info_params(package, origin, foreign_destination, integration)
-
- expect(params[:customs_signer]).to eq('Jane Doe')
- expect(params[:contents_type]).to eq('gift')
- end
-
it 'defaults the incoterm to DAP so the recipient is billed for duties' do
integration = SpreeEasyPost::Integration.new(store: store)
diff --git a/spree/providers/easypost/spec/models/spree_easypost/delivery_rate_provider_spec.rb b/spree/providers/easypost/spec/models/spree_easypost/delivery_rate_provider_spec.rb
index f0805641e5..54e5b9e6b8 100644
--- a/spree/providers/easypost/spec/models/spree_easypost/delivery_rate_provider_spec.rb
+++ b/spree/providers/easypost/spec/models/spree_easypost/delivery_rate_provider_spec.rb
@@ -203,18 +203,6 @@ RSpec.describe SpreeEasyPost::DeliveryRateProvider do
)
end
- it 'converts a metric store dimensions to inches' do
- store.update!(preferred_unit_system: 'metric')
- store.default_package_type.update!(length: 30.48, width: 22.86, height: 10.16,
- dimensions_unit: 'cm')
-
- provider.estimates(package)
-
- expect(shipment_service).to have_received(:create).with(
- hash_including(parcel: hash_including(length: 12.0, width: 9.0, height: 4.0))
- )
- end
-
# A merchant can record a carton in whatever unit the supplier quoted
# it in, regardless of what the store trades in. Reading centimetres as
# inches overstates every axis by 2.54 and inflates the carrier's
diff --git a/spree/providers/easypost/spec/models/spree_easypost/integration_spec.rb b/spree/providers/easypost/spec/models/spree_easypost/integration_spec.rb
index 50955a967b..be1f8bb821 100644
--- a/spree/providers/easypost/spec/models/spree_easypost/integration_spec.rb
+++ b/spree/providers/easypost/spec/models/spree_easypost/integration_spec.rb
@@ -39,7 +39,6 @@ RSpec.describe SpreeEasyPost::Integration do
integration.can_connect?
expect(address_service).to have_received(:create).with(described_class::VERIFICATION_ADDRESS)
- expect(client).not_to respond_to(:carrier_account)
end
it 'captures the vendor message on failure' do
@@ -76,14 +75,4 @@ RSpec.describe SpreeEasyPost::Integration do
end
end
end
-
- describe 'verify before activate' do
- it 'blocks activation when the connection fails' do
- allow(integration).to receive(:can_connect?).and_return(false)
- integration.active = true
-
- expect(integration).not_to be_valid
- expect(integration.errors[:base]).to be_present
- end
- end
end
diff --git a/spree/providers/meilisearch/spec/models/spree_meilisearch/search_provider_spec.rb b/spree/providers/meilisearch/spec/models/spree_meilisearch/search_provider_spec.rb
index 939c4d0fd9..3204902e6c 100644
--- a/spree/providers/meilisearch/spec/models/spree_meilisearch/search_provider_spec.rb
+++ b/spree/providers/meilisearch/spec/models/spree_meilisearch/search_provider_spec.rb
@@ -39,11 +39,6 @@ RSpec.describe SpreeMeilisearch::SearchProvider do
allow(mock_index).to receive(:search).and_return(ms_response)
end
- it 'returns a SearchResult' do
- result = provider.search_and_filter(scope: store.products, query: 'shirt')
- expect(result).to be_a(Spree::SearchProvider::SearchResult)
- end
-
it 'queries Meilisearch with the search term' do
expect(mock_index).to receive(:search).with('shirt', hash_including(:page, :hitsPerPage))
provider.search_and_filter(scope: store.products, query: 'shirt')
@@ -59,11 +54,6 @@ RSpec.describe SpreeMeilisearch::SearchProvider do
expect(result.total_count).to eq(2)
end
- it 'does not request facets from Meilisearch' do
- expect(mock_index).to receive(:search).with(anything, satisfy { |params| !params.key?(:facets) })
- provider.search_and_filter(scope: store.products, query: 'shirt')
- end
-
context 'listing all products (no query, no filters)' do
it 'searches an empty query with only system conditions and no facets' do
expect(mock_index).to receive(:search).with('', satisfy { |p|
@@ -315,11 +305,6 @@ RSpec.describe SpreeMeilisearch::SearchProvider do
allow(mock_index).to receive(:search).and_return(ms_response)
end
- it 'returns a FiltersResult' do
- result = provider.filters(scope: store.products, query: 'shirt')
- expect(result).to be_a(Spree::SearchProvider::FiltersResult)
- end
-
it 'returns facets from Meilisearch' do
result = provider.filters(scope: store.products, query: 'shirt')
expect(result.filters).to be_an(Array)
@@ -346,10 +331,10 @@ RSpec.describe SpreeMeilisearch::SearchProvider do
end
end
- it 'returns sort options as objects' do
+ it 'returns sort options as objects, including manual (sourced from Collection::SORT_ORDERS)' do
result = provider.filters(scope: store.products, query: 'shirt')
ids = result.sort_options.map { |o| o[:id] }
- expect(ids).to include('price', '-price')
+ expect(ids).to include('price', '-price', 'manual')
end
it 'returns total count' do
@@ -441,11 +426,6 @@ RSpec.describe SpreeMeilisearch::SearchProvider do
expect(result.default_sort).to eq('manual')
end
end
-
- it 'advertises manual in the sort options (sourced from Collection::SORT_ORDERS)' do
- result = provider.filters(scope: store.products, query: '')
- expect(result.sort_options.map { |o| o[:id] }).to include('manual')
- end
end
describe '#index' do
@@ -493,15 +473,6 @@ RSpec.describe SpreeMeilisearch::SearchProvider do
end
describe '#reindex' do
- it 'configures index settings' do
- expect(mock_index).to receive(:update_filterable_attributes)
- expect(mock_index).to receive(:update_sortable_attributes)
- expect(mock_index).to receive(:update_searchable_attributes)
- allow(mock_index).to receive(:add_documents)
-
- provider.reindex(store.products)
- end
-
it 'indexes all products in batches' do
expect(mock_index).to receive(:add_documents).at_least(:once)
provider.reindex(store.products)
diff --git a/spree/providers/meilisearch/spec/presenters/spree_meilisearch/product_presenter_spec.rb b/spree/providers/meilisearch/spec/presenters/spree_meilisearch/product_presenter_spec.rb
index c867c4ae87..786027e527 100644
--- a/spree/providers/meilisearch/spec/presenters/spree_meilisearch/product_presenter_spec.rb
+++ b/spree/providers/meilisearch/spec/presenters/spree_meilisearch/product_presenter_spec.rb
@@ -271,7 +271,7 @@ RSpec.describe SpreeMeilisearch::ProductPresenter do
it 'uses the same cf_* attributes on every market/locale document' do
create(:market, store: store, name: 'US', currency: 'USD', default_locale: 'en')
create(:market, store: store, name: 'EU', currency: 'EUR', default_locale: 'de')
- create(:price, variant: product.master, amount: 9.99, currency: 'EUR')
+ create(:price, variant: product.default_variant, amount: 9.99, currency: 'EUR')
docs = described_class.new(product.reload, store.reload).call
expect(docs.size).to be > 1
diff --git a/spree/providers/stripe/spec/models/spree/payment_sessions/stripe_spec.rb b/spree/providers/stripe/spec/models/spree/payment_sessions/stripe_spec.rb
index df3c2f5175..4fe51a7c66 100644
--- a/spree/providers/stripe/spec/models/spree/payment_sessions/stripe_spec.rb
+++ b/spree/providers/stripe/spec/models/spree/payment_sessions/stripe_spec.rb
@@ -18,16 +18,6 @@ RSpec.describe Spree::PaymentSessions::Stripe, type: :model do
customer_external_id: 'cus_test_123')
end
- describe 'STI' do
- it 'uses the correct type' do
- expect(payment_session.type).to eq('Spree::PaymentSessions::Stripe')
- end
-
- it 'is a PaymentSession' do
- expect(payment_session).to be_a(Spree::PaymentSession)
- end
- end
-
describe '#owner' do
it 'returns the order when the session belongs to an order' do
expect(payment_session.owner).to eq(order)
@@ -45,29 +35,6 @@ RSpec.describe Spree::PaymentSessions::Stripe, type: :model do
end
end
- describe '#stripe_id' do
- it 'aliases external_id' do
- expect(payment_session.stripe_id).to eq('pi_test_abc123')
- end
- end
-
- describe '#client_secret' do
- it 'reads from external_data' do
- expect(payment_session.client_secret).to eq('pi_secret_xyz')
- end
-
- it 'returns nil when external_data is nil' do
- payment_session.external_data = nil
- expect(payment_session.client_secret).to be_nil
- end
- end
-
- describe '#ephemeral_key_secret' do
- it 'reads from external_data' do
- expect(payment_session.ephemeral_key_secret).to eq('ek_test_key')
- end
- end
-
describe '#stripe_payment_intent' do
let(:stripe_pi) { Stripe::StripeObject.construct_from(id: 'pi_test_abc123', status: 'succeeded') }
@@ -194,22 +161,4 @@ RSpec.describe Spree::PaymentSessions::Stripe, type: :model do
expect(order.payments.count).to eq(1)
end
end
-
- describe 'state machine' do
- it 'starts as pending' do
- expect(payment_session.status).to eq('pending')
- end
-
- it 'can transition through the full lifecycle' do
- expect(payment_session.process).to be true
- expect(payment_session.complete).to be true
- expect(payment_session.status).to eq('completed')
- end
- end
-
- describe '#api_options' do
- it 'delegates to payment_method' do
- expect(payment_session.api_options).to eq(gateway.api_options)
- end
- end
end
diff --git a/spree/providers/stripe/spec/models/spree/payment_setup_sessions/stripe_spec.rb b/spree/providers/stripe/spec/models/spree/payment_setup_sessions/stripe_spec.rb
index 820d415c9f..d2b44434c2 100644
--- a/spree/providers/stripe/spec/models/spree/payment_setup_sessions/stripe_spec.rb
+++ b/spree/providers/stripe/spec/models/spree/payment_setup_sessions/stripe_spec.rb
@@ -13,28 +13,6 @@ RSpec.describe Spree::PaymentSetupSessions::Stripe, type: :model do
external_data: { 'customer_id' => 'cus_test_123' })
end
- describe 'STI' do
- it 'uses the correct type' do
- expect(setup_session.type).to eq('Spree::PaymentSetupSessions::Stripe')
- end
-
- it 'is a PaymentSetupSession' do
- expect(setup_session).to be_a(Spree::PaymentSetupSession)
- end
- end
-
- describe '#stripe_id' do
- it 'aliases external_id' do
- expect(setup_session.stripe_id).to eq('seti_test_abc123')
- end
- end
-
- describe '#client_secret' do
- it 'aliases external_client_secret' do
- expect(setup_session.client_secret).to eq('seti_test_abc123_secret_xyz')
- end
- end
-
describe '#stripe_setup_intent' do
let(:stripe_setup_intent) { Stripe::StripeObject.construct_from(id: 'seti_test_abc123', status: 'succeeded') }
@@ -62,10 +40,4 @@ RSpec.describe Spree::PaymentSetupSessions::Stripe, type: :model do
expect(setup_session.successful?).to be false
end
end
-
- describe '#api_options' do
- it 'delegates to payment_method' do
- expect(setup_session.api_options).to eq(gateway.api_options)
- end
- end
end
diff --git a/spree/providers/stripe/spec/models/spree_stripe/gateway/payment_sessions_spec.rb b/spree/providers/stripe/spec/models/spree_stripe/gateway/payment_sessions_spec.rb
index 2ba69a4f22..cbeb82047c 100644
--- a/spree/providers/stripe/spec/models/spree_stripe/gateway/payment_sessions_spec.rb
+++ b/spree/providers/stripe/spec/models/spree_stripe/gateway/payment_sessions_spec.rb
@@ -28,18 +28,6 @@ RSpec.describe SpreeStripe::Gateway::PaymentSessions do
allow(gateway).to receive(:create_ephemeral_key).and_return(ephemeral_key_response)
end
- describe '#session_required?' do
- it 'returns true' do
- expect(gateway.session_required?).to be true
- end
- end
-
- describe '#payment_session_class' do
- it 'returns Spree::PaymentSessions::Stripe' do
- expect(gateway.payment_session_class).to eq(Spree::PaymentSessions::Stripe)
- end
- end
-
describe '#create_payment_session' do
subject { gateway.create_payment_session(order: order) }
@@ -294,7 +282,7 @@ RSpec.describe SpreeStripe::Gateway::PaymentSessions do
context 'when the payment intent is accepted and succeeded' do
let(:stripe_pi) { Stripe::StripeObject.construct_from(id: 'pi_complete_123', status: 'succeeded', latest_charge: 'ch_test_123', payment_method: { type: 'card' }) }
- let(:payment) { create(:payment, order: order, payment_method: gateway, amount: order.total, state: 'checkout') }
+ let(:payment) { create(:payment, order: order, payment_method: gateway, amount: order.total, status: 'checkout') }
before do
allow(gateway).to receive(:retrieve_payment_intent).and_return(stripe_pi)
@@ -484,7 +472,7 @@ RSpec.describe SpreeStripe::Gateway::PaymentSessions do
next_action: { type: 'setup_future_usage' }
)
end
- let(:payment) { create(:payment, order: order, payment_method: gateway, amount: order.total, state: 'checkout') }
+ let(:payment) { create(:payment, order: order, payment_method: gateway, amount: order.total, status: 'checkout') }
before do
allow(gateway).to receive(:retrieve_payment_intent).and_return(stripe_pi)
@@ -529,7 +517,7 @@ RSpec.describe SpreeStripe::Gateway::PaymentSessions do
payment_method: { type: 'card' }
)
end
- let(:payment) { create(:payment, order: order, payment_method: gateway, amount: order.total, state: 'checkout') }
+ let(:payment) { create(:payment, order: order, payment_method: gateway, amount: order.total, status: 'checkout') }
before do
allow(gateway).to receive(:retrieve_payment_intent).and_return(stripe_pi)
@@ -660,29 +648,6 @@ RSpec.describe SpreeStripe::Gateway::PaymentSessions do
end
end
- context 'with payment_intent.amount_capturable_updated event' do
- let(:stripe_event) do
- Stripe::StripeObject.construct_from(
- type: 'payment_intent.amount_capturable_updated',
- data: { object: { id: 'pi_authorized_123' } }
- )
- end
- let!(:payment_session) do
- create(:stripe_payment_session, owner: order, payment_method: gateway, external_id: 'pi_authorized_123')
- end
-
- before do
- allow(gateway).to receive(:verify_webhook_signature).and_return(stripe_event)
- end
-
- it 'returns authorized action' do
- result = gateway.parse_webhook_event(raw_body, headers)
-
- expect(result[:action]).to eq(:authorized)
- expect(result[:payment_session]).to eq(payment_session)
- end
- end
-
context 'with unsupported event type' do
let(:stripe_event) do
Stripe::StripeObject.construct_from(
@@ -716,18 +681,5 @@ RSpec.describe SpreeStripe::Gateway::PaymentSessions do
expect(gateway.parse_webhook_event(raw_body, headers)).to be_nil
end
end
-
- context 'with invalid signature' do
- before do
- allow(gateway).to receive(:verify_webhook_signature)
- .and_raise(Spree::PaymentMethod::WebhookSignatureError)
- end
-
- it 'raises WebhookSignatureError' do
- expect {
- gateway.parse_webhook_event(raw_body, headers)
- }.to raise_error(Spree::PaymentMethod::WebhookSignatureError)
- end
- end
end
end
diff --git a/spree/providers/stripe/spec/models/spree_stripe/gateway_spec.rb b/spree/providers/stripe/spec/models/spree_stripe/gateway_spec.rb
index 0ae208d6db..6c335b0b2f 100644
--- a/spree/providers/stripe/spec/models/spree_stripe/gateway_spec.rb
+++ b/spree/providers/stripe/spec/models/spree_stripe/gateway_spec.rb
@@ -399,11 +399,10 @@ RSpec.describe SpreeStripe::Gateway do
let!(:order) { create(:order, store: store, total: 10, customer: create(:customer)) }
let!(:gateway_customer) { create(:gateway_customer, customer: order.customer, payment_method: gateway) }
- let!(:payment) { create(:payment, state: 'completed', order: order, payment_method: gateway, amount: 10.0, response_code: payment_intent_id) }
+ let!(:payment) { create(:payment, status: 'completed', order: order, payment_method: gateway, amount: 10.0, response_code: payment_intent_id) }
let!(:refund) { create(:refund, payment: payment, amount: 2.0) }
let(:payment_intent_id) { 'pi_3QXmL12ESifGlJez0v0B8tUn' }
- let(:refund_id) { 're_3QXmL12ESifGlJez0GcOBHng' }
it 'creates a refund with credit_allowed_amount' do
VCR.use_cassette('create_refund') do
@@ -413,12 +412,6 @@ RSpec.describe SpreeStripe::Gateway do
expect(subject.success?).to be(true)
expect(subject.authorization).to eq(payment_intent_id)
-
- expect(subject.params['id']).to eq(refund_id)
- expect(subject.params['status']).to eq('succeeded')
- expect(subject.params['payment_intent']).to eq(payment_intent_id)
- expect(subject.params['object']).to eq('refund')
- expect(subject.params['amount']).to eq(800)
end
end
@@ -964,29 +957,6 @@ RSpec.describe SpreeStripe::Gateway do
end
end
- describe 'being a provider' do
- let(:provider_methods) { %i[authorize purchase capture void credit] }
-
- it 'implements provider methods without delegating back to itself' do
- provider_methods.each do |method|
- expect(gateway).to respond_to method
- expect { gateway.send(method) }.to raise_error(ArgumentError)
- end
- end
- end
-
- describe '#setup_session_supported?' do
- it 'returns true' do
- expect(gateway.setup_session_supported?).to be(true)
- end
- end
-
- describe '#payment_setup_session_class' do
- it 'returns the Stripe STI subclass' do
- expect(gateway.payment_setup_session_class).to eq(Spree::PaymentSetupSessions::Stripe)
- end
- end
-
describe '#create_payment_setup_session' do
subject { gateway.create_payment_setup_session(customer: customer) }
@@ -1243,13 +1213,5 @@ RSpec.describe SpreeStripe::Gateway do
expect(keys).to contain_exactly(:publishable_key, :secret_key)
end
-
- it 'still holds what Stripe hands back' do
- gateway.preferred_webhook_signing_secret = 'whsec_payments'
- gateway.preferred_connect_webhook_signing_secret = 'whsec_connect'
-
- expect(gateway.preferred_webhook_signing_secret).to eq('whsec_payments')
- expect(gateway.preferred_connect_webhook_signing_secret).to eq('whsec_connect')
- end
end
end
diff --git a/spree/providers/stripe/spec/models/spree_stripe/payout_provider_spec.rb b/spree/providers/stripe/spec/models/spree_stripe/payout_provider_spec.rb
index 45fcdf5e87..d1dbb07f92 100644
--- a/spree/providers/stripe/spec/models/spree_stripe/payout_provider_spec.rb
+++ b/spree/providers/stripe/spec/models/spree_stripe/payout_provider_spec.rb
@@ -134,36 +134,6 @@ RSpec.describe SpreeStripe::PayoutProvider do
expect { described_class.new.transfer!(seller_transfer) }.to raise_error(Stripe::InvalidRequestError)
end
-
- context 'when the customer paid by card' do
- # Funds the transfer from that charge, so it settles with the charge
- # rather than out of the marketplace's own balance.
- # Stripe funds a transfer from a charge. `response_code` holds the
- # payment intent that produced it, which Stripe cannot use here — the
- # charge is recorded on the payment when its session completes.
- it 'names the charge as the funding source' do
- create(:payment, order: order, payment_method: gateway, status: 'completed',
- response_code: 'pi_123', amount: 100,
- metadata: { 'stripe_charge_id' => 'ch_123' })
-
- expect(Stripe::Transfer).to receive(:create).
- with(hash_including(source_transaction: 'ch_123'), anything).
- and_return(Stripe::StripeObject.construct_from(id: 'tr_1'))
-
- described_class.new.transfer!(seller_transfer)
- end
- end
-
- context 'when there is no charge to draw on' do
- it 'omits the funding source rather than sending a null one' do
- expect(Stripe::Transfer).to receive(:create) do |payload, _options|
- expect(payload).not_to have_key(:source_transaction)
- Stripe::StripeObject.construct_from(id: 'tr_1')
- end
-
- described_class.new.transfer!(seller_transfer)
- end
- end
end
# An account settles in its own currency and Stripe converts on the way in, so
@@ -508,12 +478,6 @@ RSpec.describe SpreeStripe::PayoutProvider do
end
end
- describe '.requires_payout_account?' do
- it 'is true — nothing can be sent to a seller without a connected account' do
- expect(described_class.requires_payout_account?).to be(true)
- end
- end
-
describe '.available_for_store?' do
it 'is false without an active Stripe payment method' do
gateway.update!(active: false)