Skip to content
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
10 changes: 6 additions & 4 deletions core/lib/spree/testing_support/common_rake.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# frozen_string_literal: true

require 'generators/spree/dummy/dummy_generator'
require 'logger'

class CommonRakeTasks
include Rake::DSL
attr_reader :logger

def initialize
Rails.logger ||= Logger.new($stdout)
@logger = Logger.new($stdout)
namespace :common do
task :test_app, :user_class do |_t, args|
args.with_defaults(user_class: "Spree::LegacyUser")
Expand Down Expand Up @@ -46,19 +48,19 @@ def initialize
sh "bin/rails g solidus_frontend:install --auto-accept"
end

Rails.logger.info "Setting up dummy database..."
logger.info "Setting up dummy database..."

sh "bin/rails db:environment:set RAILS_ENV=test"
sh "bin/rails db:drop db:create db:migrate VERBOSE=false RAILS_ENV=test"

if extension_installation_generator_exists?
Rails.logger.info 'Running extension installation generator...'
logger.info 'Running extension installation generator...'
sh "bin/rails generate #{rake_generator_namespace}:install --auto-run-migrations"
end
end

task :seed do |_t, _args|
Rails.logger.info "Seeding ..."
logger.info "Seeding ..."

sh "bundle exec rake db:seed RAILS_ENV=test"
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def run_migrations
if run_migrations
run "bin/rails db:migrate"
else
Rails.logger.info "Skipping bin/rails db:migrate, don't forget to run it!"
say "Skipping bin/rails db:migrate, don't forget to run it!"
end
end

Expand Down
11 changes: 7 additions & 4 deletions promotions/lib/solidus_promotions/promotion_migrator.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# frozen_string_literal: true

require "logger"

module SolidusPromotions
class PromotionMigrator
PROMOTION_IGNORED_ATTRIBUTES = ["id", "type", "promotion_category_id", "promotion_id"]

attr_reader :promotion_map
attr_reader :promotion_map, :logger

def initialize(promotion_map)
def initialize(promotion_map, logger: nil)
@logger = logger || Logger.new($stdout)
@promotion_map = promotion_map
end

Expand Down Expand Up @@ -78,7 +81,7 @@ def copy_promotion(old_promotion)
def generate_new_benefits(old_promotion_action)
promo_action_config = promotion_map[:actions][old_promotion_action.class]
if promo_action_config.nil?
Rails.logger.info("#{old_promotion_action.class} is not supported")
logger.info("#{old_promotion_action.class} is not supported")
return nil
end
promo_action_config.call(old_promotion_action)
Expand All @@ -87,7 +90,7 @@ def generate_new_benefits(old_promotion_action)
def generate_new_promotion_conditions(old_promotion_rule)
new_promo_condition_class = promotion_map[:conditions][old_promotion_rule.class]
if new_promo_condition_class.nil?
Rails.logger.info("#{old_promotion_rule.class} is not supported")
logger.info("#{old_promotion_rule.class} is not supported")
[]
elsif new_promo_condition_class.respond_to?(:call)
new_promo_condition_class.call(old_promotion_rule)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ namespace :solidus_promotions do
task migrate_existing_promotions: :environment do
require "solidus_promotions/promotion_map"

SolidusPromotions::PromotionMigrator.new(SolidusPromotions::PROMOTION_MAP).call
SolidusPromotions::PromotionMigrator.new(SolidusPromotions::PROMOTION_MAP, logger: Rails.logger).call
end
end
Loading