suspenders-ocs 0.0.1

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 (75) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +5 -0
  3. data/.ruby-version +1 -0
  4. data/.travis.yml +11 -0
  5. data/CONTRIBUTING.md +51 -0
  6. data/Gemfile +3 -0
  7. data/LICENSE +21 -0
  8. data/NEWS.md +486 -0
  9. data/README.md +233 -0
  10. data/RELEASING.md +19 -0
  11. data/Rakefile +8 -0
  12. data/bin/rake +16 -0
  13. data/bin/rspec +16 -0
  14. data/bin/setup +13 -0
  15. data/bin/suspenders +23 -0
  16. data/lib/suspenders.rb +5 -0
  17. data/lib/suspenders/actions.rb +33 -0
  18. data/lib/suspenders/adapters/heroku.rb +125 -0
  19. data/lib/suspenders/app_builder.rb +523 -0
  20. data/lib/suspenders/generators/app_generator.rb +269 -0
  21. data/lib/suspenders/version.rb +5 -0
  22. data/spec/adapters/heroku_spec.rb +52 -0
  23. data/spec/fakes/bin/heroku +5 -0
  24. data/spec/fakes/bin/hub +5 -0
  25. data/spec/features/github_spec.rb +15 -0
  26. data/spec/features/heroku_spec.rb +93 -0
  27. data/spec/features/new_project_spec.rb +234 -0
  28. data/spec/spec_helper.rb +20 -0
  29. data/spec/support/fake_github.rb +21 -0
  30. data/spec/support/fake_heroku.rb +53 -0
  31. data/spec/support/suspenders.rb +58 -0
  32. data/suspenders.gemspec +34 -0
  33. data/templates/Gemfile.erb +63 -0
  34. data/templates/Procfile +2 -0
  35. data/templates/README.md.erb +28 -0
  36. data/templates/_analytics.html.erb +7 -0
  37. data/templates/_css_overrides.html.erb +8 -0
  38. data/templates/_flashes.html.erb +7 -0
  39. data/templates/_javascript.html.erb +12 -0
  40. data/templates/action_mailer.rb +5 -0
  41. data/templates/app.json.erb +42 -0
  42. data/templates/application.scss +9 -0
  43. data/templates/bin_deploy +12 -0
  44. data/templates/bin_setup +21 -0
  45. data/templates/bin_setup_review_app.erb +19 -0
  46. data/templates/browserslist +3 -0
  47. data/templates/bundler_audit.rake +12 -0
  48. data/templates/capybara_webkit.rb +5 -0
  49. data/templates/circle.yml.erb +6 -0
  50. data/templates/config_locales_en.yml.erb +19 -0
  51. data/templates/database_cleaner_rspec.rb +21 -0
  52. data/templates/dev.rake +12 -0
  53. data/templates/disable_xml_params.rb +1 -0
  54. data/templates/dotfiles/.ctags +2 -0
  55. data/templates/dotfiles/.env +13 -0
  56. data/templates/errors.rb +34 -0
  57. data/templates/factories.rb +2 -0
  58. data/templates/factory_girl_rspec.rb +3 -0
  59. data/templates/flashes_helper.rb +5 -0
  60. data/templates/hound.yml +14 -0
  61. data/templates/i18n.rb +3 -0
  62. data/templates/json_encoding.rb +1 -0
  63. data/templates/newrelic.yml.erb +34 -0
  64. data/templates/postgresql_database.yml.erb +21 -0
  65. data/templates/puma.rb +28 -0
  66. data/templates/rack_mini_profiler.rb +5 -0
  67. data/templates/rails_helper.rb +22 -0
  68. data/templates/secrets.yml +14 -0
  69. data/templates/shoulda_matchers_config_rspec.rb +6 -0
  70. data/templates/smtp.rb +9 -0
  71. data/templates/spec_helper.rb +29 -0
  72. data/templates/staging.rb +5 -0
  73. data/templates/suspenders_gitignore +13 -0
  74. data/templates/suspenders_layout.html.erb.erb +22 -0
  75. metadata +204 -0
