voyage 1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +5 -0
- data/.ruby-version +1 -0
- data/.travis.yml +11 -0
- data/CONTRIBUTING.md +54 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/NEWS.md +510 -0
- data/README.md +233 -0
- data/RELEASING.md +19 -0
- data/Rakefile +8 -0
- data/USAGE +13 -0
- data/bin/rake +16 -0
- data/bin/rspec +16 -0
- data/bin/setup +13 -0
- data/bin/suspenders +23 -0
- data/bin/voyage +20 -0
- data/lib/suspenders.rb +6 -0
- data/lib/suspenders/actions.rb +33 -0
- data/lib/suspenders/adapters/heroku.rb +127 -0
- data/lib/suspenders/app_builder.rb +486 -0
- data/lib/suspenders/generators/app_generator.rb +287 -0
- data/lib/suspenders/generators/static_generator.rb +9 -0
- data/lib/suspenders/version.rb +8 -0
- data/lib/voyage.rb +9 -0
- data/lib/voyage/app_builder.rb +469 -0
- data/lib/voyage/generators/app_generator.rb +118 -0
- data/lib/voyage/templates/Gemfile.erb +118 -0
- data/lib/voyage/templates/README.md.erb +28 -0
- data/lib/voyage/templates/about.html.erb +1 -0
- data/lib/voyage/templates/application.js +19 -0
- data/lib/voyage/templates/config_locales_en.yml.erb +25 -0
- data/lib/voyage/templates/controller_helpers.rb +14 -0
- data/lib/voyage/templates/custom_cancan_matchers.rb +54 -0
- data/lib/voyage/templates/rails_helper.rb.erb +99 -0
- data/lib/voyage/templates/seeder.rb.erb +46 -0
- data/lib/voyage/templates/seeds.rb.erb +50 -0
- data/lib/voyage/templates/simplecov.rb +31 -0
- data/lib/voyage/templates/users_index.html.slim.erb +25 -0
- data/lib/voyage/templates/welcome.html.erb +11 -0
- data/lib/voyage/version.rb +8 -0
- data/spec/adapters/heroku_spec.rb +57 -0
- data/spec/fakes/bin/heroku +5 -0
- data/spec/fakes/bin/hub +5 -0
- data/spec/features/cli_help_spec.rb +36 -0
- data/spec/features/github_spec.rb +16 -0
- data/spec/features/heroku_spec.rb +75 -0
- data/spec/features/new_project_spec.rb +270 -0
- data/spec/spec_helper.rb +20 -0
- data/spec/support/fake_github.rb +21 -0
- data/spec/support/fake_heroku.rb +53 -0
- data/spec/support/suspenders.rb +83 -0
- data/suspenders.gemspec +34 -0
- data/templates/Gemfile.erb +64 -0
- data/templates/Procfile +2 -0
- data/templates/README.md.erb +28 -0
- data/templates/_analytics.html.erb +7 -0
- data/templates/_css_overrides.html.erb +7 -0
- data/templates/_flashes.html.erb +7 -0
- data/templates/_javascript.html.erb +12 -0
- data/templates/action_mailer.rb +5 -0
- data/templates/app.json.erb +42 -0
- data/templates/application.scss +9 -0
- data/templates/bin_deploy +12 -0
- data/templates/bin_setup +21 -0
- data/templates/bin_setup_review_app.erb +19 -0
- data/templates/browserslist +3 -0
- data/templates/bundler_audit.rake +12 -0
- data/templates/capybara_webkit.rb +5 -0
- data/templates/circle.yml.erb +6 -0
- data/templates/config_locales_en.yml.erb +19 -0
- data/templates/database_cleaner_rspec.rb +21 -0
- data/templates/dev.rake +12 -0
- data/templates/dotfiles/.ctags +2 -0
- data/templates/dotfiles/.env +13 -0
- data/templates/errors.rb +34 -0
- data/templates/factories.rb +2 -0
- data/templates/factory_girl_rspec.rb +3 -0
- data/templates/flashes_helper.rb +5 -0
- data/templates/hound.yml +14 -0
- data/templates/i18n.rb +3 -0
- data/templates/json_encoding.rb +1 -0
- data/templates/postgresql_database.yml.erb +21 -0
- data/templates/puma.rb +28 -0
- data/templates/rack_mini_profiler.rb +5 -0
- data/templates/rails_helper.rb +22 -0
- data/templates/secrets.yml +14 -0
- data/templates/shoulda_matchers_config_rspec.rb +6 -0
- data/templates/smtp.rb +13 -0
- data/templates/spec_helper.rb +29 -0
- data/templates/suspenders_gitignore +13 -0
- data/templates/suspenders_layout.html.erb.erb +22 -0
- metadata +207 -0
@@ -0,0 +1,287 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/rails/app/app_generator'
|
3
|
+
|
4
|
+
module Suspenders
|
5
|
+
class AppGenerator < Rails::Generators::AppGenerator
|
6
|
+
hide!
|
7
|
+
|
8
|
+
class_option :database, type: :string, aliases: "-d", default: "postgresql",
|
9
|
+
desc: "Configure for selected database (options: #{DATABASES.join("/")})"
|
10
|
+
|
11
|
+
class_option :heroku, type: :boolean, aliases: "-H", default: false,
|
12
|
+
desc: "Create staging and production Heroku apps"
|
13
|
+
|
14
|
+
class_option :heroku_flags, type: :string, default: "",
|
15
|
+
desc: "Set extra Heroku flags"
|
16
|
+
|
17
|
+
class_option :github, type: :string, aliases: "-G", default: nil,
|
18
|
+
desc: "Create Github repository and add remote origin pointed to repo"
|
19
|
+
|
20
|
+
class_option :skip_test_unit, type: :boolean, aliases: "-T", default: true,
|
21
|
+
desc: "Skip Test::Unit files"
|
22
|
+
|
23
|
+
class_option :skip_turbolinks, type: :boolean, default: true,
|
24
|
+
desc: "Skip turbolinks gem"
|
25
|
+
|
26
|
+
class_option :skip_bundle, type: :boolean, aliases: "-B", default: true,
|
27
|
+
desc: "Don't run bundle install"
|
28
|
+
|
29
|
+
class_option :version, type: :boolean, aliases: "-v", group: :suspenders,
|
30
|
+
desc: "Show Suspenders version number and quit"
|
31
|
+
|
32
|
+
class_option :help, type: :boolean, aliases: '-h', group: :suspenders,
|
33
|
+
desc: "Show this help message and quit"
|
34
|
+
|
35
|
+
class_option :path, type: :string, default: nil,
|
36
|
+
desc: "Path to the gem"
|
37
|
+
|
38
|
+
def finish_template
|
39
|
+
invoke :suspenders_customization
|
40
|
+
super
|
41
|
+
end
|
42
|
+
|
43
|
+
def suspenders_customization
|
44
|
+
invoke :customize_gemfile
|
45
|
+
invoke :setup_development_environment
|
46
|
+
invoke :setup_test_environment
|
47
|
+
invoke :setup_production_environment
|
48
|
+
invoke :setup_secret_token
|
49
|
+
invoke :create_suspenders_views
|
50
|
+
invoke :configure_app
|
51
|
+
invoke :setup_stylesheets
|
52
|
+
invoke :install_bitters
|
53
|
+
invoke :install_refills
|
54
|
+
invoke :copy_miscellaneous_files
|
55
|
+
invoke :customize_error_pages
|
56
|
+
invoke :remove_config_comment_lines
|
57
|
+
invoke :remove_routes_comment_lines
|
58
|
+
invoke :setup_dotfiles
|
59
|
+
invoke :setup_git
|
60
|
+
invoke :setup_database
|
61
|
+
invoke :create_local_heroku_setup
|
62
|
+
invoke :create_heroku_apps
|
63
|
+
invoke :create_github_repo
|
64
|
+
invoke :setup_segment
|
65
|
+
invoke :setup_bundler_audit
|
66
|
+
invoke :setup_spring
|
67
|
+
invoke :generate_default
|
68
|
+
invoke :outro
|
69
|
+
end
|
70
|
+
|
71
|
+
def customize_gemfile
|
72
|
+
build :replace_gemfile, options[:path]
|
73
|
+
build :set_ruby_to_version_being_used
|
74
|
+
bundle_command 'install'
|
75
|
+
build :configure_simple_form
|
76
|
+
end
|
77
|
+
|
78
|
+
def setup_database
|
79
|
+
say 'Setting up database'
|
80
|
+
|
81
|
+
if 'postgresql' == options[:database]
|
82
|
+
build :use_postgres_config_template
|
83
|
+
end
|
84
|
+
|
85
|
+
build :create_database
|
86
|
+
end
|
87
|
+
|
88
|
+
def setup_development_environment
|
89
|
+
say 'Setting up the development environment'
|
90
|
+
build :raise_on_missing_assets_in_test
|
91
|
+
build :raise_on_delivery_errors
|
92
|
+
build :set_test_delivery_method
|
93
|
+
build :add_bullet_gem_configuration
|
94
|
+
build :raise_on_unpermitted_parameters
|
95
|
+
build :provide_setup_script
|
96
|
+
build :provide_dev_prime_task
|
97
|
+
build :configure_generators
|
98
|
+
build :configure_i18n_for_missing_translations
|
99
|
+
build :configure_quiet_assets
|
100
|
+
end
|
101
|
+
|
102
|
+
def setup_test_environment
|
103
|
+
say 'Setting up the test environment'
|
104
|
+
build :set_up_factory_girl_for_rspec
|
105
|
+
build :generate_factories_file
|
106
|
+
build :set_up_hound
|
107
|
+
build :generate_rspec
|
108
|
+
build :configure_rspec
|
109
|
+
build :configure_background_jobs_for_rspec
|
110
|
+
build :enable_database_cleaner
|
111
|
+
build :provide_shoulda_matchers_config
|
112
|
+
build :configure_spec_support_features
|
113
|
+
build :configure_ci
|
114
|
+
build :configure_i18n_for_test_environment
|
115
|
+
build :configure_action_mailer_in_specs
|
116
|
+
build :configure_capybara_webkit
|
117
|
+
end
|
118
|
+
|
119
|
+
def setup_production_environment
|
120
|
+
say 'Setting up the production environment'
|
121
|
+
build :configure_smtp
|
122
|
+
build :configure_rack_timeout
|
123
|
+
build :enable_rack_canonical_host
|
124
|
+
build :enable_rack_deflater
|
125
|
+
build :setup_asset_host
|
126
|
+
end
|
127
|
+
|
128
|
+
def setup_secret_token
|
129
|
+
say 'Moving secret token out of version control'
|
130
|
+
build :setup_secret_token
|
131
|
+
end
|
132
|
+
|
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
|
+
def configure_app
|
143
|
+
say 'Configuring app'
|
144
|
+
build :configure_action_mailer
|
145
|
+
build :configure_active_job
|
146
|
+
build :configure_time_formats
|
147
|
+
build :setup_default_rake_task
|
148
|
+
build :configure_puma
|
149
|
+
build :set_up_forego
|
150
|
+
build :setup_rack_mini_profiler
|
151
|
+
end
|
152
|
+
|
153
|
+
def setup_stylesheets
|
154
|
+
say 'Set up stylesheets'
|
155
|
+
build :setup_stylesheets
|
156
|
+
end
|
157
|
+
|
158
|
+
def install_bitters
|
159
|
+
say 'Install Bitters'
|
160
|
+
build :install_bitters
|
161
|
+
end
|
162
|
+
|
163
|
+
def install_refills
|
164
|
+
say "Install Refills"
|
165
|
+
build :install_refills
|
166
|
+
end
|
167
|
+
|
168
|
+
def setup_git
|
169
|
+
if !options[:skip_git]
|
170
|
+
say "Initializing git"
|
171
|
+
invoke :setup_default_directories
|
172
|
+
invoke :init_git
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
def create_local_heroku_setup
|
177
|
+
say "Creating local Heroku setup"
|
178
|
+
build :create_review_apps_setup_script
|
179
|
+
build :create_deploy_script
|
180
|
+
build :create_heroku_application_manifest_file
|
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_serve_static_files
|
188
|
+
build :set_heroku_remotes
|
189
|
+
build :set_heroku_rails_secrets
|
190
|
+
build :set_heroku_application_host
|
191
|
+
build :create_heroku_pipeline
|
192
|
+
build :configure_automatic_deployment
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
def create_github_repo
|
197
|
+
if !options[:skip_git] && options[:github]
|
198
|
+
say 'Creating Github repo'
|
199
|
+
build :create_github_repo, options[:github]
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
def setup_segment
|
204
|
+
say 'Setting up Segment'
|
205
|
+
build :setup_segment
|
206
|
+
end
|
207
|
+
|
208
|
+
def setup_dotfiles
|
209
|
+
build :copy_dotfiles
|
210
|
+
end
|
211
|
+
|
212
|
+
def setup_default_directories
|
213
|
+
build :setup_default_directories
|
214
|
+
end
|
215
|
+
|
216
|
+
def setup_bundler_audit
|
217
|
+
say "Setting up bundler-audit"
|
218
|
+
build :setup_bundler_audit
|
219
|
+
end
|
220
|
+
|
221
|
+
def setup_spring
|
222
|
+
say "Springifying binstubs"
|
223
|
+
build :setup_spring
|
224
|
+
end
|
225
|
+
|
226
|
+
def init_git
|
227
|
+
build :init_git
|
228
|
+
end
|
229
|
+
|
230
|
+
def copy_miscellaneous_files
|
231
|
+
say 'Copying miscellaneous support files'
|
232
|
+
build :copy_miscellaneous_files
|
233
|
+
end
|
234
|
+
|
235
|
+
def customize_error_pages
|
236
|
+
say 'Customizing the 500/404/422 pages'
|
237
|
+
build :customize_error_pages
|
238
|
+
end
|
239
|
+
|
240
|
+
def remove_config_comment_lines
|
241
|
+
build :remove_config_comment_lines
|
242
|
+
end
|
243
|
+
|
244
|
+
def remove_routes_comment_lines
|
245
|
+
build :remove_routes_comment_lines
|
246
|
+
end
|
247
|
+
|
248
|
+
def generate_default
|
249
|
+
run("spring stop")
|
250
|
+
|
251
|
+
generate("suspenders:static")
|
252
|
+
|
253
|
+
bundle_command "install"
|
254
|
+
end
|
255
|
+
|
256
|
+
def outro
|
257
|
+
say 'Congratulations! You just pulled our suspenders.'
|
258
|
+
say honeybadger_outro
|
259
|
+
end
|
260
|
+
|
261
|
+
def self.banner
|
262
|
+
"suspenders #{arguments.map(&:usage).join(' ')} [options]"
|
263
|
+
end
|
264
|
+
|
265
|
+
protected
|
266
|
+
|
267
|
+
def get_builder_class
|
268
|
+
Suspenders::AppBuilder
|
269
|
+
end
|
270
|
+
|
271
|
+
def using_active_record?
|
272
|
+
!options[:skip_active_record]
|
273
|
+
end
|
274
|
+
|
275
|
+
private
|
276
|
+
|
277
|
+
def honeybadger_outro
|
278
|
+
"Run 'bundle exec honeybadger heroku install' with your API key#{honeybadger_message_suffix}."
|
279
|
+
end
|
280
|
+
|
281
|
+
def honeybadger_message_suffix
|
282
|
+
if options[:heroku]
|
283
|
+
" unless you're using the Heroku Honeybadger add-on"
|
284
|
+
end
|
285
|
+
end
|
286
|
+
end
|
287
|
+
end
|
data/lib/voyage.rb
ADDED
@@ -0,0 +1,469 @@
|
|
1
|
+
module Suspenders
|
2
|
+
class AppBuilder < Rails::AppBuilder
|
3
|
+
def agree?(prompt)
|
4
|
+
puts prompt
|
5
|
+
response = STDIN.gets.chomp
|
6
|
+
|
7
|
+
response.empty? || %w(y yes).include?(response.downcase.strip)
|
8
|
+
end
|
9
|
+
|
10
|
+
def accept_defaults
|
11
|
+
if agree?('Would you like to accept all defaults? [slim, devise w/ first & last name, refills nav & footer] (Y/n)')
|
12
|
+
@@accept_defaults = true
|
13
|
+
else
|
14
|
+
@@accept_defaults = false
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def use_slim
|
19
|
+
if @@accept_defaults || agree?('Would you like to use slim? (Y/n)')
|
20
|
+
@@use_slim = true
|
21
|
+
run 'gem install html2slim'
|
22
|
+
|
23
|
+
find = <<-RUBY.gsub(/^ {8}/, '')
|
24
|
+
<%#
|
25
|
+
Configure default and controller-, and view-specific titles in
|
26
|
+
config/locales/en.yml. For more see:
|
27
|
+
https://github.com/calebthompson/title#usage
|
28
|
+
%>
|
29
|
+
RUBY
|
30
|
+
|
31
|
+
replace = <<-RUBY.gsub(/^ {8}/, '')
|
32
|
+
<% # Configure default and controller-, and view-specific titles in
|
33
|
+
# config/locales/en.yml. For more see:
|
34
|
+
# https://github.com/calebthompson/title#usage %>
|
35
|
+
RUBY
|
36
|
+
|
37
|
+
replace_in_file 'app/views/layouts/application.html.erb', find, replace
|
38
|
+
|
39
|
+
if @@use_slim
|
40
|
+
inside('lib') do # arbitrary, run in context of newly generated app
|
41
|
+
run "erb2slim '../app/views/layouts' '../app/views/layouts'"
|
42
|
+
run "erb2slim -d '../app/views/layouts'"
|
43
|
+
|
44
|
+
run "erb2slim '../app/views/application' '../app/views/application'"
|
45
|
+
run "erb2slim -d '../app/views/application'"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
else
|
49
|
+
@@use_slim = false
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# ------------
|
54
|
+
# DEVISE SETUP
|
55
|
+
# ------------
|
56
|
+
def install_devise
|
57
|
+
if @@accept_defaults || agree?('Would you like to install Devise? (Y/n)')
|
58
|
+
bundle_command 'exec rails generate devise:install'
|
59
|
+
|
60
|
+
if @@accept_defaults || agree?("Would you like to add first_name and last_name to the devise model? (Y/n)")
|
61
|
+
adding_first_and_last_name = true
|
62
|
+
|
63
|
+
bundle_command "exec rails generate resource user first_name:string last_name:string"
|
64
|
+
|
65
|
+
replace_in_file 'spec/factories/users.rb',
|
66
|
+
'first_name "MyString"', 'first_name { Faker::Name.first_name }'
|
67
|
+
replace_in_file 'spec/factories/users.rb',
|
68
|
+
'last_name "MyString"', 'last_name { Faker::Name.last_name }'
|
69
|
+
end
|
70
|
+
|
71
|
+
bundle_command "exec rails generate devise user"
|
72
|
+
bundle_command 'exec rails generate devise:views'
|
73
|
+
|
74
|
+
if @@use_slim
|
75
|
+
inside('lib') do # arbitrary, run in context of newly generated app
|
76
|
+
run "erb2slim '../app/views/devise' '../app/views/devise'"
|
77
|
+
run "erb2slim -d '../app/views/devise'"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
customize_devise_views if adding_first_and_last_name
|
82
|
+
customize_application_controller_for_devise(adding_first_and_last_name)
|
83
|
+
customize_resource_controller_for_devise(adding_first_and_last_name)
|
84
|
+
add_views_for_devise_resource(adding_first_and_last_name)
|
85
|
+
authorize_devise_resource_for_index_action
|
86
|
+
add_canard_roles_to_devise_resource
|
87
|
+
update_devise_initializer
|
88
|
+
add_sign_in_and_sign_out_routes_for_devise
|
89
|
+
customize_user_factory(adding_first_and_last_name)
|
90
|
+
generate_seeder_templates(using_devise: true)
|
91
|
+
else
|
92
|
+
generate_seeder_templates(using_devise: false)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def customize_devise_views
|
97
|
+
%w(edit new).each do |file|
|
98
|
+
if @@use_slim
|
99
|
+
file_path = "app/views/devise/registrations/#{file}.html.slim"
|
100
|
+
inject_into_file file_path, before: " = f.input :email, required: true, autofocus: true" do <<-'RUBY'.gsub(/^ {8}/, '')
|
101
|
+
= f.input :first_name, required: true, autofocus: true
|
102
|
+
= f.input :last_name, required: true
|
103
|
+
RUBY
|
104
|
+
end
|
105
|
+
else
|
106
|
+
file_path = "app/views/devise/registrations/#{file}.html.erb"
|
107
|
+
inject_into_file file_path, before: " <%= f.input :email, required: true, autofocus: true %>" do <<-'RUBY'.gsub(/^ {8}/, '')
|
108
|
+
<%= f.input :first_name, required: true, autofocus: true %>
|
109
|
+
<%= f.input :last_name, required: true %>
|
110
|
+
RUBY
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def customize_application_controller_for_devise(adding_first_and_last_name)
|
117
|
+
inject_into_file 'app/controllers/application_controller.rb', after: " protect_from_forgery with: :exception" do <<-RUBY.gsub(/^ {6}/, '').gsub(/^ {8}\n/, '')
|
118
|
+
\n
|
119
|
+
before_action :configure_permitted_parameters, if: :devise_controller?
|
120
|
+
|
121
|
+
protected
|
122
|
+
|
123
|
+
def configure_permitted_parameters
|
124
|
+
devise_parameter_sanitizer.for(:sign_up) do |u|
|
125
|
+
u.permit(
|
126
|
+
#{':first_name,' if adding_first_and_last_name}
|
127
|
+
#{':last_name,' if adding_first_and_last_name}
|
128
|
+
:email,
|
129
|
+
:password,
|
130
|
+
:password_confirmation,
|
131
|
+
:remember_me,
|
132
|
+
)
|
133
|
+
end
|
134
|
+
|
135
|
+
devise_parameter_sanitizer.for(:sign_in) do |u|
|
136
|
+
u.permit(:login, :email, :password, :remember_me)
|
137
|
+
end
|
138
|
+
|
139
|
+
devise_parameter_sanitizer.for(:account_update) do |u|
|
140
|
+
u.permit(
|
141
|
+
#{':first_name,' if adding_first_and_last_name}
|
142
|
+
#{':last_name,' if adding_first_and_last_name}
|
143
|
+
:email,
|
144
|
+
:password,
|
145
|
+
:password_confirmation,
|
146
|
+
:current_password,
|
147
|
+
)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
RUBY
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def customize_resource_controller_for_devise(adding_first_and_last_name)
|
155
|
+
bundle_command "exec rails generate controller users"
|
156
|
+
|
157
|
+
inject_into_class "app/controllers/users_controller.rb", "UsersController" do <<-RUBY.gsub(/^ {6}/, '')
|
158
|
+
# https://github.com/CanCanCommunity/cancancan/wiki/authorizing-controller-actions
|
159
|
+
load_and_authorize_resource only: [:index, :show]
|
160
|
+
RUBY
|
161
|
+
end
|
162
|
+
|
163
|
+
unless adding_first_and_last_name
|
164
|
+
inject_into_file 'config/routes.rb', after: ' devise_for :users' do <<-RUBY.gsub(/^ {8}/, '')
|
165
|
+
\n
|
166
|
+
resources :users
|
167
|
+
RUBY
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
def add_views_for_devise_resource(adding_first_and_last_name)
|
173
|
+
config = { adding_first_and_last_name: adding_first_and_last_name }
|
174
|
+
template '../templates/users_index.html.slim.erb', 'app/views/users/index.html.slim', config
|
175
|
+
end
|
176
|
+
|
177
|
+
def authorize_devise_resource_for_index_action
|
178
|
+
generate "canard:ability user can:manage:user cannot:destroy:user"
|
179
|
+
generate "canard:ability admin can:destroy:user"
|
180
|
+
|
181
|
+
%w(admins users).each do |resource_name|
|
182
|
+
replace_in_file "spec/abilities/#{resource_name}_spec.rb", 'Factory.create', 'build_stubbed'
|
183
|
+
replace_in_file "spec/abilities/#{resource_name}_spec.rb", "require_relative '../spec_helper'", "require 'rails_helper'"
|
184
|
+
replace_in_file "spec/abilities/#{resource_name}_spec.rb", 'require "cancan/matchers"', "require_relative '../support/matchers/custom_cancan'"
|
185
|
+
# NOTE: (2016-02-09) jonk => this replaces both should and should_not and results in is_expected.to_not in the latter case
|
186
|
+
replace_in_file "spec/abilities/#{resource_name}_spec.rb", 'should', "is_expected.to"
|
187
|
+
end
|
188
|
+
|
189
|
+
replace_in_file 'spec/abilities/users_spec.rb', ':user_user', ':user'
|
190
|
+
replace_in_file 'spec/abilities/admins_spec.rb', ':admin_user', ':user, :admin'
|
191
|
+
replace_in_file 'spec/abilities/admins_spec.rb', '@user = build_stubbed(:user, :admin)', '@admin = build_stubbed(:user, :admin)'
|
192
|
+
replace_in_file 'spec/abilities/admins_spec.rb', 'subject { Ability.new(@user) }', 'subject { Ability.new(@admin) }'
|
193
|
+
|
194
|
+
generate "migration add_roles_mask_to_users roles_mask:integer"
|
195
|
+
template '../templates/custom_cancan_matchers.rb', 'spec/support/matchers/custom_cancan.rb'
|
196
|
+
end
|
197
|
+
|
198
|
+
def add_canard_roles_to_devise_resource
|
199
|
+
inject_into_file 'app/models/user.rb', before: /^end/ do <<-RUBY.gsub(/^ {6}/, '')
|
200
|
+
\n
|
201
|
+
# Permissions cascade/inherit through the roles listed below. The order of
|
202
|
+
# this list is important, it should progress from least to most privelage
|
203
|
+
ROLES = [:admin].freeze
|
204
|
+
acts_as_user roles: ROLES
|
205
|
+
roles ROLES
|
206
|
+
RUBY
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
def update_devise_initializer
|
211
|
+
replace_in_file 'config/initializers/devise.rb',
|
212
|
+
'config.sign_out_via = :delete', 'config.sign_out_via = :get'
|
213
|
+
|
214
|
+
replace_in_file 'config/initializers/devise.rb',
|
215
|
+
"config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com'",
|
216
|
+
"config.mailer_sender = 'user@example.com'"
|
217
|
+
end
|
218
|
+
|
219
|
+
def add_sign_in_and_sign_out_routes_for_devise
|
220
|
+
inject_into_file 'config/routes.rb', before: /^end/ do <<-RUBY.gsub(/^ {6}/, '')
|
221
|
+
authenticated :user do
|
222
|
+
# root to: 'dashboard#show', as: :authenticated_root
|
223
|
+
end
|
224
|
+
|
225
|
+
devise_scope :user do
|
226
|
+
get 'sign-in', to: 'devise/sessions#new'
|
227
|
+
get 'sign-out', to: 'devise/sessions#destroy'
|
228
|
+
end
|
229
|
+
RUBY
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
def customize_user_factory(adding_first_and_last_name)
|
234
|
+
inject_into_file 'spec/factories/users.rb', before: /^ end/ do <<-'RUBY'.gsub(/^ {4}/, '')
|
235
|
+
password 'password'
|
236
|
+
sequence(:email) { |n| "user_#{n}@example.com" }
|
237
|
+
|
238
|
+
trait :admin do
|
239
|
+
roles [:admin]
|
240
|
+
sequence(:email) { |n| "admin_#{n}@example.com" }
|
241
|
+
end
|
242
|
+
RUBY
|
243
|
+
end
|
244
|
+
|
245
|
+
if adding_first_and_last_name
|
246
|
+
inject_into_file 'spec/factories/users.rb', after: /roles \[:admin\]\n/ do <<-'RUBY'.gsub(/^ {4}/, '')
|
247
|
+
first_name 'Admin'
|
248
|
+
last_name 'User'
|
249
|
+
RUBY
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|
253
|
+
# ----------------
|
254
|
+
# END DEVISE SETUP
|
255
|
+
# ----------------
|
256
|
+
|
257
|
+
def generate_seeder_templates(using_devise:)
|
258
|
+
config = { force: true, using_devise: true }
|
259
|
+
template '../templates/seeder.rb.erb', 'lib/seeder.rb', config
|
260
|
+
template '../templates/seeds.rb.erb', 'db/seeds.rb', config
|
261
|
+
end
|
262
|
+
|
263
|
+
def customize_application_js
|
264
|
+
template '../templates/application.js', 'app/assets/javascripts/application.js', force: true
|
265
|
+
end
|
266
|
+
|
267
|
+
def require_files_in_lib
|
268
|
+
create_file 'config/initializers/require_files_in_lib.rb',
|
269
|
+
"Dir[File.join(Rails.root, 'lib', '**', '*.rb')].each { |l| require l }\n"
|
270
|
+
end
|
271
|
+
|
272
|
+
def generate_ruby_version_and_gemset
|
273
|
+
create_file '.ruby-gemset', "#{app_name}\n"
|
274
|
+
end
|
275
|
+
|
276
|
+
def generate_data_migrations
|
277
|
+
generate 'data_migrations:install'
|
278
|
+
|
279
|
+
empty_directory_with_keep_file 'db/data_migrate'
|
280
|
+
end
|
281
|
+
|
282
|
+
def add_high_voltage_static_pages
|
283
|
+
template '../templates/about.html.erb', "app/views/pages/about.html.#{@@use_slim ? 'slim' : 'erb'}"
|
284
|
+
template '../templates/welcome.html.erb', "app/views/pages/welcome.html.erb"
|
285
|
+
|
286
|
+
inject_into_file 'config/routes.rb', before: /^end/ do <<-RUBY.gsub(/^ {6}/, '')
|
287
|
+
root 'high_voltage/pages#show', id: 'welcome'
|
288
|
+
RUBY
|
289
|
+
end
|
290
|
+
|
291
|
+
create_file 'config/initializers/high_voltage.rb' do <<-RUBY.gsub(/^ {8}/, '')
|
292
|
+
HighVoltage.configure do |config|
|
293
|
+
config.route_drawer = HighVoltage::RouteDrawers::Root
|
294
|
+
end
|
295
|
+
RUBY
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
|
300
|
+
# -------------------------
|
301
|
+
# ADDING REFILLS COMPONENTS
|
302
|
+
# -------------------------
|
303
|
+
def generate_refills
|
304
|
+
if @@accept_defaults || agree?('Would you like to install default Refill components? (Y/n)')
|
305
|
+
bundle_command 'exec rails generate refills:import navigation'
|
306
|
+
bundle_command 'exec rails generate refills:import footer'
|
307
|
+
|
308
|
+
convert_refill_views if @@use_slim
|
309
|
+
add_refills_to_layout
|
310
|
+
add_refills_to_stylesheets
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
def convert_refill_views
|
315
|
+
inside('lib') do # arbitrary, run in context of newly generated app
|
316
|
+
run "erb2slim '../app/views/refills' '../app/views/refills'"
|
317
|
+
run "erb2slim -d '../app/views/refills'"
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
321
|
+
def add_refills_to_layout
|
322
|
+
if @@use_slim
|
323
|
+
inject_into_file 'app/views/layouts/application.html.slim', before: ' = yield' do <<-RUBY.gsub(/^ {8}/, '')
|
324
|
+
= render 'refills/navigation'
|
325
|
+
RUBY
|
326
|
+
end
|
327
|
+
inject_into_file 'app/views/layouts/application.html.slim', before: ' = render "javascript"' do <<-RUBY.gsub(/^ {8}/, '')
|
328
|
+
= render 'refills/footer'
|
329
|
+
RUBY
|
330
|
+
end
|
331
|
+
else
|
332
|
+
inject_into_file 'app/views/layouts/application.html.erb', before: ' <%= yield %>' do <<-RUBY.gsub(/^ {8}/, '')
|
333
|
+
<%= render 'refills/navigation' %>
|
334
|
+
RUBY
|
335
|
+
end
|
336
|
+
inject_into_file 'app/views/layouts/application.html.erb', before: ' <%= render "javascript" %>' do <<-RUBY.gsub(/^ {8}/, '')
|
337
|
+
<%= render 'refills/footer' %>
|
338
|
+
RUBY
|
339
|
+
end
|
340
|
+
end
|
341
|
+
end
|
342
|
+
|
343
|
+
def add_refills_to_stylesheets
|
344
|
+
inject_into_file 'app/assets/stylesheets/application.scss', after: '@import "refills/flashes";' do <<-RUBY.gsub(/^ {8}/, '')
|
345
|
+
\n@import "refills/navigation";
|
346
|
+
@import "refills/footer";
|
347
|
+
RUBY
|
348
|
+
end
|
349
|
+
end
|
350
|
+
# -----------------------------
|
351
|
+
# END ADDING REFILLS COMPONENTS
|
352
|
+
# -----------------------------
|
353
|
+
|
354
|
+
def generate_test_environment
|
355
|
+
template '../templates/controller_helpers.rb', 'spec/support/controller_helpers.rb'
|
356
|
+
template '../templates/simplecov.rb', '.simplecov'
|
357
|
+
end
|
358
|
+
|
359
|
+
def update_test_environment
|
360
|
+
inject_into_file 'spec/support/factory_girl.rb', before: /^end/ do <<-RUBY.gsub(/^ {6}/, '')
|
361
|
+
|
362
|
+
# Spring doesn't reload factory_girl
|
363
|
+
config.before(:all) do
|
364
|
+
FactoryGirl.reload
|
365
|
+
end
|
366
|
+
RUBY
|
367
|
+
end
|
368
|
+
|
369
|
+
template "../templates/rails_helper.rb.erb", "spec/rails_helper.rb", force: true
|
370
|
+
end
|
371
|
+
|
372
|
+
# Do this last
|
373
|
+
def rake_db_setup
|
374
|
+
rake 'db:migrate'
|
375
|
+
rake 'db:seed' if File.exist?('config/initializers/devise.rb')
|
376
|
+
end
|
377
|
+
|
378
|
+
def configure_rvm_prepend_bin_to_path
|
379
|
+
run "rm -f $rvm_path/hooks/after_cd_bundler"
|
380
|
+
|
381
|
+
run "touch $rvm_path/hooks/after_cd_bundler"
|
382
|
+
|
383
|
+
git_safe_dir = <<-RUBY.gsub(/^ {8}/, '')
|
384
|
+
#!/usr/bin/env bash
|
385
|
+
export PATH=".git/safe/../../bin:$PATH"
|
386
|
+
RUBY
|
387
|
+
|
388
|
+
run "echo '#{git_safe_dir}' >> $rvm_path/hooks/after_cd_bundler"
|
389
|
+
|
390
|
+
run 'chmod +x $rvm_path/hooks/after_cd_bundler'
|
391
|
+
|
392
|
+
run 'mkdir -p .git/safe'
|
393
|
+
end
|
394
|
+
|
395
|
+
###############################
|
396
|
+
# OVERRIDE SUSPENDERS METHODS #
|
397
|
+
###############################
|
398
|
+
def configure_generators
|
399
|
+
config = <<-RUBY.gsub(/^ {4}/, '')
|
400
|
+
config.generators do |g|
|
401
|
+
g.helper false
|
402
|
+
g.javascript_engine false
|
403
|
+
g.request_specs false
|
404
|
+
g.routing_specs false
|
405
|
+
g.stylesheets false
|
406
|
+
g.test_framework :rspec
|
407
|
+
g.view_specs false
|
408
|
+
g.fixture_replacement :factory_girl, dir: 'spec/factories'
|
409
|
+
g.template_engine :slim
|
410
|
+
end
|
411
|
+
RUBY
|
412
|
+
|
413
|
+
inject_into_class 'config/application.rb', 'Application', config
|
414
|
+
end
|
415
|
+
|
416
|
+
def set_ruby_to_version_being_used
|
417
|
+
create_file '.ruby-version', "#{Voyage::RUBY_VERSION}\n"
|
418
|
+
end
|
419
|
+
|
420
|
+
# --------------------------------
|
421
|
+
# setup_test_environment overrides
|
422
|
+
# --------------------------------
|
423
|
+
def generate_factories_file
|
424
|
+
# NOTE: (2016-02-03) jonk => don't want this
|
425
|
+
end
|
426
|
+
|
427
|
+
def configure_ci
|
428
|
+
template "circle.yml.erb", "circle.yml"
|
429
|
+
end
|
430
|
+
|
431
|
+
def configure_background_jobs_for_rspec
|
432
|
+
run 'rails g delayed_job:active_record'
|
433
|
+
end
|
434
|
+
|
435
|
+
def configure_capybara_webkit
|
436
|
+
# NOTE: (2016-02-03) jonk => don't want this
|
437
|
+
end
|
438
|
+
# ------------------------------------
|
439
|
+
# End setup_test_environment overrides
|
440
|
+
# ------------------------------------
|
441
|
+
|
442
|
+
|
443
|
+
# -------------
|
444
|
+
# Configure App
|
445
|
+
# -------------
|
446
|
+
def configure_active_job
|
447
|
+
configure_application_file(
|
448
|
+
"config.active_job.queue_adapter = :delayed_job"
|
449
|
+
)
|
450
|
+
configure_environment "test", "config.active_job.queue_adapter = :inline"
|
451
|
+
end
|
452
|
+
|
453
|
+
def configure_puma
|
454
|
+
# NOTE: (2016-02-03) jonk => don't want this
|
455
|
+
end
|
456
|
+
|
457
|
+
def set_up_forego
|
458
|
+
# NOTE: (2016-02-03) jonk => don't want this
|
459
|
+
end
|
460
|
+
# -----------------
|
461
|
+
# End Configure App
|
462
|
+
# -----------------
|
463
|
+
|
464
|
+
|
465
|
+
def remove_config_comment_lines
|
466
|
+
# NOTE: (2016-02-09) jonk => don't want this
|
467
|
+
end
|
468
|
+
end
|
469
|
+
end
|