myrails 6.0.0 → 7.0.0

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 (60) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +48 -30
  3. data/lib/myrails.rb +46 -122
  4. data/lib/myrails/modules/application_generator_actions.rb +61 -0
  5. data/lib/myrails/modules/application_generators.rb +80 -0
  6. data/lib/myrails/modules/assets.rb +28 -2
  7. data/lib/myrails/modules/bootstrap.rb +16 -12
  8. data/lib/myrails/modules/capistrano.rb +11 -6
  9. data/lib/myrails/modules/database_generator.rb +33 -0
  10. data/lib/myrails/modules/database_generator_actions.rb +18 -0
  11. data/lib/myrails/modules/devise.rb +11 -5
  12. data/lib/myrails/modules/dotenv.rb +30 -6
  13. data/lib/myrails/modules/draper.rb +29 -0
  14. data/lib/myrails/modules/engine_generator_actions.rb +117 -0
  15. data/lib/myrails/modules/engine_generators.rb +66 -0
  16. data/lib/myrails/modules/figaro.rb +18 -2
  17. data/lib/myrails/modules/gems.rb +7 -2
  18. data/lib/myrails/modules/heroku.rb +28 -9
  19. data/lib/myrails/modules/material.rb +23 -13
  20. data/lib/myrails/modules/pundit.rb +30 -6
  21. data/lib/myrails/modules/rails_generator_actions.rb +110 -0
  22. data/lib/myrails/modules/rails_generators.rb +49 -95
  23. data/lib/myrails/modules/rspec.rb +70 -40
  24. data/lib/myrails/modules/rspec_generator_actions.rb +56 -0
  25. data/lib/myrails/modules/rspec_generators.rb +36 -35
  26. data/lib/myrails/modules/ui.rb +24 -7
  27. data/lib/myrails/templates/rails/app/assets/javascripts/application.js +0 -4
  28. data/lib/myrails/templates/rails/app/controllers/controller.rb +6 -6
  29. data/lib/myrails/templates/rails/app/controllers/namespace_controller.rb +1 -1
  30. data/lib/myrails/templates/rails/app/decorators/application_decorator.rb +10 -0
  31. data/lib/myrails/templates/rails/app/decorators/decoration.rb +13 -0
  32. data/lib/myrails/templates/rails/app/helpers/application_helper.rb +0 -7
  33. data/lib/myrails/templates/rails/app/mailers/dev_mail_interceptor.rb +1 -1
  34. data/lib/myrails/templates/rails/app/models/model.rb +1 -1
  35. data/lib/myrails/templates/rails/app/models/namespace_model.rb +2 -2
  36. data/lib/myrails/templates/rails/app/policies/pundit.rb +2 -8
  37. data/lib/myrails/templates/rails/app/presenters/presenter.rb +5 -5
  38. data/lib/myrails/templates/rails/app/presenters/presenter_spec.rb +4 -4
  39. data/lib/myrails/templates/rails/app/views/layout/material/footer.html.haml +24 -0
  40. data/lib/myrails/templates/rails/config/application.example.yml +23 -23
  41. data/lib/myrails/templates/rails/config/initializers/sendgrid.rb +10 -0
  42. data/lib/myrails/templates/spec/controller.rb +37 -37
  43. data/lib/myrails/templates/spec/decorator_spec.rb +16 -0
  44. data/lib/myrails/templates/spec/factory.rb +1 -1
  45. data/lib/myrails/templates/spec/feature.rb +2 -2
  46. data/lib/myrails/templates/spec/helper.rb +1 -1
  47. data/lib/myrails/templates/spec/model.rb +1 -1
  48. data/lib/myrails/templates/spec/pundit.rb +5 -4
  49. data/lib/myrails/templates/spec/request.rb +27 -27
  50. data/lib/myrails/templates/spec/shared_example.rb +2 -2
  51. data/lib/myrails/templates/{rails/app/presenters/presenter_config.rb → spec/support/configs/decorator_presenter.rb} +0 -0
  52. data/lib/myrails/templates/ui/ui_controller.rb +1 -1
  53. data/lib/myrails/version.rb +1 -1
  54. data/myrails.gemspec +3 -3
  55. metadata +24 -15
  56. data/lib/myrails/modules/application.rb +0 -13
  57. data/lib/myrails/modules/database.rb +0 -15
  58. data/lib/myrails/modules/engine.rb +0 -107
  59. data/lib/myrails/modules/footnotes.rb +0 -19
  60. data/lib/myrails/templates/rails/app/mailers/sendgrid.rb +0 -8
