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.
Files changed (180) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +262 -206
  3. data/MIT-LICENSE +20 -0
  4. data/README.rdoc +1 -1
  5. data/{bin → exe}/rails +0 -0
  6. data/lib/rails.rb +19 -1
  7. data/lib/rails/all.rb +10 -9
  8. data/lib/rails/api/task.rb +7 -14
  9. data/lib/rails/{app_rails_loader.rb → app_loader.rb} +4 -3
  10. data/lib/rails/application.rb +31 -41
  11. data/lib/rails/application/bootstrap.rb +1 -14
  12. data/lib/rails/application/configuration.rb +94 -95
  13. data/lib/rails/application/default_middleware_stack.rb +30 -16
  14. data/lib/rails/application/finisher.rb +11 -2
  15. data/lib/rails/application/routes_reloader.rb +1 -3
  16. data/lib/rails/application_controller.rb +1 -1
  17. data/lib/rails/cli.rb +2 -2
  18. data/lib/rails/code_statistics.rb +6 -8
  19. data/lib/rails/code_statistics_calculator.rb +8 -1
  20. data/lib/rails/command.rb +70 -0
  21. data/lib/rails/commands.rb +5 -3
  22. data/lib/rails/commands/commands_tasks.rb +25 -14
  23. data/lib/rails/commands/console.rb +7 -52
  24. data/lib/rails/commands/console_helper.rb +34 -0
  25. data/lib/rails/commands/dbconsole.rb +59 -78
  26. data/lib/rails/commands/dev_cache.rb +21 -0
  27. data/lib/rails/commands/plugin.rb +1 -1
  28. data/lib/rails/commands/rake_proxy.rb +34 -0
  29. data/lib/rails/commands/runner.rb +0 -1
  30. data/lib/rails/commands/server.rb +29 -36
  31. data/lib/rails/commands/test.rb +9 -0
  32. data/lib/rails/configuration.rb +21 -5
  33. data/lib/rails/console/app.rb +5 -0
  34. data/lib/rails/console/helpers.rb +1 -1
  35. data/lib/rails/engine.rb +68 -58
  36. data/lib/rails/engine/commands.rb +4 -2
  37. data/lib/rails/engine/configuration.rb +4 -10
  38. data/lib/rails/gem_version.rb +4 -4
  39. data/lib/rails/generators.rb +30 -7
  40. data/lib/rails/generators/.named_base.rb.swp +0 -0
  41. data/lib/rails/generators/actions.rb +19 -5
  42. data/lib/rails/generators/app_base.rb +65 -45
  43. data/lib/rails/generators/base.rb +6 -6
  44. data/lib/rails/generators/erb/mailer/mailer_generator.rb +5 -8
  45. data/lib/rails/generators/erb/scaffold/templates/_form.html.erb +9 -7
  46. data/lib/rails/generators/erb/scaffold/templates/edit.html.erb +1 -1
  47. data/lib/rails/generators/erb/scaffold/templates/index.html.erb +2 -2
  48. data/lib/rails/generators/erb/scaffold/templates/new.html.erb +1 -1
  49. data/lib/rails/generators/generated_attribute.rb +5 -1
  50. data/lib/rails/generators/migration.rb +7 -7
  51. data/lib/rails/generators/named_base.rb +21 -5
  52. data/lib/rails/generators/rails/app/USAGE +0 -1
  53. data/lib/rails/generators/rails/app/app_generator.rb +75 -11
  54. data/lib/rails/generators/rails/app/templates/Gemfile +17 -13
  55. data/lib/rails/generators/rails/app/templates/{README.rdoc → README.md} +1 -5
  56. data/lib/rails/generators/rails/app/templates/app/assets/config/manifest.js.tt +7 -0
  57. data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +1 -1
  58. data/lib/rails/generators/rails/app/templates/app/assets/javascripts/cable.coffee +11 -0
  59. data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css +3 -3
  60. data/lib/rails/generators/rails/app/templates/app/channels/application_cable/channel.rb +5 -0
  61. data/lib/rails/generators/rails/app/templates/app/channels/application_cable/connection.rb +5 -0
  62. data/lib/rails/generators/rails/app/templates/app/controllers/application_controller.rb.tt +3 -1
  63. data/lib/rails/generators/rails/app/templates/app/jobs/application_job.rb +2 -0
  64. data/lib/rails/generators/rails/app/templates/app/mailers/application_mailer.rb +4 -0
  65. data/lib/rails/generators/rails/app/templates/app/models/application_record.rb +3 -0
  66. data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +20 -17
  67. data/lib/rails/generators/rails/app/templates/app/views/layouts/mailer.html.erb.tt +13 -0
  68. data/lib/rails/generators/{erb/mailer/templates/layout.text.erb → rails/app/templates/app/views/layouts/mailer.text.erb.tt} +0 -0
  69. data/lib/rails/generators/rails/app/templates/bin/setup +17 -12
  70. data/lib/rails/generators/rails/app/templates/bin/update +28 -0
  71. data/lib/rails/generators/rails/app/templates/config.ru.tt +11 -0
  72. data/lib/rails/generators/rails/app/templates/config/application.rb +9 -14
  73. data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml +1 -1
  74. data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml +2 -2
  75. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +20 -3
  76. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +18 -11
  77. data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +7 -3
  78. data/lib/rails/generators/rails/app/templates/config/initializers/active_record_belongs_to_required_by_default.rb +5 -0
  79. data/lib/rails/generators/rails/app/templates/config/initializers/application_controller_renderer.rb +6 -0
  80. data/lib/rails/generators/rails/app/templates/config/initializers/callback_terminator.rb +5 -0
  81. data/lib/rails/generators/rails/app/templates/config/initializers/cookies_serializer.rb +1 -0
  82. data/lib/rails/generators/rails/app/templates/config/initializers/cors.rb +16 -0
  83. data/lib/rails/generators/rails/app/templates/config/initializers/request_forgery_protection.rb +4 -0
  84. data/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt +2 -2
  85. data/lib/rails/generators/rails/app/templates/config/redis/cable.yml +9 -0
  86. data/lib/rails/generators/rails/app/templates/config/routes.rb +3 -53
  87. data/lib/rails/generators/rails/app/templates/db/seeds.rb.tt +3 -3
  88. data/lib/rails/generators/rails/app/templates/gitignore +7 -1
  89. data/lib/rails/generators/rails/controller/controller_generator.rb +6 -4
  90. data/lib/rails/generators/rails/migration/migration_generator.rb +1 -1
  91. data/lib/rails/generators/rails/model/USAGE +6 -1
  92. data/lib/rails/generators/rails/model/model_generator.rb +1 -1
  93. data/lib/rails/generators/rails/plugin/plugin_generator.rb +88 -35
  94. data/lib/rails/generators/rails/plugin/templates/%name%.gemspec +6 -9
  95. data/lib/rails/generators/rails/plugin/templates/Gemfile +3 -7
  96. data/lib/rails/generators/rails/plugin/templates/README.md +3 -0
  97. data/lib/rails/generators/rails/plugin/templates/Rakefile +2 -2
  98. data/lib/rails/generators/rails/plugin/templates/app/controllers/%namespaced_name%/application_controller.rb.tt +5 -0
  99. data/lib/rails/generators/rails/plugin/templates/app/helpers/%namespaced_name%/application_helper.rb.tt +5 -0
  100. data/lib/rails/generators/rails/plugin/templates/app/jobs/%namespaced_name%/application_job.rb.tt +5 -0
  101. data/lib/rails/generators/rails/plugin/templates/app/models/application_record.rb.tt +6 -0
  102. data/lib/rails/generators/rails/plugin/templates/app/views/layouts/%namespaced_name%/application.html.erb.tt +14 -0
  103. data/lib/rails/generators/rails/plugin/templates/bin/rails.tt +1 -1
  104. data/lib/rails/generators/rails/plugin/templates/bin/test.tt +8 -0
  105. data/lib/rails/generators/rails/plugin/templates/config/routes.rb +1 -1
  106. data/lib/rails/generators/rails/plugin/templates/gitignore +2 -3
  107. data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%.rb +5 -0
  108. data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/engine.rb +7 -0
  109. data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/version.rb +1 -0
  110. data/lib/rails/generators/rails/plugin/templates/lib/tasks/{%name%_tasks.rake → %namespaced_name%_tasks.rake} +1 -1
  111. data/lib/rails/generators/rails/plugin/templates/rails/application.rb +3 -3
  112. data/lib/rails/generators/rails/plugin/templates/rails/dummy_manifest.js +11 -0
  113. data/lib/rails/generators/rails/plugin/templates/rails/engine_manifest.js +6 -0
  114. data/lib/rails/generators/rails/plugin/templates/rails/javascripts.js +1 -1
  115. data/lib/rails/generators/rails/plugin/templates/rails/routes.rb +1 -2
  116. data/lib/rails/generators/rails/plugin/templates/rails/stylesheets.css +3 -3
  117. data/lib/rails/generators/rails/plugin/templates/test/%namespaced_name%_test.rb +7 -0
  118. data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb +4 -2
  119. data/lib/rails/generators/rails/resource/resource_generator.rb +0 -1
  120. data/lib/rails/generators/rails/resource_route/resource_route_generator.rb +0 -1
  121. data/lib/rails/generators/rails/scaffold/USAGE +1 -1
  122. data/lib/rails/generators/rails/scaffold/scaffold_generator.rb +2 -1
  123. data/lib/rails/generators/rails/scaffold/templates/scaffold.css +35 -7
  124. data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +4 -1
  125. data/lib/rails/generators/rails/scaffold_controller/templates/api_controller.rb +61 -0
  126. data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb +1 -1
  127. data/lib/rails/generators/resource_helpers.rb +3 -3
  128. data/lib/rails/generators/test_unit/controller/templates/.functional_test.rb.swp +0 -0
  129. data/lib/rails/generators/test_unit/controller/templates/functional_test.rb +3 -5
  130. data/lib/rails/generators/test_unit/mailer/mailer_generator.rb +8 -3
  131. data/lib/rails/generators/test_unit/mailer/templates/functional_test.rb +2 -2
  132. data/lib/rails/generators/test_unit/mailer/templates/preview.rb +4 -4
  133. data/lib/rails/generators/test_unit/model/model_generator.rb +1 -1
  134. data/lib/rails/generators/test_unit/model/templates/fixtures.yml +2 -0
  135. data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +5 -1
  136. data/lib/rails/generators/test_unit/scaffold/templates/.api_functional_test.rb.swp +0 -0
  137. data/lib/rails/generators/test_unit/scaffold/templates/.functional_test.rb.swp +0 -0
  138. data/lib/rails/generators/test_unit/scaffold/templates/api_functional_test.rb +44 -0
  139. data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb +14 -14
  140. data/lib/rails/generators/testing/assertions.rb +0 -2
  141. data/lib/rails/generators/testing/behaviour.rb +4 -17
  142. data/lib/rails/info.rb +2 -2
  143. data/lib/rails/info_controller.rb +23 -2
  144. data/lib/rails/mailers_controller.rb +2 -2
  145. data/lib/rails/paths.rb +14 -6
  146. data/lib/rails/rack.rb +1 -3
  147. data/lib/rails/rack/debugger.rb +2 -23
  148. data/lib/rails/rack/logger.rb +4 -0
  149. data/lib/rails/ruby_version_check.rb +3 -3
  150. data/lib/rails/source_annotation_extractor.rb +1 -1
  151. data/lib/rails/tasks.rb +4 -1
  152. data/lib/rails/tasks/engine.rake +1 -1
  153. data/lib/rails/tasks/framework.rake +18 -16
  154. data/lib/rails/tasks/initializers.rake +6 -0
  155. data/lib/rails/tasks/restart.rake +5 -0
  156. data/lib/rails/tasks/statistics.rake +5 -6
  157. data/lib/rails/tasks/tmp.rake +4 -12
  158. data/lib/rails/templates/rails/mailers/email.html.erb +17 -3
  159. data/lib/rails/templates/rails/welcome/index.html.erb +10 -3
  160. data/lib/rails/test_help.rb +7 -8
  161. data/lib/rails/test_unit/minitest_plugin.rb +91 -0
  162. data/lib/rails/test_unit/reporter.rb +74 -0
  163. data/lib/rails/test_unit/test_requirer.rb +28 -0
  164. data/lib/rails/test_unit/testing.rake +18 -39
  165. metadata +80 -33
  166. data/lib/rails/deprecation.rb +0 -19
  167. data/lib/rails/generators/erb/mailer/templates/layout.html.erb +0 -5
  168. data/lib/rails/generators/rails/app/templates/config.ru +0 -4
  169. data/lib/rails/generators/rails/app/templates/config/initializers/to_time_preserves_timezone.rb +0 -10
  170. data/lib/rails/generators/rails/plugin/templates/README.rdoc +0 -3
  171. data/lib/rails/generators/rails/plugin/templates/app/controllers/%name%/application_controller.rb.tt +0 -5
  172. data/lib/rails/generators/rails/plugin/templates/app/helpers/%name%/application_helper.rb.tt +0 -4
  173. data/lib/rails/generators/rails/plugin/templates/app/views/layouts/%name%/application.html.erb.tt +0 -14
  174. data/lib/rails/generators/rails/plugin/templates/lib/%name%.rb +0 -6
  175. data/lib/rails/generators/rails/plugin/templates/lib/%name%/engine.rb +0 -7
  176. data/lib/rails/generators/rails/plugin/templates/lib/%name%/version.rb +0 -3
  177. data/lib/rails/generators/rails/plugin/templates/test/%name%_test.rb +0 -7
  178. data/lib/rails/rack/log_tailer.rb +0 -38
  179. data/lib/rails/tasks/documentation.rake +0 -70
  180. 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/<%= name -%>/engine', __FILE__)
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__)
@@ -0,0 +1,8 @@
1
+ $: << File.expand_path(File.expand_path('../../test', __FILE__))
2
+
3
+ require 'bundler/setup'
4
+ require 'rails/test_unit/minitest_plugin'
5
+
6
+ Rails::TestUnitReporter.executable = 'bin/test'
7
+
8
+ exit Minitest.run(ARGV)
@@ -1,5 +1,5 @@
1
1
  <% if mountable? -%>
