Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Explicit deprecation warning mocks #3753

Merged
merged 2 commits into from
Sep 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions api/spec/requests/spree/api/checkouts_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,13 @@ module Spree
}
end

before do
expect(Spree::Deprecation).to receive(:warn).
with(/^Passing existing_card_id to PaymentCreate is deprecated/, any_args)
end

it 'succeeds' do
Spree::Deprecation.silence do
put spree.api_checkout_path(order), params: params
end
put spree.api_checkout_path(order), params: params

expect(response.status).to eq 200
expect(order.credit_cards).to match_array [credit_card]
Expand Down
27 changes: 11 additions & 16 deletions core/spec/lib/spree/core/controller_helpers/order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,22 @@
end

describe '#simple_current_order' do
before do
expect(Spree::Deprecation).to receive(:warn).
with(/^simple_current_order is deprecated and will be removed/, any_args)
end

it "returns an empty order" do
Spree::Deprecation.silence do
expect(controller.simple_current_order.item_count).to eq 0
end
expect(controller.simple_current_order.item_count).to eq 0
end

it 'returns Spree::Order instance' do
Spree::Deprecation.silence do
allow(controller).to receive_messages(cookies: double(signed: { guest_token: order.guest_token }))
expect(controller.simple_current_order).to eq order
end
allow(controller).to receive_messages(cookies: double(signed: { guest_token: order.guest_token }))
expect(controller.simple_current_order).to eq order
end

it 'assigns the current_store id' do
Spree::Deprecation.silence do
expect(controller.simple_current_order.store_id).to eq store.id
end
end
it 'is deprecated' do
Spree::Deprecation.silence do
expect(Spree::Deprecation).to(receive(:warn))
controller.simple_current_order
end
expect(controller.simple_current_order.store_id).to eq store.id
end
end

Expand Down
11 changes: 8 additions & 3 deletions core/spec/lib/spree/core/controller_helpers/pricing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,28 @@
end

describe '#current_currency' do
before do
expect(Spree::Deprecation).to receive(:warn).
with(/^current_currency is deprecated and will be removed/, any_args)
end

subject { controller.current_currency }

context "when store default_currency is nil" do
let(:store) { nil }
it { Spree::Deprecation.silence { is_expected.to eq('USD') } }
it { is_expected.to eq('USD') }
end

context "when the current store default_currency empty" do
let(:store) { FactoryBot.create :store, default_currency: '' }

it { Spree::Deprecation.silence { is_expected.to eq('USD') } }
it { is_expected.to eq('USD') }
end

context "when the current store default_currency is a currency" do
let(:store) { FactoryBot.create :store, default_currency: 'EUR' }

it { Spree::Deprecation.silence { is_expected.to eq('EUR') } }
it { is_expected.to eq('EUR') }
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,9 @@

describe '#permitted_checkout_attributes' do
it 'returns Array class' do
Spree::Deprecation.silence do
expect(controller.permitted_checkout_attributes.class).to eq Spree::CheckoutAdditionalAttributes
end
end

it 'is deprecated' do
expect(Spree::Deprecation).to receive(:warn)
controller.permitted_checkout_attributes
expect(Spree::Deprecation).to receive(:warn).
with(/^checkout_attributes is deprecated/, any_args)
expect(controller.permitted_checkout_attributes.class).to eq Spree::CheckoutAdditionalAttributes
end
end

Expand Down
12 changes: 6 additions & 6 deletions core/spec/lib/spree/core/current_store_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@

RSpec.describe Spree::Core::CurrentStore do
describe "#store" do
subject { Spree::Deprecation.silence { Spree::Core::CurrentStore.new(request).store } }
before do
expect(Spree::Deprecation).to receive(:warn).
with(/^Using Spree::Core::CurrentStore is deprecated/, any_args)
end

subject { Spree::Core::CurrentStore.new(request).store }

context "with a default" do
let(:request) { double(headers: {}, env: {}) }
Expand All @@ -24,10 +29,5 @@
end
end
end

