os_suspenders 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/.travis.yml +13 -0
- data/CONTRIBUTING.md +38 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +133 -0
- data/LICENSE +21 -0
- data/NEWS.md +167 -0
- data/README.md +2 -0
- data/Rakefile +8 -0
- data/bin/rspec +16 -0
- data/bin/suspenders +18 -0
- data/lib/suspenders/actions.rb +35 -0
- data/lib/suspenders/app_builder.rb +352 -0
- data/lib/suspenders/generators/app_generator.rb +207 -0
- data/lib/suspenders/version.rb +3 -0
- data/lib/suspenders.rb +3 -0
- data/spec/fakes/bin/heroku +5 -0
- data/spec/fakes/bin/hub +5 -0
- data/spec/features/github_spec.rb +10 -0
- data/spec/features/heroku_spec.rb +13 -0
- data/spec/features/new_project_spec.rb +38 -0
- data/spec/spec_helper.rb +24 -0
- data/spec/support/fake_github.rb +21 -0
- data/spec/support/fake_heroku.rb +36 -0
- data/spec/support/suspenders.rb +50 -0
- data/suspenders.gemspec +35 -0
- data/templates/Gemfile_clean +44 -0
- data/templates/Procfile +2 -0
- data/templates/README.md.erb +25 -0
- data/templates/_flashes.html.erb +5 -0
- data/templates/_javascript.html.erb +10 -0
- data/templates/application.css.scss +8 -0
- data/templates/background_jobs_rspec.rb +19 -0
- data/templates/bin_setup +32 -0
- data/templates/config_locales_en.yml +11 -0
- data/templates/database_cleaner_rspec.rb +21 -0
- data/templates/development_seeds.rb +13 -0
- data/templates/disable_xml_params.rb +3 -0
- data/templates/errors.rb +28 -0
- data/templates/factories_spec.rb +13 -0
- data/templates/factories_spec_rake_task.rb +15 -0
- data/templates/factory_girl_syntax_rspec.rb +3 -0
- data/templates/postgresql_database.yml.erb +11 -0
- data/templates/rack_timeout.rb +1 -0
- data/templates/sample.env +3 -0
- data/templates/secret_token.rb +10 -0
- data/templates/smtp.rb +10 -0
- data/templates/spec_helper.rb +29 -0
- data/templates/staging.rb +3 -0
- data/templates/suspenders_gitignore +13 -0
- data/templates/suspenders_layout.html.erb.erb +15 -0
- data/templates/unicorn.rb +29 -0
- metadata +195 -0
@@ -0,0 +1,352 @@
|
|
1
|
+
module Suspenders
|
2
|
+
class AppBuilder < Rails::AppBuilder
|
3
|
+
include Suspenders::Actions
|
4
|
+
|
5
|
+
def readme
|
6
|
+
template 'README.md.erb', 'README.md'
|
7
|
+
end
|
8
|
+
|
9
|
+
def raise_on_delivery_errors
|
10
|
+
replace_in_file 'config/environments/development.rb',
|
11
|
+
'raise_delivery_errors = false', 'raise_delivery_errors = true'
|
12
|
+
end
|
13
|
+
|
14
|
+
def raise_on_unpermitted_parameters
|
15
|
+
action_on_unpermitted_parameters = <<-RUBY
|
16
|
+
|
17
|
+
# Raise an ActionController::UnpermittedParameters exception when
|
18
|
+
# a parameter is not explcitly permitted but is passed anyway.
|
19
|
+
config.action_controller.action_on_unpermitted_parameters = :raise
|
20
|
+
RUBY
|
21
|
+
inject_into_file(
|
22
|
+
"config/environments/development.rb",
|
23
|
+
action_on_unpermitted_parameters,
|
24
|
+
before: "\nend"
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
def provide_setup_script
|
29
|
+
copy_file 'bin_setup', 'bin/setup'
|
30
|
+
run 'chmod a+x bin/setup'
|
31
|
+
end
|
32
|
+
|
33
|
+
def provide_dev_prime_task
|
34
|
+
copy_file 'development_seeds.rb', 'lib/tasks/development_seeds.rake'
|
35
|
+
end
|
36
|
+
|
37
|
+
def configure_generators
|
38
|
+
config = <<-RUBY
|
39
|
+
config.generators do |generate|
|
40
|
+
generate.helper false
|
41
|
+
generate.javascript_engine false
|
42
|
+
generate.request_specs false
|
43
|
+
generate.routing_specs false
|
44
|
+
generate.stylesheets false
|
45
|
+
generate.test_framework :rspec
|
46
|
+
generate.view_specs false
|
47
|
+
end
|
48
|
+
|
49
|
+
RUBY
|
50
|
+
|
51
|
+
inject_into_class 'config/application.rb', 'Application', config
|
52
|
+
end
|
53
|
+
|
54
|
+
def enable_factory_girl_syntax
|
55
|
+
copy_file 'factory_girl_syntax_rspec.rb', 'spec/support/factory_girl.rb'
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_factories_first
|
59
|
+
copy_file 'factories_spec.rb', 'spec/models/factories_spec.rb'
|
60
|
+
append_file 'Rakefile', factories_spec_rake_task
|
61
|
+
end
|
62
|
+
|
63
|
+
def configure_smtp
|
64
|
+
copy_file 'smtp.rb', 'config/initializers/smtp.rb'
|
65
|
+
|
66
|
+
prepend_file 'config/environments/production.rb',
|
67
|
+
"require Rails.root.join('config/initializers/smtp')\n"
|
68
|
+
|
69
|
+
config = <<-RUBY
|
70
|
+
|
71
|
+
config.action_mailer.delivery_method = :smtp
|
72
|
+
config.action_mailer.smtp_settings = SMTP_SETTINGS
|
73
|
+
RUBY
|
74
|
+
|
75
|
+
inject_into_file 'config/environments/production.rb', config,
|
76
|
+
:after => 'config.action_mailer.raise_delivery_errors = false'
|
77
|
+
end
|
78
|
+
|
79
|
+
def enable_rack_deflater
|
80
|
+
config = <<-RUBY
|
81
|
+
|
82
|
+
# Enable deflate / gzip compression of controller-generated responses
|
83
|
+
config.middleware.use Rack::Deflater
|
84
|
+
RUBY
|
85
|
+
|
86
|
+
inject_into_file 'config/environments/production.rb', config,
|
87
|
+
:after => "config.serve_static_assets = false\n"
|
88
|
+
end
|
89
|
+
|
90
|
+
def setup_staging_environment
|
91
|
+
staging_file = 'config/environments/staging.rb'
|
92
|
+
copy_file 'staging.rb', staging_file
|
93
|
+
|
94
|
+
config = <<-RUBY
|
95
|
+
|
96
|
+
#{app_name.classify}::Application.configure do
|
97
|
+
# ...
|
98
|
+
end
|
99
|
+
RUBY
|
100
|
+
|
101
|
+
append_file staging_file, config
|
102
|
+
end
|
103
|
+
|
104
|
+
def setup_secret_token
|
105
|
+
template 'secret_token.rb',
|
106
|
+
'config/initializers/secret_token.rb',
|
107
|
+
:force => true
|
108
|
+
end
|
109
|
+
|
110
|
+
def create_partials_directory
|
111
|
+
empty_directory 'app/views/application'
|
112
|
+
end
|
113
|
+
|
114
|
+
def create_shared_flashes
|
115
|
+
copy_file '_flashes.html.erb', 'app/views/application/_flashes.html.erb'
|
116
|
+
end
|
117
|
+
|
118
|
+
def create_shared_javascripts
|
119
|
+
copy_file '_javascript.html.erb', 'app/views/application/_javascript.html.erb'
|
120
|
+
end
|
121
|
+
|
122
|
+
def create_application_layout
|
123
|
+
template 'suspenders_layout.html.erb.erb',
|
124
|
+
'app/views/layouts/application.html.erb',
|
125
|
+
force: true
|
126
|
+
end
|
127
|
+
|
128
|
+
def remove_turbolinks
|
129
|
+
replace_in_file 'app/assets/javascripts/application.js',
|
130
|
+
/\/\/= require turbolinks\n/,
|
131
|
+
''
|
132
|
+
end
|
133
|
+
|
134
|
+
def use_postgres_config_template
|
135
|
+
template 'postgresql_database.yml.erb', 'config/database.yml',
|
136
|
+
force: true
|
137
|
+
end
|
138
|
+
|
139
|
+
def create_database
|
140
|
+
bundle_command 'exec rake db:create db:migrate'
|
141
|
+
end
|
142
|
+
|
143
|
+
def replace_gemfile
|
144
|
+
remove_file 'Gemfile'
|
145
|
+
copy_file 'Gemfile_clean', 'Gemfile'
|
146
|
+
end
|
147
|
+
|
148
|
+
def set_ruby_to_version_being_used
|
149
|
+
inject_into_file 'Gemfile', "\n\nruby '#{RUBY_VERSION}'",
|
150
|
+
after: /source 'https:\/\/rubygems.org'/
|
151
|
+
create_file '.ruby-version', "#{RUBY_VERSION}#{patchlevel}\n"
|
152
|
+
end
|
153
|
+
|
154
|
+
def setup_heroku_specific_gems
|
155
|
+
inject_into_file 'Gemfile', "\n\s\sgem 'rails_12factor'",
|
156
|
+
after: /group :staging, :production do/
|
157
|
+
end
|
158
|
+
|
159
|
+
def enable_database_cleaner
|
160
|
+
copy_file 'database_cleaner_rspec.rb', 'spec/support/database_cleaner.rb'
|
161
|
+
end
|
162
|
+
|
163
|
+
def configure_spec_support_features
|
164
|
+
empty_directory_with_keep_file 'spec/features'
|
165
|
+
empty_directory_with_keep_file 'spec/support/features'
|
166
|
+
end
|
167
|
+
|
168
|
+
def configure_rspec
|
169
|
+
remove_file 'spec/spec_helper.rb'
|
170
|
+
copy_file 'spec_helper.rb', 'spec/spec_helper.rb'
|
171
|
+
end
|
172
|
+
|
173
|
+
def use_spring_binstubs
|
174
|
+
run 'bundle exec spring binstub --all'
|
175
|
+
end
|
176
|
+
|
177
|
+
# def configure_background_jobs_for_rspec
|
178
|
+
# copy_file 'background_jobs_rspec.rb', 'spec/support/background_jobs.rb'
|
179
|
+
# run 'rails g delayed_job:active_record'
|
180
|
+
# end
|
181
|
+
|
182
|
+
def configure_time_zone
|
183
|
+
config = <<-RUBY
|
184
|
+
config.active_record.default_timezone = :utc
|
185
|
+
|
186
|
+
RUBY
|
187
|
+
inject_into_class 'config/application.rb', 'Application', config
|
188
|
+
end
|
189
|
+
|
190
|
+
def configure_time_formats
|
191
|
+
remove_file 'config/locales/en.yml'
|
192
|
+
copy_file 'config_locales_en.yml', 'config/locales/en.yml'
|
193
|
+
end
|
194
|
+
|
195
|
+
def configure_rack_timeout
|
196
|
+
copy_file 'rack_timeout.rb', 'config/initializers/rack_timeout.rb'
|
197
|
+
end
|
198
|
+
|
199
|
+
def configure_action_mailer
|
200
|
+
action_mailer_host 'development', "#{app_name}.local"
|
201
|
+
action_mailer_host 'test', 'www.example.com'
|
202
|
+
action_mailer_host 'staging', "staging.#{app_name}.com"
|
203
|
+
action_mailer_host 'production', "#{app_name}.com"
|
204
|
+
end
|
205
|
+
|
206
|
+
def fix_i18n_deprecation_warning
|
207
|
+
config = <<-RUBY
|
208
|
+
config.i18n.enforce_available_locales = true
|
209
|
+
|
210
|
+
RUBY
|
211
|
+
inject_into_class 'config/application.rb', 'Application', config
|
212
|
+
end
|
213
|
+
|
214
|
+
def generate_rspec
|
215
|
+
generate 'rspec:install'
|
216
|
+
end
|
217
|
+
|
218
|
+
def configure_unicorn
|
219
|
+
copy_file 'unicorn.rb', 'config/unicorn.rb'
|
220
|
+
end
|
221
|
+
|
222
|
+
def setup_foreman
|
223
|
+
copy_file 'sample.env', '.sample.env'
|
224
|
+
copy_file 'Procfile', 'Procfile'
|
225
|
+
end
|
226
|
+
|
227
|
+
def setup_stylesheets
|
228
|
+
remove_file 'app/assets/stylesheets/application.css'
|
229
|
+
copy_file 'application.css.scss',
|
230
|
+
'app/assets/stylesheets/application.css.scss'
|
231
|
+
end
|
232
|
+
|
233
|
+
def gitignore_files
|
234
|
+
remove_file '.gitignore'
|
235
|
+
copy_file 'suspenders_gitignore', '.gitignore'
|
236
|
+
[
|
237
|
+
'app/views/pages',
|
238
|
+
'spec/lib',
|
239
|
+
'spec/controllers',
|
240
|
+
'spec/helpers',
|
241
|
+
'spec/support/matchers',
|
242
|
+
'spec/support/mixins',
|
243
|
+
'spec/support/shared_examples'
|
244
|
+
].each do |dir|
|
245
|
+
run "mkdir #{dir}"
|
246
|
+
run "touch #{dir}/.keep"
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
def init_git
|
251
|
+
run 'git init'
|
252
|
+
end
|
253
|
+
|
254
|
+
def create_heroku_apps
|
255
|
+
path_addition = override_path_for_tests
|
256
|
+
run "#{path_addition} heroku create #{app_name}-production --remote=production"
|
257
|
+
run "#{path_addition} heroku create #{app_name}-staging --remote=staging"
|
258
|
+
run "#{path_addition} heroku config:add RACK_ENV=staging RAILS_ENV=staging --remote=staging"
|
259
|
+
end
|
260
|
+
|
261
|
+
def set_heroku_remotes
|
262
|
+
remotes = <<-RUBY
|
263
|
+
|
264
|
+
# Set up staging and production git remotes
|
265
|
+
git remote add staging git@heroku.com:#{app_name}-staging.git
|
266
|
+
git remote add production git@heroku.com:#{app_name}-production.git
|
267
|
+
RUBY
|
268
|
+
|
269
|
+
append_file 'bin/setup', remotes
|
270
|
+
end
|
271
|
+
|
272
|
+
def set_heroku_rails_secrets
|
273
|
+
path_addition = override_path_for_tests
|
274
|
+
run "#{path_addition} heroku config:add SECRET_KEY_BASE=#{generate_secret} --remote=staging"
|
275
|
+
run "#{path_addition} heroku config:add SECRET_KEY_BASE=#{generate_secret} --remote=production"
|
276
|
+
end
|
277
|
+
|
278
|
+
def create_github_repo(repo_name)
|
279
|
+
path_addition = override_path_for_tests
|
280
|
+
run "#{path_addition} hub create #{repo_name}"
|
281
|
+
end
|
282
|
+
|
283
|
+
def copy_miscellaneous_files
|
284
|
+
copy_file 'errors.rb', 'config/initializers/errors.rb'
|
285
|
+
end
|
286
|
+
|
287
|
+
def customize_error_pages
|
288
|
+
meta_tags =<<-EOS
|
289
|
+
<meta charset='utf-8' />
|
290
|
+
<meta name='ROBOTS' content='NOODP' />
|
291
|
+
EOS
|
292
|
+
|
293
|
+
%w(500 404 422).each do |page|
|
294
|
+
inject_into_file "public/#{page}.html", meta_tags, :after => "<head>\n"
|
295
|
+
replace_in_file "public/#{page}.html", /<!--.+-->\n/, ''
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
def remove_routes_comment_lines
|
300
|
+
replace_in_file 'config/routes.rb',
|
301
|
+
/Application\.routes\.draw do.*end/m,
|
302
|
+
"Application.routes.draw do\nend"
|
303
|
+
end
|
304
|
+
|
305
|
+
def disable_xml_params
|
306
|
+
copy_file 'disable_xml_params.rb', 'config/initializers/disable_xml_params.rb'
|
307
|
+
end
|
308
|
+
|
309
|
+
def setup_default_rake_task
|
310
|
+
append_file 'Rakefile' do
|
311
|
+
"task(:default).clear\ntask :default => [:spec]\n"
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
def generate_devise
|
316
|
+
generate 'devise:install'
|
317
|
+
end
|
318
|
+
|
319
|
+
def generate_devise_user
|
320
|
+
generate 'devise User'
|
321
|
+
end
|
322
|
+
|
323
|
+
def devise_migrate
|
324
|
+
bundle_command 'exec rake db:migrate db:test:prepare'
|
325
|
+
end
|
326
|
+
|
327
|
+
private
|
328
|
+
|
329
|
+
def override_path_for_tests
|
330
|
+
if ENV['TESTING']
|
331
|
+
support_bin = File.expand_path(File.join('..', '..', 'spec', 'fakes', 'bin'))
|
332
|
+
"PATH=#{support_bin}:$PATH"
|
333
|
+
end
|
334
|
+
end
|
335
|
+
|
336
|
+
def factories_spec_rake_task
|
337
|
+
IO.read find_in_source_paths('factories_spec_rake_task.rb')
|
338
|
+
end
|
339
|
+
|
340
|
+
def generate_secret
|
341
|
+
SecureRandom.hex(64)
|
342
|
+
end
|
343
|
+
|
344
|
+
def patchlevel
|
345
|
+
if RUBY_PATCHLEVEL == 0 && RUBY_VERSION >= '2.1.0'
|
346
|
+
''
|
347
|
+
else
|
348
|
+
"-p#{RUBY_PATCHLEVEL}"
|
349
|
+
end
|
350
|
+
end
|
351
|
+
end
|
352
|
+
end
|
@@ -0,0 +1,207 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/rails/app/app_generator'
|
3
|
+
|
4
|
+
module Suspenders
|
5
|
+
class AppGenerator < Rails::Generators::AppGenerator
|
6
|
+
class_option :database, :type => :string, :aliases => '-d', :default => 'postgresql',
|
7
|
+
:desc => "Preconfigure for selected database (options: #{DATABASES.join('/')})"
|
8
|
+
|
9
|
+
class_option :heroku, :type => :boolean, :aliases => '-H', :default => false,
|
10
|
+
:desc => 'Create staging and production Heroku apps'
|
11
|
+
|
12
|
+
class_option :github, :type => :string, :aliases => '-G', :default => nil,
|
13
|
+
:desc => 'Create Github repository and add remote origin pointed to repo'
|
14
|
+
|
15
|
+
class_option :skip_test_unit, :type => :boolean, :aliases => '-T', :default => true,
|
16
|
+
:desc => 'Skip Test::Unit files'
|
17
|
+
|
18
|
+
def finish_template
|
19
|
+
invoke :suspenders_customization
|
20
|
+
super
|
21
|
+
end
|
22
|
+
|
23
|
+
def suspenders_customization
|
24
|
+
invoke :customize_gemfile
|
25
|
+
invoke :setup_development_environment
|
26
|
+
invoke :setup_test_environment
|
27
|
+
invoke :setup_production_environment
|
28
|
+
invoke :setup_staging_environment
|
29
|
+
invoke :setup_secret_token
|
30
|
+
invoke :create_suspenders_views
|
31
|
+
invoke :setup_coffeescript
|
32
|
+
invoke :configure_app
|
33
|
+
invoke :setup_stylesheets
|
34
|
+
invoke :copy_miscellaneous_files
|
35
|
+
invoke :customize_error_pages
|
36
|
+
invoke :remove_routes_comment_lines
|
37
|
+
invoke :setup_git
|
38
|
+
invoke :setup_database
|
39
|
+
invoke :setup_devise
|
40
|
+
invoke :create_heroku_apps
|
41
|
+
invoke :create_github_repo
|
42
|
+
invoke :outro
|
43
|
+
end
|
44
|
+
|
45
|
+
def customize_gemfile
|
46
|
+
build :replace_gemfile
|
47
|
+
build :set_ruby_to_version_being_used
|
48
|
+
|
49
|
+
if options[:heroku]
|
50
|
+
build :setup_heroku_specific_gems
|
51
|
+
end
|
52
|
+
|
53
|
+
bundle_command 'install'
|
54
|
+
end
|
55
|
+
|
56
|
+
def setup_database
|
57
|
+
say 'Setting up database'
|
58
|
+
|
59
|
+
if 'postgresql' == options[:database]
|
60
|
+
build :use_postgres_config_template
|
61
|
+
end
|
62
|
+
|
63
|
+
build :create_database
|
64
|
+
end
|
65
|
+
|
66
|
+
def setup_devise
|
67
|
+
say 'Setting up devise'
|
68
|
+
|
69
|
+
build :generate_devise
|
70
|
+
build :generate_user
|
71
|
+
build :devise_migrate
|
72
|
+
end
|
73
|
+
|
74
|
+
def setup_development_environment
|
75
|
+
say 'Setting up the development environment'
|
76
|
+
build :raise_on_delivery_errors
|
77
|
+
build :raise_on_unpermitted_parameters
|
78
|
+
build :provide_setup_script
|
79
|
+
build :provide_dev_prime_task
|
80
|
+
build :configure_generators
|
81
|
+
end
|
82
|
+
|
83
|
+
def setup_test_environment
|
84
|
+
say 'Setting up the test environment'
|
85
|
+
build :enable_factory_girl_syntax
|
86
|
+
build :test_factories_first
|
87
|
+
build :generate_rspec
|
88
|
+
build :configure_rspec
|
89
|
+
build :use_spring_binstubs
|
90
|
+
# build :configure_background_jobs_for_rspec
|
91
|
+
build :enable_database_cleaner
|
92
|
+
build :configure_spec_support_features
|
93
|
+
end
|
94
|
+
|
95
|
+
def setup_production_environment
|
96
|
+
say 'Setting up the production environment'
|
97
|
+
build :configure_smtp
|
98
|
+
build :enable_rack_deflater
|
99
|
+
end
|
100
|
+
|
101
|
+
def setup_staging_environment
|
102
|
+
say 'Setting up the staging environment'
|
103
|
+
build :setup_staging_environment
|
104
|
+
end
|
105
|
+
|
106
|
+
def setup_secret_token
|
107
|
+
say 'Moving secret token out of version control'
|
108
|
+
build :setup_secret_token
|
109
|
+
end
|
110
|
+
|
111
|
+
def create_suspenders_views
|
112
|
+
say 'Creating suspenders views'
|
113
|
+
build :create_partials_directory
|
114
|
+
build :create_shared_flashes
|
115
|
+
build :create_shared_javascripts
|
116
|
+
build :create_application_layout
|
117
|
+
end
|
118
|
+
|
119
|
+
def setup_coffeescript
|
120
|
+
say 'Setting up CoffeeScript defaults'
|
121
|
+
build :remove_turbolinks
|
122
|
+
end
|
123
|
+
|
124
|
+
def configure_app
|
125
|
+
say 'Configuring app'
|
126
|
+
build :configure_action_mailer
|
127
|
+
build :configure_time_zone
|
128
|
+
build :configure_time_formats
|
129
|
+
build :configure_rack_timeout
|
130
|
+
build :disable_xml_params
|
131
|
+
build :fix_i18n_deprecation_warning
|
132
|
+
build :setup_default_rake_task
|
133
|
+
build :configure_unicorn
|
134
|
+
build :setup_foreman
|
135
|
+
end
|
136
|
+
|
137
|
+
def setup_stylesheets
|
138
|
+
say 'Set up stylesheets'
|
139
|
+
build :setup_stylesheets
|
140
|
+
end
|
141
|
+
|
142
|
+
def setup_git
|
143
|
+
if !options[:skip_git]
|
144
|
+
say 'Initializing git'
|
145
|
+
invoke :setup_gitignore
|
146
|
+
invoke :init_git
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def create_heroku_apps
|
151
|
+
if options[:heroku]
|
152
|
+
say 'Creating Heroku apps'
|
153
|
+
build :create_heroku_apps
|
154
|
+
build :set_heroku_remotes
|
155
|
+
build :set_heroku_rails_secrets
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
def create_github_repo
|
160
|
+
if !options[:skip_git] && options[:github]
|
161
|
+
say 'Creating Github repo'
|
162
|
+
build :create_github_repo, options[:github]
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
def setup_gitignore
|
167
|
+
build :gitignore_files
|
168
|
+
end
|
169
|
+
|
170
|
+
def init_git
|
171
|
+
build :init_git
|
172
|
+
end
|
173
|
+
|
174
|
+
def copy_miscellaneous_files
|
175
|
+
say 'Copying miscellaneous support files'
|
176
|
+
build :copy_miscellaneous_files
|
177
|
+
end
|
178
|
+
|
179
|
+
def customize_error_pages
|
180
|
+
say 'Customizing the 500/404/422 pages'
|
181
|
+
build :customize_error_pages
|
182
|
+
end
|
183
|
+
|
184
|
+
def remove_routes_comment_lines
|
185
|
+
build :remove_routes_comment_lines
|
186
|
+
end
|
187
|
+
|
188
|
+
def outro
|
189
|
+
say 'Congratulations! You just pulled our suspenders.'
|
190
|
+
say "Remember to run 'rails generate airbrake' with your API key."
|
191
|
+
end
|
192
|
+
|
193
|
+
def run_bundle
|
194
|
+
# Let's not: We'll bundle manually at the right spot
|
195
|
+
end
|
196
|
+
|
197
|
+
protected
|
198
|
+
|
199
|
+
def get_builder_class
|
200
|
+
Suspenders::AppBuilder
|
201
|
+
end
|
202
|
+
|
203
|
+
def using_active_record?
|
204
|
+
!options[:skip_active_record]
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
data/lib/suspenders.rb
ADDED
data/spec/fakes/bin/hub
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
feature 'Heroku' do
|
4
|
+
scenario 'Suspend a project with --heroku=true' do
|
5
|
+
run_suspenders('--heroku=true')
|
6
|
+
|
7
|
+
expect(FakeHeroku).to have_gem_included(project_path, 'rails_12factor')
|
8
|
+
expect(FakeHeroku).to have_created_app_for('staging')
|
9
|
+
expect(FakeHeroku).to have_created_app_for('production')
|
10
|
+
expect(FakeHeroku).to have_configured_vars('staging', 'SECRET_KEY_BASE')
|
11
|
+
expect(FakeHeroku).to have_configured_vars('production', 'SECRET_KEY_BASE')
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
feature 'Suspend a new project with default configuration' do
|
4
|
+
scenario 'specs pass' do
|
5
|
+
run_suspenders
|
6
|
+
|
7
|
+
Dir.chdir(project_path) do
|
8
|
+
Bundler.with_clean_env do
|
9
|
+
expect(`rake`).to include('0 failures')
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
scenario 'staging config is inherited from production' do
|
15
|
+
run_suspenders
|
16
|
+
|
17
|
+
staging_file = IO.read("#{project_path}/config/environments/staging.rb")
|
18
|
+
config_stub = "Dummy::Application.configure do"
|
19
|
+
expect(staging_file).to match(/^require_relative 'production'/)
|
20
|
+
expect(staging_file).to match(/#{config_stub}/), staging_file
|
21
|
+
end
|
22
|
+
|
23
|
+
if RUBY_PATCHLEVEL == 0 && RUBY_VERSION >= '2.1.0'
|
24
|
+
scenario '.ruby-version does not include patchlevel for Ruby 2.1.0+' do
|
25
|
+
run_suspenders
|
26
|
+
|
27
|
+
ruby_version_file = IO.read("#{project_path}/.ruby-version")
|
28
|
+
expect(ruby_version_file).to eq "#{RUBY_VERSION}\n"
|
29
|
+
end
|
30
|
+
else
|
31
|
+
scenario '.ruby-version includes patchlevel for all pre-Ruby 2.1.0 versions' do
|
32
|
+
run_suspenders
|
33
|
+
|
34
|
+
ruby_version_file = IO.read("#{project_path}/.ruby-version")
|
35
|
+
expect(ruby_version_file).to eq "#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}\n"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'capybara/rspec'
|
2
|
+
require 'bundler/setup'
|
3
|
+
|
4
|
+
Bundler.require(:default, :test)
|
5
|
+
|
6
|
+
require (Pathname.new(__FILE__).dirname + '../lib/suspenders').expand_path
|
7
|
+
|
8
|
+
Dir['./spec/support/**/*.rb'].each { |file| require file }
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.include SuspendersTestHelpers
|
12
|
+
|
13
|
+
config.before(:all) do
|
14
|
+
create_tmp_directory
|
15
|
+
end
|
16
|
+
|
17
|
+
config.before(:each) do
|
18
|
+
drop_dummy_database
|
19
|
+
remove_project_directory
|
20
|
+
|
21
|
+
FakeHeroku.clear!
|
22
|
+
FakeGithub.clear!
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class FakeGithub
|
2
|
+
RECORDER = File.expand_path(File.join('..', '..', 'tmp', 'hub_commands'), File.dirname(__FILE__))
|
3
|
+
|
4
|
+
def initialize(args)
|
5
|
+
@args = args
|
6
|
+
end
|
7
|
+
|
8
|
+
def run!
|
9
|
+
File.open(RECORDER, 'a') do |file|
|
10
|
+
file.write @args.join(' ')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.clear!
|
15
|
+
FileUtils.rm_rf RECORDER
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.has_created_repo?(repo_name)
|
19
|
+
File.read(RECORDER) == "create #{repo_name}"
|
20
|
+
end
|
21
|
+
end
|