ajmalafif-jumpstart 1.18.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -0
  3. data/.ruby-version +1 -0
  4. data/.travis.yml +11 -0
  5. data/CONTRIBUTING.md +36 -0
  6. data/Gemfile +3 -0
  7. data/Gemfile.lock +135 -0
  8. data/LICENSE +21 -0
  9. data/NEWS.md +292 -0
  10. data/README.md +190 -0
  11. data/Rakefile +8 -0
  12. data/bin/jumpstart +18 -0
  13. data/bin/rake +16 -0
  14. data/bin/rspec +16 -0
  15. data/bin/setup +13 -0
  16. data/jumpstart.gemspec +38 -0
  17. data/lib/jumpstart.rb +4 -0
  18. data/lib/jumpstart/actions.rb +25 -0
  19. data/lib/jumpstart/app_builder.rb +398 -0
  20. data/lib/jumpstart/generators/app_generator.rb +215 -0
  21. data/lib/jumpstart/version.rb +5 -0
  22. data/spec/fakes/bin/heroku +5 -0
  23. data/spec/fakes/bin/hub +5 -0
  24. data/spec/features/github_spec.rb +10 -0
  25. data/spec/features/heroku_spec.rb +19 -0
  26. data/spec/features/new_project_spec.rb +117 -0
  27. data/spec/spec_helper.rb +24 -0
  28. data/spec/support/fake_github.rb +21 -0
  29. data/spec/support/fake_heroku.rb +38 -0
  30. data/spec/support/jumpstart.rb +49 -0
  31. data/templates/Gemfile.erb +52 -0
  32. data/templates/Procfile +2 -0
  33. data/templates/README.md.erb +35 -0
  34. data/templates/_analytics.html.erb +7 -0
  35. data/templates/_flashes.html.erb +7 -0
  36. data/templates/_javascript.html.erb +12 -0
  37. data/templates/action_mailer.rb +5 -0
  38. data/templates/application.css.scss +7 -0
  39. data/templates/background_jobs_rspec.rb +19 -0
  40. data/templates/bin_setup.erb +34 -0
  41. data/templates/config_i18n_tasks.yml +13 -0
  42. data/templates/config_locales_en.yml.erb +19 -0
  43. data/templates/database_cleaner_rspec.rb +21 -0
  44. data/templates/development_seeds.rb +12 -0
  45. data/templates/disable_xml_params.rb +3 -0
  46. data/templates/errors.rb +34 -0
  47. data/templates/factory_girl_rspec.rb +3 -0
  48. data/templates/i18n.rb +3 -0
  49. data/templates/jumpstart_gitignore +17 -0
  50. data/templates/jumpstart_layout.html.erb.erb +16 -0
  51. data/templates/newrelic.yml.erb +34 -0
  52. data/templates/postgresql_database.yml.erb +12 -0
  53. data/templates/rack_timeout.rb +1 -0
  54. data/templates/rails_helper.rb +23 -0
  55. data/templates/sample.env +3 -0
  56. data/templates/secrets.yml +14 -0
  57. data/templates/smtp.rb +9 -0
  58. data/templates/spec_helper.rb +16 -0
  59. data/templates/staging.rb +5 -0
  60. data/templates/travis.yml.erb +24 -0
  61. data/templates/unicorn.rb +30 -0
  62. metadata +223 -0