@@ -0,0 +1,269 @@
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: "Configure 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 :heroku_flags, type: :string, default: "",
13
+ desc: "Set extra Heroku flags"
14
+
15
+ class_option :github, type: :string, aliases: "-G", default: nil,
16
+ desc: "Create Github repository and add remote origin pointed to repo"
17
+
18
+ class_option :skip_test_unit, type: :boolean, aliases: "-T", default: true,
19
+ desc: "Skip Test::Unit files"
20
+
21
+ class_option :skip_turbolinks, type: :boolean, default: true,
22
+ desc: "Skip turbolinks gem"
23
+
24
+ class_option :skip_bundle, type: :boolean, aliases: "-B", default: true,
25
+ desc: "Don't run bundle install"
26
+
27
+ def finish_template
28
+ invoke :suspenders_customization
29
+ super
30
+ end
31
+
32
+ def suspenders_customization
33
+ invoke :customize_gemfile
34
+ invoke :setup_development_environment
35
+ invoke :setup_test_environment
36
+ invoke :setup_production_environment
37
+ invoke :setup_staging_environment
38
+ invoke :setup_secret_token
39
+ invoke :create_suspenders_views
40
+ invoke :configure_app
41
+ invoke :setup_stylesheets
42
+ invoke :install_bitters
43
+ invoke :install_refills
44
+ invoke :copy_miscellaneous_files
45
+ invoke :customize_error_pages
46
+ invoke :remove_config_comment_lines
47
+ invoke :remove_routes_comment_lines
48
+ invoke :setup_dotfiles
49
+ invoke :setup_git
50
+ invoke :setup_database
51
+ invoke :create_heroku_apps
52
+ invoke :create_github_repo
53
+ invoke :setup_segment
54
+ invoke :setup_bundler_audit
55
+ invoke :setup_spring
56
+ invoke :outro
57
+ end
58
+
59
+ def customize_gemfile
60
+ build :set_ruby_to_version_being_used
61
+
62
+ if options[:heroku]
63
+ build :set_up_heroku_specific_gems
64
+ end
65
+
66
+ bundle_command 'install'
67
+ build :configure_simple_form
68
+ end
69
+
70
+ def setup_database
71
+ say 'Setting up database'
72
+
73
+ if 'postgresql' == options[:database]
74
+ build :use_postgres_config_template
75
+ end
76
+
77
+ build :create_database
78
+ end
79
+
80
+ def setup_development_environment
81
+ say 'Setting up the development environment'
82
+ build :raise_on_missing_assets_in_test
83
+ build :raise_on_delivery_errors
84
+ build :set_test_delivery_method
85
+ build :add_bullet_gem_configuration
86
+ build :raise_on_unpermitted_parameters
87
+ build :provide_setup_script
88
+ build :provide_dev_prime_task
89
+ build :configure_generators
90
+ build :configure_i18n_for_missing_translations
91
+ build :configure_quiet_assets
92
+ end
93
+
94
+ def setup_test_environment
95
+ say 'Setting up the test environment'
96
+ build :set_up_factory_girl_for_rspec
97
+ build :generate_factories_file
98
+ build :set_up_hound
99
+ build :generate_rspec
100
+ build :configure_rspec
101
+ build :configure_background_jobs_for_rspec
102
+ build :enable_database_cleaner
103
+ build :provide_shoulda_matchers_config
104
+ build :configure_spec_support_features
105
+ build :configure_ci
106
+ build :configure_i18n_for_test_environment
107
+ build :configure_action_mailer_in_specs
108
+ build :configure_capybara_webkit
109
+ end
110
+
111
+ def setup_production_environment
112
+ say 'Setting up the production environment'
113
+ build :configure_newrelic
114
+ build :configure_smtp
115
+ build :configure_rack_timeout
116
+ build :enable_rack_canonical_host
117
+ build :enable_rack_deflater
118
+ build :setup_asset_host
119
+ end
120
+
121
+ def setup_staging_environment
122
+ say 'Setting up the staging environment'
123
+ build :setup_staging_environment
124
+ end
125
+
126
+ def setup_secret_token
127
+ say 'Moving secret token out of version control'
128
+ build :setup_secret_token
129
+ end
130
+
131
+ def create_suspenders_views
132
+ say 'Creating suspenders views'
133
+ build :create_partials_directory
134
+ build :create_shared_flashes
135
+ build :create_shared_javascripts
136
+ build :create_shared_css_overrides
137
+ build :create_application_layout
138
+ end
139
+
140
+ def configure_app
141
+ say 'Configuring app'
142
+ build :configure_action_mailer
143
+ build :configure_active_job
144
+ build :configure_time_formats
145
+ build :disable_xml_params
146
+ build :setup_default_rake_task
147
+ build :configure_puma
148
+ build :set_up_forego
149
+ build :setup_rack_mini_profiler
150
+ end
151
+
152
+ def setup_stylesheets
153
+ say 'Set up stylesheets'
154
+ build :setup_stylesheets
155
+ end
156
+
157
+ def install_bitters
158
+ say 'Install Bitters'
159
+ build :install_bitters
160
+ end
161
+
162
+ def install_refills
163
+ say "Install Refills"
164
+ build :install_refills
165
+ end
166
+
167
+ def setup_git
168
+ if !options[:skip_git]
169
+ say "Initializing git"
170
+ invoke :setup_default_directories
171
+ invoke :init_git
172
+ end
173
+ end
174
+
175
+ def create_heroku_apps
176
+ if options[:heroku]
177
+ say "Creating Heroku apps"
178
+ build :create_heroku_apps, options[:heroku_flags]
179
+ build :provide_review_apps_setup_script
180
+ build :set_heroku_serve_static_files
181
+ build :set_heroku_remotes
182
+ build :set_heroku_rails_secrets
183
+ build :create_heroku_pipelines_config_file
184
+ build :create_heroku_pipeline
185
+ build :provide_deploy_script
186
+ build :configure_automatic_deployment
187
+ end
188
+ end
189
+
190
+ def create_github_repo
191
+ if !options[:skip_git] && options[:github]
192
+ say 'Creating Github repo'
193
+ build :create_github_repo, options[:github]
194
+ end
195
+ end
196
+
197
+ def setup_segment
198
+ say 'Setting up Segment'
199
+ build :setup_segment
200
+ end
201
+
202
+ def setup_dotfiles
203
+ build :copy_dotfiles
204
+ end
205
+
206
+ def setup_default_directories
207
+ build :setup_default_directories
208
+ end
209
+
210
+ def setup_bundler_audit
211
+ say "Setting up bundler-audit"
212
+ build :setup_bundler_audit
213
+ end
214
+
215
+ def setup_spring
216
+ say "Springifying binstubs"
217
+ build :setup_spring
218
+ end
219
+
220
+ def init_git
221
+ build :init_git
222
+ end
223
+
224
+ def copy_miscellaneous_files
225
+ say 'Copying miscellaneous support files'
226
+ build :copy_miscellaneous_files
227
+ end
228
+
229
+ def customize_error_pages
230
+ say 'Customizing the 500/404/422 pages'
231
+ build :customize_error_pages
232
+ end
233
+
234
+ def remove_config_comment_lines
235
+ build :remove_config_comment_lines
236
+ end
237
+
238
+ def remove_routes_comment_lines
239
+ build :remove_routes_comment_lines
240
+ end
241
+
242
+ def outro
243
+ say 'Congratulations! You just pulled our suspenders.'
244
+ say honeybadger_outro
245
+ end
246
+
247
+ protected
248
+
249
+ def get_builder_class
250
+ Suspenders::AppBuilder
251
+ end
252
+
253
+ def using_active_record?
254
+ !options[:skip_active_record]
255
+ end
256
+
257
+ private
258
+
259
+ def honeybadger_outro
260
+ "Run 'bundle exec honeybadger heroku install' with your API key#{honeybadger_message_suffix}."
261
+ end
262
+
263
+ def honeybadger_message_suffix
264
+ if options[:heroku]
265
+ " unless you're using the Heroku Honeybadger add-on"
266
+ end
267
+ end
268
+ end
269
+ end
@@ -0,0 +1,5 @@
1
+ module Suspenders
2
+ RAILS_VERSION = "~> 4.2.0"
3
+ RUBY_VERSION = IO.read("#{File.dirname(__FILE__)}/../../.ruby-version").strip
4
+ VERSION = "0.0.1"
5
+ end
@@ -0,0 +1,52 @@
1
+ require "spec_helper"
2
+
3
+ module Suspenders
4
+ module Adapters
5
+ RSpec.describe Heroku do
6
+ it "sets the heroku remotes" do
7
+ setup_file = "bin/setup"
8
+ app_builder = double(app_name: app_name)
9
+ allow(app_builder).to receive(:append_file)
10
+
11
+ Heroku.new(app_builder).set_heroku_remotes
12
+
13
+ expect(app_builder).to have_received(:append_file).
14
+ with(setup_file, /heroku join --app #{app_name.dasherize}-production/)
15
+ expect(app_builder).to have_received(:append_file).
16
+ with(setup_file, /heroku join --app #{app_name.dasherize}-staging/)
17
+ end
18
+
19
+ it "sets up the heroku specific gems" do
20
+ app_builder = double(app_name: app_name)
21
+ allow(app_builder).to receive(:inject_into_file)
22
+
23
+ Heroku.new(app_builder).set_up_heroku_specific_gems
24
+
25
+ expect(app_builder).to have_received(:inject_into_file).
26
+ with("Gemfile", /rails_stdout_logging/, anything)
27
+ end
28
+
29
+ it "sets the heroku rails secrets" do
30
+ app_builder = double(app_name: app_name)
31
+ allow(app_builder).to receive(:run)
32
+
33
+ Heroku.new(app_builder).set_heroku_rails_secrets
34
+
35
+ expect(app_builder).to(
36
+ have_configured_var("staging", "SECRET_KEY_BASE"),
37
+ )
38
+ expect(app_builder).to(
39
+ have_configured_var("production", "SECRET_KEY_BASE"),
40
+ )
41
+ end
42
+
43
+ def app_name
44
+ SuspendersTestHelpers::APP_NAME
45
+ end
46
+
47
+ def have_configured_var(remote_name, var)
48
+ have_received(:run).with(/config:add #{var}=.+ --remote #{remote_name}/)
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path(File.join('..', '..', 'support', 'fake_heroku'), File.dirname(__FILE__))
4
+
5
+ FakeHeroku.new(ARGV).run!
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path(File.join('..', '..', 'support', 'fake_github'), File.dirname(__FILE__))
4
+
5
+ FakeGithub.new(ARGV).run!
@@ -0,0 +1,15 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe "GitHub" do
4
+ before do
5
+ drop_dummy_database
6
+ remove_project_directory
7
+ end
8
+
9
+ it "suspends a project with --github option" do
10
+ repo_name = 'test'
11
+ run_suspenders("--github=#{repo_name}")
12
+
13
+ expect(FakeGithub).to have_created_repo(repo_name)
14
+ end
15
+ end
@@ -0,0 +1,93 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe "Heroku" do
4
+ context "--heroku" do
5
+ before(:all) do
6
+ clean_up
7
+ run_suspenders("--heroku=true")
8
+ end
9
+
10
+ it "suspends a project for Heroku" do
11
+ app_name = SuspendersTestHelpers::APP_NAME.dasherize
12
+
13
+ expect(FakeHeroku).to(
14
+ have_gem_included(project_path, "rails_stdout_logging"),
15
+ )
16
+ expect(FakeHeroku).to have_created_app_for("staging")
17
+ expect(FakeHeroku).to have_created_app_for("production")
18
+ expect(FakeHeroku).to have_configured_vars("staging", "SECRET_KEY_BASE")
19
+ expect(FakeHeroku).to have_configured_vars(
20
+ "production",
21
+ "SECRET_KEY_BASE",
22
+ )
23
+ expect(FakeHeroku).to have_setup_pipeline_for(app_name)
24
+
25
+ bin_setup_path = "#{project_path}/bin/setup"
26
+ bin_setup = IO.read(bin_setup_path)
27
+
28
+ expect(bin_setup).to include("heroku join --app #{app_name}-production")
29
+ expect(bin_setup).to include("heroku join --app #{app_name}-staging")
30
+ expect(bin_setup).to include("git config heroku.remote staging")
31
+ expect(File.stat(bin_setup_path)).to be_executable
32
+
33
+ bin_setup_path = "#{project_path}/bin/setup_review_app"
34
+ bin_setup = IO.read(bin_setup_path)
35
+
36
+ expect(bin_setup).to include("heroku run rake db:migrate --app #{app_name}-staging-pr-$1")
37
+ expect(bin_setup).to include("heroku ps:scale worker=1 --app #{app_name}-staging-pr-$1")
38
+ expect(bin_setup).to include("heroku restart --app #{app_name}-staging-pr-$1")
39
+ expect(File.stat(bin_setup_path)).to be_executable
40
+
41
+ bin_deploy_path = "#{project_path}/bin/deploy"
42
+ bin_deploy = IO.read(bin_deploy_path)
43
+
44
+ expect(bin_deploy).to include("heroku run rake db:migrate")
45
+ expect(File.stat(bin_deploy_path)).to be_executable
46
+
47
+ readme = IO.read("#{project_path}/README.md")
48
+
49
+ expect(readme).to include("./bin/deploy staging")
50
+ expect(readme).to include("./bin/deploy production")
51
+
52
+ circle_yml_path = "#{project_path}/circle.yml"
53
+ circle_yml = IO.read(circle_yml_path)
54
+
55
+ expect(circle_yml).to include <<-YML.strip_heredoc
56
+ deployment:
57
+ staging:
58
+ branch: master
59
+ commands:
60
+ - bin/deploy staging
61
+ YML
62
+ end
63
+
64
+ it "adds app.json file" do
65
+ expect(File).to exist("#{project_path}/app.json")
66
+ end
67
+
68
+ it "includes application name in app.json file" do
69
+ app_json_file = IO.read("#{project_path}/app.json")
70
+ app_name = SuspendersTestHelpers::APP_NAME.dasherize
71
+
72
+ expect(app_json_file).to match(/"name":"#{app_name}"/)
73
+ end
74
+ end
75
+
76
+ context "--heroku with region flag" do
77
+ before(:all) do
78
+ clean_up
79
+ run_suspenders(%{--heroku=true --heroku-flags="--region eu"})
80
+ end
81
+
82
+ it "suspends a project with extra Heroku flags" do
83
+ expect(FakeHeroku).to have_created_app_for("staging", "--region eu")
84
+ expect(FakeHeroku).to have_created_app_for("production", "--region eu")
85
+ end
86
+ end
87
+
88
+ def clean_up
89
+ drop_dummy_database
90
+ remove_project_directory
91
+ FakeHeroku.clear!
92
+ end
93
+ end