@@ -2,15 +2,41 @@ module Install
2
2
  module Assets
3
3
  def self.included(thor)
4
4
  thor.class_eval do
5
-
6
- def install_assets
5
+
6
+ desc 'remove_css_manifest', 'delete application.css stylesheet'
7
+ def remove_css_manifest
7
8
  run "rm app/assets/stylesheets/application.css"
9
+ end
10
+
11
+ desc 'generate_sass_manifest', 'create applicatin.css.sass manifest'
12
+ def generate_sass_manifest
8
13
  copy_file 'rails/app/assets/stylesheets/application.css.sass', 'app/assets/stylesheets/application.css.sass'
14
+ end
15
+
16
+ desc 'generate_js_manifest', 'create application.js manifest'
17
+ def generate_js_manifest
9
18
  copy_file 'rails/app/assets/javascripts/application.js', 'app/assets/javascripts/application.js'
19
+ end
20
+
21
+ desc 'generate_animate_css', 'create animate.css file'
22
+ def generate_animate_css
10
23
  copy_file 'rails/app/assets/stylesheets/animate.scss', 'app/assets/stylesheets/animate.scss'
24
+ end
25
+
26
+ desc 'generate_will_paginate', 'create will paginate css'
27
+ def generate_will_paginate
11
28
  copy_file 'rails/app/assets/stylesheets/will_paginate.scss', 'app/assets/stylesheets/will_paginate.scss'
12
29
  end
13
30
 
31
+ desc 'setup_assets', 'install CSS librarys and configure CSS & JS manifests'
32
+ def setup_assets
33
+ remove_css_manifest
34
+ generate_sass_manifest
35
+ generate_js_manifest
36
+ generate_animate_css
37
+ generate_will_paginate
38
+ end
39
+
14
40
  end
15
41
  end
16
42
  end
@@ -1,16 +1,19 @@
1
1
  module Layout
2
2
  module Bootstrap
3
+
3
4
  def self.included(thor)
4
5
  thor.class_eval do
6
+
7
+ desc 'choose_bootstrap_theme', 'Select a bootswatch.com bootstrap theme'
5
8
  def choose_bootstrap_theme
6
- themes = Dir[File.join(@templates, 'rails', 'app','assets', 'stylesheets', 'bootstrap', 'bootstrap_themes', '*')]
9
+ themes = Dir[File.join("#{__dir__}", '..', 'templates', 'rails', 'app','assets', 'stylesheets', 'bootstrap', 'bootstrap_themes', '*')]
7
10
 
8
11
  themes.each_with_index do |theme, index|
9
12
  say "[#{index}] #{File.basename(theme,'.*')}"
10
13
  end
11
14
 
12
- idx = ask("Choose a color theme (by number) for the application. Default: 'spacelab'")
13
- idx = idx.empty? ? themes.index{|theme| theme if theme.include?('spacelab')} : idx.to_i
15
+ idx = ask "Choose a color theme (by number) for the application. Default: ", :yellow,
16
+ default: themes.index{|theme| theme if theme.include?('spacelab')}
14
17
 
15
18
  copy_file(themes[idx], "app/assets/stylesheets/#{File.basename(themes[idx])}")
16
19
 
@@ -20,16 +23,17 @@ module Layout
20
23
  end
