ajmalafif-suspenders 1.18.0

Sign up to get free protection for your applications and to get access to all the features.
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/rake +16 -0
  13. data/bin/rspec +16 -0
  14. data/bin/setup +13 -0
  15. data/bin/suspenders +18 -0
  16. data/lib/suspenders.rb +4 -0
  17. data/lib/suspenders/actions.rb +25 -0
  18. data/lib/suspenders/app_builder.rb +398 -0
  19. data/lib/suspenders/generators/app_generator.rb +215 -0
  20. data/lib/suspenders/version.rb +5 -0
  21. data/spec/fakes/bin/heroku +5 -0
  22. data/spec/fakes/bin/hub +5 -0
  23. data/spec/features/github_spec.rb +10 -0
  24. data/spec/features/heroku_spec.rb +19 -0
  25. data/spec/features/new_project_spec.rb +117 -0
  26. data/spec/spec_helper.rb +24 -0
  27. data/spec/support/fake_github.rb +21 -0
  28. data/spec/support/fake_heroku.rb +38 -0
  29. data/spec/support/suspenders.rb +49 -0
  30. data/suspenders.gemspec +38 -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/newrelic.yml.erb +34 -0
  50. data/templates/postgresql_database.yml.erb +12 -0
  51. data/templates/rack_timeout.rb +1 -0
  52. data/templates/rails_helper.rb +23 -0
  53. data/templates/sample.env +3 -0
  54. data/templates/secrets.yml +14 -0
  55. data/templates/smtp.rb +9 -0
  56. data/templates/spec_helper.rb +16 -0
  57. data/templates/staging.rb +5 -0
  58. data/templates/suspenders_gitignore +17 -0
  59. data/templates/suspenders_layout.html.erb.erb +16 -0
  60. data/templates/travis.yml.erb +24 -0
  61. data/templates/unicorn.rb +30 -0
  62. metadata +223 -0
