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

Fix remove code from promotions migration #3108

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
class RemoveCodeFromSpreePromotions < ActiveRecord::Migration[5.1]
class Promotion < ActiveRecord::Base
self.table_name = "spree_promotions"
self.ignored_columns = %w(type)
end

def up
promotions_with_code = Promotion.where.not(code: nil)
promotions_with_code = Promotion.where.not(code: [nil, ''])

if promotions_with_code.any?
# You have some promotions with "code" field present! This is not good
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,18 @@
DatabaseCleaner.clean_with(:truncation)
end

let(:promotion_with_code) { create(:promotion) }

before do
# We can't set code via factory since `code=` is currently raising
# an error, see more at:
# https://github.com/solidusio/solidus/blob/cf96b03eb9e80002b69736e082fd485c870ab5d9/core/app/models/spree/promotion.rb#L65
promotion_with_code.update_column(:code, code)
end

context 'when there are no promotions with code' do
let(:code) { '' }

it 'does not call any promotion with code handler' do
expect(described_class).not_to receive(:promotions_with_code_handler)

Expand All @@ -53,14 +64,7 @@
end

context 'when there are promotions with code' do
let(:promotion_with_code) { create(:promotion) }

before do
# We can't set code via factory since `code=` is currently raising
# an error, see more at:
# https://github.com/solidusio/solidus/blob/cf96b03eb9e80002b69736e082fd485c870ab5d9/core/app/models/spree/promotion.rb#L65
promotion_with_code.update_column(:code, 'Just An Old Promo Code')
end
let(:code) { 'Just An Old Promo Code' }

context 'with the deafult handler (Solidus::Migrations::PromotionWithCodeHandlers::RaiseException)' do
it 'raise a StandardError exception' do
Expand Down Expand Up @@ -96,6 +100,14 @@
end
end

context 'with promotions with type set (legacy feature)' do
let(:promotion_with_code) { create(:promotion, type: 'Spree::Promotion') }

it 'does not raise a STI error' do
expect { subject }.not_to raise_error
end
end

context 'when there is a Spree::PromotionCode with the same value' do
context 'associated with the same promotion' do
let!(:existing_promotion_code) { create(:promotion_code, value: 'just an old promo code', promotion: promotion_with_code) }
Expand Down