Skip to content

Commit

Permalink
Merge pull request #3117 from nebulab/kennyadsl/v2.8.2
Browse files Browse the repository at this point in the history
v2.8.2
  • Loading branch information
kennyadsl authored Feb 25, 2019
2 parents 34138e7 + 9031158 commit 906bc40
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 17 deletions.
2 changes: 1 addition & 1 deletion backend/app/views/spree/admin/products/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
<% end %>
</div>
</div>

<% else %>
<div id="shipping_specs" class="row">
<% [:height, :width, :depth, :weight].each_with_index do |field, index| %>
<div id="shipping_specs_<%= field %>_field" class="col-6">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,35 @@ def up
StoreCreditReason.create!(name: update_reason.name)
end

drop_table :spree_store_credit_update_reasons
rename_column :spree_store_credit_events, :update_reason_id, :store_credit_reason_id
add_column :spree_store_credit_events, :store_credit_reason_id, :integer
execute "update spree_store_credit_events set store_credit_reason_id = update_reason_id"

# TODO: table spree_store_credit_update_reasons and column
# column spree_store_credit_update_reasons.update_reason_id
# must be dropped in a future Solidus release
end

def down
create_table :spree_store_credit_update_reasons do |t|
t.string :name

t.timestamps
# This table and column may not exist anymore as another irreversible
# migration may have removed it later. They must be added back or the
# `up` method would fail
unless table_exists? :spree_store_credit_update_reasons
create_table :spree_store_credit_update_reasons do |t|
t.string :name

t.timestamps
end

unless column_exists? :spree_store_credit_events, :update_reason_id
add_column :spree_store_credit_events, :update_reason_id, :integer
end
end

StoreCreditReason.all.each do |store_credit_reason|
StoreCreditUpdateReason.create!(name: store_credit_reason.name)
end

drop_table :spree_store_credit_reasons
rename_column :spree_store_credit_events, :store_credit_reason_id, :update_reason_id
remove_column :spree_store_credit_events, :store_credit_reason_id
end
end
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

0 comments on commit 906bc40

Please sign in to comment.