21
24
  end
22
25
 
26
+ desc 'choose_bootstrap_footer', 'Select a bootstrap footer template'
23
27
  def choose_bootstrap_footer
24
- footers = Dir[File.join(@templates, 'rails', 'app', 'views','layout', 'bootstrap', 'footers', '*.haml')]
25
- footers_css = Dir[File.join(@templates, 'rails', 'app', 'views', 'layout', 'bootstrap', 'footers', 'css', '*')]
28
+ footers = Dir[File.join("#{__dir__}", '..', 'templates', 'rails', 'app', 'views','layout', 'bootstrap', 'footers', '*.haml')]
29
+ footers_css = Dir[File.join("#{__dir__}", '..', 'templates', 'rails', 'app', 'views', 'layout', 'bootstrap', 'footers', 'css', '*')]
26
30
 
27
31
  footers.each_with_index do |footer, index|
28
32
  say "[#{index}] #{File.basename(footer,'.html.*')}"
29
33
  end
30
34
 
31
- idx = ask("Chose a footer theme (by number) for the application. Deault: 'footer-distributed (Basic)'")
32
- idx = idx.empty? ? footers.index{|footer| footer if footer.include?('footer-distributed.html.haml')} : idx.to_i
35
+ idx = ask "Chose a footer theme (by number) for the application. Deault: ", :yellow, default: footers.index{|footer| footer if footer.include?('footer-distributed.html.haml')}
36
+
33
37
  copy_file footers[idx], "app/views/layouts/_footer.html.haml"
34
38
  copy_file footers_css[idx], "app/assets/stylesheets/#{File.basename(footers_css[idx])}"
35
39
 
@@ -38,19 +42,18 @@ module Layout
38
42
  CODE
39
43
  end
40
44
  end
41
-
45
+
46
+ desc 'copy_bootstrap_files', 'generate layout navigation and flash messages'
42
47
  def copy_bootstrap_files
43
48
  template 'rails/app/views/layout/bootstrap/application.html.haml', 'app/views/layouts/application.html.haml'
44
49
  template 'rails/app/views/layout/bootstrap/_nav.html.haml', 'app/views/layouts/_nav.html.haml'
45
50
  copy_file 'rails/app/views/layout/bootstrap/_info_messages.html.haml', 'app/views/layouts/_info_messages.html.haml'
46
51
  copy_file 'rails/app/views/layout/bootstrap/_success_message.html.haml', 'app/views/layouts/_success_message.html.haml'
47
52
  copy_file 'rails/app/views/layout/bootstrap/_error_messages.html.haml', 'app/views/layouts/_error_messages.html.haml'
48
- # copy_file 'rails/app/views/layout/bootstrap/_footer.html.haml', 'app/views/layouts/_footer.html.haml'
49
53
  end
50
54
 
51
- desc 'install_bootstrap', 'Generate Bootrap css theme'
52
- def install_bootstrap
53
- @templates = "#{__dir__}/../templates"
55
+ desc 'setup_bootstrap', 'Generate layout using Bootrap CSS Framework'
56
+ def setup_bootstrap
54
57
 
55
58
  insert_into_file 'Gemfile', after: "gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]\n" do <<-CODE
56
59
  gem 'bootstrap-sass', '~> 3.3.1'
@@ -68,6 +71,7 @@ CODE
68
71
  //= require bootstrap-sprockets
69
72
  CODE
70
73
  end
74
+
71
75
  run 'bundle install'
72
76
  choose_bootstrap_theme
73
77
  choose_bootstrap_footer
@@ -2,7 +2,8 @@ module Install
2
2
  module Capistrano
3
3
  def self.included(thor)
4
4
  thor.class_eval do
5
-
5
+
6
+ desc 'add_capistrano_gems', 'Add campistrano to Gemfile and install'
6
7
  def add_capistrano_gems
7
8
  insert_into_file 'Gemfile', after: "group :development do\n" do <<-CODE
