Sha256: 38594f7815ee09bea605c102df22c4f052ff1f45258c774a1b3f0ca892cdfecd

Contents?: true

Size: 1.76 KB

Versions: 6

Compression:

Stored size: 1.76 KB

Contents

# frozen_string_literal: true

unless defined?(Solidus::InstallGenerator)
  require 'generators/solidus/install/install_generator'
end

require 'generators/spree/dummy/dummy_generator'

class CommonRakeTasks
  include Rake::DSL

  def initialize
    namespace :common do
      task :test_app, :user_class do |_t, args|
        args.with_defaults(user_class: "Spree::LegacyUser")
        require ENV['LIB_NAME']

        force_rails_environment_to_test

        Spree::DummyGenerator.start ["--lib_name=#{ENV['LIB_NAME']}", "--quiet"]
        Solidus::InstallGenerator.start ["--lib_name=#{ENV['LIB_NAME']}", "--auto-accept", "--with-authentication=false", "--payment-method=none", "--migrate=false", "--seed=false", "--sample=false", "--quiet", "--user_class=#{args[:user_class]}"]

        puts "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?
          puts 'Running extension installation generator...'
          sh "bin/rails generate #{rake_generator_namespace}:install --auto-run-migrations"
        end
      end

      task :seed do |_t, _args|
        puts "Seeding ..."

        sh "bundle exec rake db:seed RAILS_ENV=test"
      end
    end
  end

  private

  def force_rails_environment_to_test
    ENV["RAILS_ENV"] = 'test'
    Rails.env = 'test'
  end

  def extension_installation_generator_exists?
    require "generators/#{generator_namespace}/install/install_generator"

    true
  rescue LoadError
    false
  end

  def generator_namespace
    "#{ENV['LIB_NAMESPACE']&.underscore || ENV['LIB_NAME']}"
  end

  def rake_generator_namespace
    generator_namespace.gsub("/", ":")
  end
end

CommonRakeTasks.new

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
solidus_core-3.2.4 lib/spree/testing_support/common_rake.rb
solidus_core-3.2.3 lib/spree/testing_support/common_rake.rb
solidus_core-3.2.2 lib/spree/testing_support/common_rake.rb
solidus_core-3.2.1 lib/spree/testing_support/common_rake.rb
solidus_core-3.2.0 lib/spree/testing_support/common_rake.rb
solidus_core-3.2.0.alpha lib/spree/testing_support/common_rake.rb