it 'is deprecated' do
expect(Spree::Deprecation).to(receive(:warn))
Spree::Core::CurrentStore.new(double)
end
end
end
7 changes: 5 additions & 2 deletions core/spec/lib/spree/core/role_configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ class OtherDummyPermissionSet < Spree::PermissionSets::Base; end
let(:instance) { Spree::RoleConfiguration.new }

describe ".configure" do
around(:each) do |example|
Spree::Deprecation.silence { example.run }
before do
expect(Spree::Deprecation).to receive(:warn).
with(/^Spree::RoleConfiguration\.configure is deprecated/i, any_args)
end

it "yields with the instance" do
expect(Spree::Deprecation).to receive(:warn).
with(/^Spree::RoleConfiguration\.instance is deprecated/i, any_args)
expect { |b| described_class.configure(&b) }.to yield_with_args(described_class.instance)
end

Expand Down
7 changes: 4 additions & 3 deletions core/spec/lib/spree/core/testing_support/preferences_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
describe 'resetting the app configuration' do
around do |example|
with_unfrozen_spree_preference_store do
Spree::Deprecation.silence do
example.run
end
example.run
end
end

before do
expect(Spree::Deprecation).to receive(:warn).
with(/^reset_spree_preferences is deprecated and will be removed/, any_args).
at_least(:once)
reset_spree_preferences
@original_spree_mails_from = Spree::Config.mails_from
@original_spree_searcher_class = Spree::Config.searcher_class
Expand Down
59 changes: 32 additions & 27 deletions core/spec/lib/spree/money_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@

describe '#initialize' do
subject do
Spree::Deprecation.silence do
described_class.new(amount, currency: currency, with_currency: true).to_s
end
described_class.new(amount, currency: currency, with_currency: true).to_s
end

context 'with no currency' do
Expand Down Expand Up @@ -39,30 +37,37 @@
it { should == "$10.00 USD" }
end

context "with symbol" do
let(:amount){ '$10.00' }
it { should == "$10.00 USD" }
end

context "with extra currency" do
let(:amount){ '$10.00 USD' }
it { should == "$10.00 USD" }
end

context "with different currency" do
let(:currency){ 'USD' }
let(:amount){ '$10.00 CAD' }
it { should == "$10.00 CAD" }
end

context "with commas" do
let(:amount){ '1,000.00' }
it { should == "$1,000.00 USD" }
end

context "with comma for decimal point" do
let(:amount){ '10,00' }
it { should == "$10.00 USD" }
context 'with deprecated amount format' do
before do
expect(Spree::Deprecation).to receive(:warn).
with(/^Spree::Money was initialized with ".*", which will not be supported in the future/, any_args)
end

context "with symbol" do
let(:amount){ '$10.00' }
it { should == "$10.00 USD" }
end

context "with extra currency" do
let(:amount){ '$10.00 USD' }
it { should == "$10.00 USD" }
end

context "with different currency" do
let(:currency){ 'USD' }
let(:amount){ '$10.00 CAD' }
it { should == "$10.00 CAD" }
end

context "with commas" do
let(:amount){ '1,000.00' }
it { should == "$1,000.00 USD" }
end

context "with comma for decimal point" do
let(:amount){ '10,00' }
it { should == "$10.00 USD" }
end
end

context 'with fixnum' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@

RSpec.describe 'solidus:migrations:migrate_shipping_rate_taxes' do
describe 'up' do
before do
expect(Spree::Deprecation).to receive(:warn).
with(/^rake spree:migrations:migrate_shipping_rate_taxes:up has been deprecated/, any_args)
end

include_context(
'rake',
task_path: Spree::Core::Engine.root.join('lib/tasks/migrations/migrate_shipping_rate_taxes.rake'),
task_name: 'solidus:migrations:migrate_shipping_rate_taxes:up',
)

it 'runs' do
Spree::Deprecation.silence do
expect { task.invoke }.to output(
"Adding persisted tax notes to historic shipping rates ... Success.\n"
).to_stdout
end
expect { task.invoke }.to output(
"Adding persisted tax notes to historic shipping rates ... Success.\n"
).to_stdout
end
end
end
12 changes: 9 additions & 3 deletions core/spec/mailers/test_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@
RSpec.describe Spree::TestMailer, type: :mailer do
let(:user) { create(:user) }