8
9
  gem 'capistrano', '~> 3.6', group: :development
@@ -13,7 +14,8 @@ CODE
13
14
 
14
15
  run 'bundle install'
15
16
  end
16
-
17
+
18
+ desc 'configure_capfile', 'Add required libraries to capistrano capfile'
17
19
  def configure_capfile
18
20
  gsub_file 'Capfile', '# require "capistrano/rvm"', 'require "capistrano/rvm"'
19
21
 
@@ -23,6 +25,7 @@ CODE
23
25
  end
24
26
  end
25
27
 
28
+ desc 'configure_deploy', 'Add default options to capistrano deploy file'
26
29
  def configure_deploy
27
30
  gsub_file 'config/deploy.rb', '# ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp', 'ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp'
28
31
  gsub_file 'config/deploy.rb', '# set :deploy_to, "/var/www/my_app_name"', 'set :deploy_to, "/var/www/#{fetch(:application)}"'
@@ -35,14 +38,14 @@ set :ssh_options, {forward_agent: true}
35
38
  end
36
39
  end
37
40
 
41
+ desc 'copy_templates', 'Add capistrano templates used to manage the remote server'
38
42
  def copy_templates
39
- puts __dir__
40
- Dir["#{__dir__}/../templates/capistrano/**/*"].each do |file|
41
- puts file
43
+ Dir[File.join("#{__dir__}", "..", "templates","capistrano","**","*")].each do |file|
42
44
  copy_file file, "#{file.gsub(__dir__+'/../templates/capistrano/', '')}" unless File.directory? file
43
45
  end
44
46
  end
45
47
 
48
+ desc 'configure_env_files', 'Configure capistrano environemnt specific information'
46
49
  def configure_env_files
47
50
  insert_into_file 'config/deploy/production.rb', before: "# role-based syntax" do <<-CODE
48
51
  set :fqdn,'domain.com'
@@ -55,6 +58,7 @@ set :fqdn,'domain.com'
55
58
  end
56
59
  end
57
60
 
61
+ desc 'add_tasks', 'Add custom deploy tasks to capistrano deploy file'
58
62
  def add_tasks
59
63
  insert_into_file 'config/deploy.rb', after: "# set :ssh_options, verify_host_key: :secure\n" do <<-CODE
60
64
  namespace :deploy do
@@ -94,7 +98,8 @@ set :fqdn,'domain.com'
94
98
  end
95
99
  end
96
100
 
97
- def install_capistrano
101
+ desc 'setup_capistrano', 'Run all capistrano setup actions in order'
102
+ def setup_capistrano
98
103
  add_capistrano_gems
99
104
  run 'bundle exec cap install'
100
105
  configure_capfile
@@ -0,0 +1,33 @@
1
+ module Database
2
+ module Generators
3
+ def self.included(thor)
4
+ thor.class_eval do
5
+
6
+ desc 'db <OPTION>', 'Execute without options to see HELP.'
7
+ def db(*opts)
8
+ item = opts[0]
9
+
10
+ option = {
11
+ mysql_switch: 'Switch DB from SQLITE3 to MySQL'
12
+ }
13
+
14
+ unless item
15
+ say 'ERROR: "myrails db" was called with no arguments'
16
+ say 'Usage: "myrails db <OPTION> <NAME>"'
17
+ say "Available Options:\n"
18
+ option.each{|k,v| say "* #{k}: #{v}"}
19
+ exit
20
+ end
21
+
22
+ case item
23
+ when 'mysql_switch'
24
+ mysql_switch
25
+ else
26
+ say "Unknown Action!"
27
+ end
28
+ end
29
+
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,18 @@
1
+ module Database
2
+ module Generator
3
+ module Actions
4
+ def self.included(thor)
5
+ thor.class_eval do
6
+
7
+ desc 'mysql_switch', 'Convert a rails database configuration from sqlite3 to mysql2'
8
+ def mysql_switch
9
+ gsub_file 'Gemfile', "gem 'sqlite3'", "gem 'mysql2'"
10
+ run 'bundle install'
11
+ copy_file 'db/mysql_database.yml', 'config/database.yml'
12
+ end
13
+
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -3,6 +3,7 @@ module Install
3
3
  def self.included(thor)
