railties 4.1.16 → 4.2.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +80 -439
  3. data/RDOC_MAIN.rdoc +1 -1
  4. data/README.rdoc +6 -2
  5. data/lib/rails.rb +7 -1
  6. data/lib/rails/all.rb +1 -0
  7. data/lib/rails/api/task.rb +7 -0
  8. data/lib/rails/app_rails_loader.rb +4 -2
  9. data/lib/rails/application.rb +74 -47
  10. data/lib/rails/application/configuration.rb +23 -1
  11. data/lib/rails/application/finisher.rb +0 -2
  12. data/lib/rails/code_statistics.rb +4 -2
  13. data/lib/rails/commands/commands_tasks.rb +1 -6
  14. data/lib/rails/commands/console.rb +24 -12
  15. data/lib/rails/commands/dbconsole.rb +2 -2
  16. data/lib/rails/commands/plugin.rb +1 -1
  17. data/lib/rails/commands/server.rb +22 -9
  18. data/lib/rails/engine.rb +7 -7
  19. data/lib/rails/gem_version.rb +3 -3
  20. data/lib/rails/generators.rb +68 -15
  21. data/lib/rails/generators/actions.rb +27 -7
  22. data/lib/rails/generators/actions/create_migration.rb +2 -1
  23. data/lib/rails/generators/app_base.rb +55 -65
  24. data/lib/rails/generators/base.rb +2 -2
  25. data/lib/rails/generators/erb/scaffold/templates/_form.html.erb +0 -5
  26. data/lib/rails/generators/erb/scaffold/templates/edit.html.erb +1 -1
  27. data/lib/rails/generators/erb/scaffold/templates/index.html.erb +3 -1
  28. data/lib/rails/generators/erb/scaffold/templates/new.html.erb +1 -1
  29. data/lib/rails/generators/generated_attribute.rb +24 -4
  30. data/lib/rails/generators/model_helpers.rb +28 -0
  31. data/lib/rails/generators/rails/app/app_generator.rb +8 -2
  32. data/lib/rails/generators/rails/app/templates/Gemfile +21 -6
  33. data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +1 -1
  34. data/lib/rails/generators/rails/app/templates/bin/setup +28 -0
  35. data/lib/rails/generators/rails/app/templates/config/application.rb +5 -1
  36. data/lib/rails/generators/rails/app/templates/config/boot.rb +1 -2
  37. data/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml +1 -3
  38. data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml +1 -1
  39. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +4 -0
  40. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +8 -10
  41. data/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +3 -0
  42. data/lib/rails/generators/rails/app/templates/config/initializers/cookies_serializer.rb +1 -1
  43. data/lib/rails/generators/rails/app/templates/gitignore +2 -0
  44. data/lib/rails/generators/rails/controller/USAGE +0 -1
  45. data/lib/rails/generators/rails/controller/controller_generator.rb +6 -2
  46. data/lib/rails/generators/rails/helper/USAGE +0 -4
  47. data/lib/rails/generators/rails/model/USAGE +11 -1
  48. data/lib/rails/generators/rails/model/model_generator.rb +4 -0
  49. data/lib/rails/generators/rails/plugin/plugin_generator.rb +1 -3
  50. data/lib/rails/generators/rails/plugin/templates/%name%.gemspec +1 -1
  51. data/lib/rails/generators/rails/plugin/templates/Gemfile +10 -6
  52. data/lib/rails/generators/rails/plugin/templates/Rakefile +4 -0
  53. data/lib/rails/generators/rails/plugin/templates/app/controllers/%name%/application_controller.rb.tt +0 -1
  54. data/lib/rails/generators/rails/plugin/templates/rails/javascripts.js +1 -1
  55. data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb +2 -10
  56. data/lib/rails/generators/rails/resource_route/resource_route_generator.rb +2 -4
  57. data/lib/rails/generators/rails/scaffold/USAGE +7 -1
  58. data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +0 -1
  59. data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb +1 -1
  60. data/lib/rails/generators/resource_helpers.rb +2 -11
  61. data/lib/rails/generators/test_unit/helper/helper_generator.rb +1 -5
  62. data/lib/rails/generators/testing/behaviour.rb +17 -0
  63. data/lib/rails/info.rb +1 -1
  64. data/lib/rails/info_controller.rb +1 -1
  65. data/lib/rails/mailers_controller.rb +14 -16
  66. data/lib/rails/paths.rb +1 -1
  67. data/lib/rails/rack.rb +1 -1
  68. data/lib/rails/rack/log_tailer.rb +4 -0
  69. data/lib/rails/rack/logger.rb +1 -1
  70. data/lib/rails/railtie.rb +2 -2
  71. data/lib/rails/ruby_version_check.rb +1 -1
  72. data/lib/rails/source_annotation_extractor.rb +23 -16
  73. data/lib/rails/tasks/framework.rake +1 -1
  74. data/lib/rails/tasks/statistics.rake +8 -3
  75. data/lib/rails/templates/rails/mailers/email.html.erb +2 -13
  76. data/lib/rails/templates/rails/mailers/index.html.erb +2 -2
  77. data/lib/rails/templates/rails/mailers/mailer.html.erb +1 -1
  78. data/lib/rails/test_unit/sub_test_task.rb +2 -2
  79. metadata +13 -13
  80. data/lib/rails/generators/test_unit/helper/templates/helper_test.rb +0 -6
  81. data/lib/rails/rubyprof_ext.rb +0 -35