it "confirm_email accepts a user id as an alternative to a User object" do
Spree::Deprecation.silence do
Spree::TestMailer.test_email('[email protected]')
describe '#test_email' do
subject { described_class.test_email('[email protected]') }

it "is deprecated" do
expect(Spree::Deprecation).to receive(:warn).
with(/^Spree::TestMailer has been deprecated and will be removed/, any_args)

test_email = subject
expect(test_email.to).to eq(['[email protected]'])
end
end
end
28 changes: 21 additions & 7 deletions core/spec/models/spree/adjustment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,13 @@ def expect_deprecation_warning
)
end

def doesnt_expect_deprecation_warning
expect(Spree::Deprecation).not_to receive(:warn).with(
/Adjustment \d+ was not added to #{adjustable.class} #{adjustable.id}/,
any_args
)
end

context 'when adding adjustments via the wrong association' do
def create_adjustment
adjustment_source.adjustments.create!(
Expand All @@ -256,7 +263,7 @@ def create_adjustment

context 'when the adjustment is destroyed before after_commit runs' do
it 'does not repair' do
expect(Spree::Deprecation).not_to receive(:warn)
doesnt_expect_deprecation_warning
Spree::Adjustment.transaction do
adjustment = create_adjustment
adjustment.destroy!
Expand All @@ -267,7 +274,7 @@ def create_adjustment

context 'when adjustable.adjustments is not loaded' do
it 'does repair' do
expect(Spree::Deprecation).not_to receive(:warn)
doesnt_expect_deprecation_warning
create_adjustment
end
end
Expand All @@ -287,14 +294,14 @@ def create_adjustment
before { adjustable.adjustments.to_a }

it 'does not repair' do
expect(Spree::Deprecation).not_to receive(:warn)
doesnt_expect_deprecation_warning
create_adjustment
end
end

context 'when adjustable.adjustments is not loaded' do
it 'does not repair' do
expect(Spree::Deprecation).not_to receive(:warn)
doesnt_expect_deprecation_warning
create_adjustment
end
end
Expand All @@ -315,6 +322,13 @@ def expect_deprecation_warning(adjustable)
)
end

def doesnt_expect_deprecation_warning
expect(Spree::Deprecation).not_to receive(:warn).with(
/Adjustment #{adjustment.id} was not removed from #{adjustable.class} #{adjustable.id}/,
any_args
)
end

context 'when destroying adjustments not via association' do
context 'when adjustable.adjustments is loaded' do
before { adjustable.adjustments.to_a }
Expand All @@ -328,7 +342,7 @@ def expect_deprecation_warning(adjustable)

context 'when adjustable.adjustments is not loaded' do
it 'does not repair' do
expect(Spree::Deprecation).not_to receive(:warn)
doesnt_expect_deprecation_warning
adjustment.destroy!
end
end
Expand All @@ -339,14 +353,14 @@ def expect_deprecation_warning(adjustable)
before { adjustable.adjustments.to_a }

it 'does not repair' do
expect(Spree::Deprecation).not_to receive(:warn)
doesnt_expect_deprecation_warning
adjustable.adjustments.destroy(adjustment)
end
end

context 'when adjustable.adjustments is not loaded' do
it 'does not repair' do
expect(Spree::Deprecation).not_to receive(:warn)
doesnt_expect_deprecation_warning
adjustable.adjustments.destroy(adjustment)
end
end
Expand Down
9 changes: 6 additions & 3 deletions core/spec/models/spree/calculator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ class SimpleComputable
end

describe "#calculators" do
before do
expect(Spree::Deprecation).to receive(:warn).
with(/^Calling \.calculators is deprecated/, any_args)
end

subject { Spree::Calculator.calculators }

it 'returns the (deprecated) calculator step' do
Spree::Deprecation.silence do
expect(subject).to be_a Spree::Core::Environment::Calculators
end
expect(subject).to be_a Spree::Core::Environment::Calculators
end
end

Expand Down
Loading