Class: CommonRakeTasks

Inherits:
Object
  • Object
show all
Includes:
Rake::DSL
Defined in:
lib/spree/testing_support/common_rake.rb

Instance Method Summary collapse

Constructor Details

#initializeCommonRakeTasks

Returns a new instance of CommonRakeTasks.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/spree/testing_support/common_rake.rb', line 8

def initialize
  namespace :common do
    task :test_app, :user_class do |_t, args|
      args.with_defaults(user_class: "Spree::LegacyUser")
      lib_name = ENV['LIB_NAME'] or
        raise "Please provide a library name via the LIB_NAME environment variable."

      require lib_name

      force_rails_environment_to_test

      Spree::DummyGenerator.start [
        "--lib-name=#{lib_name}",
        "--quiet",
      ]

      # While the dummy app is generated the current directory
      # within ruby is changed to that of the dummy app.
      sh({
        'FRONTEND' => ENV['FRONTEND'] || 'none',
      }, [
        'bin/rails',
        'generate',
        'solidus:install',
        Dir.pwd, # use the current dir as Rails.root
        "--auto-accept",
        "--admin-preview=#{ENV.fetch('ADMIN_PREVIEW', 'false')}",
        "--authentication=none",
        "--payment-method=none",
        "--migrate=false",
        "--seed=false",
        "--sample=false",
        "--user-class=#{args[:user_class]}",
        "--quiet",
      ].shelljoin)

      if Bundler.locked_gems.dependencies['solidus_frontend']
        sh "bin/rails g solidus_frontend:install --auto-accept"
      end

      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