brace 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.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/.ruby-version +1 -0
- data/CONTRIBUTING.md +43 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +139 -0
- data/LICENSE +21 -0
- data/NEWS.md +351 -0
- data/README.md +166 -0
- data/Rakefile +8 -0
- data/bin/brace +18 -0
- data/bin/rake +16 -0
- data/bin/rspec +16 -0
- data/bin/setup +13 -0
- data/brace.gemspec +35 -0
- data/lib/brace.rb +4 -0
- data/lib/brace/actions.rb +25 -0
- data/lib/brace/app_builder.rb +469 -0
- data/lib/brace/generators/app_generator.rb +248 -0
- data/lib/brace/version.rb +6 -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 +40 -0
- data/spec/features/new_project_spec.rb +115 -0
- data/spec/spec_helper.rb +24 -0
- data/spec/support/braces.rb +49 -0
- data/spec/support/fake_github.rb +21 -0
- data/spec/support/fake_heroku.rb +43 -0
- data/templates/Gemfile.erb +88 -0
- data/templates/Procfile +2 -0
- data/templates/README.md.erb +32 -0
- data/templates/_analytics.html.erb +7 -0
- data/templates/_javascript.html.erb +12 -0
- data/templates/action_mailer.rb +5 -0
- data/templates/application.css.scss +8 -0
- data/templates/bin_deploy +12 -0
- data/templates/bin_setup.erb +36 -0
- data/templates/brace_gitignore +14 -0
- data/templates/brace_layout.html.slim.erb +15 -0
- data/templates/bundler_audit.rake +12 -0
- data/templates/config_i18n_tasks.yml +13 -0
- data/templates/config_locales_en.yml.erb +19 -0
- data/templates/database_cleaner_rspec.rb +21 -0
- data/templates/development_seeds.rb +12 -0
- data/templates/devise_rspec.rb +3 -0
- data/templates/disable_xml_params.rb +3 -0
- data/templates/errors.rb +34 -0
- data/templates/factory_girl_rspec.rb +3 -0
- data/templates/i18n.rb +3 -0
- data/templates/json_encoding.rb +1 -0
- data/templates/newrelic.yml.erb +34 -0
- data/templates/postgresql_database.yml.erb +12 -0
- data/templates/rack_timeout.rb +1 -0
- data/templates/rails_helper.rb +22 -0
- data/templates/redis.rb +10 -0
- data/templates/sample.env +5 -0
- data/templates/secrets.yml +14 -0
- data/templates/sidekiq.rb +7 -0
- data/templates/sidekiq_rspec.rb +7 -0
- data/templates/smtp.rb +9 -0
- data/templates/spec_helper.rb +16 -0
- data/templates/stripe.rb +1 -0
- data/templates/vcr_helper.rb +12 -0
- metadata +197 -0
@@ -0,0 +1,248 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/rails/app/app_generator'
|
3
|
+
|
4
|
+
module Brace
|
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 :brace_customization
|
29
|
+
super
|
30
|
+
end
|
31
|
+
|
32
|
+
def brace_customization
|
33
|
+
invoke :customize_gemfile
|
34
|
+
invoke :setup_development_environment
|
35
|
+
invoke :setup_test_environment
|
36
|
+
invoke :setup_production_environment
|
37
|
+
invoke :setup_secret_token
|
38
|
+
invoke :create_brace_views
|
39
|
+
invoke :configure_app
|
40
|
+
invoke :setup_stylesheets
|
41
|
+
invoke :install_devise
|
42
|
+
invoke :install_bitters
|
43
|
+
invoke :install_responders
|
44
|
+
invoke :copy_miscellaneous_files
|
45
|
+
invoke :customize_error_pages
|
46
|
+
invoke :remove_routes_comment_lines
|
47
|
+
invoke :setup_stripe
|
48
|
+
invoke :setup_git
|
49
|
+
invoke :setup_redis
|
50
|
+
invoke :setup_sidekiq
|
51
|
+
invoke :setup_database
|
52
|
+
invoke :create_heroku_apps
|
53
|
+
invoke :create_github_repo
|
54
|
+
invoke :setup_segment_io
|
55
|
+
invoke :setup_bundler_audit
|
56
|
+
invoke :outro
|
57
|
+
end
|
58
|
+
|
59
|
+
def customize_gemfile
|
60
|
+
build :replace_gemfile
|
61
|
+
build :set_ruby_to_version_being_used
|
62
|
+
|
63
|
+
if options[:heroku]
|
64
|
+
build :setup_heroku_specific_gems
|
65
|
+
end
|
66
|
+
|
67
|
+
bundle_command 'install'
|
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_delivery_errors
|
83
|
+
build :set_test_delivery_method
|
84
|
+
build :raise_on_unpermitted_parameters
|
85
|
+
build :provide_setup_script
|
86
|
+
build :provide_dev_prime_task
|
87
|
+
build :configure_generators
|
88
|
+
build :configure_i18n_for_missing_translations
|
89
|
+
build :configure_action_mailer_development
|
90
|
+
end
|
91
|
+
|
92
|
+
def setup_test_environment
|
93
|
+
say 'Setting up the test environment'
|
94
|
+
build :set_up_factory_girl_for_rspec
|
95
|
+
build :set_up_devise_for_rspec
|
96
|
+
build :generate_rspec
|
97
|
+
build :configure_rspec
|
98
|
+
build :configure_sidekiq_for_rspec
|
99
|
+
build :enable_database_cleaner
|
100
|
+
build :configure_spec_support_features
|
101
|
+
build :configure_i18n_for_test_environment
|
102
|
+
build :configure_i18n_tasks
|
103
|
+
build :configure_action_mailer_in_specs
|
104
|
+
end
|
105
|
+
|
106
|
+
def setup_production_environment
|
107
|
+
say 'Setting up the production environment'
|
108
|
+
build :configure_newrelic
|
109
|
+
build :configure_smtp
|
110
|
+
build :enable_rack_deflater
|
111
|
+
build :setup_asset_host
|
112
|
+
end
|
113
|
+
|
114
|
+
def setup_secret_token
|
115
|
+
say 'Moving secret token out of version control'
|
116
|
+
build :setup_secret_token
|
117
|
+
end
|
118
|
+
|
119
|
+
def create_brace_views
|
120
|
+
say 'Creating api template views'
|
121
|
+
build :create_partials_directory
|
122
|
+
build :create_shared_javascripts
|
123
|
+
build :create_application_layout
|
124
|
+
end
|
125
|
+
|
126
|
+
def configure_app
|
127
|
+
say 'Configuring app'
|
128
|
+
build :configure_action_mailer
|
129
|
+
build :configure_time_formats
|
130
|
+
build :configure_rack_timeout
|
131
|
+
build :configure_eager_load_paths
|
132
|
+
build :configure_action_mailer_previews
|
133
|
+
build :configure_responders
|
134
|
+
build :disable_xml_params
|
135
|
+
build :fix_i18n_deprecation_warning
|
136
|
+
build :setup_default_rake_task
|
137
|
+
build :setup_foreman
|
138
|
+
end
|
139
|
+
|
140
|
+
def setup_stylesheets
|
141
|
+
say 'Set up stylesheets'
|
142
|
+
build :setup_stylesheets
|
143
|
+
end
|
144
|
+
|
145
|
+
def install_devise
|
146
|
+
say 'Install Devise'
|
147
|
+
build :install_devise
|
148
|
+
end
|
149
|
+
|
150
|
+
def install_bitters
|
151
|
+
say 'Install Bitters'
|
152
|
+
build :install_bitters
|
153
|
+
end
|
154
|
+
|
155
|
+
def install_responders
|
156
|
+
say 'Install Responders'
|
157
|
+
build :install_responders
|
158
|
+
end
|
159
|
+
|
160
|
+
def setup_git
|
161
|
+
if !options[:skip_git]
|
162
|
+
say 'Initializing git'
|
163
|
+
invoke :setup_gitignore
|
164
|
+
invoke :init_git
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
def setup_redis
|
169
|
+
say 'Setting up Redis'
|
170
|
+
build :add_redis_initializer
|
171
|
+
end
|
172
|
+
|
173
|
+
def setup_sidekiq
|
174
|
+
say 'Setting up Sidekiq'
|
175
|
+
build :add_sidekiq_initializer
|
176
|
+
end
|
177
|
+
|
178
|
+
def setup_stripe
|
179
|
+
say 'Setting up Stripe'
|
180
|
+
build :add_stripe_initializer
|
181
|
+
end
|
182
|
+
|
183
|
+
def create_heroku_apps
|
184
|
+
if options[:heroku]
|
185
|
+
say "Creating Heroku apps"
|
186
|
+
build :create_heroku_apps, options[:heroku_flags]
|
187
|
+
build :set_heroku_remotes
|
188
|
+
build :set_heroku_rails_secrets
|
189
|
+
build :set_memory_management_variable
|
190
|
+
build :provide_deploy_script
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
def create_github_repo
|
195
|
+
if !options[:skip_git] && options[:github]
|
196
|
+
say 'Creating Github repo'
|
197
|
+
build :create_github_repo, options[:github]
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
def setup_segment_io
|
202
|
+
say 'Setting up Segment.io'
|
203
|
+
build :setup_segment_io
|
204
|
+
end
|
205
|
+
|
206
|
+
def setup_gitignore
|
207
|
+
build :gitignore_files
|
208
|
+
end
|
209
|
+
|
210
|
+
def setup_bundler_audit
|
211
|
+
say "Setting up bundler-audit"
|
212
|
+
build :setup_bundler_audit
|
213
|
+
end
|
214
|
+
|
215
|
+
def init_git
|
216
|
+
build :init_git
|
217
|
+
end
|
218
|
+
|
219
|
+
def copy_miscellaneous_files
|
220
|
+
say 'Copying miscellaneous support files'
|
221
|
+
build :copy_miscellaneous_files
|
222
|
+
end
|
223
|
+
|
224
|
+
def customize_error_pages
|
225
|
+
say 'Customizing the 500/404/422 pages'
|
226
|
+
build :customize_error_pages
|
227
|
+
end
|
228
|
+
|
229
|
+
def remove_routes_comment_lines
|
230
|
+
build :remove_routes_comment_lines
|
231
|
+
end
|
232
|
+
|
233
|
+
def outro
|
234
|
+
say 'Congratulations! You just generated a rails api!'
|
235
|
+
say "Remember to run 'rails generate rollbar' with your token."
|
236
|
+
end
|
237
|
+
|
238
|
+
protected
|
239
|
+
|
240
|
+
def get_builder_class
|
241
|
+
Brace::AppBuilder
|
242
|
+
end
|
243
|
+
|
244
|
+
def using_active_record?
|
245
|
+
!options[:skip_active_record]
|
246
|
+
end
|
247
|
+
end
|
248
|
+
end
|
data/spec/fakes/bin/hub
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
feature "Heroku" do
|
4
|
+
scenario "Suspend a project for Heroku" do
|
5
|
+
run_brace("--heroku=true")
|
6
|
+
|
7
|
+
expect(FakeHeroku).
|
8
|
+
to have_gem_included(project_path, "rails_stdout_logging")
|
9
|
+
expect(FakeHeroku).to have_created_app_for("staging")
|
10
|
+
expect(FakeHeroku).to have_created_app_for("production")
|
11
|
+
expect(FakeHeroku).to have_configured_vars("staging", "SECRET_KEY_BASE")
|
12
|
+
expect(FakeHeroku).to have_configured_vars("production", "SECRET_KEY_BASE")
|
13
|
+
|
14
|
+
bin_setup_path = "#{project_path}/bin/setup"
|
15
|
+
bin_setup = IO.read(bin_setup_path)
|
16
|
+
app_name = BraceTestHelpers::APP_NAME
|
17
|
+
|
18
|
+
expect(bin_setup).to include("heroku join --app #{app_name}-staging")
|
19
|
+
expect(bin_setup).to include("heroku join --app #{app_name}-production")
|
20
|
+
expect(File.stat(bin_setup_path)).to be_executable
|
21
|
+
|
22
|
+
bin_deploy_path = "#{project_path}/bin/deploy"
|
23
|
+
bin_deploy = IO.read(bin_deploy_path)
|
24
|
+
|
25
|
+
expect(bin_deploy).to include("heroku run rake db:migrate")
|
26
|
+
expect(File.stat(bin_deploy_path)).to be_executable
|
27
|
+
|
28
|
+
readme = IO.read("#{project_path}/README.md")
|
29
|
+
|
30
|
+
expect(readme).to include("./bin/deploy staging")
|
31
|
+
expect(readme).to include("./bin/deploy production")
|
32
|
+
end
|
33
|
+
|
34
|
+
scenario "Suspend a project with extra Heroku flags" do
|
35
|
+
run_brace(%{--heroku=true --heroku-flags="--region eu"})
|
36
|
+
|
37
|
+
expect(FakeHeroku).to have_created_app_for("staging", "--region eu")
|
38
|
+
expect(FakeHeroku).to have_created_app_for("production", "--region eu")
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
feature 'Suspend a new project with default configuration' do
|
4
|
+
scenario 'specs pass' do
|
5
|
+
run_brace
|
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 'generated .ruby-version is pulled from Brace .ruby-version' do
|
15
|
+
run_brace
|
16
|
+
|
17
|
+
ruby_version_file = IO.read("#{project_path}/.ruby-version")
|
18
|
+
|
19
|
+
expect(ruby_version_file).to eq "#{RUBY_VERSION}\n"
|
20
|
+
end
|
21
|
+
|
22
|
+
scenario 'secrets.yml reads secret from env' do
|
23
|
+
run_brace
|
24
|
+
|
25
|
+
secrets_file = IO.read("#{project_path}/config/secrets.yml")
|
26
|
+
|
27
|
+
expect(secrets_file).to match(/secret_key_base: <%= ENV\["SECRET_KEY_BASE"\] %>/)
|
28
|
+
end
|
29
|
+
|
30
|
+
scenario 'action mailer support file is added' do
|
31
|
+
run_brace
|
32
|
+
|
33
|
+
expect(File).to exist("#{project_path}/spec/support/action_mailer.rb")
|
34
|
+
end
|
35
|
+
|
36
|
+
scenario "i18n support file is added" do
|
37
|
+
run_brace
|
38
|
+
|
39
|
+
expect(File).to exist("#{project_path}/spec/support/i18n.rb")
|
40
|
+
end
|
41
|
+
|
42
|
+
scenario 'newrelic.yml reads NewRelic license from env' do
|
43
|
+
run_brace
|
44
|
+
|
45
|
+
newrelic_file = IO.read("#{project_path}/config/newrelic.yml")
|
46
|
+
|
47
|
+
expect(newrelic_file).to match(
|
48
|
+
/license_key: "<%= ENV\["NEW_RELIC_LICENSE_KEY"\] %>"/
|
49
|
+
)
|
50
|
+
end
|
51
|
+
|
52
|
+
scenario 'records pageviews through Segment.io if ENV variable set' do
|
53
|
+
run_brace
|
54
|
+
|
55
|
+
expect(analytics_partial).
|
56
|
+
to include(%{<% if ENV["SEGMENT_IO_KEY"] %>})
|
57
|
+
expect(analytics_partial).
|
58
|
+
to include(%{window.analytics.load("<%= ENV["SEGMENT_IO_KEY"] %>");})
|
59
|
+
end
|
60
|
+
|
61
|
+
scenario "raises on unpermitted parameters in all environments" do
|
62
|
+
run_brace
|
63
|
+
|
64
|
+
result = IO.read("#{project_path}/config/application.rb")
|
65
|
+
|
66
|
+
expect(result).to match(
|
67
|
+
/^ +config.action_controller.action_on_unpermitted_parameters = :raise$/
|
68
|
+
)
|
69
|
+
end
|
70
|
+
|
71
|
+
scenario "raises on missing translations in development and test" do
|
72
|
+
run_brace
|
73
|
+
|
74
|
+
%w[development test].each do |environment|
|
75
|
+
environment_file =
|
76
|
+
IO.read("#{project_path}/config/environments/#{environment}.rb")
|
77
|
+
expect(environment_file).to match(
|
78
|
+
/^ +config.action_view.raise_on_missing_translations = true$/
|
79
|
+
)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
scenario "specs for missing or unused translations" do
|
84
|
+
run_brace
|
85
|
+
|
86
|
+
expect(File).to exist("#{project_path}/spec/i18n_spec.rb")
|
87
|
+
end
|
88
|
+
|
89
|
+
scenario "config file for i18n tasks" do
|
90
|
+
run_brace
|
91
|
+
|
92
|
+
expect(File).to exist("#{project_path}/config/i18n-tasks.yml")
|
93
|
+
end
|
94
|
+
|
95
|
+
scenario "generated en.yml is evaluated" do
|
96
|
+
run_brace
|
97
|
+
|
98
|
+
locales_en_file = IO.read("#{project_path}/config/locales/en.yml")
|
99
|
+
app_name = BraceTestHelpers::APP_NAME
|
100
|
+
|
101
|
+
expect(locales_en_file).to match(/application: #{app_name.humanize}/)
|
102
|
+
end
|
103
|
+
|
104
|
+
scenario "config :test email delivery method for development" do
|
105
|
+
run_brace
|
106
|
+
|
107
|
+
dev_env_file = IO.read("#{project_path}/config/environments/development.rb")
|
108
|
+
expect(dev_env_file).
|
109
|
+
to match(/^ +config.action_mailer.delivery_method = :test$/)
|
110
|
+
end
|
111
|
+
|
112
|
+
def analytics_partial
|
113
|
+
IO.read("#{project_path}/app/views/application/_analytics.html.erb")
|
114
|
+
end
|
115
|
+
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/brace').expand_path
|
7
|
+
|
8
|
+
Dir['./spec/support/**/*.rb'].each { |file| require file }
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.include BraceTestHelpers
|
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
|