Skip to content

Commit

Permalink
Merge pull request #3080 from nebulab/kennyadsl/cleanup-core-tasks
Browse files Browse the repository at this point in the history
Deprecate core tasks and migration scripts
  • Loading branch information
kennyadsl committed Feb 13, 2019
2 parents 54eb04f + e98c402 commit 7fba0eb
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 12 deletions.
2 changes: 2 additions & 0 deletions core/app/mailers/spree/test_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module Spree
class TestMailer < BaseMailer
def test_email(email)
Spree::Deprecation.warn("Spree::TestMailer has been deprecated and will be removed with Solidus 3.0")

store = Spree::Store.default
subject = "#{store.name} #{t('.subject')}"
mail(to: email, from: from_address(store), subject: subject)
Expand Down
17 changes: 9 additions & 8 deletions core/db/migrate/20170608074534_rename_bogus_gateways.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
# frozen_string_literal: true

class RenameBogusGateways < ActiveRecord::Migration[5.0]
# This migration was only performing a data migration useful updating to
# Solidus v2.3.
# Once the update is done, this is no more required to run so we can clean
# this file to just be a noop.
# For more info on the original content see:
# https://github.com/solidusio/solidus/pull/2001

def up
require 'solidus/migrations/rename_gateways'
say_with_time 'Renaming bogus gateways into payment methods' do
Solidus::Migrations::RenameGateways.new.up
end
# no-op
end

def down
require 'solidus/migrations/rename_gateways'
say_with_time 'Renaming bogus payment methods into gateways' do
Solidus::Migrations::RenameGateways.new.down
end
# no-op
end
end
2 changes: 2 additions & 0 deletions core/lib/solidus/migrations/rename_gateways.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class RenameGateways
attr_reader :gateway_mapping

def initialize(gateway_mapping = DEFAULT_MAPPING)
Spree::Deprecation.warn 'Solidus::Migrations::RenameGateways is deprecated and will be removed with Solidus 3.0.'

@gateway_mapping = gateway_mapping
end

Expand Down
2 changes: 2 additions & 0 deletions core/lib/tasks/email.rake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace :email do
desc 'Sends test email to specified address - Example: EMAIL=spree@example.com bundle exec rake email:test'
task test: :environment do
Spree::Deprecation.warn("rake email:test has been deprecated and will be removed with Solidus 3.0")

raise ArgumentError, "Must pass EMAIL environment variable. Example: EMAIL=spree@example.com bundle exec rake email:test" unless ENV['EMAIL'].present?
Spree::TestMailer.test_email(ENV['EMAIL']).deliver!
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ namespace 'spree:migrations:copy_order_bill_address_to_credit_card' do
# This task should be safe to run multiple times.

task up: :environment do
Spree::Deprecation.warn("rake spree:migrations:copy_order_bill_address_to_credit_card:up has been deprecated and will be removed with Solidus 3.0.")

if Spree::CreditCard.connection.adapter_name =~ /postgres/i
postgres_copy
else
Expand All @@ -21,6 +23,8 @@ namespace 'spree:migrations:copy_order_bill_address_to_credit_card' do
end

task down: :environment do
Spree::Deprecation.warn("rake spree:migrations:copy_order_bill_address_to_credit_card:down has been deprecated and will be removed with Solidus 3.0.")

Spree::CreditCard.update_all(address_id: nil)
end

Expand Down
2 changes: 2 additions & 0 deletions core/lib/tasks/migrations/migrate_shipping_rate_taxes.rake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ namespace :solidus do
namespace :migrations do
namespace :migrate_shipping_rate_taxes do
task up: :environment do
Spree::Deprecation.warn("rake spree:migrations:migrate_shipping_rate_taxes:up has been deprecated and will be removed with Solidus 3.0.")

print "Adding persisted tax notes to historic shipping rates ... "
Spree::ShippingRate.where.not(tax_rate_id: nil).find_each do |shipping_rate|
tax_rate = Spree::TaxRate.unscoped.find(shipping_rate.tax_rate_id)
Expand Down
3 changes: 3 additions & 0 deletions core/lib/tasks/migrations/migrate_user_addresses.rake
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ namespace 'spree:migrations:migrate_user_addresses' do
# to the user's address book. This will catch up all the historical data.

task up: :environment do
Spree::Deprecation.warn("rake spree:migrations:migrate_user_addresses:up has been deprecated and will be removed with Solidus 3.0.")

Spree.user_class.find_each(batch_size: 500) do |user|
ship_address = Spree::Address.find_by(id: user.ship_address_id)
bill_address = Spree::Address.find_by(id: user.bill_address_id)
Expand All @@ -26,6 +28,7 @@ namespace 'spree:migrations:migrate_user_addresses' do
end

task down: :environment do
Spree::Deprecation.warn("rake spree:migrations:migrate_user_addresses:down has been deprecated and will be removed with Solidus 3.0.")
Spree::UserAddress.delete_all
end
end
2 changes: 2 additions & 0 deletions core/lib/tasks/migrations/rename_gateways.rake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ require 'solidus/migrations/rename_gateways'

namespace 'solidus:migrations:rename_gateways' do
task up: :environment do
Spree::Deprecation.warn("rake solidus:migrations:rename_gateways:up has been deprecated and will be removed with Solidus 3.0.")
count = Solidus::Migrations::RenameGateways.new.up

unless ENV['VERBOSE'] == 'false' || !verbose
Expand All @@ -12,6 +13,7 @@ namespace 'solidus:migrations:rename_gateways' do
end

task down: :environment do
Spree::Deprecation.warn("rake solidus:migrations:rename_gateways:down has been deprecated and will be removed with Solidus 3.0.")
count = Solidus::Migrations::RenameGateways.new.down

unless ENV['VERBOSE'] == 'false' || !verbose
Expand Down
2 changes: 2 additions & 0 deletions core/lib/tasks/order_capturing.rake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace :order_capturing do
desc "Looks for orders with inventory that is fully shipped/short-shipped, and captures money for it"
task capture_payments: :environment do
Spree::Deprecation.warn("rake order_capturing:capture_payments has been deprecated and will be removed with Solidus 3.0.")

failures = []
orders = Spree::Order.complete.where(payment_state: 'balance_due').where('completed_at > ?', Spree::Config[:order_capturing_time_window].days.ago)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
)

it 'runs' do
expect { task.invoke }.to output(
"Adding persisted tax notes to historic shipping rates ... Success.\n"
).to_stdout
Spree::Deprecation.silence do
expect { task.invoke }.to output(
"Adding persisted tax notes to historic shipping rates ... Success.\n"
).to_stdout
end
end
end
end
4 changes: 3 additions & 1 deletion core/spec/mailers/test_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
let(:user) { create(:user) }

it "confirm_email accepts a user id as an alternative to a User object" do
Spree::TestMailer.test_email('test@example.com')
Spree::Deprecation.silence do
Spree::TestMailer.test_email('test@example.com')
end
end
end

0 comments on commit 7fba0eb

Please sign in to comment.