4
4
  thor.class_eval do
5
5
 
6
+ desc 'add_gem', 'Add devise to Gemfile and run bundler'
6
7
  def add_gem
7
8
  insert_into_file 'Gemfile', after: "gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]\n" do <<-CODE
8
9
  gem 'devise'
@@ -11,13 +12,15 @@ CODE
11
12
  run 'bundle update'
12
13
  end
13
14
 
15
+ desc 'add_rspec_config', 'Add RSpec support file for feature and controller tests'
14
16
  def add_rspec_config
15
17
  copy_file 'spec/support/configs/devise.rb', 'spec/support/configs/devise.rb'
16
18
  end
17
19
 
20
+ desc 'configure_devise', 'Genreate devise with a given model name'
18
21
  def configure_devise
19
- @devise_model = ask("What would you like to call the devise model? Default: user")
20
- @devise_model = @devise_model.empty? ? 'user' : @devise_model
22
+ @devise_model = ask "What would you like to call the devise model? Default: ", :yellow, default: 'user'
23
+ # @devise_model = @devise_model.empty? ? 'user' : @devise_model
21
24
  run 'rails generate devise:install'
22
25
  run 'rake db:migrate'
23
26
  run "rails generate devise #{@devise_model}"
@@ -32,6 +35,7 @@ CODE
32
35
  add_additional_fields
33
36
  end
34
37
 
38
+ desc 'configure_ui_controller', 'Add code to not prompt for a login if there is a ui_controller'
35
39
  def configure_ui_controller
36
40
  if File.exist?('app/controllers/ui_controller.rb')
37
41
  inject_into_file 'app/controllers/ui_controller.rb', after: "class UiController < ApplicationController\n" do <<-CODE
@@ -41,8 +45,9 @@ CODE
41
45
  end
42
46
  end
43
47
 
48
+ desc 'add_additional_fields', 'Ask if you want to include additional devise fields like first_name & last_name'
44
49
  def add_additional_fields
45
- if yes?('Will you be needing registration params override? Answer "yes" if you will be adding attributes to the user model')
50
+ if yes? "Will you be needing registration params override? Explicitly answer 'yes' / 'no' if you will be adding attributes to your #{@devise_model} model", :yellow
46
51
  inject_into_file 'app/controllers/application_controller.rb', after: "before_action :authenticate_#{@devise_model}!\n" do <<-CODE
47
52
  # Before action include additional registration params
48
53
  # (see #configure_permitted_parameters)
@@ -59,8 +64,9 @@ CODE
59
64
  end
60
65
  end
61
66
  end
62
-
63
- def install_devise
67
+
68
+ desc 'setup_devise', 'Run devise setup actions in order'
69
+ def setup_devise
64
70
  add_gem
65
71
  add_rspec_config
66
72
  configure_devise
@@ -2,25 +2,49 @@ module Install
2
2
  module DotEnv
3
3
  def self.included(thor)
4
4
  thor.class_eval do
5
-
6
- desc 'install_dotenv', 'Install dotenv gem'
7
- def install_dotenv
5
+
6
+ desc 'add_dotenv_gem', 'Add dotenv gem to Gemfile and run bundler'
7
+ def add_dotenv_gem
8
8
  insert_into_file 'Gemfile', after: "gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]\n" do <<-CODE
9
- gem 'dotenv-rails', groups: [:development, :test]
10
- CODE
9
+ gem 'dotenv-rails', groups: [:development, :test]
10
+ CODE
11
11
  end
12
12
 
13
13
  run 'bundle install'
