welaika-suspenders 2.28.0 → 2.29.0.alpha.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +5 -5
  2. data/.ruby-version +1 -1
  3. data/.travis.yml +3 -1
  4. data/CONTRIBUTING.md +8 -3
  5. data/NEWS.md +35 -0
  6. data/README.md +1 -1
  7. data/RELEASING.md +6 -7
  8. data/Rakefile +1 -1
  9. data/diff_suspenders.sh +15 -0
  10. data/lib/suspenders.rb +21 -8
  11. data/lib/suspenders/actions.rb +55 -8
  12. data/lib/suspenders/app_builder.rb +20 -191
  13. data/lib/suspenders/generators/app_generator.rb +26 -55
  14. data/lib/suspenders/generators/ci_generator.rb +22 -0
  15. data/lib/suspenders/generators/db_optimizations_generator.rb +30 -0
  16. data/lib/suspenders/generators/decorator_generator.rb +19 -0
  17. data/lib/suspenders/generators/error_reporting_generator.rb +55 -0
  18. data/lib/suspenders/generators/factories_generator.rb +23 -0
  19. data/lib/suspenders/generators/faker_generator.rb +19 -0
  20. data/lib/suspenders/generators/forms_generator.rb +18 -0
  21. data/lib/suspenders/generators/js_driver_generator.rb +20 -0
  22. data/lib/suspenders/generators/lint_generator.rb +35 -0
  23. data/lib/suspenders/generators/production/email_generator.rb +45 -0
  24. data/lib/suspenders/generators/production/force_tls_generator.rb +14 -0
  25. data/lib/suspenders/generators/production/timeout_generator.rb +21 -0
  26. data/lib/suspenders/generators/security_generator.rb +29 -0
  27. data/lib/suspenders/generators/testing_generator.rb +72 -0
  28. data/lib/suspenders/generators/views_generator.rb +44 -0
  29. data/lib/suspenders/version.rb +2 -2
  30. data/spec/features/api_spec.rb +18 -0
  31. data/spec/features/new_project_spec.rb +9 -21
  32. data/spec/features/production/email_spec.rb +47 -0
  33. data/spec/support/contain_json_matcher.rb +24 -0
  34. data/spec/support/exist_as_a_file_matcher.rb +7 -0
  35. data/spec/support/match_contents_matcher.rb +6 -0
  36. data/spec/support/suspenders.rb +113 -30
  37. data/suspenders.gemspec +2 -2
  38. data/templates/Gemfile.erb +8 -31
  39. data/templates/Procfile +1 -1
  40. data/templates/_css_overrides.html.slim +4 -0
  41. data/templates/_javascript.html.slim +3 -3
  42. data/templates/action_mailer.rb +2 -0
  43. data/templates/app.json.erb +0 -15
  44. data/templates/brakeman.rake +2 -0
  45. data/templates/bundler_audit.rake +3 -1
  46. data/templates/capybara_helpers.rb +15 -0
  47. data/templates/chromedriver.rb +20 -0
  48. data/templates/dev.rake +4 -2
  49. data/templates/dotfiles/.env +2 -1
  50. data/templates/email.rb +5 -0
  51. data/templates/errors.rb +2 -0
  52. data/templates/factory_bot_rspec.rb +5 -0
  53. data/templates/faker_rspec.rb +2 -0
  54. data/templates/flashes_helper.rb +2 -0
  55. data/templates/i18n.rb +2 -0
  56. data/templates/json_encoding.rb +2 -0
  57. data/templates/puma.rb +2 -0
  58. data/templates/queries_helper_rspec.rb +2 -0
  59. data/templates/rack_mini_profiler.rb +2 -0
  60. data/templates/rails_helper.rb +11 -1
  61. data/templates/rubocop.rake +2 -0
  62. data/templates/rubocop.yml +2 -22
  63. data/templates/sentry.rb +8 -0
  64. data/templates/shoulda_matchers_config_rspec.rb +2 -0
  65. data/templates/slim-lint.rake +2 -0
  66. data/templates/slim.rb +2 -0
  67. data/templates/smtp.rb +2 -4
  68. data/templates/spec_helper.rb +12 -3
  69. data/templates/suspenders_layout.html.slim +3 -3
  70. metadata +42 -36
  71. data/lib/suspenders/generators/enforce_ssl_generator.rb +0 -12
  72. data/lib/suspenders/generators/initialize_active_job_generator.rb +0 -19
  73. data/templates/_css_overrides.html.erb +0 -7
  74. data/templates/active_job.rb +0 -13
  75. data/templates/capybara.rb +0 -29
  76. data/templates/circle.yml.erb +0 -15
  77. data/templates/database_cleaner_rspec.rb +0 -28
  78. data/templates/errbit.rb +0 -12
  79. data/templates/factories.rb +0 -2
  80. data/templates/factory_girl_rspec.rb +0 -3
  81. data/templates/fixtures_helper_rspec.rb +0 -9
  82. data/templates/sample_service.rb +0 -5
