-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3987 from nebulab/waiting-for-dev/dont_allow_nil_…
…amount Do not allow prices with nil amount
- Loading branch information
Showing
6 changed files
with
53 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
core/db/migrate/20210312061050_change_column_null_on_prices.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class ChangeColumnNullOnPrices < ActiveRecord::Migration[5.2] | ||
def change | ||
change_column_null(:spree_prices, :amount, false) | ||
end | ||
end |
13 changes: 13 additions & 0 deletions
13
core/lib/tasks/migrations/delete_prices_with_nil_amount.rake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
namespace :solidus do | ||
namespace :migrations do | ||
namespace :delete_prices_with_nil_amount do | ||
task up: :environment do | ||
print "Deleting prices wich amount attribute is nil ... " | ||
Spree::Price.where(amount: nil).delete_all | ||
puts "Success" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
core/spec/lib/tasks/migrations/delete_prices_with_nil_amount_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
path = Spree::Core::Engine.root.join('lib/tasks/migrations/delete_prices_with_nil_amount.rake') | ||
|
||
RSpec.describe 'solidus:migrations:delete_prices_with_nil_amount' do | ||
describe 'up' do | ||
include_context( | ||
'rake', | ||
task_path: path, | ||
task_name: 'solidus:migrations:delete_prices_with_nil_amount:up' | ||
) | ||
|
||
it 'removes all prices which amount column is NULL' do | ||
price = create(:price) | ||
expect(Spree::Price).to receive(:where).with(amount: nil).and_return(Spree::Price.where(id: price)) | ||
|
||
task.invoke | ||
|
||
expect { price.reload }.to raise_error(ActiveRecord::RecordNotFound) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters