railties 6.1.6 → 7.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +626 -259
- data/MIT-LICENSE +1 -1
- data/RDOC_MAIN.md +99 -0
- data/README.rdoc +5 -6
- data/lib/minitest/rails_plugin.rb +64 -1
- data/lib/rails/all.rb +0 -1
- data/lib/rails/api/task.rb +35 -4
- data/lib/rails/app_updater.rb +9 -6
- data/lib/rails/application/bootstrap.rb +41 -7
- data/lib/rails/application/configuration.rb +262 -88
- data/lib/rails/application/default_middleware_stack.rb +29 -4
- data/lib/rails/application/dummy_config.rb +19 -0
- data/lib/rails/application/finisher.rb +89 -124
- data/lib/rails/application/routes_reloader.rb +8 -0
- data/lib/rails/application.rb +200 -125
- data/lib/rails/application_controller.rb +3 -3
- data/lib/rails/autoloaders/inflector.rb +21 -0
- data/lib/rails/autoloaders.rb +42 -42
- data/lib/rails/backtrace_cleaner.rb +1 -1
- data/lib/rails/cli.rb +5 -2
- data/lib/rails/code_statistics.rb +2 -2
- data/lib/rails/code_statistics_calculator.rb +10 -1
- data/lib/rails/command/actions.rb +10 -12
- data/lib/rails/command/base.rb +61 -45
- data/lib/rails/command/behavior.rb +1 -1
- data/lib/rails/command/environment_argument.rb +33 -17
- data/lib/rails/command/helpers/editor.rb +17 -12
- data/lib/rails/command.rb +90 -36
- data/lib/rails/commands/about/about_command.rb +14 -0
- data/lib/rails/commands/application/application_command.rb +2 -0
- data/lib/rails/commands/console/console_command.rb +17 -13
- data/lib/rails/commands/credentials/USAGE +53 -53
- data/lib/rails/commands/credentials/credentials_command/diffing.rb +31 -19
- data/lib/rails/commands/credentials/credentials_command.rb +67 -69
- data/lib/rails/commands/db/system/change/change_command.rb +2 -1
- data/lib/rails/commands/dbconsole/dbconsole_command.rb +26 -117
- data/lib/rails/commands/destroy/destroy_command.rb +3 -2
- data/lib/rails/commands/dev/dev_command.rb +1 -6
- data/lib/rails/commands/encrypted/USAGE +15 -20
- data/lib/rails/commands/encrypted/encrypted_command.rb +46 -35
- data/lib/rails/commands/gem_help/USAGE +16 -0
- data/lib/rails/commands/gem_help/gem_help_command.rb +13 -0
- data/lib/rails/commands/generate/generate_command.rb +2 -2
- data/lib/rails/commands/help/USAGE +15 -14
- data/lib/rails/commands/help/help_command.rb +21 -2
- data/lib/rails/commands/initializers/initializers_command.rb +1 -4
- data/lib/rails/commands/middleware/middleware_command.rb +17 -0
- data/lib/rails/commands/new/new_command.rb +2 -0
- data/lib/rails/commands/notes/notes_command.rb +2 -1
- data/lib/rails/commands/plugin/plugin_command.rb +2 -0
- data/lib/rails/commands/rake/rake_command.rb +25 -22
- data/lib/rails/commands/restart/restart_command.rb +14 -0
- data/lib/rails/commands/routes/routes_command.rb +13 -1
- data/lib/rails/commands/runner/USAGE +14 -12
- data/lib/rails/commands/runner/runner_command.rb +34 -21
- data/lib/rails/commands/secret/secret_command.rb +13 -0
- data/lib/rails/commands/secrets/USAGE +44 -49
- data/lib/rails/commands/secrets/secrets_command.rb +20 -38
- data/lib/rails/commands/server/server_command.rb +33 -30
- data/lib/rails/commands/test/USAGE +14 -0
- data/lib/rails/commands/test/test_command.rb +56 -14
- data/lib/rails/commands/unused_routes/unused_routes_command.rb +75 -0
- data/lib/rails/commands/version/version_command.rb +1 -0
- data/lib/rails/configuration.rb +23 -28
- data/lib/rails/console/app.rb +1 -4
- data/lib/rails/console/helpers.rb +2 -2
- data/lib/rails/deprecator.rb +7 -0
- data/lib/rails/engine/configuration.rb +53 -9
- data/lib/rails/engine.rb +63 -48
- data/lib/rails/gem_version.rb +3 -3
- data/lib/rails/generators/actions/create_migration.rb +2 -4
- data/lib/rails/generators/actions.rb +231 -73
- data/lib/rails/generators/active_model.rb +28 -14
- data/lib/rails/generators/app_base.rb +476 -176
- data/lib/rails/generators/app_name.rb +3 -14
- data/lib/rails/generators/base.rb +24 -20
- data/lib/rails/generators/database.rb +39 -1
- data/lib/rails/generators/erb/mailer/templates/layout.html.erb.tt +1 -1
- data/lib/rails/generators/erb/scaffold/scaffold_generator.rb +2 -0
- data/lib/rails/generators/erb/scaffold/templates/_form.html.erb.tt +8 -8
- data/lib/rails/generators/erb/scaffold/templates/edit.html.erb.tt +8 -4
- data/lib/rails/generators/erb/scaffold/templates/index.html.erb.tt +11 -28
- data/lib/rails/generators/erb/scaffold/templates/new.html.erb.tt +7 -3
- data/lib/rails/generators/erb/scaffold/templates/partial.html.erb.tt +17 -0
- data/lib/rails/generators/erb/scaffold/templates/show.html.erb.tt +8 -17
- data/lib/rails/generators/erb.rb +1 -1
- data/lib/rails/generators/generated_attribute.rb +57 -9
- data/lib/rails/generators/migration.rb +2 -7
- data/lib/rails/generators/model_helpers.rb +3 -2
- data/lib/rails/generators/named_base.rb +13 -13
- data/lib/rails/generators/rails/app/USAGE +22 -6
- data/lib/rails/generators/rails/app/app_generator.rb +113 -114
- data/lib/rails/generators/rails/app/templates/Dockerfile.tt +103 -0
- data/lib/rails/generators/rails/app/templates/Gemfile.tt +43 -53
- data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css.tt +2 -2
- data/lib/rails/generators/rails/app/templates/app/mailers/application_mailer.rb.tt +2 -2
- data/lib/rails/generators/rails/app/templates/app/models/application_record.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +3 -9
- data/lib/rails/generators/rails/app/templates/app/views/layouts/mailer.html.erb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/bin/rails.tt +1 -4
- data/lib/rails/generators/rails/app/templates/bin/rake.tt +0 -3
- data/lib/rails/generators/rails/app/templates/bin/setup.tt +16 -12
- data/lib/rails/generators/rails/app/templates/config/application.rb.tt +6 -18
- data/lib/rails/generators/rails/app/templates/config/boot.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml.tt +2 -2
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml.tt +3 -3
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml.tt +7 -7
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml.tt +5 -5
- data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml.tt +3 -3
- data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml.tt +2 -2
- data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml.tt +7 -9
- data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml.tt +4 -4
- data/lib/rails/generators/rails/app/templates/config/databases/sqlserver.yml.tt +5 -5
- data/lib/rails/generators/rails/app/templates/config/databases/trilogy.yml.tt +59 -0
- data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +16 -12
- data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +38 -61
- data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +14 -15
- data/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +3 -5
- data/lib/rails/generators/rails/app/templates/config/initializers/content_security_policy.rb.tt +21 -28
- data/lib/rails/generators/rails/app/templates/config/initializers/cors.rb.tt +3 -3
- data/lib/rails/generators/rails/app/templates/config/initializers/filter_parameter_logging.rb.tt +3 -1
- data/lib/rails/generators/rails/app/templates/config/initializers/inflections.rb.tt +4 -4
- data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_7_1.rb.tt +283 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/permissions_policy.rb.tt +11 -9
- data/lib/rails/generators/rails/app/templates/config/locales/en.yml +13 -15
- data/lib/rails/generators/rails/app/templates/config/puma.rb.tt +12 -20
- data/lib/rails/generators/rails/app/templates/config/routes.rb.tt +8 -1
- data/lib/rails/generators/rails/app/templates/config/storage.yml.tt +5 -5
- data/lib/rails/generators/rails/app/templates/db/seeds.rb.tt +6 -4
- data/lib/rails/generators/rails/app/templates/docker-entrypoint.tt +10 -0
- data/lib/rails/generators/rails/app/templates/dockerignore.tt +43 -0
- data/lib/rails/generators/rails/app/templates/gitattributes.tt +0 -5
- data/lib/rails/generators/rails/app/templates/gitignore.tt +7 -9
- data/lib/rails/generators/rails/app/templates/node-version.tt +1 -0
- data/lib/rails/generators/rails/app/templates/test/channels/application_cable/connection_test.rb.tt +10 -8
- data/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt +10 -8
- data/lib/rails/generators/rails/application_record/application_record_generator.rb +4 -0
- data/lib/rails/generators/rails/benchmark/benchmark_generator.rb +2 -1
- data/lib/rails/generators/rails/controller/USAGE +12 -4
- data/lib/rails/generators/rails/controller/controller_generator.rb +6 -2
- data/lib/rails/generators/rails/controller/templates/controller.rb.tt +1 -5
- data/lib/rails/generators/rails/credentials/credentials_generator.rb +29 -24
- data/lib/rails/generators/rails/credentials/templates/credentials.yml.tt +8 -0
- data/lib/rails/generators/rails/db/system/change/change_generator.rb +31 -1
- data/lib/rails/generators/rails/encryption_key_file/encryption_key_file_generator.rb +1 -2
- data/lib/rails/generators/rails/generator/templates/%file_name%_generator.rb.tt +1 -1
- data/lib/rails/generators/rails/migration/USAGE +21 -11
- data/lib/rails/generators/rails/model/model_generator.rb +4 -0
- data/lib/rails/generators/rails/plugin/USAGE +17 -6
- data/lib/rails/generators/rails/plugin/plugin_generator.rb +69 -30
- data/lib/rails/generators/rails/plugin/templates/%name%.gemspec.tt +7 -3
- data/lib/rails/generators/rails/plugin/templates/Gemfile.tt +9 -31
- data/lib/rails/generators/rails/plugin/templates/MIT-LICENSE.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/README.md.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/app/mailers/%namespaced_name%/application_mailer.rb.tt +2 -2
- data/lib/rails/generators/rails/plugin/templates/app/views/layouts/%namespaced_name%/application.html.erb.tt +0 -3
- data/lib/rails/generators/rails/plugin/templates/bin/rails.tt +5 -20
- data/lib/rails/generators/rails/plugin/templates/gitignore.tt +0 -7
- data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/engine.rb.tt +2 -2
- data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/version.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/rails/boot.rb.tt +2 -2
- data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb.tt +6 -11
- data/lib/rails/generators/rails/resource/resource_generator.rb +6 -0
- data/lib/rails/generators/rails/scaffold/scaffold_generator.rb +2 -20
- data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +1 -1
- data/lib/rails/generators/rails/scaffold_controller/templates/api_controller.rb.tt +1 -5
- data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb.tt +6 -10
- data/lib/rails/generators/resource_helpers.rb +2 -2
- data/lib/rails/generators/test_case.rb +2 -2
- data/lib/rails/generators/test_unit/generator/templates/generator_test.rb.tt +1 -1
- data/lib/rails/generators/test_unit/model/templates/fixtures.yml.tt +2 -2
- data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +4 -4
- data/lib/rails/generators/test_unit/scaffold/templates/api_functional_test.rb.tt +5 -5
- data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb.tt +7 -7
- data/lib/rails/generators/test_unit/scaffold/templates/system_test.rb.tt +9 -11
- data/lib/rails/generators/testing/{behaviour.rb → behavior.rb} +7 -5
- data/lib/rails/generators.rb +14 -29
- data/lib/rails/health_controller.rb +55 -0
- data/lib/rails/info.rb +2 -2
- data/lib/rails/info_controller.rb +31 -13
- data/lib/rails/initializable.rb +1 -1
- data/lib/rails/mailers_controller.rb +17 -9
- data/lib/rails/paths.rb +14 -11
- data/lib/rails/rack/logger.rb +16 -15
- data/lib/rails/rackup/server.rb +15 -0
- data/lib/rails/railtie/configuration.rb +15 -3
- data/lib/rails/railtie.rb +54 -31
- data/lib/rails/ruby_version_check.rb +5 -3
- data/lib/rails/secrets.rb +10 -8
- data/lib/rails/source_annotation_extractor.rb +68 -19
- data/lib/rails/tasks/engine.rake +8 -8
- data/lib/rails/tasks/framework.rake +4 -12
- data/lib/rails/tasks/log.rake +1 -1
- data/lib/rails/tasks/misc.rake +3 -14
- data/lib/rails/tasks/statistics.rake +8 -5
- data/lib/rails/tasks/tmp.rake +13 -6
- data/lib/rails/tasks/yarn.rake +8 -9
- data/lib/rails/tasks/zeitwerk.rake +14 -42
- data/lib/rails/tasks.rb +0 -2
- data/lib/rails/templates/layouts/application.html.erb +15 -0
- data/lib/rails/templates/rails/mailers/email.html.erb +45 -11
- data/lib/rails/templates/rails/mailers/index.html.erb +14 -7
- data/lib/rails/templates/rails/mailers/mailer.html.erb +11 -5
- data/lib/rails/templates/rails/welcome/index.html.erb +65 -48
- data/lib/rails/test_help.rb +13 -14
- data/lib/rails/test_unit/line_filtering.rb +1 -1
- data/lib/rails/test_unit/railtie.rb +0 -4
- data/lib/rails/test_unit/reporter.rb +6 -2
- data/lib/rails/test_unit/runner.rb +45 -20
- data/lib/rails/test_unit/test_parser.rb +88 -0
- data/lib/rails/test_unit/testing.rake +18 -43
- data/lib/rails/testing/maintain_test_schema.rb +16 -0
- data/lib/rails/version.rb +1 -1
- data/lib/rails/welcome_controller.rb +1 -0
- data/lib/rails/zeitwerk_checker.rb +15 -0
- data/lib/rails.rb +26 -15
- metadata +74 -42
- data/RDOC_MAIN.rdoc +0 -97
- data/lib/rails/.DS_Store +0 -0
- data/lib/rails/application/dummy_erb_compiler.rb +0 -18
- data/lib/rails/command/spellchecker.rb +0 -57
- data/lib/rails/generators/css/assets/assets_generator.rb +0 -15
- data/lib/rails/generators/css/assets/templates/stylesheet.css +0 -4
- data/lib/rails/generators/css/scaffold/scaffold_generator.rb +0 -18
- data/lib/rails/generators/rails/app/templates/app/javascript/channels/consumer.js +0 -6
- data/lib/rails/generators/rails/app/templates/app/javascript/channels/index.js +0 -5
- data/lib/rails/generators/rails/app/templates/app/javascript/packs/application.js.tt +0 -23
- data/lib/rails/generators/rails/app/templates/bin/spring.tt +0 -13
- data/lib/rails/generators/rails/app/templates/bin/yarn.tt +0 -16
- data/lib/rails/generators/rails/app/templates/config/initializers/application_controller_renderer.rb.tt +0 -8
- data/lib/rails/generators/rails/app/templates/config/initializers/backtrace_silencers.rb.tt +0 -8
- data/lib/rails/generators/rails/app/templates/config/initializers/cookies_serializer.rb.tt +0 -5
- data/lib/rails/generators/rails/app/templates/config/initializers/mime_types.rb.tt +0 -4
- data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_6_1.rb.tt +0 -67
- data/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt +0 -16
- data/lib/rails/generators/rails/app/templates/config/spring.rb.tt +0 -6
- data/lib/rails/generators/rails/app/templates/package.json.tt +0 -11
- data/lib/rails/generators/rails/assets/USAGE +0 -16
- data/lib/rails/generators/rails/assets/assets_generator.rb +0 -26
- data/lib/rails/generators/rails/assets/templates/stylesheet.css +0 -4
- data/lib/rails/generators/rails/model/USAGE +0 -113
- data/lib/rails/generators/rails/scaffold/templates/scaffold.css +0 -80
- data/lib/rails/tasks/middleware.rake +0 -9
- data/lib/rails/tasks/restart.rake +0 -9
@@ -1,10 +1,21 @@
|
|
1
1
|
Description:
|
2
|
-
The
|
3
|
-
|
4
|
-
|
2
|
+
The `rails plugin new` command creates a Rails plugin with the ability
|
3
|
+
to run tests using a dummy Rails application. A plugin is a gem with
|
4
|
+
either a railtie or an engine.
|
5
5
|
|
6
|
-
|
7
|
-
rails plugin new ~/Code/Ruby/blog
|
6
|
+
Examples:
|
7
|
+
`rails plugin new ~/Code/Ruby/blog`
|
8
8
|
|
9
|
-
This generates a
|
9
|
+
This generates a Rails railtie gem in ~/Code/Ruby/blog.
|
10
10
|
See the README in the newly created plugin to get going.
|
11
|
+
|
12
|
+
`rails plugin new blog --full`
|
13
|
+
|
14
|
+
This generates a full Rails engine gem in ./blog. The `--mountable`
|
15
|
+
option may also be used to generate a mountable, namespace-isolated
|
16
|
+
engine with assets and layouts.
|
17
|
+
|
18
|
+
`rails plugin new blog --mountable --skip-asset-pipeline`
|
19
|
+
|
20
|
+
This generates a mountable Rails engine gem at ./blog without an asset
|
21
|
+
pipeline. Any part of Rails can be skipped during plugin generation.
|
@@ -26,11 +26,15 @@ module Rails
|
|
26
26
|
empty_directory_with_keep_file "app/assets/images/#{namespaced_name}"
|
27
27
|
end
|
28
28
|
|
29
|
+
empty_directory_with_keep_file "app/models/concerns"
|
30
|
+
empty_directory_with_keep_file "app/controllers/concerns"
|
29
31
|
remove_dir "app/mailers" if options[:skip_action_mailer]
|
30
32
|
remove_dir "app/jobs" if options[:skip_active_job]
|
31
33
|
elsif full?
|
32
34
|
empty_directory_with_keep_file "app/models"
|
33
35
|
empty_directory_with_keep_file "app/controllers"
|
36
|
+
empty_directory_with_keep_file "app/models/concerns"
|
37
|
+
empty_directory_with_keep_file "app/controllers/concerns"
|
34
38
|
empty_directory_with_keep_file "app/mailers" unless options[:skip_action_mailer]
|
35
39
|
empty_directory_with_keep_file "app/jobs" unless options[:skip_active_job]
|
36
40
|
|
@@ -51,7 +55,7 @@ module Rails
|
|
51
55
|
end
|
52
56
|
|
53
57
|
def license
|
54
|
-
template "MIT-LICENSE"
|
58
|
+
template "MIT-LICENSE" unless inside_application?
|
55
59
|
end
|
56
60
|
|
57
61
|
def gemspec
|
@@ -64,7 +68,7 @@ module Rails
|
|
64
68
|
|
65
69
|
def version_control
|
66
70
|
if !options[:skip_git] && !options[:pretend]
|
67
|
-
run
|
71
|
+
run git_init_command, capture: options[:quiet], abort_on_failure: false
|
68
72
|
end
|
69
73
|
end
|
70
74
|
|
@@ -87,12 +91,18 @@ module Rails
|
|
87
91
|
def test
|
88
92
|
template "test/test_helper.rb"
|
89
93
|
template "test/%namespaced_name%_test.rb"
|
90
|
-
append_file "Rakefile", <<-EOF
|
91
94
|
|
92
|
-
#{rakefile_test_tasks}
|
93
|
-
task default: :test
|
94
|
-
EOF
|
95
95
|
if engine?
|
96
|
+
empty_directory_with_keep_file "test/fixtures/files"
|
97
|
+
empty_directory_with_keep_file "test/controllers"
|
98
|
+
empty_directory_with_keep_file "test/mailers"
|
99
|
+
empty_directory_with_keep_file "test/models"
|
100
|
+
empty_directory_with_keep_file "test/integration"
|
101
|
+
|
102
|
+
unless api?
|
103
|
+
empty_directory_with_keep_file "test/helpers"
|
104
|
+
end
|
105
|
+
|
96
106
|
template "test/integration/navigation_test.rb"
|
97
107
|
end
|
98
108
|
end
|
@@ -103,11 +113,8 @@ task default: :test
|
|
103
113
|
opts = options.transform_keys(&:to_sym).except(*DUMMY_IGNORE_OPTIONS)
|
104
114
|
opts[:force] = force
|
105
115
|
opts[:skip_bundle] = true
|
106
|
-
opts[:skip_spring] = true
|
107
|
-
opts[:skip_listen] = true
|
108
116
|
opts[:skip_git] = true
|
109
|
-
opts[:
|
110
|
-
opts[:skip_webpack_install] = true
|
117
|
+
opts[:skip_hotwire] = true
|
111
118
|
opts[:dummy_app] = true
|
112
119
|
|
113
120
|
invoke Rails::Generators::AppGenerator,
|
@@ -117,17 +124,19 @@ task default: :test
|
|
117
124
|
def test_dummy_config
|
118
125
|
template "rails/boot.rb", "#{dummy_path}/config/boot.rb", force: true
|
119
126
|
|
120
|
-
insert_into_file "#{dummy_path}/config/application.rb", <<~RUBY, after: /^Bundler\.require.+\n/
|
121
|
-
require #{namespaced_name.inspect}
|
122
|
-
RUBY
|
123
|
-
|
124
127
|
if mountable?
|
125
128
|
template "rails/routes.rb", "#{dummy_path}/config/routes.rb", force: true
|
126
129
|
end
|
130
|
+
if engine? && !api?
|
131
|
+
insert_into_file "#{dummy_path}/config/application.rb", indent(<<~RUBY, 4), after: /^\s*config\.load_defaults.*\n/
|
132
|
+
|
133
|
+
# For compatibility with applications that use this config
|
134
|
+
config.action_controller.include_all_helpers = false
|
135
|
+
RUBY
|
136
|
+
end
|
127
137
|
end
|
128
138
|
|
129
|
-
def
|
130
|
-
template "rails/javascripts.js", "#{dummy_path}/app/javascript/packs/application.js", force: true
|
139
|
+
def test_dummy_sprocket_assets
|
131
140
|
template "rails/stylesheets.css", "#{dummy_path}/app/assets/stylesheets/application.css", force: true
|
132
141
|
template "rails/dummy_manifest.js", "#{dummy_path}/app/assets/config/manifest.js", force: true
|
133
142
|
end
|
@@ -205,18 +214,28 @@ task default: :test
|
|
205
214
|
def initialize(*args)
|
206
215
|
@dummy_path = nil
|
207
216
|
super
|
217
|
+
imply_options
|
218
|
+
|
219
|
+
if !engine? || !with_dummy_app?
|
220
|
+
self.options = options.merge(skip_asset_pipeline: true).freeze
|
221
|
+
end
|
208
222
|
end
|
209
223
|
|
224
|
+
public_task :report_implied_options
|
210
225
|
public_task :set_default_accessors!
|
211
226
|
public_task :create_root
|
212
227
|
|
228
|
+
def target_rails_prerelease
|
229
|
+
super("plugin new")
|
230
|
+
end
|
231
|
+
|
213
232
|
def create_root_files
|
214
233
|
build(:readme)
|
215
234
|
build(:rakefile)
|
216
235
|
build(:gemspec) unless options[:skip_gemspec]
|
217
236
|
build(:license)
|
218
237
|
build(:gitignore) unless options[:skip_git]
|
219
|
-
build(:gemfile)
|
238
|
+
build(:gemfile)
|
220
239
|
build(:version_control)
|
221
240
|
end
|
222
241
|
|
@@ -284,6 +303,34 @@ task default: :test
|
|
284
303
|
end
|
285
304
|
|
286
305
|
private
|
306
|
+
def gemfile_entries
|
307
|
+
[
|
308
|
+
rails_gemfile_entry,
|
309
|
+
simplify_gemfile_entries(
|
310
|
+
web_server_gemfile_entry,
|
311
|
+
database_gemfile_entry,
|
312
|
+
asset_pipeline_gemfile_entry,
|
313
|
+
),
|
314
|
+
].flatten.compact
|
315
|
+
end
|
316
|
+
|
317
|
+
def rails_gemfile_entry
|
318
|
+
if options[:skip_gemspec]
|
319
|
+
super
|
320
|
+
elsif rails_prerelease?
|
321
|
+
super.dup.tap do |entry|
|
322
|
+
entry.comment = <<~COMMENT
|
323
|
+
Your gem is dependent on a prerelease version of Rails. Once you can lock this
|
324
|
+
dependency down to a specific version, move it to your gemspec.
|
325
|
+
COMMENT
|
326
|
+
end
|
327
|
+
end
|
328
|
+
end
|
329
|
+
|
330
|
+
def simplify_gemfile_entries(*gemfile_entries)
|
331
|
+
gemfile_entries.flatten.compact.map { |entry| GemfileEntry.floats(entry.name) }
|
332
|
+
end
|
333
|
+
|
287
334
|
def create_dummy_app(path = nil)
|
288
335
|
dummy_path(path) if path
|
289
336
|
|
@@ -291,7 +338,7 @@ task default: :test
|
|
291
338
|
mute do
|
292
339
|
build(:generate_test_dummy)
|
293
340
|
build(:test_dummy_config)
|
294
|
-
build(:
|
341
|
+
build(:test_dummy_sprocket_assets) unless skip_sprockets?
|
295
342
|
build(:test_dummy_clean)
|
296
343
|
# ensure that bin/rails has proper dummy_path
|
297
344
|
build(:bin, true)
|
@@ -373,6 +420,10 @@ task default: :test
|
|
373
420
|
end
|
374
421
|
end
|
375
422
|
|
423
|
+
def rails_version_specifier(gem_version = Rails.gem_version)
|
424
|
+
[">= #{gem_version}"]
|
425
|
+
end
|
426
|
+
|
376
427
|
def valid_const?
|
377
428
|
if /-\d/.match?(original_name)
|
378
429
|
raise Error, "Invalid plugin name #{original_name}. Please give a name which does not contain a namespace starting with numeric characters."
|
@@ -393,18 +444,6 @@ task default: :test
|
|
393
444
|
defined?(::PluginBuilder) ? ::PluginBuilder : Rails::PluginBuilder
|
394
445
|
end
|
395
446
|
|
396
|
-
def rakefile_test_tasks
|
397
|
-
<<-RUBY
|
398
|
-
require "rake/testtask"
|
399
|
-
|
400
|
-
Rake::TestTask.new(:test) do |t|
|
401
|
-
t.libs << 'test'
|
402
|
-
t.pattern = 'test/**/*_test.rb'
|
403
|
-
t.verbose = false
|
404
|
-
end
|
405
|
-
RUBY
|
406
|
-
end
|
407
|
-
|
408
447
|
def dummy_path(path = nil)
|
409
448
|
@dummy_path = path if path
|
410
449
|
@dummy_path || options[:dummy_path]
|
@@ -8,9 +8,11 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.homepage = "TODO"
|
9
9
|
spec.summary = "TODO: Summary of <%= camelized_modules %>."
|
10
10
|
spec.description = "TODO: Description of <%= camelized_modules %>."
|
11
|
+
<%- unless inside_application? -%>
|
11
12
|
spec.license = "MIT"
|
13
|
+
<%- end -%>
|
12
14
|
|
13
|
-
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the
|
15
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the "allowed_push_host"
|
14
16
|
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
15
17
|
spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
16
18
|
|
@@ -18,7 +20,9 @@ Gem::Specification.new do |spec|
|
|
18
20
|
spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
|
19
21
|
spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
20
22
|
|
21
|
-
spec.files = Dir
|
23
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
24
|
+
Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"]
|
25
|
+
end
|
22
26
|
|
23
|
-
<%=
|
27
|
+
<%= "# " if rails_prerelease? -%>spec.add_dependency "rails", "<%= Array(rails_version_specifier).join('", "') %>"
|
24
28
|
end
|
@@ -1,41 +1,19 @@
|
|
1
|
-
source
|
1
|
+
source "https://rubygems.org"
|
2
2
|
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
3
|
+
<% unless options[:skip_gemspec] -%>
|
3
4
|
|
4
|
-
<% if options[:skip_gemspec] -%>
|
5
|
-
<%= '# ' if options.dev? || options.edge? || options.master? -%>gem 'rails', '<%= Array(rails_version_specifier).join("', '") %>'
|
6
|
-
<% else -%>
|
7
5
|
# Specify your gem's dependencies in <%= name %>.gemspec.
|
8
6
|
gemspec
|
9
7
|
<% end -%>
|
10
|
-
<%
|
11
|
-
|
12
|
-
group :development do
|
13
|
-
gem '<%= gem_for_database[0] %>'
|
14
|
-
end
|
8
|
+
<% gemfile_entries.each do |gemfile_entry| %>
|
9
|
+
<%= gemfile_entry %>
|
15
10
|
<% end -%>
|
11
|
+
<% if RUBY_ENGINE == "ruby" -%>
|
16
12
|
|
17
|
-
|
18
|
-
#
|
19
|
-
# dependency down to a specific version, move it to your gemspec.
|
20
|
-
<% max_width = gemfile_entries.map { |g| g.name.length }.max -%>
|
21
|
-
<% gemfile_entries.each do |gem| -%>
|
22
|
-
<% if gem.comment -%>
|
23
|
-
|
24
|
-
# <%= gem.comment %>
|
25
|
-
<% end -%>
|
26
|
-
<%= gem.commented_out ? '# ' : '' %>gem '<%= gem.name %>'<%= %(, '#{gem.version}') if gem.version -%>
|
27
|
-
<% if gem.options.any? -%>
|
28
|
-
, <%= gem.options.map { |k,v|
|
29
|
-
"#{k}: #{v.inspect}" }.join(', ') %>
|
30
|
-
<% end -%>
|
31
|
-
<% end -%>
|
32
|
-
|
33
|
-
<% end -%>
|
34
|
-
<% if RUBY_ENGINE == 'ruby' -%>
|
35
|
-
# To use a debugger
|
36
|
-
# gem 'byebug', group: [:development, :test]
|
13
|
+
# Start debugger with binding.b [https://github.com/ruby/debug]
|
14
|
+
# gem "debug", ">= 1.0.0"
|
37
15
|
<% end -%>
|
38
|
-
<% if RUBY_PLATFORM.match(/
|
16
|
+
<% if RUBY_PLATFORM.match?(/mingw|mswin|java/) -%>
|
39
17
|
|
40
|
-
gem
|
18
|
+
gem "tzinfo-data", platforms: %i[ <%= bundler_windows_platforms %> jruby ]
|
41
19
|
<% end -%>
|
@@ -1,30 +1,15 @@
|
|
1
1
|
# This command will automatically be run when you run "rails" with Rails gems
|
2
2
|
# installed from the root of your application.
|
3
3
|
|
4
|
-
ENGINE_ROOT = File.expand_path(
|
5
|
-
ENGINE_PATH = File.expand_path(
|
4
|
+
ENGINE_ROOT = File.expand_path("..", __dir__)
|
5
|
+
ENGINE_PATH = File.expand_path("../lib/<%= namespaced_name -%>/engine", __dir__)
|
6
6
|
<% if with_dummy_app? -%>
|
7
|
-
APP_PATH = File.expand_path(
|
7
|
+
APP_PATH = File.expand_path("../<%= dummy_path -%>/config/application", __dir__)
|
8
8
|
<% end -%>
|
9
9
|
|
10
10
|
# Set up gems listed in the Gemfile.
|
11
|
-
ENV[
|
11
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
|
12
12
|
require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"])
|
13
13
|
|
14
|
-
|
15
|
-
require "rails/all"
|
16
|
-
<% else -%>
|
17
|
-
require "rails"
|
18
|
-
# Pick the frameworks you want:
|
19
|
-
require "active_model/railtie"
|
20
|
-
require "active_job/railtie"
|
21
|
-
<%= comment_if :skip_active_record %>require "active_record/railtie"
|
22
|
-
<%= comment_if :skip_active_storage %>require "active_storage/engine"
|
23
|
-
require "action_controller/railtie"
|
24
|
-
<%= comment_if :skip_action_mailer %>require "action_mailer/railtie"
|
25
|
-
require "action_view/railtie"
|
26
|
-
<%= comment_if :skip_action_cable %>require "action_cable/engine"
|
27
|
-
<%= comment_if :skip_sprockets %>require "sprockets/railtie"
|
28
|
-
<%= comment_if :skip_test %>require "rails/test_unit/railtie"
|
29
|
-
<% end -%>
|
14
|
+
<%= rails_require_statement %>
|
30
15
|
require "rails/engine/commands"
|
@@ -9,13 +9,6 @@
|
|
9
9
|
/<%= dummy_path %>/db/*.sqlite3-*
|
10
10
|
<% end -%>
|
11
11
|
/<%= dummy_path %>/log/*.log
|
12
|
-
<% unless options[:skip_javascript] -%>
|
13
|
-
/<%= dummy_path %>/node_modules/
|
14
|
-
/<%= dummy_path %>/yarn-error.log
|
15
|
-
<% end -%>
|
16
|
-
<% unless skip_active_storage? -%>
|
17
12
|
/<%= dummy_path %>/storage/
|
18
|
-
<% end -%>
|
19
13
|
/<%= dummy_path %>/tmp/
|
20
14
|
<% end -%>
|
21
|
-
.byebug_history
|
@@ -1,7 +1,7 @@
|
|
1
1
|
<%= wrap_in_modules <<~rb
|
2
2
|
class Engine < ::Rails::Engine
|
3
|
-
#{mountable? ?
|
4
|
-
#{api? ? " config.generators.api_only = true" :
|
3
|
+
#{mountable? ? " isolate_namespace " + camelized_modules : " "}
|
4
|
+
#{api? ? " config.generators.api_only = true" : " "}
|
5
5
|
end
|
6
6
|
rb
|
7
7
|
%>
|
@@ -1 +1 @@
|
|
1
|
-
<%= wrap_in_modules
|
1
|
+
<%= wrap_in_modules 'VERSION = "0.1.0"' %>
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# Set up gems listed in the Gemfile.
|
2
|
-
ENV[
|
2
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../Gemfile", __dir__)
|
3
3
|
|
4
4
|
require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"])
|
5
|
-
$LOAD_PATH.unshift File.expand_path(
|
5
|
+
$LOAD_PATH.unshift File.expand_path("../../../lib", __dir__)
|
@@ -1,26 +1,21 @@
|
|
1
1
|
# Configure Rails Environment
|
2
2
|
ENV["RAILS_ENV"] = "test"
|
3
3
|
|
4
|
-
require_relative "<%= File.join(
|
4
|
+
require_relative "<%= File.join("..", options[:dummy_path], "config/environment") -%>"
|
5
5
|
<% unless options[:skip_active_record] -%>
|
6
6
|
ActiveRecord::Migrator.migrations_paths = [File.expand_path("../<%= options[:dummy_path] -%>/db/migrate", __dir__)]
|
7
7
|
<% if options[:mountable] -%>
|
8
|
-
ActiveRecord::Migrator.migrations_paths << File.expand_path(
|
8
|
+
ActiveRecord::Migrator.migrations_paths << File.expand_path("../db/migrate", __dir__)
|
9
9
|
<% end -%>
|
10
10
|
<% end -%>
|
11
11
|
require "rails/test_help"
|
12
12
|
|
13
|
-
<% unless engine? -%>
|
14
|
-
require "rails/test_unit/reporter"
|
15
|
-
Rails::TestUnitReporter.executable = 'bin/test'
|
16
|
-
<% end -%>
|
17
|
-
|
18
13
|
<% unless options[:skip_active_record] -%>
|
19
14
|
# Load fixtures from the engine
|
20
|
-
if ActiveSupport::TestCase.respond_to?(:
|
21
|
-
ActiveSupport::TestCase.
|
22
|
-
ActionDispatch::IntegrationTest.
|
23
|
-
ActiveSupport::TestCase.file_fixture_path =
|
15
|
+
if ActiveSupport::TestCase.respond_to?(:fixture_paths=)
|
16
|
+
ActiveSupport::TestCase.fixture_paths = [File.expand_path("fixtures", __dir__)]
|
17
|
+
ActionDispatch::IntegrationTest.fixture_paths = ActiveSupport::TestCase.fixture_paths
|
18
|
+
ActiveSupport::TestCase.file_fixture_path = File.expand_path("fixtures", __dir__) + "/files"
|
24
19
|
ActiveSupport::TestCase.fixtures :all
|
25
20
|
end
|
26
21
|
<% end -%>
|
@@ -8,29 +8,11 @@ module Rails
|
|
8
8
|
remove_hook_for :resource_controller
|
9
9
|
remove_class_option :actions
|
10
10
|
|
11
|
-
class_option :api, type: :boolean
|
12
|
-
|
13
|
-
class_option :stylesheet_engine, desc: "Engine for Stylesheets"
|
14
|
-
class_option :assets, type: :boolean
|
11
|
+
class_option :api, type: :boolean,
|
12
|
+
desc: "Generate API-only controller and tests, with no view templates"
|
15
13
|
class_option :resource_route, type: :boolean
|
16
|
-
class_option :scaffold_stylesheet, type: :boolean
|
17
|
-
|
18
|
-
def handle_skip
|
19
|
-
@options = @options.merge(stylesheets: false) unless options[:assets]
|
20
|
-
@options = @options.merge(stylesheet_engine: false) unless options[:stylesheets] && options[:scaffold_stylesheet]
|
21
|
-
end
|
22
14
|
|
23
15
|
hook_for :scaffold_controller, required: true
|
24
|
-
|
25
|
-
hook_for :assets do |assets|
|
26
|
-
invoke assets, [controller_name]
|
27
|
-
end
|
28
|
-
|
29
|
-
hook_for :stylesheet_engine do |stylesheet_engine|
|
30
|
-
if behavior == :invoke
|
31
|
-
invoke stylesheet_engine, [controller_name]
|
32
|
-
end
|
33
|
-
end
|
34
16
|
end
|
35
17
|
end
|
36
18
|
end
|
@@ -13,7 +13,7 @@ module Rails
|
|
13
13
|
class_option :orm, banner: "NAME", type: :string, required: true,
|
14
14
|
desc: "ORM to generate the controller for"
|
15
15
|
class_option :api, type: :boolean,
|
16
|
-
desc: "
|
16
|
+
desc: "Generate API controller"
|
17
17
|
|
18
18
|
class_option :skip_routes, type: :boolean, desc: "Don't add routes to config/routes.rb."
|
19
19
|
|
@@ -1,10 +1,6 @@
|
|
1
|
-
<% if namespaced? -%>
|
2
|
-
require_dependency "<%= namespaced_path %>/application_controller"
|
3
|
-
|
4
|
-
<% end -%>
|
5
1
|
<% module_namespacing do -%>
|
6
2
|
class <%= controller_class_name %>Controller < ApplicationController
|
7
|
-
before_action :set_<%= singular_table_name %>, only: [
|
3
|
+
before_action :set_<%= singular_table_name %>, only: %i[ show update destroy ]
|
8
4
|
|
9
5
|
# GET <%= route_url %>
|
10
6
|
def index
|
@@ -1,10 +1,6 @@
|
|
1
|
-
<% if namespaced? -%>
|
2
|
-
require_dependency "<%= namespaced_path %>/application_controller"
|
3
|
-
|
4
|
-
<% end -%>
|
5
1
|
<% module_namespacing do -%>
|
6
2
|
class <%= controller_class_name %>Controller < ApplicationController
|
7
|
-
before_action :set_<%= singular_table_name %>, only: [
|
3
|
+
before_action :set_<%= singular_table_name %>, only: %i[ show edit update destroy ]
|
8
4
|
|
9
5
|
# GET <%= route_url %>
|
10
6
|
def index
|
@@ -29,25 +25,25 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
29
25
|
@<%= singular_table_name %> = <%= orm_class.build(class_name, "#{singular_table_name}_params") %>
|
30
26
|
|
31
27
|
if @<%= orm_instance.save %>
|
32
|
-
redirect_to <%= redirect_resource_name %>, notice: <%= "
|
28
|
+
redirect_to <%= redirect_resource_name %>, notice: <%= %("#{human_name} was successfully created.") %>
|
33
29
|
else
|
34
|
-
render :new
|
30
|
+
render :new, status: :unprocessable_entity
|
35
31
|
end
|
36
32
|
end
|
37
33
|
|
38
34
|
# PATCH/PUT <%= route_url %>/1
|
39
35
|
def update
|
40
36
|
if @<%= orm_instance.update("#{singular_table_name}_params") %>
|
41
|
-
redirect_to <%= redirect_resource_name %>, notice: <%= "
|
37
|
+
redirect_to <%= redirect_resource_name %>, notice: <%= %("#{human_name} was successfully updated.") %>, status: :see_other
|
42
38
|
else
|
43
|
-
render :edit
|
39
|
+
render :edit, status: :unprocessable_entity
|
44
40
|
end
|
45
41
|
end
|
46
42
|
|
47
43
|
# DELETE <%= route_url %>/1
|
48
44
|
def destroy
|
49
45
|
@<%= orm_instance.destroy %>
|
50
|
-
redirect_to <%= index_helper %>_url, notice: <%= "
|
46
|
+
redirect_to <%= index_helper %>_url, notice: <%= %("#{human_name} was successfully destroyed.") %>, status: :see_other
|
51
47
|
end
|
52
48
|
|
53
49
|
private
|
@@ -8,13 +8,13 @@ module Rails
|
|
8
8
|
# Deal with controller names on scaffold and add some helpers to deal with
|
9
9
|
# ActiveModel.
|
10
10
|
module ResourceHelpers # :nodoc:
|
11
|
-
def self.included(base)
|
11
|
+
def self.included(base) # :nodoc:
|
12
12
|
base.include(Rails::Generators::ModelHelpers)
|
13
13
|
base.class_option :model_name, type: :string, desc: "ModelName to be used"
|
14
14
|
end
|
15
15
|
|
16
16
|
# Set controller variables on initialization.
|
17
|
-
def initialize(*args)
|
17
|
+
def initialize(*args) # :nodoc:
|
18
18
|
super
|
19
19
|
controller_name = name
|
20
20
|
if options[:model_name]
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "rails/generators"
|
4
|
-
require "rails/generators/testing/
|
4
|
+
require "rails/generators/testing/behavior"
|
5
5
|
require "rails/generators/testing/setup_and_teardown"
|
6
6
|
require "rails/generators/testing/assertions"
|
7
7
|
require "fileutils"
|
@@ -28,7 +28,7 @@ module Rails
|
|
28
28
|
# setup :prepare_destination
|
29
29
|
# end
|
30
30
|
class TestCase < ActiveSupport::TestCase
|
31
|
-
include Rails::Generators::Testing::
|
31
|
+
include Rails::Generators::Testing::Behavior
|
32
32
|
include Rails::Generators::Testing::SetupAndTeardown
|
33
33
|
include Rails::Generators::Testing::Assertions
|
34
34
|
include FileUtils
|
@@ -4,7 +4,7 @@ require "<%= generator_path %>"
|
|
4
4
|
<% module_namespacing do -%>
|
5
5
|
class <%= class_name %>GeneratorTest < Rails::Generators::TestCase
|
6
6
|
tests <%= class_name %>Generator
|
7
|
-
destination Rails.root.join(
|
7
|
+
destination Rails.root.join("tmp/generators")
|
8
8
|
setup :prepare_destination
|
9
9
|
|
10
10
|
# test "generator runs without errors" do
|
@@ -4,7 +4,7 @@
|
|
4
4
|
<%= name %>:
|
5
5
|
<% attributes.each do |attribute| -%>
|
6
6
|
<%- if attribute.password_digest? -%>
|
7
|
-
password_digest: <%%= BCrypt::Password.create(
|
7
|
+
password_digest: <%%= BCrypt::Password.create("secret") %>
|
8
8
|
<%- elsif attribute.reference? -%>
|
9
9
|
<%= yaml_key_value(attribute.column_name.delete_suffix("_id"), attribute.default || name) %>
|
10
10
|
<%- elsif !attribute.virtual? -%>
|
@@ -18,7 +18,7 @@
|
|
18
18
|
<% else -%>
|
19
19
|
|
20
20
|
# This model initially had no columns defined. If you add columns to the
|
21
|
-
# model remove the
|
21
|
+
# model remove the "{}" from the fixture names and add the columns immediately
|
22
22
|
# below each fixture, per the syntax in the comments below
|
23
23
|
#
|
24
24
|
one: {}
|
@@ -11,7 +11,7 @@ module TestUnit # :nodoc:
|
|
11
11
|
check_class_collision suffix: "ControllerTest"
|
12
12
|
|
13
13
|
class_option :api, type: :boolean,
|
14
|
-
desc: "
|
14
|
+
desc: "Generate API functional tests"
|
15
15
|
|
16
16
|
class_option :system_tests, type: :string,
|
17
17
|
desc: "Skip system test files"
|
@@ -45,13 +45,13 @@ module TestUnit # :nodoc:
|
|
45
45
|
def attributes_hash
|
46
46
|
return {} if attributes_names.empty?
|
47
47
|
|
48
|
-
attributes_names.
|
48
|
+
attributes_names.filter_map do |name|
|
49
49
|
if %w(password password_confirmation).include?(name) && attributes.any?(&:password_digest?)
|
50
|
-
["#{name}", "
|
50
|
+
["#{name}", '"secret"']
|
51
51
|
elsif !virtual?(name)
|
52
52
|
["#{name}", "@#{singular_table_name}.#{name}"]
|
53
53
|
end
|
54
|
-
end.
|
54
|
+
end.sort.to_h
|
55
55
|
end
|
56
56
|
|
57
57
|
def boolean?(name)
|