14
-
14
+ end
15
+
16
+ desc 'require_dotenv', 'Add dotenv to config.ru'
17
+ def require_dotenv
15
18
  inject_into_file 'config.ru', after: "require_relative 'config/environment'\n" do <<-CODE
16
19
  require 'dotenv'
17
20
  Dotenv.load
18
21
  CODE
19
22
  end
23
+ end
24
+
25
+ desc 'create_dev_dotenv', 'Generate deveopment env file'
26
+ def create_dev_dotenv
20
27
  copy_file 'rails/env.config', '.env.development'
28
+ end
29
+
30
+ desc 'create_test_dotenv', 'Generate test env file'
31
+ def create_test_dotenv
21
32
  copy_file 'rails/env.config', '.env.test'
33
+ end
34
+
35
+ desc 'create_prod_dotenv', 'Generate production env file'
36
+ def create_prod_dotenv
22
37
  run 'touch .env.production'
23
38
  end
39
+
40
+ desc 'setup_dotenv', 'Install dotenv gem'
41
+ def setup_dotenv
42
+ add_dotenv_gem
43
+ require_dotenv
44
+ create_dev_dotenv
45
+ create_test_dotenv
46
+ create_prod_dotenv
47
+ end
24
48
 
25
49
  end
26
50
  end