@@ -0,0 +1,215 @@
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 :install_bitters
35
+ invoke :copy_miscellaneous_files
36
+ invoke :customize_error_pages
37
+ invoke :remove_routes_comment_lines
38
+ invoke :setup_git
39
+ invoke :setup_database
40
+ invoke :create_heroku_apps
41
+ invoke :create_github_repo
42
+ invoke :setup_segment_io
43
+ invoke :outro
44
+ end
45
+
46
+ def customize_gemfile
47
+ build :replace_gemfile
48
+ build :set_ruby_to_version_being_used
49
+
50
+ if options[:heroku]
51
+ build :setup_heroku_specific_gems
52
+ end
53
+
54
+ bundle_command 'install'
55
+ end
56
+
57
+ def setup_database
58
+ say 'Setting up database'
59
+
60
+ if 'postgresql' == options[:database]
61
+ build :use_postgres_config_template
62
+ end
63
+
64
+ build :create_database
65
+ end
66
+
67
+ def setup_development_environment
68
+ say 'Setting up the development environment'
69
+ build :raise_on_delivery_errors
70
+ build :raise_on_unpermitted_parameters
71
+ build :provide_setup_script
72
+ build :provide_dev_prime_task
73
+ build :configure_generators
74
+ build :configure_i18n_for_missing_translations
75
+ end
76
+
77
+ def setup_test_environment
78
+ say 'Setting up the test environment'
79
+ build :set_up_factory_girl_for_rspec
80
+ build :generate_rspec
81
+ build :configure_rspec
82
+ build :configure_background_jobs_for_rspec
83
+ build :enable_database_cleaner
84
+ build :configure_spec_support_features
85
+ build :configure_travis
86
+ build :configure_i18n_for_test_environment
87
+ build :configure_i18n_tasks
88
+ build :configure_action_mailer_in_specs
89
+ end
90
+
91
+ def setup_production_environment
92
+ say 'Setting up the production environment'
93
+ build :configure_newrelic
94
+ build :configure_smtp
95
+ build :enable_rack_deflater
96
+ build :setup_asset_host
97
+ end
98
+
99
+ def setup_staging_environment
100
+ say 'Setting up the staging environment'
101
+ build :setup_staging_environment
102
+ end
103
+
104
+ def setup_secret_token
105
+ say 'Moving secret token out of version control'
106
+ build :setup_secret_token
107
+ end
108
+
109
+ def create_suspenders_views
110
+ say 'Creating suspenders views'
111
+ build :create_partials_directory
112
+ build :create_shared_flashes
113
+ build :create_shared_javascripts
114
+ build :create_application_layout
115
+ end
116
+
117
+ def setup_coffeescript
118
+ say 'Setting up CoffeeScript defaults'
119
+ build :remove_turbolinks
120
+ end
121
+
122
+ def configure_app
123
+ say 'Configuring app'
124
+ build :configure_action_mailer
125
+ build :configure_time_zone
126
+ build :configure_time_formats
127
+ build :configure_rack_timeout
128
+ build :disable_xml_params
129
+ build :fix_i18n_deprecation_warning
130
+ build :setup_default_rake_task
131
+ build :configure_unicorn
132
+ build :setup_foreman
133
+ end
134
+
135
+ def setup_stylesheets
136
+ say 'Set up stylesheets'
137
+ build :setup_stylesheets
138
+ end
139
+
140
+ def install_bitters
141
+ say 'Install Bitters'
142
+ build :install_bitters
143
+ end
144
+
145
+ def setup_git
146
+ if !options[:skip_git]
147
+ say 'Initializing git'
148
+ invoke :setup_gitignore
149
+ invoke :init_git
150
+ end
151
+ end
152
+
153
+ def create_heroku_apps
154
+ if options[:heroku]
155
+ say 'Creating Heroku apps'
156
+ build :create_heroku_apps
157
+ build :set_heroku_remotes
158
+ build :set_heroku_rails_secrets
159
+ end
160
+ end
161
+
162
+ def create_github_repo
163
+ if !options[:skip_git] && options[:github]
164
+ say 'Creating Github repo'
165
+ build :create_github_repo, options[:github]
166
+ end
167
+ end
168
+
169
+ def setup_segment_io
170
+ say 'Setting up Segment.io'
171
+ build :setup_segment_io
172
+ end
173
+
174
+ def setup_gitignore
175
+ build :gitignore_files
176
+ end
177
+
178
+ def init_git
179
+ build :init_git
180
+ end
181
+
182
+ def copy_miscellaneous_files
183
+ say 'Copying miscellaneous support files'
184
+ build :copy_miscellaneous_files
185
+ end
186
+
187
+ def customize_error_pages
188
+ say 'Customizing the 500/404/422 pages'
189
+ build :customize_error_pages
190
+ end
191
+
192
+ def remove_routes_comment_lines
193
+ build :remove_routes_comment_lines
194
+ end
195
+
196
+ def outro
197
+ say 'Congratulations! You just pulled our suspenders.'
198
+ say "Remember to run 'rails generate airbrake' with your API key."
199
+ end
200
+
201
+ def run_bundle
202
+ # Let's not: We'll bundle manually at the right spot
203
+ end
204
+
205
+ protected
206
+
207
+ def get_builder_class
208
+ Suspenders::AppBuilder
209
+ end
210
+
211
+ def using_active_record?
212
+ !options[:skip_active_record]
213
+ end
214
+ end
215
+ end
@@ -0,0 +1,5 @@
1
+ module Suspenders
2
+ RAILS_VERSION = "4.1.8"
3
+ RUBY_VERSION = IO.read("#{File.dirname(__FILE__)}/../../.ruby-version").strip
4
+ VERSION = "1.18.0"
5
+ 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,10 @@
1
+ require 'spec_helper'
2
+
3
+ feature 'GitHub' do
4
+ scenario 'Suspend a project with --github option' do
5
+ repo_name = 'test'
6
+ run_suspenders("--github=#{repo_name}")
7
+
8
+ expect(FakeGithub).to have_created_repo(repo_name)
9
+ end
10
+ end
@@ -0,0 +1,19 @@
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
+
13
+ bin_setup = IO.read("#{project_path}/bin/setup")
14
+ app_name = SuspendersTestHelpers::APP_NAME
15
+
16
+ expect(bin_setup).to include("heroku join --app #{app_name}-staging")
17
+ expect(bin_setup).to include("heroku join --app #{app_name}-production")
18
+ end
19
+ end
@@ -0,0 +1,117 @@
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 = "Rails.application.configure do"
19
+
20
+ expect(staging_file).to match(/^require_relative "production"/)
21
+ expect(staging_file).to match(/#{config_stub}/), staging_file
22
+ end
23
+
24
+ scenario 'generated .ruby-version is pulled from Suspenders .ruby-version' do
25
+ run_suspenders
26
+
27
+ ruby_version_file = IO.read("#{project_path}/.ruby-version")
28
+
29
+ expect(ruby_version_file).to eq "#{RUBY_VERSION}\n"
30
+ end
31
+
32
+ scenario 'secrets.yml reads secret from env' do
33
+ run_suspenders
34
+
35
+ secrets_file = IO.read("#{project_path}/config/secrets.yml")
36
+
37
+ expect(secrets_file).to match(/secret_key_base: <%= ENV\["SECRET_KEY_BASE"\] %>/)
38
+ end
39
+
40
+ scenario 'action mailer support file is added' do
41
+ run_suspenders
42
+
43
+ expect(File).to exist("#{project_path}/spec/support/action_mailer.rb")
44
+ end
45
+
46
+ scenario "i18n support file is added" do
47
+ run_suspenders
48
+
49
+ expect(File).to exist("#{project_path}/spec/support/i18n.rb")
50
+ end
51
+
52
+ scenario 'newrelic.yml reads NewRelic license from env' do
53
+ run_suspenders
54
+
55
+ newrelic_file = IO.read("#{project_path}/config/newrelic.yml")
56
+
57
+ expect(newrelic_file).to match(
58
+ /license_key: "<%= ENV\["NEW_RELIC_LICENSE_KEY"\] %>"/
59
+ )
60
+ end
61
+
62
+ scenario 'records pageviews through Segment.io if ENV variable set' do
63
+ run_suspenders
64
+
65
+ expect(analytics_partial).
66
+ to include(%{<% if ENV["SEGMENT_IO_KEY"] %>})
67
+ expect(analytics_partial).
68
+ to include(%{window.analytics.load("<%= ENV["SEGMENT_IO_KEY"] %>");})
69
+ end
70
+
71
+ scenario "raises on unpermitted parameters in all environments" do
72
+ run_suspenders
73
+
74
+ result = IO.read("#{project_path}/config/application.rb")
75
+
76
+ expect(result).to match(
77
+ /^ +config.action_controller.action_on_unpermitted_parameters = :raise$/
78
+ )
79
+ end
80
+
81
+ scenario "raises on missing translations in development and test" do
82
+ run_suspenders
83
+
84
+ %w[development test].each do |environment|
85
+ environment_file =
86
+ IO.read("#{project_path}/config/environments/#{environment}.rb")
87
+ expect(environment_file).to match(
88
+ /^ +config.action_view.raise_on_missing_translations = true$/
89
+ )
90
+ end
91
+ end
92
+
93
+ scenario "specs for missing or unused translations" do
94
+ run_suspenders
95
+
96
+ expect(File).to exist("#{project_path}/spec/i18n_spec.rb")
97
+ end
98
+
99
+ scenario "config file for i18n tasks" do
100
+ run_suspenders
101
+
102
+ expect(File).to exist("#{project_path}/config/i18n-tasks.yml")
103
+ end
104
+
105
+ scenario "generated en.yml is evaluated" do
106
+ run_suspenders
107
+
108
+ locales_en_file = IO.read("#{project_path}/config/locales/en.yml")
109
+ app_name = SuspendersTestHelpers::APP_NAME
110
+
111
+ expect(locales_en_file).to match(/application: #{app_name.humanize}/)
112
+ end
113
+
114
+ def analytics_partial
115
+ IO.read("#{project_path}/app/views/application/_analytics.html.erb")
116
+ end
117
+ end
@@ -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
@@ -0,0 +1,38 @@
1
+ class FakeHeroku
2
+ RECORDER = File.expand_path(File.join('..', '..', 'tmp', 'heroku_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.puts @args.join(' ')
11
+ end
12
+ end
13
+
14
+ def self.clear!
15
+ FileUtils.rm_rf RECORDER
16
+ end
17
+
18
+ def self.has_gem_included?(project_path, gem_name)
19
+ gemfile = File.open(File.join(project_path, 'Gemfile'), 'a')
20
+
21
+ File.foreach(gemfile).any? do |line|
22
+ line.match(/#{Regexp.quote(gem_name)}/)
23
+ end
24
+ end
25
+
26
+ def self.has_created_app_for?(remote_name)
27
+ app_name = "#{SuspendersTestHelpers::APP_NAME}-#{remote_name}"
28
+ expected_line = "create #{app_name} --remote=#{remote_name}\n"
29
+
30
+ File.foreach(RECORDER).any? { |line| line == expected_line }
31
+ end
32
+
33
+ def self.has_configured_vars?(remote_name, var)
34
+ File.foreach(RECORDER).any? do |line|
35
+ line =~ /^config:add #{var}=.+ --remote=#{remote_name}\n$/
36
+ end
37
+ end
38
+ end