@@ -40,10 +40,8 @@ module Suspenders
40
40
  def suspenders_customization
41
41
  invoke :customize_gemfile
42
42
  invoke :setup_development_environment
43
- invoke :setup_test_environment
44
43
  invoke :setup_production_environment
45
44
  invoke :setup_secret_token
46
- invoke :create_suspenders_views
47
45
  invoke :configure_app
48
46
  invoke :copy_miscellaneous_files
49
47
  invoke :customize_error_pages
@@ -51,23 +49,19 @@ module Suspenders
51
49
  invoke :remove_routes_comment_lines
52
50
  invoke :setup_dotfiles
53
51
  invoke :setup_database
54
- invoke :create_local_heroku_setup
55
- invoke :create_heroku_apps
56
52
  invoke :setup_spring
57
- invoke :create_binstubs
58
53
  invoke :generate_default
59
54
  invoke :setup_default_directories
55
+ invoke :create_local_heroku_setup
56
+ invoke :create_heroku_apps
57
+ invoke :generate_production_default
60
58
  invoke :outro
61
59
  end
62
60
 
63
61
  def customize_gemfile
64
62
  build :replace_gemfile, options[:path]
65
- build :set_ruby_to_version_being_used
66
63
  bundle_command 'install'
67
- build :configure_simple_form
68
- build :configure_draper
69
- build :configure_active_interaction
70
- build :configure_errbit
64
+ bundle_command 'binstubs bundler --force'
71
65
  end
72
66
 
73
67
  def setup_database
@@ -82,44 +76,19 @@ module Suspenders
82
76
 
83
77
  def setup_development_environment
84
78
  say 'Setting up the development environment'
79
+ build :configure_local_mail
85
80
  build :raise_on_missing_assets_in_test
86
81
  build :raise_on_delivery_errors
87
82
  build :set_test_delivery_method
88
- build :add_bullet_gem_configuration
89
83
  build :raise_on_unpermitted_parameters
90
84
  build :provide_setup_script
91
- build :provide_dev_prime_task
92
85
  build :configure_generators
93
86
  build :configure_i18n_for_missing_translations
94
87
  build :configure_quiet_assets
95
- build :setup_rubocop
96
- build :setup_slim_lint
97
- build :setup_brakeman
98
- build :setup_bundler_audit
99
- end
100
-
101
- def setup_test_environment
102
- say 'Setting up the test environment'
103
- build :set_up_factory_girl_for_rspec
104
- build :add_helpers_for_rspec
105
- build :generate_factories_file
106
- build :generate_rspec
107
- build :configure_rspec
108
- build :configure_background_jobs_for_rspec
109
- build :enable_database_cleaner
110
- build :provide_shoulda_matchers_config
111
- build :configure_spec_support_features
112
- build :configure_ci
113
- build :configure_i18n_for_test_environment
114
- build :configure_action_mailer_in_specs
115
- build :set_up_faker
116
- build :configure_capybara
117
88
  end
