Class: Spree::Generators::TestAppGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/spree/test_app_generator.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.verboseObject

Returns the value of attribute verbose.



8
9
10
# File 'lib/generators/spree/test_app_generator.rb', line 8

def verbose
  @verbose
end

Class Method Details

.source_rootObject



15
16
17
# File 'lib/generators/spree/test_app_generator.rb', line 15

def self.source_root
  File.expand_path('../../templates', __FILE__)
end

Instance Method Details

#append_db_adapter_gemObject



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/generators/spree/test_app_generator.rb', line 81

def append_db_adapter_gem
  silence_stream(STDOUT) {
    case database_name
    when "mysql"
      gem "mysql2"
      append_file '../../Gemfile' do
        "gem 'mysql2'"
      end
    else
      gem "sqlite3-ruby"
      append_file '../../Gemfile' do
        "gem 'sqlite3-ruby'"
      end
    end
  }
end

#create_databases_ymlObject



61
62
63
64
65
66
67
# File 'lib/generators/spree/test_app_generator.rb', line 61

def create_databases_yml
  silence_stream(STDOUT) {
    remove_file "config/database.yml"
    template "config/database.yml.#{database_name}"
    mv "spec/test_app/config/database.yml.#{database_name}", "spec/test_app/config/database.yml", :verbose => false
  }
end

#create_rootObject



34
35
36
# File 'lib/generators/spree/test_app_generator.rb', line 34

def create_root
  self.destination_root = File.expand_path("spec/#{test_app}", destination_root)
end

#create_rspec_gemfileObject



26
27
28
29
30
31
32
# File 'lib/generators/spree/test_app_generator.rb', line 26

def create_rspec_gemfile
  # newer versions of rspec require a Gemfile in the local gem dirs so create one there as well as in spec/test_app
  silence_stream(STDOUT) {
    template "Gemfile", :force => true
    remove_file "Gemfile.lock"
  }
end

#generate_appObject



19
20
21
22
23
24
# File 'lib/generators/spree/test_app_generator.rb', line 19

def generate_app
    remove_directory_if_exists("spec/#{test_app}")
    inside "spec" do
      run "bundle exec rails new #{test_app} --database=#{database_name} -GJTq --skip-gemfile"
    end
end

#remove_unneeded_filesObject



38
39
40
41
42
43
44
45
46
47
# File 'lib/generators/spree/test_app_generator.rb', line 38

def remove_unneeded_files
  silence_stream(STDOUT) {
    remove_file "doc"
    remove_file "lib/tasks"
    remove_file "public/images/rails.png"
    remove_file "public/index.html"
    remove_file "README"
    remove_file "vendor"
  }
end

#replace_gemfileObject



49
50
51
52
53
# File 'lib/generators/spree/test_app_generator.rb', line 49

def replace_gemfile
  silence_stream(STDOUT) {
    template "Gemfile"
  }
end

#setup_environmentsObject



55
56
57
58
59
# File 'lib/generators/spree/test_app_generator.rb', line 55

def setup_environments
  silence_stream(STDOUT) {
    template "config/environments/cucumber.rb"
  }
end

#tweak_gemfileObject



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/generators/spree/test_app_generator.rb', line 69

def tweak_gemfile
  silence_stream(STDOUT) {
    append_file '../../Gemfile' do
      full_path_for_local_gems
    end

    append_file 'Gemfile' do
      full_path_for_local_gems
    end
  }
end