@@ -5,13 +5,9 @@ Description:
5
5
  To create a helper within a module, specify the helper name as a
6
6
  path like 'parent_module/helper_name'.
7
7
 
8
- This generates a helper class in app/helpers and invokes the configured
9
- test framework.
10
-
11
8
  Example:
12
9
  `rails generate helper CreditCard`
13
10
 
14
11
  Credit card helper.
15
12
  Helper: app/helpers/credit_card_helper.rb
16
- Test: test/helpers/credit_card_helper_test.rb
17
13
 
@@ -6,6 +6,11 @@ Description:
6
6
  model's attributes. Timestamps are added by default, so you don't have to
7
7
  specify them by hand as 'created_at:datetime updated_at:datetime'.
8
8
 
9
+ As a special case, specifying 'password:digest' will generate a
10
+ password_digest field of string type, and configure your generated model and
11
+ tests for use with ActiveModel has_secure_password (assuming the default ORM
12
+ and test framework are being used).
13
+
9
14
  You don't have to think up every attribute up front, but it helps to
10
15
  sketch out a few so you can start working with the model immediately.
11
16
 
@@ -27,7 +32,8 @@ Available field types:
27
32
  `rails generate model post title:string body:text`
28
33
 
29
34
  will generate a title column with a varchar type and a body column with a text
30
- type. You can use the following types:
35
+ type. If no type is specified the string type will be used by default.
36
+ You can use the following types:
31
37
 
32
38
  integer
33
39
  primary_key
@@ -73,6 +79,10 @@ Available field types:
73
79
  `rails generate model user username:string{30}:uniq`
74
80
  `rails generate model product supplier:references{polymorphic}:index`
75
81
 
82
+ If you require a `password_digest` string column for use with
83
+ has_secure_password, you should specify `password:digest`:
84
+
85
+ `rails generate model user password:digest`
76
86
 
77
87
  Examples:
78
88
  `rails generate model account`
@@ -1,6 +1,10 @@
1
+ require 'rails/generators/model_helpers'
2
+
1
3
  module Rails
2
4
  module Generators
3
5
  class ModelGenerator < NamedBase # :nodoc:
6
+ include Rails::Generators::ModelHelpers
7
+
4
8
  argument :attributes, type: :array, default: [], banner: "field[:type][:index] field[:type][:index]"
5
9
  hook_for :orm, required: true
6
10
  end
@@ -241,7 +241,7 @@ task default: :test
241
241
  build(:leftovers)
242
242
  end
243
243
 