118
89
 
119
90
  def setup_production_environment
120
91
  say 'Setting up the production environment'
121
- build :configure_smtp
122
- build :configure_rack_timeout
123
92
  build :enable_rack_canonical_host
124
93
  build :enable_rack_deflater
125
94
  build :setup_asset_host
@@ -130,21 +99,10 @@ module Suspenders
130
99
  build :setup_secret_token
131
100
  end
132
101
 
133
- def create_suspenders_views
134
- say 'Creating suspenders views'
135
- build :create_partials_directory
136
- build :create_shared_flashes
137
- build :create_shared_javascripts
138
- build :create_shared_css_overrides
139
- build :create_application_layout
140
- end
141
-
142
102
  def configure_app
143
103
  say 'Configuring app'
144
104
  build :configure_action_mailer
145
105
  build :configure_locales_and_time_zone
146
- build :configure_active_job
147
- build :configure_slim
148
106
  build :configure_time_formats
149
107
  build :setup_default_rake_task
150
108
  build :replace_default_puma_configuration
@@ -186,11 +144,6 @@ module Suspenders
186
144
  build :setup_spring
187
145
  end
188
146
 
189
- def create_binstubs
190
- say "Create binstubs"
191
- build :create_binstubs
192
- end
193
-
194
147
  def copy_miscellaneous_files
195
148
  say 'Copying miscellaneous support files'
196
149
  build :copy_miscellaneous_files
@@ -211,15 +164,33 @@ module Suspenders
211
164
 
212
165
  def generate_default
213
166
  run("spring stop")
214
- generate("suspenders:initialize_active_job")
215
- generate("suspenders:enforce_ssl")
216
167
  generate("suspenders:static")
217
168
  generate("suspenders:stylesheet_base")
169
+ generate("suspenders:testing")
170
+ generate("suspenders:ci")
171
+ generate("suspenders:js_driver")
172
+ unless options[:api]
173
+ generate("suspenders:forms")
174
+ end
175
+ generate("suspenders:db_optimizations")
176
+ generate("suspenders:factories")
177
+ generate("suspenders:lint")
178
+ generate("suspenders:views")
179
+ generate("suspenders:decorator")
180
+ generate("suspenders:faker")
181
+ generate("suspenders:security")
182
+ generate("suspenders:error_reporting")
183
+ end
184
+
185
+ def generate_production_default
186
+ generate("suspenders:production:force_tls")
187
+ generate("suspenders:production:email")
188
+ generate("suspenders:production:timeout")
218
189
  end
219
190
 
220
191
  def outro
221
192
  say "Congratulations! You just pulled our suspenders."
222
- say "Read README.md and configure Errbit."
193
+ say "Read README.md!"
223
194
  end
224
195
 
225
196
  def self.banner