data/README.md ADDED
@@ -0,0 +1,190 @@
1
+ # Jumpstart [![Build Status](https://secure.travis-ci.org/thoughtbot/jumpstart.png?branch=master)](http://travis-ci.org/thoughtbot/jumpstart)
2
+
3
+ Jumpstart is the base Rails application used at
4
+ [thoughtbot](http://thoughtbot.com).
5
+
6
+ ![Jumpstart boy](http://media.tumblr.com/1TEAMALpseh5xzf0Jt6bcwSMo1_400.png)
7
+
8
+ Installation
9
+ ------------
10
+
11
+ First install the jumpstart gem:
12
+
13
+ gem install jumpstart
14
+
15
+ Then run:
16
+
17
+ jumpstart projectname
18
+
19
+ This will create a Rails app in `projectname` using the latest version of Rails.
20
+
21
+ Gemfile
22
+ -------
23
+
24
+ To see the latest and greatest gems, look at Jumpstart'
25
+ [Gemfile](templates/Gemfile.erb), which will be appended to the default
26
+ generated projectname/Gemfile.
27
+
28
+ It includes application gems like:
29
+
30
+ * [Airbrake](https://github.com/airbrake/airbrake) for exception notification
31
+ * [Bourbon](https://github.com/thoughtbot/bourbon) for Sass mixins
32
+ * [Bitters](https://github.com/thoughtbot/bitters) for scaffold application styles
33
+ * [Delayed Job](https://github.com/collectiveidea/delayed_job) for background
34
+ processing
35
+ * [Email Validator](https://github.com/balexand/email_validator) for email
36
+ validation
37
+ * [Flutie](https://github.com/thoughtbot/flutie) for and `body_class` view
38
+ helper
39
+ * [High Voltage](https://github.com/thoughtbot/high_voltage) for static pages
40
+ * [jQuery Rails](https://github.com/rails/jquery-rails) for jQuery
41
+ * [Neat](https://github.com/thoughtbot/neat) for semantic grids
42
+ * [New Relic RPM](https://github.com/newrelic/rpm) for monitoring performance
43
+ * [Normalize](https://necolas.github.io/normalize.css/) for resetting browser styles
44
+ * [Postgres](https://github.com/ged/ruby-pg) for access to the Postgres database
45
+ * [Rack Timeout](https://github.com/kch/rack-timeout) to abort requests that are
46
+ taking too long
47
+ * [Recipient Interceptor](https://github.com/croaky/recipient_interceptor) to
48
+ avoid accidentally sending emails to real people from staging
49
+ * [Simple Form](https://github.com/plataformatec/simple_form) for form markup
50
+ and style
51
+ * [Title](https://github.com/calebthompson/title) for storing titles in
52
+ translations
53
+ * [Unicorn](https://github.com/defunkt/unicorn) to serve HTTP requests
54
+
55
+ And development gems like:
56
+
57
+ * [Dotenv](https://github.com/bkeepers/dotenv) for loading environment variables
58
+ * [Pry Rails](https://github.com/rweng/pry-rails) for interactively exploring
59
+ objects
60
+ * [ByeBug](https://github.com/deivid-rodriguez/byebug) for interactively
61
+ debugging behavior
62
+ * [Spring](https://github.com/rails/spring) for fast Rails actions via
63
+ pre-loading
64
+
65
+ And testing gems like:
66
+
67
+ * [Capybara](https://github.com/jnicklas/capybara) and
68
+ [Capybara Webkit](https://github.com/thoughtbot/capybara-webkit) for
69
+ integration testing
70
+ * [Factory Girl](https://github.com/thoughtbot/factory_girl) for test data
71
+ * [Formulaic](https://github.com/thoughtbot/formulaic) for integration testing
72
+ HTML forms
73
+ * [RSpec](https://github.com/rspec/rspec) for unit testing
74
+ * [RSpec Mocks](https://github.com/rspec/rspec-mocks) for stubbing and spying
75
+ * [Shoulda Matchers](https://github.com/thoughtbot/shoulda-matchers) for common
76
+ RSpec matchers
77
+ * [Timecop](https://github.com/jtrupiano/timecop-console) for testing time
78
+
79
+ Other goodies
80
+ -------------
81
+
82
+ Jumpstart also comes with:
83
+
84
+ * The [`./bin/setup`][bin] convention for new developer setup
85
+ * Rails' flashes set up and in application layout
86
+ * A few nice time formats set up for localization
87
+ * `Rack::Deflater` to [compress responses with Gzip][compress]
88
+ * A [low database connection pool limit][pool]
89
+ * [Safe binstubs][binstub]
90
+ * [t() and l() in specs without prefixing with I18n][i18n]
91
+ * An automatically-created `SECRET_KEY_BASE` environment variable in all
92
+ environments.
93
+ * Configuration for [Travis Pro][travis] continuous integration.
94
+ * The analytics adapter [Segment.io][segment] (and therefore config for Google
95
+ Analytics, Intercom, Facebook Ads, Twitter Ads, etc.).
96
+
97
+ [bin]: http://robots.thoughtbot.com/bin-setup
98
+ [compress]: http://robots.thoughtbot.com/content-compression-with-rack-deflater/
99
+ [pool]: https://devcenter.heroku.com/articles/concurrency-and-database-connections
100
+ [binstub]: https://github.com/thoughtbot/jumpstart/pull/282
101
+ [i18n]: https://github.com/thoughtbot/jumpstart/pull/304
102
+ [travis]: http://docs.travis-ci.com/user/travis-pro/
103
+ [segment]: https://segment.io
104
+
105
+ Heroku
106
+ ------
107
+
108
+ You can optionally create Heroku staging and production apps:
109
+
110
+ jumpstart app --heroku true
111
+
112
+ This:
113
+
114
+ * Creates a staging and production Heroku app
115
+ * Sets them as `staging` and `production` Git remotes
116
+ * Configures staging with `RACK_ENV` and `RAILS_ENV` environment variables set
117
+ to `staging`
118
+ * Adds the [Rails 12 Factor](https://github.com/heroku/rails_12factor) gem
119
+ to make running Rails 4 apps easier on Heroku
120
+
121
+ Git
122
+ ---
123
+
124
+ This will initialize a new git repository for your Rails app. You can
125
+ bypass this with the `--skip-git` option:
126
+
127
+ jumpstart app --skip-git true
128
+
129
+ GitHub
130
+ ------
131
+
132
+ You can optionally create a GitHub repository for the suspended Rails app. It
133
+ requires that you have [Hub](https://github.com/github/hub) on your system:
134
+
135
+ curl http://hub.github.com/standalone -sLo ~/bin/hub && chmod +x ~/bin/hub
136
+ jumpstart app --github organization/project
137
+
138
+ This has the same effect as running:
139
+
140
+ hub create organization/project
141
+
142
+ Dependencies
143
+ ------------
144
+
145
+ Jumpstart requires the latest version of Ruby.
146
+
147
+ Some gems included in Jumpstart have native extensions. You should have GCC
148
+ installed on your machine before generating an app with Jumpstart.
149
+
150
+ Use [OS X GCC Installer](https://github.com/kennethreitz/osx-gcc-installer/) for
151
+ Snow Leopard (OS X 10.6).
152
+
153
+ Use [Command Line Tools for XCode](https://developer.apple.com/downloads/index.action)
154
+ for Lion (OS X 10.7) or Mountain Lion (OS X 10.8).
155
+
156
+ We use [Capybara Webkit](https://github.com/thoughtbot/capybara-webkit) for
157
+ full-stack JavaScript integration testing. It requires QT. Instructions for
158
+ installing QT are
159
+ [here](https://github.com/thoughtbot/capybara-webkit/wiki/Installing-Qt-and-compiling-capybara-webkit).
160
+
161
+ PostgreSQL needs to be installed and running for the `db:create` rake task.
162
+
163
+ Issues
164
+ ------
165
+
166
+ If you have problems, please create a
167
+ [GitHub Issue](https://github.com/thoughtbot/jumpstart/issues).
168
+
169
+ Contributing
170
+ ------------
171
+
172
+ To update Jumpstart' Ruby version, change `.ruby-version` and `.travis.yml`.
173
+
174
+ Please see [CONTRIBUTING.md](CONTRIBUTING.md) for further details.
175
+
176
+ Credits
177
+ -------
178
+
179
+ ![thoughtbot](http://thoughtbot.com/images/tm/logo.png)
180
+
181
+ Jumpstart is maintained and funded by
182
+ [thoughtbot, inc](http://thoughtbot.com/community).
183
+
184
+ The names and logos for thoughtbot are trademarks of thoughtbot, inc.
185
+
186
+ License
187
+ -------
188
+
189
+ Jumpstart is Copyright © 2008-2014 thoughtbot. It is free software, and may be
190
+ redistributed under the terms specified in the LICENSE file.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'bundler/setup'
2
+ require 'bundler/gem_tasks'
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:rspec)
6
+
7
+ desc 'Run the test suite'
8
+ task :default => :rspec
data/bin/jumpstart ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pathname'
3
+
4
+ source_path = (Pathname.new(__FILE__).dirname + '../lib').expand_path
5
+ $LOAD_PATH << source_path
6
+
7
+ require 'jumpstart'
8
+
9
+ if ['create', '--create'].include? ARGV[0]
10
+ ARGV.shift
11
+ puts "[WARNING] the jumpstart create argument is deprecated. Just use `jumpstart #{ARGV.join}` instead"
12
+ end
13
+
14
+ templates_root = File.expand_path(File.join("..", "templates"), File.dirname(__FILE__))
15
+ Jumpstart::AppGenerator.source_root templates_root
16
+ Jumpstart::AppGenerator.source_paths << Rails::Generators::AppGenerator.source_root << templates_root
17
+
18
+ Jumpstart::AppGenerator.start
data/bin/rake ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rake' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rake', 'rake')
data/bin/rspec ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rspec' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rspec-core', 'rspec')
data/bin/setup ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env sh
2
+
3
+ # Run this script immediately after cloning the codebase.
4
+
5
+ # Exit if any subcommand fails
6
+ set -e
7
+
8
+ # Set up Ruby dependencies via Bundler
9
+ bundle install
10
+
11
+ # Add binstubs to PATH in ~/.zshenv like this:
12
+ # export PATH=".git/safe/../../bin:$PATH"
13
+ mkdir -p .git/safe
data/jumpstart.gemspec ADDED
@@ -0,0 +1,38 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'jumpstart/version'
4
+ require 'date'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.required_ruby_version = ">= #{Jumpstart::RUBY_VERSION}"
8
+ s.authors = ['ajmalafif']
9
+ s.date = Date.today.strftime('%Y-%m-%d')
10
+
11
+ s.description = <<-HERE
12
+ Jumpstart is a base Rails project that you can upgrade. It is used by
13
+ thoughtbot to get a jump start on a working app. Use Jumpstart if you're in a
14
+ rush to build something amazing; don't use it if you like missing deadlines.
15
+ HERE
16
+
17
+ s.email = 'pembaris+rubygems@gmail.com'
18
+ s.executables = ['jumpstart']
19
+ s.extra_rdoc_files = %w[README.md LICENSE]
20
+ s.files = `git ls-files`.split("\n")
21
+ s.homepage = 'http://github.com/ajmalafif/suspenders'
22
+ s.license = 'MIT'
23
+ s.name = 'ajmalafif-jumpstart'
24
+ s.rdoc_options = ['--charset=UTF-8']
25
+ s.require_paths = ['lib']
26
+ s.summary = "Generate a Rails app using thoughtbot's best practices."
27
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
28
+ s.version = Jumpstart::VERSION
29
+
30
+ s.add_dependency 'bitters', '~> 0.10.0'
31
+ s.add_dependency 'bundler', '~> 1.3'
32
+ s.add_dependency 'rails', Jumpstart::RAILS_VERSION
33
+
34
+ s.add_development_dependency 'aruba', '~> 0.5'
35
+ s.add_development_dependency 'cucumber', '~> 1.2'
36
+ s.add_development_dependency 'rspec', '~> 2.0'
37
+ s.add_development_dependency 'capybara', '~> 2.2', '>= 2.2.0'
38
+ end
data/lib/jumpstart.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'jumpstart/version'
2
+ require 'jumpstart/generators/app_generator'
3
+ require 'jumpstart/actions'
4
+ require 'jumpstart/app_builder'
@@ -0,0 +1,25 @@
1
+ module Jumpstart
2
+ module Actions
3
+ def replace_in_file(relative_path, find, replace)
4
+ path = File.join(destination_root, relative_path)
5
+ contents = IO.read(path)
6
+ unless contents.gsub!(find, replace)
7
+ raise "#{find.inspect} not found in #{relative_path}"
8
+ end
9
+ File.open(path, "w") { |file| file.write(contents) }
10
+ end
11
+
12
+ def action_mailer_host(rails_env, host)
13
+ host_config = "config.action_mailer.default_url_options = { host: '#{host}' }"
14
+ configure_environment(rails_env, host_config)
15
+ end
16
+
17
+ def configure_environment(rails_env, config)
18
+ inject_into_file(
19
+ "config/environments/#{rails_env}.rb",
20
+ "\n\n #{config}",
21
+ before: "\nend"
22
+ )
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,398 @@
1
+ module Jumpstart
2
+ class AppBuilder < Rails::AppBuilder
3
+ include Jumpstart::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
+ config = <<-RUBY
16
+ config.action_controller.action_on_unpermitted_parameters = :raise
17
+ RUBY
18
+
19
+ inject_into_class "config/application.rb", "Application", config
20
+ end
21
+
22
+ def provide_setup_script
23
+ template 'bin_setup.erb', 'bin/setup', port_number: port_number
24
+ run 'chmod a+x bin/setup'
25
+ end
26
+
27
+ def provide_dev_prime_task
28
+ copy_file 'development_seeds.rb', 'lib/tasks/development_seeds.rake'
29
+ end
30
+
31
+ def configure_generators
32
+ config = <<-RUBY
33
+
34
+ config.generators do |generate|
35
+ generate.helper false
36
+ generate.javascript_engine false
37
+ generate.request_specs false
38
+ generate.routing_specs false
39
+ generate.stylesheets false
40
+ generate.test_framework :rspec
41
+ generate.view_specs false
42
+ end
43
+
44
+ RUBY
45
+
46
+ inject_into_class 'config/application.rb', 'Application', config
47
+ end
48
+
49
+ def set_up_factory_girl_for_rspec
50
+ copy_file 'factory_girl_rspec.rb', 'spec/support/factory_girl.rb'
51
+ end
52
+
53
+ def configure_newrelic
54
+ template 'newrelic.yml.erb', 'config/newrelic.yml'
55
+ end
56
+
57
+ def configure_smtp
58
+ copy_file 'smtp.rb', 'config/smtp.rb'
59
+
60
+ prepend_file 'config/environments/production.rb',
61
+ %{require Rails.root.join("config/smtp")\n}
62
+
63
+ config = <<-RUBY
64
+
65
+ config.action_mailer.delivery_method = :smtp
66
+ config.action_mailer.smtp_settings = SMTP_SETTINGS
67
+ RUBY
68
+
69
+ inject_into_file 'config/environments/production.rb', config,
70
+ :after => 'config.action_mailer.raise_delivery_errors = false'
71
+ end
72
+
73
+ def enable_rack_deflater
74
+ config = <<-RUBY
75
+
76
+ # Enable deflate / gzip compression of controller-generated responses
77
+ config.middleware.use Rack::Deflater
78
+ RUBY
79
+
80
+ inject_into_file 'config/environments/production.rb', config,
81
+ :after => "config.serve_static_assets = false\n"
82
+ end
83
+
84
+ def setup_asset_host
85
+ replace_in_file 'config/environments/production.rb',
86
+ '# config.action_controller.asset_host = "http://assets.example.com"',
87
+ 'config.action_controller.asset_host = ENV.fetch("ASSET_HOST")'
88
+
89
+ replace_in_file 'config/initializers/assets.rb',
90
+ "config.assets.version = '1.0'",
91
+ 'config.assets.version = (ENV["ASSETS_VERSION"] || "1.0")'
92
+
93
+ replace_in_file 'config/environments/production.rb',
94
+ 'config.serve_static_assets = false',
95
+ 'config.static_cache_control = "public, max-age=#{1.year.to_i}"'
96
+ end
97
+
98
+ def setup_staging_environment
99
+ staging_file = 'config/environments/staging.rb'
100
+ copy_file 'staging.rb', staging_file
101
+
102
+ config = <<-RUBY
103
+
104
+ Rails.application.configure do
105
+ # ...
106
+ end
107
+ RUBY
108
+
109
+ append_file staging_file, config
110
+ end
111
+
112
+ def setup_secret_token
113
+ template 'secrets.yml', 'config/secrets.yml', force: true
114
+ end
115
+
116
+ def create_partials_directory
117
+ empty_directory 'app/views/application'
118
+ end
119
+
120
+ def create_shared_flashes
121
+ copy_file '_flashes.html.erb', 'app/views/application/_flashes.html.erb'
122
+ end
123
+
124
+ def create_shared_javascripts
125
+ copy_file '_javascript.html.erb', 'app/views/application/_javascript.html.erb'
126
+ end
127
+
128
+ def create_application_layout
129
+ template 'jumpstart_layout.html.erb.erb',
130
+ 'app/views/layouts/application.html.erb',
131
+ force: true
132
+ end
133
+
134
+ def remove_turbolinks
135
+ replace_in_file 'app/assets/javascripts/application.js',
136
+ /\/\/= require turbolinks\n/,
137
+ ''
138
+ end
139
+
140
+ def use_postgres_config_template
141
+ template 'postgresql_database.yml.erb', 'config/database.yml',
142
+ force: true
143
+ end
144
+
145
+ def create_database
146
+ bundle_command 'exec rake db:create db:migrate'
147
+ end
148
+
149
+ def replace_gemfile
150
+ remove_file 'Gemfile'
151
+ template 'Gemfile.erb', 'Gemfile'
152
+ end
153
+
154
+ def set_ruby_to_version_being_used
155
+ create_file '.ruby-version', "#{Jumpstart::RUBY_VERSION}\n"
156
+ end
157
+
158
+ def setup_heroku_specific_gems
159
+ inject_into_file 'Gemfile', "\n\s\sgem 'rails_12factor'",
160
+ after: /group :staging, :production do/
161
+ end
162
+
163
+ def enable_database_cleaner
164
+ copy_file 'database_cleaner_rspec.rb', 'spec/support/database_cleaner.rb'
165
+ end
166
+
167
+ def configure_spec_support_features
168
+ empty_directory_with_keep_file 'spec/features'
169
+ empty_directory_with_keep_file 'spec/support/features'
170
+ end
171
+
172
+ def configure_rspec
173
+ remove_file "spec/rails_helper.rb"
174
+ remove_file "spec/spec_helper.rb"
175
+ copy_file "rails_helper.rb", "spec/rails_helper.rb"
176
+ copy_file "spec_helper.rb", "spec/spec_helper.rb"
177
+ end
178
+
179
+ def configure_travis
180
+ template 'travis.yml.erb', '.travis.yml'
181
+ end
182
+
183
+ def configure_i18n_for_test_environment
184
+ copy_file "i18n.rb", "spec/support/i18n.rb"
185
+ end
186
+
187
+ def configure_i18n_for_missing_translations
188
+ raise_on_missing_translations_in("development")
189
+ raise_on_missing_translations_in("test")
190
+ end
191
+
192
+ def configure_i18n_tasks
193
+ run "cp $(i18n-tasks gem-path)/templates/rspec/i18n_spec.rb spec/"
194
+ copy_file "config_i18n_tasks.yml", "config/i18n-tasks.yml"
195
+ end
196
+
197
+ def configure_background_jobs_for_rspec
198
+ copy_file 'background_jobs_rspec.rb', 'spec/support/background_jobs.rb'
199
+ run 'rails g delayed_job:active_record'
200
+ end
201
+
202
+ def configure_action_mailer_in_specs
203
+ copy_file 'action_mailer.rb', 'spec/support/action_mailer.rb'
204
+ end
205
+
206
+ def configure_time_zone
207
+ config = <<-RUBY
208
+ config.active_record.default_timezone = :utc
209
+ RUBY
210
+
211
+ inject_into_class 'config/application.rb', 'Application', config
212
+ end
213
+
214
+ def configure_time_formats
215
+ remove_file "config/locales/en.yml"
216
+ template "config_locales_en.yml.erb", "config/locales/en.yml"
217
+ end
218
+
219
+ def configure_rack_timeout
220
+ copy_file 'rack_timeout.rb', 'config/initializers/rack_timeout.rb'
221
+ end
222
+
223
+ def configure_action_mailer
224
+ action_mailer_host 'development', "localhost:#{port_number}"
225
+ action_mailer_host 'test', 'www.example.com'
226
+ action_mailer_host 'staging', "staging.#{app_name}.com"
227
+ action_mailer_host 'production', "#{app_name}.com"
228
+ end
229
+
230
+ def fix_i18n_deprecation_warning
231
+ config = <<-RUBY
232
+ config.i18n.enforce_available_locales = true
233
+ RUBY
234
+
235
+ inject_into_class 'config/application.rb', 'Application', config
236
+ end
237
+
238
+ def generate_rspec
239
+ generate 'rspec:install'
240
+ end
241
+
242
+ def configure_unicorn
243
+ copy_file 'unicorn.rb', 'config/unicorn.rb'
244
+ end
245
+
246
+ def setup_foreman
247
+ copy_file 'sample.env', '.sample.env'
248
+ copy_file 'Procfile', 'Procfile'
249
+ end
250
+
251
+ def setup_stylesheets
252
+ remove_file 'app/assets/stylesheets/application.css'
253
+ copy_file 'application.css.scss',
254
+ 'app/assets/stylesheets/application.css.scss'
255
+ end
256
+
257
+ def install_bitters
258
+ run "bitters install --path app/assets/stylesheets"
259
+ end
260
+
261
+ def gitignore_files
262
+ remove_file '.gitignore'
263
+ copy_file 'jumpstart_gitignore', '.gitignore'
264
+ [
265
+ 'app/views/pages',
266
+ 'spec/lib',
267
+ 'spec/controllers',
268
+ 'spec/helpers',
269
+ 'spec/support/matchers',
270
+ 'spec/support/mixins',
271
+ 'spec/support/shared_examples'
272
+ ].each do |dir|
273
+ run "mkdir #{dir}"
274
+ run "touch #{dir}/.keep"
275
+ end
276
+ end
277
+
278
+ def init_git
279
+ run 'git init'
280
+ end
281
+
282
+ def create_heroku_apps
283
+ path_addition = override_path_for_tests
284
+ run "#{path_addition} heroku create #{app_name}-production --remote=production"
285
+ run "#{path_addition} heroku create #{app_name}-staging --remote=staging"
286
+ run "#{path_addition} heroku config:add RACK_ENV=staging RAILS_ENV=staging --remote=staging"
287
+ end
288
+
289
+ def set_heroku_remotes
290
+ remotes = <<-SHELL
291
+
292
+ # Set up the staging and production apps.
293
+ #{join_heroku_app('staging')}
294
+ #{join_heroku_app('production')}
295
+ SHELL
296
+
297
+ append_file 'bin/setup', remotes
298
+ end
299
+
300
+ def join_heroku_app(environment)
301
+ heroku_app_name = "#{app_name}-#{environment}"
302
+ <<-SHELL
303
+ if heroku join --app #{heroku_app_name} &> /dev/null; then
304
+ git remote add #{environment} git@heroku.com:#{heroku_app_name}.git || true
305
+ printf 'You are a collaborator on the "#{heroku_app_name}" Heroku app\n'
306
+ else
307
+ printf 'Ask for access to the "#{heroku_app_name}" Heroku app\n'
308
+ fi
309
+ SHELL
310
+ end
311
+
312
+ def set_heroku_rails_secrets
313
+ path_addition = override_path_for_tests
314
+ run "#{path_addition} heroku config:add SECRET_KEY_BASE=#{generate_secret} --remote=staging"
315
+ run "#{path_addition} heroku config:add SECRET_KEY_BASE=#{generate_secret} --remote=production"
316
+ end
317
+
318
+ def create_github_repo(repo_name)
319
+ path_addition = override_path_for_tests
320
+ run "#{path_addition} hub create #{repo_name}"
321
+ end
322
+
323
+ def setup_segment_io
324
+ copy_file '_analytics.html.erb',
325
+ 'app/views/application/_analytics.html.erb'
326
+ end
327
+
328
+ def copy_miscellaneous_files
329
+ copy_file 'errors.rb', 'config/initializers/errors.rb'
330
+ end
331
+
332
+ def customize_error_pages
333
+ meta_tags =<<-EOS
334
+ <meta charset="utf-8" />
335
+ <meta name="ROBOTS" content="NOODP" />
336
+ <meta name="viewport" content="initial-scale=1" />
337
+ EOS
338
+
339
+ %w(500 404 422).each do |page|
340
+ inject_into_file "public/#{page}.html", meta_tags, :after => "<head>\n"
341
+ replace_in_file "public/#{page}.html", /<!--.+-->\n/, ''
342
+ end
343
+ end
344
+
345
+ def remove_routes_comment_lines
346
+ replace_in_file 'config/routes.rb',
347
+ /Rails\.application\.routes\.draw do.*end/m,
348
+ "Rails.application.routes.draw do\nend"
349
+ end
350
+
351
+ def disable_xml_params
352
+ copy_file 'disable_xml_params.rb', 'config/initializers/disable_xml_params.rb'
353
+ end
354
+
355
+ def setup_default_rake_task
356
+ append_file 'Rakefile' do
357
+ <<-EOS
358
+ task(:default).clear
359
+ task default: [:spec]
360
+
361
+ if defined? RSpec
362
+ task(:spec).clear
363
+ RSpec::Core::RakeTask.new(:spec) do |t|
364
+ t.verbose = false
365
+ end
366
+ end
367
+ EOS
368
+ end
369
+ end
370
+
371
+ private
372
+
373
+ def raise_on_missing_translations_in(environment)
374
+ config = 'config.action_view.raise_on_missing_translations = true'
375
+
376
+ uncomment_lines("config/environments/#{environment}.rb", config)
377
+ end
378
+
379
+ def override_path_for_tests
380
+ if ENV['TESTING']
381
+ support_bin = File.expand_path(File.join('..', '..', 'spec', 'fakes', 'bin'))
382
+ "PATH=#{support_bin}:$PATH"
383
+ end
384
+ end
385
+
386
+ def factories_spec_rake_task
387
+ IO.read find_in_source_paths('factories_spec_rake_task.rb')
388
+ end
389
+
390
+ def generate_secret
391
+ SecureRandom.hex(64)
392
+ end
393
+
394
+ def port_number
395
+ @port_number ||= [3000, 4000, 5000, 7000, 8000, 9000].sample
396
+ end
397
+ end
398
+ end