244
- public_task :apply_rails_template
244
+ public_task :apply_rails_template, :run_bundle
245
245
 
246
246
  def name
247
247
  @name ||= begin
@@ -315,7 +315,6 @@ task default: :test
315
315
  else
316
316
  @author = `git config user.name`.chomp rescue default
317
317
  end
318
- @author
319
318
  end
320
319
 
321
320
  def email
@@ -325,7 +324,6 @@ task default: :test
325
324
  else
326
325
  @email = `git config user.email`.chomp rescue default
327
326
  end
328
- @email
329
327
  end
330
328
 
331
329
  def valid_const?
@@ -22,6 +22,6 @@ Gem::Specification.new do |s|
22
22
  <%= '# ' if options.dev? || options.edge? -%>s.add_dependency "rails", "~> <%= Rails::VERSION::STRING %>"
23
23
  <% unless options[:skip_active_record] -%>
24
24
 
25
- s.add_development_dependency "<%= gem_for_database[0] %>"
25
+ s.add_development_dependency "<%= gem_for_database %>"
26
26
  <% end -%>
27
27
  end
@@ -1,7 +1,7 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
3
  <% if options[:skip_gemspec] -%>
4
- <%= '# ' if options.dev? || options.edge? -%>gem "rails", "~> <%= Rails::VERSION::STRING %>"
4
+ <%= '# ' if options.dev? || options.edge? -%>gem 'rails', '~> <%= Rails::VERSION::STRING %>'
5
5
  <% else -%>
6
6
  # Declare your gem's dependencies in <%= name %>.gemspec.
7
7
  # Bundler will treat runtime dependencies like base dependencies, and
@@ -11,7 +11,7 @@ gemspec
11
11
 
12
12
  <% if options[:skip_gemspec] -%>
13
13
  group :development do
14
- gem "<%= gem_for_database[0] %>"
14
+ gem '<%= gem_for_database %>'
15
15
  end
16
16
  <% else -%>
17
17
  # Declare any dependencies that are still in development here instead of in
@@ -31,13 +31,17 @@ end
31
31
  <% end -%>
32
32
  <%= gem.commented_out ? '# ' : '' %>gem '<%= gem.name %>'<%= %(, '#{gem.version}') if gem.version -%>
33
33
  <% if gem.options.any? -%>