@@ -0,0 +1,29 @@
1
+ module Install
2
+ module Draper
3
+ def self.included(thor)
4
+ thor.class_eval do
5
+
6
+ desc 'add_draper_gem', 'Add draper gem to Gemfile and run bundler'
7
+ def add_draper_gem
8
+ insert_into_file 'Gemfile', after: "gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]\n" do <<-CODE
9
+ gem 'draper'
10
+ CODE
11
+ end
12
+
13
+ run 'bundle install'
14
+ end
15
+
16
+ desc 'create_draper_application_decorator', 'Generate draper application decorator'
17
+ def create_draper_application_decorator
18
+ copy_file 'rails/app/decorators/application_decorator.rb', 'app/decorators/application_decorator.rb'
19
+ end
20
+
21
+ desc 'setup_draper', 'Install draper gem'
22
+ def setup_draper
23
+ add_draper_gem
24
+ create_draper_application_decorator
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,117 @@
1
+ module Engine
2
+ module Generator
3
+ module Actions
4
+ def self.included(thor)
5
+ thor.class_eval do
6
+
7
+ desc 'new_engine', 'Generate a full or mountable engine. default: mountable'
8
+ def new_engine
9
+ type = ask 'Type (mountable or full)? Default: ', :yellow, default: 'mountable'
10
+ run "rails plugin new #{@name} --dummy-path=spec/dummy --skip-test-unit --#{type}"
11
+ end
12
+
13
+ desc 'gemspec_setup', 'Generate gemspec info for a rails engine'
14
+ def gemspec_setup
15
+ @email = ask 'What email address would you like to use for this rails engine?:', :yellow
16
+ @author = ask 'Who is the author of this rails engine?', :yellow
17
+
18
+ gsub_file "#{@name}.gemspec", "s.authors = [\"TODO: Your name\"]", "s.authors = [\"#{@author}\"]"
19
+ gsub_file "#{@name}.gemspec", "s.email = [\"TODO: Your email\"]", "s.email = [\"#{@email}\"]"
20
+ gsub_file "#{@name}.gemspec", 's.homepage = "TODO"', 's.homepage = "http://TBD.com"'
21
+ gsub_file "#{@name}.gemspec", "s.summary = \"TODO: Summary of #{@name.camelize}.\"", "s.summary = \"Summary of #{@name.camelize}.\""
22
+ gsub_file "#{@name}.gemspec", "s.description = \"TODO: Description of #{@name.camelize}.\"", "s.description = \"Description of #{@name.camelize}.\""
23
+
24
+ inject_into_file "#{@name}.gemspec", after: "s.license = \"MIT\"\n" do <<-CODE
25
+ s.test_files = Dir["spec/**/*"]
26
+ CODE
27
+ end
28
+
29
+ gem_setup
30
+ end
31
+
32
+ desc 'gem_setup', 'Generate gem dependencies for a rails engine'
33
+ def gem_setup
34
+ inject_into_file "#{@name}.gemspec", after: "s.add_development_dependency \"sqlite3\"\n" do <<-CODE
35
+ s.add_development_dependency 'rspec-rails'
36
+ s.add_development_dependency 'capybara'
37
+ s.add_development_dependency 'factory_bot_rails'
38
+ s.add_development_dependency "faker"
39
+ s.add_development_dependency "byebug"
40
+ s.add_development_dependency 'rails-controller-testing'
41
+ s.add_development_dependency 'pundit-matchers'
42
+ s.add_development_dependency "simplecov"
43
+ s.add_development_dependency "shoulda-matchers"
44
+ s.add_development_dependency "database_cleaner"
45
+ s.add_dependency 'pundit'
46
+ s.add_dependency 'bootstrap-sass'
47
+ s.add_dependency 'autoprefixer-rails'
48
+ s.add_dependency "haml-rails"
49
+ s.add_dependency "font-awesome-rails"
50
+ s.add_dependency 'record_tag_helper'
51
+ CODE
52
+ end
53
+
54
+ run 'bundle'
55
+ end
56
+
57
+ desc 'rake_setup', 'Generate custom rake file for rails engine'
58
+ def rake_setup
59
+ run 'cp Rakefile Rakefile.bak'
60
+ copy_file 'engines/rakefile', 'Rakefile'
61
+ end
62
+
63
+ desc 'rspec_setup', 'Install and configure rspec for a rails engine'
64
+ def rspec_setup
65
+ run 'rails g rspec:install'
66
+
67
+ gsub_file 'spec/rails_helper.rb', "# Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }", "Dir[File.join(__dir__, 'support', '**', '*.rb')].each { |f| require f }"
68
+
69
+ gsub_file 'spec/rails_helper.rb', "require File.expand_path('../../config/environment', __FILE__)", "require_relative 'dummy/config/environment'"
70
+
71
+ inject_into_file 'spec/rails_helper.rb', after: "require 'rspec/rails'\n" do <<-CODE
72
+ require 'shoulda/matchers'
73
+ require 'factory_bot'
74
+ require 'database_cleaner'
75
+ CODE
76
+ end
77
+
78
+ inject_into_file 'spec/rails_helper.rb', after: "RSpec.configure do |config|\n" do <<-CODE
79
+ config.mock_with :rspec
80
+ config.infer_base_class_for_anonymous_controllers = false
81
+ config.order = "random"
82
+ CODE
83
+ end
84
+
85
+ Dir["#{__dir__}/../templates/spec/support/**/*"].each do |file|
86
+ unless File.directory? file
87
+ copy_file file, "spec/support/#{File.basename(file)}"
88
+ end
89
+ end
90
+ end
91
+
92
+ desc 'engin_setup', 'Configure a rails engine after its generated'
93
+ def engine_setup
94
+ inject_into_file "lib/#{@name}/engine.rb", after: "class Engine < ::Rails::Engine\n" do <<-CODE
95
+ config.generators do |g|
96
+ g.test_framework :rspec, :fixture => false
97
+ g.fixture_replacement :factory_bot, :dir => 'spec/factories'
98
+ g.assets false
99
+ g.helper false
100
+ end
101
+ CODE
102
+ end
103
+ end
104
+
105
+ desc 'auto_setup', 'Configure rails engine for development with RSpec, Capybara and FactoryBot'
106
+ def auto_setup
107
+ engine_setup unless Dir["lib/#{@name}/engine.rb"].empty?
108
+ gemspec_setup
109
+ rake_setup
110
+ rspec_setup
111
+ end
112
+
113
+ end
114
+ end
115
+ end
116
+ end
117
+ end