railties 4.2.11.3 → 5.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +262 -206
- data/MIT-LICENSE +20 -0
- data/README.rdoc +1 -1
- data/{bin → exe}/rails +0 -0
- data/lib/rails.rb +19 -1
- data/lib/rails/all.rb +10 -9
- data/lib/rails/api/task.rb +7 -14
- data/lib/rails/{app_rails_loader.rb → app_loader.rb} +4 -3
- data/lib/rails/application.rb +31 -41
- data/lib/rails/application/bootstrap.rb +1 -14
- data/lib/rails/application/configuration.rb +94 -95
- data/lib/rails/application/default_middleware_stack.rb +30 -16
- data/lib/rails/application/finisher.rb +11 -2
- data/lib/rails/application/routes_reloader.rb +1 -3
- data/lib/rails/application_controller.rb +1 -1
- data/lib/rails/cli.rb +2 -2
- data/lib/rails/code_statistics.rb +6 -8
- data/lib/rails/code_statistics_calculator.rb +8 -1
- data/lib/rails/command.rb +70 -0
- data/lib/rails/commands.rb +5 -3
- data/lib/rails/commands/commands_tasks.rb +25 -14
- data/lib/rails/commands/console.rb +7 -52
- data/lib/rails/commands/console_helper.rb +34 -0
- data/lib/rails/commands/dbconsole.rb +59 -78
- data/lib/rails/commands/dev_cache.rb +21 -0
- data/lib/rails/commands/plugin.rb +1 -1
- data/lib/rails/commands/rake_proxy.rb +34 -0
- data/lib/rails/commands/runner.rb +0 -1
- data/lib/rails/commands/server.rb +29 -36
- data/lib/rails/commands/test.rb +9 -0
- data/lib/rails/configuration.rb +21 -5
- data/lib/rails/console/app.rb +5 -0
- data/lib/rails/console/helpers.rb +1 -1
- data/lib/rails/engine.rb +68 -58
- data/lib/rails/engine/commands.rb +4 -2
- data/lib/rails/engine/configuration.rb +4 -10
- data/lib/rails/gem_version.rb +4 -4
- data/lib/rails/generators.rb +30 -7
- data/lib/rails/generators/.named_base.rb.swp +0 -0
- data/lib/rails/generators/actions.rb +19 -5
- data/lib/rails/generators/app_base.rb +65 -45
- data/lib/rails/generators/base.rb +6 -6
- data/lib/rails/generators/erb/mailer/mailer_generator.rb +5 -8
- data/lib/rails/generators/erb/scaffold/templates/_form.html.erb +9 -7
- data/lib/rails/generators/erb/scaffold/templates/edit.html.erb +1 -1
- data/lib/rails/generators/erb/scaffold/templates/index.html.erb +2 -2
- data/lib/rails/generators/erb/scaffold/templates/new.html.erb +1 -1
- data/lib/rails/generators/generated_attribute.rb +5 -1
- data/lib/rails/generators/migration.rb +7 -7
- data/lib/rails/generators/named_base.rb +21 -5
- data/lib/rails/generators/rails/app/USAGE +0 -1
- data/lib/rails/generators/rails/app/app_generator.rb +75 -11
- data/lib/rails/generators/rails/app/templates/Gemfile +17 -13
- data/lib/rails/generators/rails/app/templates/{README.rdoc → README.md} +1 -5
- data/lib/rails/generators/rails/app/templates/app/assets/config/manifest.js.tt +7 -0
- data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +1 -1
- data/lib/rails/generators/rails/app/templates/app/assets/javascripts/cable.coffee +11 -0
- data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css +3 -3
- data/lib/rails/generators/rails/app/templates/app/channels/application_cable/channel.rb +5 -0
- data/lib/rails/generators/rails/app/templates/app/channels/application_cable/connection.rb +5 -0
- data/lib/rails/generators/rails/app/templates/app/controllers/application_controller.rb.tt +3 -1
- data/lib/rails/generators/rails/app/templates/app/jobs/application_job.rb +2 -0
- data/lib/rails/generators/rails/app/templates/app/mailers/application_mailer.rb +4 -0
- data/lib/rails/generators/rails/app/templates/app/models/application_record.rb +3 -0
- data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +20 -17
- data/lib/rails/generators/rails/app/templates/app/views/layouts/mailer.html.erb.tt +13 -0
- data/lib/rails/generators/{erb/mailer/templates/layout.text.erb → rails/app/templates/app/views/layouts/mailer.text.erb.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/bin/setup +17 -12
- data/lib/rails/generators/rails/app/templates/bin/update +28 -0
- data/lib/rails/generators/rails/app/templates/config.ru.tt +11 -0
- data/lib/rails/generators/rails/app/templates/config/application.rb +9 -14
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml +1 -1
- data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml +2 -2
- data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +20 -3
- data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +18 -11
- data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +7 -3
- data/lib/rails/generators/rails/app/templates/config/initializers/active_record_belongs_to_required_by_default.rb +5 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/application_controller_renderer.rb +6 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/callback_terminator.rb +5 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/cookies_serializer.rb +1 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/cors.rb +16 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/request_forgery_protection.rb +4 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt +2 -2
- data/lib/rails/generators/rails/app/templates/config/redis/cable.yml +9 -0
- data/lib/rails/generators/rails/app/templates/config/routes.rb +3 -53
- data/lib/rails/generators/rails/app/templates/db/seeds.rb.tt +3 -3
- data/lib/rails/generators/rails/app/templates/gitignore +7 -1
- data/lib/rails/generators/rails/controller/controller_generator.rb +6 -4
- data/lib/rails/generators/rails/migration/migration_generator.rb +1 -1
- data/lib/rails/generators/rails/model/USAGE +6 -1
- data/lib/rails/generators/rails/model/model_generator.rb +1 -1
- data/lib/rails/generators/rails/plugin/plugin_generator.rb +88 -35
- data/lib/rails/generators/rails/plugin/templates/%name%.gemspec +6 -9
- data/lib/rails/generators/rails/plugin/templates/Gemfile +3 -7
- data/lib/rails/generators/rails/plugin/templates/README.md +3 -0
- data/lib/rails/generators/rails/plugin/templates/Rakefile +2 -2
- data/lib/rails/generators/rails/plugin/templates/app/controllers/%namespaced_name%/application_controller.rb.tt +5 -0
- data/lib/rails/generators/rails/plugin/templates/app/helpers/%namespaced_name%/application_helper.rb.tt +5 -0
- data/lib/rails/generators/rails/plugin/templates/app/jobs/%namespaced_name%/application_job.rb.tt +5 -0
- data/lib/rails/generators/rails/plugin/templates/app/models/application_record.rb.tt +6 -0
- data/lib/rails/generators/rails/plugin/templates/app/views/layouts/%namespaced_name%/application.html.erb.tt +14 -0
- data/lib/rails/generators/rails/plugin/templates/bin/rails.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/bin/test.tt +8 -0
- data/lib/rails/generators/rails/plugin/templates/config/routes.rb +1 -1
- data/lib/rails/generators/rails/plugin/templates/gitignore +2 -3
- data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%.rb +5 -0
- data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/engine.rb +7 -0
- data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/version.rb +1 -0
- data/lib/rails/generators/rails/plugin/templates/lib/tasks/{%name%_tasks.rake → %namespaced_name%_tasks.rake} +1 -1
- data/lib/rails/generators/rails/plugin/templates/rails/application.rb +3 -3
- data/lib/rails/generators/rails/plugin/templates/rails/dummy_manifest.js +11 -0
- data/lib/rails/generators/rails/plugin/templates/rails/engine_manifest.js +6 -0
- data/lib/rails/generators/rails/plugin/templates/rails/javascripts.js +1 -1
- data/lib/rails/generators/rails/plugin/templates/rails/routes.rb +1 -2
- data/lib/rails/generators/rails/plugin/templates/rails/stylesheets.css +3 -3
- data/lib/rails/generators/rails/plugin/templates/test/%namespaced_name%_test.rb +7 -0
- data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb +4 -2
- data/lib/rails/generators/rails/resource/resource_generator.rb +0 -1
- data/lib/rails/generators/rails/resource_route/resource_route_generator.rb +0 -1
- data/lib/rails/generators/rails/scaffold/USAGE +1 -1
- data/lib/rails/generators/rails/scaffold/scaffold_generator.rb +2 -1
- data/lib/rails/generators/rails/scaffold/templates/scaffold.css +35 -7
- data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +4 -1
- data/lib/rails/generators/rails/scaffold_controller/templates/api_controller.rb +61 -0
- data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb +1 -1
- data/lib/rails/generators/resource_helpers.rb +3 -3
- data/lib/rails/generators/test_unit/controller/templates/.functional_test.rb.swp +0 -0
- data/lib/rails/generators/test_unit/controller/templates/functional_test.rb +3 -5
- data/lib/rails/generators/test_unit/mailer/mailer_generator.rb +8 -3
- data/lib/rails/generators/test_unit/mailer/templates/functional_test.rb +2 -2
- data/lib/rails/generators/test_unit/mailer/templates/preview.rb +4 -4
- data/lib/rails/generators/test_unit/model/model_generator.rb +1 -1
- data/lib/rails/generators/test_unit/model/templates/fixtures.yml +2 -0
- data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +5 -1
- data/lib/rails/generators/test_unit/scaffold/templates/.api_functional_test.rb.swp +0 -0
- data/lib/rails/generators/test_unit/scaffold/templates/.functional_test.rb.swp +0 -0
- data/lib/rails/generators/test_unit/scaffold/templates/api_functional_test.rb +44 -0
- data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb +14 -14
- data/lib/rails/generators/testing/assertions.rb +0 -2
- data/lib/rails/generators/testing/behaviour.rb +4 -17
- data/lib/rails/info.rb +2 -2
- data/lib/rails/info_controller.rb +23 -2
- data/lib/rails/mailers_controller.rb +2 -2
- data/lib/rails/paths.rb +14 -6
- data/lib/rails/rack.rb +1 -3
- data/lib/rails/rack/debugger.rb +2 -23
- data/lib/rails/rack/logger.rb +4 -0
- data/lib/rails/ruby_version_check.rb +3 -3
- data/lib/rails/source_annotation_extractor.rb +1 -1
- data/lib/rails/tasks.rb +4 -1
- data/lib/rails/tasks/engine.rake +1 -1
- data/lib/rails/tasks/framework.rake +18 -16
- data/lib/rails/tasks/initializers.rake +6 -0
- data/lib/rails/tasks/restart.rake +5 -0
- data/lib/rails/tasks/statistics.rake +5 -6
- data/lib/rails/tasks/tmp.rake +4 -12
- data/lib/rails/templates/rails/mailers/email.html.erb +17 -3
- data/lib/rails/templates/rails/welcome/index.html.erb +10 -3
- data/lib/rails/test_help.rb +7 -8
- data/lib/rails/test_unit/minitest_plugin.rb +91 -0
- data/lib/rails/test_unit/reporter.rb +74 -0
- data/lib/rails/test_unit/test_requirer.rb +28 -0
- data/lib/rails/test_unit/testing.rake +18 -39
- metadata +80 -33
- data/lib/rails/deprecation.rb +0 -19
- data/lib/rails/generators/erb/mailer/templates/layout.html.erb +0 -5
- data/lib/rails/generators/rails/app/templates/config.ru +0 -4
- data/lib/rails/generators/rails/app/templates/config/initializers/to_time_preserves_timezone.rb +0 -10
- data/lib/rails/generators/rails/plugin/templates/README.rdoc +0 -3
- data/lib/rails/generators/rails/plugin/templates/app/controllers/%name%/application_controller.rb.tt +0 -5
- data/lib/rails/generators/rails/plugin/templates/app/helpers/%name%/application_helper.rb.tt +0 -4
- data/lib/rails/generators/rails/plugin/templates/app/views/layouts/%name%/application.html.erb.tt +0 -14
- data/lib/rails/generators/rails/plugin/templates/lib/%name%.rb +0 -6
- data/lib/rails/generators/rails/plugin/templates/lib/%name%/engine.rb +0 -7
- data/lib/rails/generators/rails/plugin/templates/lib/%name%/version.rb +0 -3
- data/lib/rails/generators/rails/plugin/templates/test/%name%_test.rb +0 -7
- data/lib/rails/rack/log_tailer.rb +0 -38
- data/lib/rails/tasks/documentation.rake +0 -70
- data/lib/rails/test_unit/sub_test_task.rb +0 -126
@@ -1,7 +1,7 @@
|
|
1
1
|
# This command will automatically be run when you run "rails" with Rails 4 gems installed from the root of your application.
|
2
2
|
|
3
3
|
ENGINE_ROOT = File.expand_path('../..', __FILE__)
|
4
|
-
ENGINE_PATH = File.expand_path('../../lib/<%=
|
4
|
+
ENGINE_PATH = File.expand_path('../../lib/<%= namespaced_name -%>/engine', __FILE__)
|
5
5
|
|
6
6
|
# Set up gems listed in the Gemfile.
|
7
7
|
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
|
@@ -1,10 +1,9 @@
|
|
1
1
|
.bundle/
|
2
2
|
log/*.log
|
3
3
|
pkg/
|
4
|
-
<% unless options[:
|
4
|
+
<% unless options[:skip_test] && options[:dummy_path] == 'test/dummy' -%>
|
5
5
|
<%= dummy_path %>/db/*.sqlite3
|
6
6
|
<%= dummy_path %>/db/*.sqlite3-journal
|
7
7
|
<%= dummy_path %>/log/*.log
|
8
8
|
<%= dummy_path %>/tmp/
|
9
|
-
|
10
|
-
<% end -%>
|
9
|
+
<% end -%>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= wrap_in_modules "VERSION = '0.1.0'" %>
|
@@ -6,13 +6,13 @@ require 'rails/all'
|
|
6
6
|
# Pick the frameworks you want:
|
7
7
|
<%= comment_if :skip_active_record %>require "active_record/railtie"
|
8
8
|
require "action_controller/railtie"
|
9
|
-
require "action_mailer/railtie"
|
9
|
+
<%= comment_if :skip_action_mailer %>require "action_mailer/railtie"
|
10
10
|
require "action_view/railtie"
|
11
11
|
<%= comment_if :skip_sprockets %>require "sprockets/railtie"
|
12
|
-
<%= comment_if :
|
12
|
+
<%= comment_if :skip_test %>require "rails/test_unit/railtie"
|
13
13
|
<% end -%>
|
14
14
|
|
15
15
|
Bundler.require(*Rails.groups)
|
16
|
-
require "<%=
|
16
|
+
require "<%= namespaced_name %>"
|
17
17
|
|
18
18
|
<%= application_definition %>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
|
2
|
+
<% unless api? -%>
|
3
|
+
//= link_tree ../images
|
4
|
+
<% end -%>
|
5
|
+
<% unless options.skip_javascript -%>
|
6
|
+
//= link_directory ../javascripts .js
|
7
|
+
<% end -%>
|
8
|
+
//= link_directory ../stylesheets .css
|
9
|
+
<% if mountable? && !api? -%>
|
10
|
+
//= link <%= underscored_name %>_manifest.js
|
11
|
+
<% end -%>
|
@@ -5,7 +5,7 @@
|
|
5
5
|
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
6
|
//
|
7
7
|
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
-
// compiled file.
|
8
|
+
// compiled file. JavaScript code in this file should be added after the last require_* statement.
|
9
9
|
//
|
10
10
|
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
11
11
|
// about supported directives.
|
@@ -6,9 +6,9 @@
|
|
6
6
|
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
7
|
*
|
8
8
|
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
-
* compiled file so the styles you add here take precedence over styles defined in any
|
10
|
-
*
|
11
|
-
* file per style scope.
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
|
10
|
+
* files in this directory. Styles in this file should be added after the last require_* statement.
|
11
|
+
* It is generally better to create a new file per style scope.
|
12
12
|
*
|
13
13
|
*= require_tree .
|
14
14
|
*= require_self
|
@@ -14,12 +14,14 @@ require "rails/test_help"
|
|
14
14
|
# to be shown.
|
15
15
|
Minitest.backtrace_filter = Minitest::BacktraceFilter.new
|
16
16
|
|
17
|
-
|
18
|
-
|
17
|
+
<% unless engine? -%>
|
18
|
+
Rails::TestUnitReporter.executable = 'bin/test'
|
19
|
+
<% end -%>
|
19
20
|
|
20
21
|
# Load fixtures from the engine
|
21
22
|
if ActiveSupport::TestCase.respond_to?(:fixture_path=)
|
22
23
|
ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
|
23
24
|
ActionDispatch::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path
|
25
|
+
ActiveSupport::TestCase.file_fixture_path = ActiveSupport::TestCase.fixture_path + "/files"
|
24
26
|
ActiveSupport::TestCase.fixtures :all
|
25
27
|
end
|
@@ -36,6 +36,6 @@ Description:
|
|
36
36
|
|
37
37
|
Examples:
|
38
38
|
`rails generate scaffold post`
|
39
|
-
`rails generate scaffold post title body:text published:boolean`
|
39
|
+
`rails generate scaffold post title:string body:text published:boolean`
|
40
40
|
`rails generate scaffold purchase amount:decimal tracking_id:integer:uniq`
|
41
41
|
`rails generate scaffold user email:uniq password:digest`
|
@@ -10,10 +10,11 @@ module Rails
|
|
10
10
|
class_option :stylesheet_engine, desc: "Engine for Stylesheets"
|
11
11
|
class_option :assets, type: :boolean
|
12
12
|
class_option :resource_route, type: :boolean
|
13
|
+
class_option :scaffold_stylesheet, type: :boolean
|
13
14
|
|
14
15
|
def handle_skip
|
15
16
|
@options = @options.merge(stylesheets: false) unless options[:assets]
|
16
|
-
@options = @options.merge(stylesheet_engine: false) unless options[:stylesheets]
|
17
|
+
@options = @options.merge(stylesheet_engine: false) unless options[:stylesheets] && options[:scaffold_stylesheet]
|
17
18
|
end
|
18
19
|
|
19
20
|
hook_for :scaffold_controller, required: true
|
@@ -1,9 +1,13 @@
|
|
1
|
-
body {
|
1
|
+
body {
|
2
|
+
background-color: #fff;
|
3
|
+
color: #333;
|
4
|
+
}
|
2
5
|
|
3
6
|
body, p, ol, ul, td {
|
4
7
|
font-family: verdana, arial, helvetica, sans-serif;
|
5
|
-
font-size:
|
8
|
+
font-size: 13px;
|
6
9
|
line-height: 18px;
|
10
|
+
margin: 33px;
|
7
11
|
}
|
8
12
|
|
9
13
|
pre {
|
@@ -12,11 +16,31 @@ pre {
|
|
12
16
|
font-size: 11px;
|
13
17
|
}
|
14
18
|
|
15
|
-
a {
|
16
|
-
|
17
|
-
|
19
|
+
a {
|
20
|
+
color: #000;
|
21
|
+
}
|
22
|
+
|
23
|
+
a:visited {
|
24
|
+
color: #666;
|
25
|
+
}
|
26
|
+
|
27
|
+
a:hover {
|
28
|
+
color: #fff;
|
29
|
+
background-color: #000;
|
30
|
+
}
|
18
31
|
|
19
|
-
|
32
|
+
th {
|
33
|
+
padding-bottom: 5px;
|
34
|
+
}
|
35
|
+
|
36
|
+
td {
|
37
|
+
padding-bottom: 7px;
|
38
|
+
padding-left: 5px;
|
39
|
+
padding-right: 5px;
|
40
|
+
}
|
41
|
+
|
42
|
+
div.field,
|
43
|
+
div.actions {
|
20
44
|
margin-bottom: 10px;
|
21
45
|
}
|
22
46
|
|
@@ -45,7 +69,7 @@ div.field, div.actions {
|
|
45
69
|
padding: 5px 5px 5px 15px;
|
46
70
|
font-size: 12px;
|
47
71
|
margin: -7px;
|
48
|
-
margin-bottom:
|
72
|
+
margin-bottom: 0;
|
49
73
|
background-color: #c00;
|
50
74
|
color: #fff;
|
51
75
|
}
|
@@ -54,3 +78,7 @@ div.field, div.actions {
|
|
54
78
|
font-size: 12px;
|
55
79
|
list-style: square;
|
56
80
|
}
|
81
|
+
|
82
|
+
label {
|
83
|
+
display: block;
|
84
|
+
}
|
@@ -10,11 +10,14 @@ module Rails
|
|
10
10
|
class_option :helper, type: :boolean
|
11
11
|
class_option :orm, banner: "NAME", type: :string, required: true,
|
12
12
|
desc: "ORM to generate the controller for"
|
13
|
+
class_option :api, type: :boolean,
|
14
|
+
desc: "Generates API controller"
|
13
15
|
|
14
16
|
argument :attributes, type: :array, default: [], banner: "field:type field:type"
|
15
17
|
|
16
18
|
def create_controller_files
|
17
|
-
|
19
|
+
template_file = options.api? ? "api_controller.rb" : "controller.rb"
|
20
|
+
template template_file, File.join('app/controllers', controller_class_path, "#{controller_file_name}_controller.rb")
|
18
21
|
end
|
19
22
|
|
20
23
|
hook_for :template_engine, :test_framework, as: :scaffold
|
@@ -0,0 +1,61 @@
|
|
1
|
+
<% if namespaced? -%>
|
2
|
+
require_dependency "<%= namespaced_path %>/application_controller"
|
3
|
+
|
4
|
+
<% end -%>
|
5
|
+
<% module_namespacing do -%>
|
6
|
+
class <%= controller_class_name %>Controller < ApplicationController
|
7
|
+
before_action :set_<%= singular_table_name %>, only: [:show, :update, :destroy]
|
8
|
+
|
9
|
+
# GET <%= route_url %>
|
10
|
+
def index
|
11
|
+
@<%= plural_table_name %> = <%= orm_class.all(class_name) %>
|
12
|
+
|
13
|
+
render json: <%= "@#{plural_table_name}" %>
|
14
|
+
end
|
15
|
+
|
16
|
+
# GET <%= route_url %>/1
|
17
|
+
def show
|
18
|
+
render json: <%= "@#{singular_table_name}" %>
|
19
|
+
end
|
20
|
+
|
21
|
+
# POST <%= route_url %>
|
22
|
+
def create
|
23
|
+
@<%= singular_table_name %> = <%= orm_class.build(class_name, "#{singular_table_name}_params") %>
|
24
|
+
|
25
|
+
if @<%= orm_instance.save %>
|
26
|
+
render json: <%= "@#{singular_table_name}" %>, status: :created, location: <%= "@#{singular_table_name}" %>
|
27
|
+
else
|
28
|
+
render json: <%= "@#{orm_instance.errors}" %>, status: :unprocessable_entity
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# PATCH/PUT <%= route_url %>/1
|
33
|
+
def update
|
34
|
+
if @<%= orm_instance.update("#{singular_table_name}_params") %>
|
35
|
+
render json: <%= "@#{singular_table_name}" %>
|
36
|
+
else
|
37
|
+
render json: <%= "@#{orm_instance.errors}" %>, status: :unprocessable_entity
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# DELETE <%= route_url %>/1
|
42
|
+
def destroy
|
43
|
+
@<%= orm_instance.destroy %>
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
# Use callbacks to share common setup or constraints between actions.
|
48
|
+
def set_<%= singular_table_name %>
|
49
|
+
@<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
|
50
|
+
end
|
51
|
+
|
52
|
+
# Only allow a trusted parameter "white list" through.
|
53
|
+
def <%= "#{singular_table_name}_params" %>
|
54
|
+
<%- if attributes_names.empty? -%>
|
55
|
+
params.fetch(:<%= singular_table_name %>, {})
|
56
|
+
<%- else -%>
|
57
|
+
params.require(:<%= singular_table_name %>).permit(<%= attributes_names.map { |name| ":#{name}" }.join(', ') %>)
|
58
|
+
<%- end -%>
|
59
|
+
end
|
60
|
+
end
|
61
|
+
<% end -%>
|
@@ -59,7 +59,7 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
59
59
|
# Only allow a trusted parameter "white list" through.
|
60
60
|
def <%= "#{singular_table_name}_params" %>
|
61
61
|
<%- if attributes_names.empty? -%>
|
62
|
-
params
|
62
|
+
params.fetch(:<%= singular_table_name %>, {})
|
63
63
|
<%- else -%>
|
64
64
|
params.require(:<%= singular_table_name %>).permit(<%= attributes_names.map { |name| ":#{name}" }.join(', ') %>)
|
65
65
|
<%- end -%>
|
@@ -8,7 +8,7 @@ module Rails
|
|
8
8
|
module ResourceHelpers # :nodoc:
|
9
9
|
|
10
10
|
def self.included(base) #:nodoc:
|
11
|
-
base.
|
11
|
+
base.include(Rails::Generators::ModelHelpers)
|
12
12
|
base.class_option :model_name, type: :string, desc: "ModelName to be used"
|
13
13
|
end
|
14
14
|
|
@@ -39,7 +39,7 @@ module Rails
|
|
39
39
|
def assign_controller_names!(name)
|
40
40
|
@controller_name = name
|
41
41
|
@controller_class_path = name.include?('/') ? name.split('/') : name.split('::')
|
42
|
-
@controller_class_path.map!
|
42
|
+
@controller_class_path.map!(&:underscore)
|
43
43
|
@controller_file_name = @controller_class_path.pop
|
44
44
|
end
|
45
45
|
|
@@ -48,7 +48,7 @@ module Rails
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def controller_class_name
|
51
|
-
(controller_class_path + [controller_file_name]).map!
|
51
|
+
(controller_class_path + [controller_file_name]).map!(&:camelize).join('::')
|
52
52
|
end
|
53
53
|
|
54
54
|
def controller_i18n_scope
|
@@ -1,11 +1,9 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
<% module_namespacing do -%>
|
4
|
-
class <%= class_name %>ControllerTest <
|
4
|
+
class <%= class_name %>ControllerTest < ActionDispatch::IntegrationTest
|
5
5
|
<% if mountable_engine? -%>
|
6
|
-
|
7
|
-
@routes = Engine.routes
|
8
|
-
end
|
6
|
+
include Engine.routes.url_helpers
|
9
7
|
|
10
8
|
<% end -%>
|
11
9
|
<% if actions.empty? -%>
|
@@ -15,7 +13,7 @@ class <%= class_name %>ControllerTest < ActionController::TestCase
|
|
15
13
|
<% else -%>
|
16
14
|
<% actions.each do |action| -%>
|
17
15
|
test "should get <%= action %>" do
|
18
|
-
get
|
16
|
+
get <%= file_name %>_<%= action %>_url
|
19
17
|
assert_response :success
|
20
18
|
end
|
21
19
|
|
@@ -6,16 +6,21 @@ module TestUnit # :nodoc:
|
|
6
6
|
argument :actions, type: :array, default: [], banner: "method method"
|
7
7
|
|
8
8
|
def check_class_collision
|
9
|
-
class_collisions "#{class_name}
|
9
|
+
class_collisions "#{class_name}MailerTest", "#{class_name}MailerPreview"
|
10
10
|
end
|
11
11
|
|
12
12
|
def create_test_files
|
13
|
-
template "functional_test.rb", File.join('test/mailers', class_path, "#{file_name}
|
13
|
+
template "functional_test.rb", File.join('test/mailers', class_path, "#{file_name}_mailer_test.rb")
|
14
14
|
end
|
15
15
|
|
16
16
|
def create_preview_files
|
17
|
-
template "preview.rb", File.join('test/mailers/previews', class_path, "#{file_name}
|
17
|
+
template "preview.rb", File.join('test/mailers/previews', class_path, "#{file_name}_mailer_preview.rb")
|
18
18
|
end
|
19
|
+
|
20
|
+
protected
|
21
|
+
def file_name
|
22
|
+
@_file_name ||= super.gsub(/\_mailer/i, '')
|
23
|
+
end
|
19
24
|
end
|
20
25
|
end
|
21
26
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
<% module_namespacing do -%>
|
4
|
-
class <%= class_name %>
|
4
|
+
class <%= class_name %>MailerTest < ActionMailer::TestCase
|
5
5
|
<% actions.each do |action| -%>
|
6
6
|
test "<%= action %>" do
|
7
|
-
mail = <%= class_name
|
7
|
+
mail = <%= class_name %>Mailer.<%= action %>
|
8
8
|
assert_equal <%= action.to_s.humanize.inspect %>, mail.subject
|
9
9
|
assert_equal ["to@example.org"], mail.to
|
10
10
|
assert_equal ["from@example.com"], mail.from
|