Sha256: ee64f7e3a1c1a6c38c42362bac44d44f7c11feca70a5cb7f55db5b90df55a543

Contents?: true

Size: 1.74 KB

Versions: 42

Compression:

Stored size: 1.74 KB

Contents

# frozen_string_literal: true

module DummyApp
  class RakeTasks
    include Rake::DSL

    def initialize(gem_root:, lib_name:)
      task :dummy_environment do
        ENV['RAILS_ENV'] = 'test'
        require lib_name
        require 'spree/testing_support/dummy_app'
        DummyApp.setup(
          gem_root: gem_root,
          lib_name: lib_name,
          auto_migrate: false
        )
      end
    end
  end
end

namespace :db do
  desc "Drops the test database"
  task drop: :dummy_environment do
    ActiveRecord::Tasks::DatabaseTasks.drop_current
  end

  desc "Creates the test database"
  task create: :dummy_environment do
    ActiveRecord::Tasks::DatabaseTasks.create_current
  end

  desc "Migrates the test database"
  task migrate: :dummy_environment do
    ActiveRecord::Migration.verbose = false

    # We want to simulate how migrations would be run if a user ran
    # railties:install:migrations and then db:migrate.
    # Migrations should be run one directory at a time
    ActiveRecord::Migrator.migrations_paths.each do |path|
      if defined?(ActiveRecord::MigrationContext)
        # Rails >= 5.2
        ActiveRecord::MigrationContext.new([path]).migrate
      else
        ActiveRecord::Migrator.migrate(path)
      end
    end

    ActiveRecord::Base.clear_cache!
  end

  desc "Recreates the test database and re-runs all migrations"
  task reset: ['db:drop', 'db:create', 'db:migrate']
end

desc "Open a sandboxed console in the test environment"
task console: :dummy_environment do
  begin
    require 'pry'
    Rails.application.config.console = Pry
  rescue LoadError
  end

  require 'rails/commands'
  require 'rails/commands/console/console_command'
  Rails::Console.new(Rails.application, sandbox: true, environment: "test").start
end

Version data entries

42 entries across 42 versions & 2 rubygems

Version Path
solidus_core-2.9.6 lib/spree/testing_support/dummy_app/rake_tasks.rb
solidus_core-2.8.6 lib/spree/testing_support/dummy_app/rake_tasks.rb
solidus_core-2.9.5 lib/spree/testing_support/dummy_app/rake_tasks.rb
solidus_core-2.9.4 lib/spree/testing_support/dummy_app/rake_tasks.rb
solidus_core-2.6.6 lib/spree/testing_support/dummy_app/rake_tasks.rb
solidus_core-2.7.4 lib/spree/testing_support/dummy_app/rake_tasks.rb
solidus_core-2.8.5 lib/spree/testing_support/dummy_app/rake_tasks.rb
solidus_core-2.9.3 lib/spree/testing_support/dummy_app/rake_tasks.rb
solidus_core-2.9.2 lib/spree/testing_support/dummy_app/rake_tasks.rb
solidus_core-2.7.3 lib/spree/testing_support/dummy_app/rake_tasks.rb
solidus_core-2.6.5 lib/spree/testing_support/dummy_app/rake_tasks.rb
solidus_core-2.9.1 lib/spree/testing_support/dummy_app/rake_tasks.rb
solidus_core-2.9.0 lib/spree/testing_support/dummy_app/rake_tasks.rb
solidus_core-2.9.0.rc.1 lib/spree/testing_support/dummy_app/rake_tasks.rb
solidus_core-2.8.4 lib/spree/testing_support/dummy_app/rake_tasks.rb
solidus_core-2.8.3 lib/spree/testing_support/dummy_app/rake_tasks.rb
solidus_core-2.7.2 lib/spree/testing_support/dummy_app/rake_tasks.rb
solidus_core-2.6.4 lib/spree/testing_support/dummy_app/rake_tasks.rb
solidus_core-2.8.2 lib/spree/testing_support/dummy_app/rake_tasks.rb
solidus_core-2.8.1 lib/spree/testing_support/dummy_app/rake_tasks.rb