@@ -0,0 +1,22 @@
1
+ require "rails/generators"
2
+
3
+ module Suspenders
4
+ class CiGenerator < Rails::Generators::Base
5
+ source_root File.expand_path(
6
+ File.join("..", "..", "..", "templates"),
7
+ File.dirname(__FILE__))
8
+
9
+ def simplecov_test_integration
10
+ inject_into_file "spec/spec_helper.rb", before: 'SimpleCov.start "rails"' do
11
+ <<-RUBY
12
+
13
+ if ENV["CIRCLE_ARTIFACTS"]
14
+ dir = File.join(ENV["CIRCLE_ARTIFACTS"], "coverage")
15
+ SimpleCov.coverage_dir(dir)
16
+ end
17
+
18
+ RUBY
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,30 @@
1
+ require "rails/generators"
2
+
3
+ module Suspenders
4
+ class DbOptimizationsGenerator < Rails::Generators::Base
5
+ def add_bullet
6
+ gem "bullet", group: %i(development test)
7
+ Bundler.with_clean_env { run "bundle install" }
8
+ end
9
+
10
+ def configure_bullet
11
+ inject_into_file(
12
+ "config/environments/development.rb",
13
+ configuration,
14
+ after: "config.action_mailer.raise_delivery_errors = true\n",
15
+ )
16
+ end
17
+
18
+ private
19
+
20
+ def configuration
21
+ <<-RUBY
22
+ config.after_initialize do
23
+ Bullet.enable = true
24
+ Bullet.bullet_logger = true
25
+ Bullet.rails_logger = true
26
+ end
27
+ RUBY
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,19 @@
1
+ require "rails/generators"
2
+
3
+ module Suspenders
4
+ class DecoratorGenerator < Rails::Generators::Base
5
+ source_root File.expand_path(
6
+ File.join("..", "..", "..", "templates"),
7
+ File.dirname(__FILE__),
8
+ )
9
+
10
+ def add_factory_bot
11
+ gem "draper"
12
+ Bundler.with_clean_env { run "bundle install" }
13
+ end
14
+
15
+ def configure_draper
16
+ generate "draper:install", "--force"
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,55 @@
1
+ require "rails/generators"
2
+ require_relative "../actions"
3
+
4
+ module Suspenders
5
+ class ErrorReportingGenerator < Rails::Generators::Base
6
+ include Suspenders::Actions
7
+
8
+ source_root File.expand_path(
9
+ File.join("..", "..", "..", "templates"),
10
+ File.dirname(__FILE__),
11
+ )
12
+
13
+ def add_sentry
14
+ gem "sentry-raven"
15
+ Bundler.with_clean_env { run "bundle install" }
16
+ end
17
+
18
+ def set_up_sentry
19
+ copy_file "sentry.rb", "config/initializers/sentry.rb"
20
+ end
21
+
22
+ def configure_sentry_context
23
+ inject_into_class(
24
+ "app/controllers/application_controller.rb",
25
+ 'ApplicationController',
26
+ context_configuration
27
+ )
28
+ end
29
+
30
+ def env_vars
31
+ expand_json(
32
+ "app.json",
33
+ env: {
34
+ SENTRY_DSN: { required: true },
35
+ SENTRY_CURRENT_ENV: { required: true }
36
+ }
37
+ )
38
+ end
39
+
40
+ private
41
+
42
+ def context_configuration
43
+ <<-RUBY
44
+ before_action :set_raven_context
45
+
46
+ private
47
+
48
+ def set_raven_context
49
+ Raven.user_context(id: session[:current_user_id])
50
+ Raven.extra_context(params: params.to_unsafe_h, url: request.url)
51
+ end
52
+ RUBY
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,23 @@
1
+ require "rails/generators"
2
+
3
+ module Suspenders
4
+ class FactoriesGenerator < Rails::Generators::Base
5
+ source_root File.expand_path(
6
+ File.join("..", "..", "..", "templates"),
7
+ File.dirname(__FILE__),
8
+ )
9
+
10
+ def add_factory_bot
11
+ gem "factory_bot_rails", group: %i(development test)
12
+ Bundler.with_clean_env { run "bundle install" }
13
+ end
14
+
15
+ def set_up_factory_bot_for_rspec
16
+ copy_file "factory_bot_rspec.rb", "spec/support/factory_bot.rb"
17
+ end
18
+
19
+ def provide_dev_prime_task
20
+ copy_file "dev.rake", "lib/tasks/dev.rake"
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,19 @@
1
+ require "rails/generators"
2
+
3
+ module Suspenders
4
+ class FakerGenerator < Rails::Generators::Base
5
+ source_root File.expand_path(
6
+ File.join("..", "..", "..", "templates"),
7
+ File.dirname(__FILE__),
8
+ )
9
+
10
+ def add_factory_bot
11
+ gem 'faker', group: %i(development test)
12
+ Bundler.with_clean_env { run "bundle install" }
13
+ end
14
+
15
+ def set_up_faker
16
+ copy_file 'faker_rspec.rb', 'spec/support/faker.rb'
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,18 @@
1
+ require "rails/generators"
2
+
3
+ module Suspenders
4
+ class FormsGenerator < Rails::Generators::Base
5
+ def add_simple_form
6
+ gem "simple_form"
7
+ Bundler.with_clean_env { run "bundle install" }
8
+ end
9
+
10
+ def configure_simple_form
11
+ create_file "config/initializers/simple_form.rb" do
12
+ "SimpleForm.setup {|config|}"
13
+ end
14
+
15
+ generate "simple_form:install", "--force"
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,20 @@
1
+ require "rails/generators"
2
+
3
+ module Suspenders
4
+ class JsDriverGenerator < Rails::Generators::Base
5
+ source_root File.expand_path(
6
+ File.join("..", "..", "..", "templates"),
7
+ File.dirname(__FILE__),
8
+ )
9
+
10
+ def add_gems
11
+ gem 'capybara', '>= 2.15', '< 4.0', group: :test
12
+ gem 'selenium-webdriver', group: :test
13
+ Bundler.with_clean_env { run "bundle install" }
14
+ end
15
+
16
+ def configure_chromedriver
17
+ copy_file "chromedriver.rb", "spec/support/chromedriver.rb"
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,35 @@
1
+ require "rails/generators"
2
+
3
+ module Suspenders
4
+ class LintGenerator < Rails::Generators::Base
5
+ source_root File.expand_path(
6
+ File.join("..", "..", "..", "templates"),
7
+ File.dirname(__FILE__),
8
+ )
9
+
10
+ def add_linters_gems
11
+ gem 'rubocop', require: false, group: :development
12
+ gem 'rubocop-rspec', require: false, group: :development
13
+ gem 'slim_lint', require: false, group: :development
14
+ Bundler.with_clean_env { run "bundle install" }
15
+ end
16
+
17
+ def setup_rubocop
18
+ copy_file "rubocop.rake", "lib/tasks/rubocop.rake"
19
+ copy_file "rubocop.yml", ".rubocop.yml"
20
+ copy_file "rubocop_todo.yml", ".rubocop_todo.yml"
21
+ end
22
+
23
+ def setup_slim_lint
24
+ copy_file "slim-lint.rake", "lib/tasks/slim-lint.rake"
25
+ copy_file "slim-lint.yml", ".slim-lint.yml"
26
+ end
27
+
28
+ def create_binstubs
29
+ Bundler.with_clean_env do
30
+ run "bundle binstubs rubocop"
31
+ run "bundle binstubs slim_lint"
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,45 @@
1
+ require "rails/generators"
2
+ require_relative "../../actions"
3
+
4
+ module Suspenders
5
+ module Production
6
+ class EmailGenerator < Rails::Generators::Base
7
+ include Suspenders::Actions
8
+
9
+ source_root File.expand_path(
10
+ File.join("..", "..", "..", "..", "templates"),
11
+ File.dirname(__FILE__),
12
+ )
13
+
14
+ def smtp_configuration
15
+ copy_file "smtp.rb", "config/smtp.rb"
16
+
17
+ prepend_file "config/environments/production.rb",
18
+ %{require Rails.root.join("config/smtp")\n}
19
+ end
20
+
21
+ def use_smtp
22
+ config = <<-RUBY
23
+
24
+ config.action_mailer.delivery_method = :smtp
25
+ config.action_mailer.smtp_settings = SMTP_SETTINGS
26
+ RUBY
27
+
28
+ inject_into_file "config/environments/production.rb", config,
29
+ after: "config.action_mailer.raise_delivery_errors = false"
30
+ end
31
+
32
+ def env_vars
33
+ expand_json(
34
+ "app.json",
35
+ env: {
36
+ SMTP_ADDRESS: { required: true },
37
+ SMTP_DOMAIN: { required: true },
38
+ SMTP_PASSWORD: { required: true },
39
+ SMTP_USERNAME: { required: true },
40
+ },
41
+ )
42
+ end
43
+ end
44
+ end
45
+ end