2
- <%= camelized %>::Engine.routes.draw do
2
+ <%= camelized_modules %>::Engine.routes.draw do
3
3
  <% else -%>
4
4
  Rails.application.routes.draw do
5
5
  <% end -%>
@@ -1,10 +1,9 @@
1
1
  .bundle/
2
2
  log/*.log
3
3
  pkg/
4
- <% unless options[:skip_test_unit] && options[:dummy_path] == 'test/dummy' -%>
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
- <%= dummy_path %>/.sass-cache
10
- <% end -%>
9
+ <% end -%>
@@ -0,0 +1,5 @@
1
+ <% if engine? -%>
2
+ require "<%= namespaced_name %>/engine"
3
+
4
+ <% end -%>
5
+ <%= wrap_in_modules "# Your code goes here..." %>
@@ -0,0 +1,7 @@
1
+ <%= wrap_in_modules <<-rb.strip_heredoc
2
+ class Engine < ::Rails::Engine
3
+ #{mountable? ? ' isolate_namespace ' + camelized_modules : ' '}
4
+ #{api? ? " config.generators.api_only = true" : ' '}
5
+ end
6
+ rb
7
+ %>
@@ -0,0 +1 @@
1
+ <%= wrap_in_modules "VERSION = '0.1.0'" %>
@@ -1,4 +1,4 @@
1
1
  # desc "Explaining what the task does"
2
- # task :<%= name %> do
2
+ # task :<%= underscored_name %> do
3
3
  # # Task goes here
4
4
  # end
@@ -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 :skip_test_unit %>require "rails/test_unit/railtie"
12
+ <%= comment_if :skip_test %>require "rails/test_unit/railtie"
13
13
  <% end -%>
14
14
 
15
15
  Bundler.require(*Rails.groups)
16
- require "<%= name %>"
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 -%>
@@ -0,0 +1,6 @@
1
+ <% if mountable? -%>
2
+ <% if !options.skip_javascript -%>
3
+ //= link_directory ../javascripts/<%= namespaced_name %> .js
4
+ <% end -%>
5
+ //= link_directory ../stylesheets/<%= namespaced_name %> .css
6
+ <% 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.
@@ -1,4 +1,3 @@
1
1
  Rails.application.routes.draw do
2
-
3
- mount <%= camelized %>::Engine => "/<%= name %>"
2
+ mount <%= camelized_modules %>::Engine => "/<%= name %>"
4
3
  end
@@ -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 styles
10
- * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
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
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class <%= camelized_modules %>::Test < ActiveSupport::TestCase
4
+ test "truth" do
5
+ assert_kind_of Module, <%= camelized_modules %>
6
+ end
7
+ end
@@ -14,12 +14,14 @@ require "rails/test_help"
14
14
  # to be shown.
15
15
  Minitest.backtrace_filter = Minitest::BacktraceFilter.new
16
16
 
17
- # Load support files
18
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
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
@@ -1,6 +1,5 @@
1
1
  require 'rails/generators/resource_helpers'
2
2
  require 'rails/generators/rails/model/model_generator'
3
- require 'active_support/core_ext/object/blank'
4
3
 
5
4
  module Rails
6
5
  module Generators
@@ -1,7 +1,6 @@
1
1
  module Rails
2
2
  module Generators
3
3
  class ResourceRouteGenerator < NamedBase # :nodoc:
4
-
5
4
  # Properly nests namespaces passed into a generator
6
5
  #
7
6
  # $ rails generate resource admin/users/products
@@ -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 { background-color: #fff; color: #333; }
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: 13px;
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 { color: #000; }
16
- a:visited { color: #666; }
17
- a:hover { color: #fff; background-color:#000; }
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
- div.field, div.actions {
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: 0px;
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
- template "controller.rb", File.join('app/controllers', controller_class_path, "#{controller_file_name}_controller.rb")
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[:<%= singular_table_name %>]
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.send :include, Rails::Generators::ModelHelpers
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! { |m| m.underscore }
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!{ |m| m.camelize }.join('::')
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 < ActionController::TestCase
4
+ class <%= class_name %>ControllerTest < ActionDispatch::IntegrationTest
5
5
  <% if mountable_engine? -%>
6
- setup do
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 :<%= action %>
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}Test", "#{class_name}Preview"
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}_test.rb")
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}_preview.rb")
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 %>Test < ActionMailer::TestCase
4
+ class <%= class_name %>MailerTest < ActionMailer::TestCase
5
5
  <% actions.each do |action| -%>
6
6
  test "<%= action %>" do
7
- mail = <%= class_name %>.<%= action %>
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