34
- ,<%= gem.padding(max_width) %><%= gem.options.map { |k,v|
34
+ , <%= gem.options.map { |k,v|
35
35
  "#{k}: #{v.inspect}" }.join(', ') %>
36
36
  <% end -%>
37
37
  <% end -%>
38
38
 
39
39
  <% end -%>
40
40
  <% unless defined?(JRUBY_VERSION) -%>
41
- # To use debugger
42
- # gem 'debugger'
41
+ # To use a debugger
42
+ <%- if RUBY_VERSION < '2.0.0' -%>
43
+ # gem 'debugger', group: [:development, :test]
44
+ <%- else -%>
45
+ # gem 'byebug', group: [:development, :test]
46
+ <%- end -%>
43
47
  <% end -%>
@@ -19,6 +19,10 @@ APP_RAKEFILE = File.expand_path("../<%= dummy_path -%>/Rakefile", __FILE__)
19
19
  load 'rails/tasks/engine.rake'
20
20
  <% end %>
21
21
 
22
+ <% if engine? -%>
23
+ load 'rails/tasks/statistics.rake'
24
+ <% end %>
25
+
22
26
  <% unless options[:skip_gemspec] -%>
23
27
 
24
28
  Bundler::GemHelper.install_tasks
@@ -1,5 +1,4 @@
1
1
  module <%= camelized %>
2
2
  class ApplicationController < ActionController::Base
3
- protect_from_forgery with: :exception
4
3
  end
5
4
  end
@@ -7,7 +7,7 @@
7
7
  // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
8
  // compiled file.
9
9
  //
10
- // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
11
  // about supported directives.
12
12
  //
13
13
  //= require_tree .
@@ -1,18 +1,10 @@
1
1
  # Configure Rails Environment
2
2
  ENV["RAILS_ENV"] = "test"
3
3
 
4
- require File.expand_path("../../<%= options[:dummy_path] -%>/config/environment.rb", __FILE__)
5
- <% unless options[:skip_active_record] -%>
6
- ActiveRecord::Migrator.migrations_paths = [File.expand_path("../../<%= options[:dummy_path] -%>/db/migrate", __FILE__)]
7
- <% if options[:mountable] -%>
8
- ActiveRecord::Migrator.migrations_paths << File.expand_path('../../db/migrate', __FILE__)
9
- <% end -%>
10
- <% end -%>
4
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
11
5
  require "rails/test_help"
12
6
 
13
- # Filter out Minitest backtrace while allowing backtrace from other libraries
14
- # to be shown.
15
- Minitest.backtrace_filter = Minitest::BacktraceFilter.new
7
+ Rails.backtrace_cleaner.remove_silencers!
16
8
 
17
9
  # Load support files
18
10
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
@@ -29,10 +29,8 @@ module Rails
29
29
  write("end", route_length - index)
30
30
  end
31
31
 
32
- # route prepends two spaces onto the front of the string that is passed, this corrects that.
33
- # Also it adds a \n to the end of each line, as route already adds that
34
- # we need to correct that too.
35
- route route_string[2..-2]
32
+ # route prepends two spaces onto the front of the string that is passed, this corrects that
33
+ route route_string[2..-1]
36
34
  end
37
35
 
38
36
  private
@@ -9,11 +9,16 @@ Description:
9
9
 
10
10
  Attributes are field arguments specifying the model's attributes. You can
11
11
  optionally pass the type and an index to each field. For instance:
12
- "title body:text tracking_id:integer:uniq" will generate a title field of
12
+ 'title body:text tracking_id:integer:uniq' will generate a title field of
13
13
  string type, a body with text type and a tracking_id as an integer with an
14
14
  unique index. "index" could also be given instead of "uniq" if one desires
15
15
  a non unique index.
16
16
 
17
+ As a special case, specifying 'password:digest' will generate a
18
+ password_digest field of string type, and configure your generated model,
19
+ controller, views, and test suite for use with ActiveModel
20
+ has_secure_password (assuming they are using Rails defaults).
21
+
17
22
  Timestamps are added by default, so you don't have to specify them by hand
18
23
  as 'created_at:datetime updated_at:datetime'.
19
24
 
@@ -33,3 +38,4 @@ Examples:
33
38
  `rails generate scaffold post`
34
39
  `rails generate scaffold post title body:text published:boolean`
35
40
  `rails generate scaffold purchase amount:decimal tracking_id:integer:uniq`
41
+ `rails generate scaffold user email:uniq password:digest`
@@ -7,7 +7,6 @@ module Rails
7
7
 
8
8
  check_class_collision suffix: "Controller"
9
9
 
10
- class_option :helper, type: :boolean
11
10
  class_option :orm, banner: "NAME", type: :string, required: true,
12
11
  desc: "ORM to generate the controller for"
13
12
 
@@ -1,5 +1,5 @@
1
1
  <% if namespaced? -%>
2
- require_dependency "<%= namespaced_path %>/application_controller"
2
+ require_dependency "<%= namespaced_file_path %>/application_controller"
3
3
 
4
4
  <% end -%>
5
5
  <% module_namespacing do -%>
@@ -1,14 +1,14 @@
1
1
  require 'rails/generators/active_model'
2
+ require 'rails/generators/model_helpers'
2
3
 
3
4
  module Rails
4
5
  module Generators
5
6
  # Deal with controller names on scaffold and add some helpers to deal with
6
7
  # ActiveModel.
7
8
  module ResourceHelpers # :nodoc:
8
- mattr_accessor :skip_warn
9
9
 
10
10
  def self.included(base) #:nodoc:
11
- base.class_option :force_plural, type: :boolean, desc: "Forces the use of a plural ModelName"
11
+ base.send :include, Rails::Generators::ModelHelpers
12
12
  base.class_option :model_name, type: :string, desc: "ModelName to be used"
13
13
  end
14
14
 
@@ -21,15 +21,6 @@ module Rails
21
21
  assign_names!(self.name)
22
22
  end
23
23
 
24
- if name == name.pluralize && name.singularize != name.pluralize && !options[:force_plural]
25
- unless ResourceHelpers.skip_warn
26
- say "Plural version of the model detected, using singularized version. Override with --force-plural."
27
- ResourceHelpers.skip_warn = true
28
- end
29
- name.replace name.singularize
30
- assign_names!(name)
31
- end
32
-
33
24
  assign_controller_names!(controller_name.pluralize)
34
25
  end
35
26
 
@@ -3,11 +3,7 @@ require 'rails/generators/test_unit'
3
3
  module TestUnit # :nodoc:
4
4
  module Generators # :nodoc:
5
5
  class HelperGenerator < Base # :nodoc:
6
- check_class_collision suffix: "HelperTest"
7
-
8
- def create_helper_files
9
- template 'helper_test.rb', File.join('test/helpers', class_path, "#{file_name}_helper_test.rb")
10
- end
6
+ # Rails does not generate anything here.
11
7
  end
12
8
  end
13
9
  end
@@ -100,6 +100,23 @@ module Rails
100
100
  dirname, file_name = File.dirname(absolute), File.basename(absolute).sub(/\.rb$/, '')
101
101
  Dir.glob("#{dirname}/[0-9]*_*.rb").grep(/\d+_#{file_name}.rb$/).first
102
102
  end
103
+
104
+ def capture(stream)
105
+ stream = stream.to_s
106
+ captured_stream = Tempfile.new(stream)
107
+ stream_io = eval("$#{stream}")
108
+ origin_stream = stream_io.dup
109
+ stream_io.reopen(captured_stream)
110
+
111
+ yield
112
+
113
+ stream_io.rewind
114
+ return captured_stream.read
115
+ ensure
116
+ captured_stream.close
117
+ captured_stream.unlink
118
+ stream_io.reopen(origin_stream)
119
+ end
103
120
  end
104
121
  end
105
122
  end
data/lib/rails/info.rb CHANGED
@@ -23,7 +23,7 @@ module Rails
23
23
  end
24
24
 
25
25
  def frameworks
26
- %w( active_record action_pack action_view action_mailer active_support )
26
+ %w( active_record action_pack action_view action_mailer active_support active_model )
27
27
  end
28
28
 
29
29
  def framework_version(framework)
@@ -5,7 +5,7 @@ class Rails::InfoController < Rails::ApplicationController # :nodoc:
5
5
  prepend_view_path ActionDispatch::DebugExceptions::RESCUES_TEMPLATE_PATH
6
6
  layout -> { request.xhr? ? false : 'application' }
7
7
 
8
- before_filter :require_local!
8
+ before_action :require_local!
9
9
 
10
10
  def index
11
11
  redirect_to action: :routes
@@ -3,8 +3,8 @@ require 'rails/application_controller'
3
3
  class Rails::MailersController < Rails::ApplicationController # :nodoc:
4
4
  prepend_view_path ActionDispatch::DebugExceptions::RESCUES_TEMPLATE_PATH
5
5
 
6
- before_filter :require_local!
7
- before_filter :find_preview, only: :preview
6
+ before_action :require_local!
7
+ before_action :find_preview, only: :preview
8
8
 
9
9
  def index
10
10
  @previews = ActionMailer::Preview.all
@@ -16,10 +16,10 @@ class Rails::MailersController < Rails::ApplicationController # :nodoc:
16
16
  @page_title = "Mailer Previews for #{@preview.preview_name}"
17
17
  render action: 'mailer'
18
18
  else
19
- @email_action = File.basename(params[:path])
19
+ email = File.basename(params[:path])
20
20
 
21
- if @preview.email_exists?(@email_action)
22
- @email = @preview.call(@email_action)
21
+ if @preview.email_exists?(email)
22
+ @email = @preview.call(email)
23
23
 
24
24
  if params[:part]
25
25
  part_type = Mime::Type.lookup(params[:part])
@@ -28,14 +28,14 @@ class Rails::MailersController < Rails::ApplicationController # :nodoc:
28
28
  response.content_type = part_type
29
29
  render text: part.respond_to?(:decoded) ? part.decoded : part
30
30
  else
31
- raise AbstractController::ActionNotFound, "Email part '#{part_type}' not found in #{@preview.name}##{@email_action}"
31
+ raise AbstractController::ActionNotFound, "Email part '#{part_type}' not found in #{@preview.name}##{email}"
32
32
  end
33
33
  else
34
34
  @part = find_preferred_part(request.format, Mime::HTML, Mime::TEXT)
35
35
  render action: 'email', layout: false, formats: %w[html]
36
36
  end
37
37
  else
38
- raise AbstractController::ActionNotFound, "Email '#{@email_action}' not found in #{@preview.name}"
38
+ raise AbstractController::ActionNotFound, "Email '#{email}' not found in #{@preview.name}"
39
39
  end
40
40
  end
41
41
  end
@@ -54,22 +54,20 @@ class Rails::MailersController < Rails::ApplicationController # :nodoc:
54
54
  end
55
55
 
56
56
  def find_preferred_part(*formats)
57
- formats.each do |format|
58
- if part = @email.find_first_mime_type(format)
59
- return part
57
+ if @email.multipart?
58
+ formats.each do |format|
59
+ return find_part(format) if @email.parts.any?{ |p| p.mime_type == format }
60
60
  end
61
- end
62
-
63
- if formats.any?{ |f| @email.mime_type == f }
61
+ else
64
62
  @email
65
63
  end
66
64
  end
67
65
 
68
66
  def find_part(format)
69
- if part = @email.find_first_mime_type(format)
70
- part
67
+ if @email.multipart?
68
+ @email.parts.find{ |p| p.mime_type == format }
71
69
  elsif @email.mime_type == format
72
70
  @email
73
71
  end
74
72
  end
75
- end
73
+ end
data/lib/rails/paths.rb CHANGED
@@ -101,7 +101,7 @@ module Rails
101
101
  def filter_by(&block)
102
102
  all_paths.find_all(&block).flat_map { |path|
103
103
  paths = path.existent
104
- paths - path.children.map { |p| yield(p) ? [] : p.existent }.flatten
104
+ paths - path.children.flat_map { |p| yield(p) ? [] : p.existent }
105
105
  }.uniq
106
106
  end
107
107
  end
data/lib/rails/rack.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Rails
2
2
  module Rack
3
- autoload :Debugger, "rails/rack/debugger"
3
+ autoload :Debugger, "rails/rack/debugger" if RUBY_VERSION < '2.0.0'
4
4
  autoload :Logger, "rails/rack/logger"
5
5
  autoload :LogTailer, "rails/rack/log_tailer"
6
6
  end
@@ -1,7 +1,11 @@
1
+ require 'active_support/deprecation'
2
+
1
3
  module Rails
2
4
  module Rack
3
5
  class LogTailer
4
6
  def initialize(app, log = nil)
7
+ ActiveSupport::Deprecation.warn "LogTailer is deprecated and will be removed on Rails 5"
8
+
5
9
  @app = app
6
10
 
7
11
  path = Pathname.new(log || "#{::File.expand_path(Rails.root)}/log/#{Rails.env}.log").cleanpath
@@ -34,7 +34,7 @@ module Rails
34
34
 
35
35
  instrumenter = ActiveSupport::Notifications.instrumenter
36
36
  instrumenter.start 'request.action_dispatch', request: request
37
- logger.info started_request_message(request)
37
+ logger.info { started_request_message(request) }
38
38
  resp = @app.call(env)
39
39
  resp[2] = ::Rack::BodyProxy.new(resp[2]) { finish(request) }
40
40
  resp