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
data/RDOC_MAIN.rdoc CHANGED
@@ -1,7 +1,7 @@
1
1
  == Welcome to \Rails
2
2
 
3
3
  \Rails is a web-application framework that includes everything needed to create
4
- database-backed web applications according to the {Model-View-Controller (MVC)}[http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller] pattern.
4
+ database-backed web applications according to the {Model-View-Controller (MVC)}[http://en.wikipedia.org/wiki/Model-view-controller] pattern.
5
5
 
6
6
  Understanding the MVC pattern is key to understanding \Rails. MVC divides your application
7
7
  into three layers, each with a specific responsibility.
data/README.rdoc CHANGED
@@ -17,7 +17,7 @@ The latest version of Railties can be installed with RubyGems:
17
17
 
18
18
  Source code can be downloaded as part of the Rails project on GitHub
19
19
 
20
- * https://github.com/rails/rails/tree/4-1-stable/railties
20
+ * https://github.com/rails/rails/tree/master/railties
21
21
 
22
22
  == License
23
23
 
@@ -31,7 +31,11 @@ API documentation is at
31
31
 
32
32
  * http://api.rubyonrails.org
33
33
 
34
- Bug reports and feature requests can be filed with the rest for the Ruby on Rails project here:
34
+ Bug reports can be filed for the Ruby on Rails project here:
35
35
 
36
36
  * https://github.com/rails/rails/issues
37
37
 
38
+ Feature requests should be discussed on the rails-core mailing list here:
39
+
40
+ * https://groups.google.com/forum/?fromgroups#!forum/rubyonrails-core
41
+
data/lib/rails.rb CHANGED
@@ -29,7 +29,13 @@ module Rails
29
29
  autoload :WelcomeController
30
30
 
31
31
  class << self
32
- attr_accessor :application, :cache, :logger
32
+ @application = @app_class = nil
33
+
34
+ attr_writer :application
35
+ attr_accessor :app_class, :cache, :logger
36
+ def application
37
+ @application ||= (app_class.instance if app_class)
38
+ end
33
39
 
34
40
  delegate :initialize!, :initialized?, to: :application
35
41
 
data/lib/rails/all.rb CHANGED
@@ -5,6 +5,7 @@ require "rails"
5
5
  action_controller
6
6
  action_view
7
7
  action_mailer
8
+ active_job
8
9
  rails/test_unit
9
10
  sprockets
10
11
  ).each do |framework|
@@ -50,6 +50,13 @@ module Rails
50
50
  )
51
51
  },
52
52
 
53
+ 'activejob' => {
54
+ :include => %w(
55
+ README.md
56
+ lib/active_job/**/*.rb
57
+ )
58
+ },
59
+
53
60
  'railties' => {
54
61
  :include => %w(
55
62
  README.rdoc
@@ -2,6 +2,8 @@ require 'pathname'
2
2
 
3
3
  module Rails
4
4
  module AppRailsLoader
5
+ extend self
6
+
5
7
  RUBY = Gem.ruby
6
8
  EXECUTABLES = ['bin/rails', 'script/rails']
7
9
  BUNDLER_WARNING = <<EOS
@@ -26,7 +28,7 @@ generate it and add it to source control:
26
28
 
27
29
  EOS
28
30
 
29
- def self.exec_app_rails
31
+ def exec_app_rails
30
32
  original_cwd = Dir.pwd
31
33
 
32
34
  loop do
@@ -54,7 +56,7 @@ EOS
54
56
  end
55
57
  end
56
58
 
57
- def self.find_executable
59
+ def find_executable
58
60
  EXECUTABLES.find { |exe| File.file?(exe) }
59
61
  end
60
62
  end
@@ -87,7 +87,15 @@ module Rails
87
87
  class << self
88
88
  def inherited(base)
89
89
  super
90
- base.instance
90
+ Rails.app_class = base
91
+ end
92
+
93
+ def instance
94
+ super.run_load_hooks!
95
+ end
96
+
97
+ def create(initial_variable_values = {}, &block)
98
+ new(initial_variable_values, &block).run_load_hooks!
91
99
  end
92
100
 
93
101
  # Makes the +new+ method public.
@@ -116,24 +124,33 @@ module Rails
116
124
  @ordered_railties = nil
117
125
  @railties = nil
118
126
  @message_verifiers = {}
127
+ @ran_load_hooks = false
119
128
 
120
- Rails.application ||= self
129
+ # are these actually used?
130
+ @initial_variable_values = initial_variable_values
131
+ @block = block
121
132
 
122
133
  add_lib_to_load_path!
134
+ end
135
+
136
+ # Returns true if the application is initialized.
137
+ def initialized?
138
+ @initialized
139
+ end
140
+
141
+ def run_load_hooks! # :nodoc:
142
+ return self if @ran_load_hooks
143
+ @ran_load_hooks = true
123
144
  ActiveSupport.run_load_hooks(:before_configuration, self)
124
145
 
125
- initial_variable_values.each do |variable_name, value|
146
+ @initial_variable_values.each do |variable_name, value|
126
147
  if INITIAL_VARIABLES.include?(variable_name)
127
148
  instance_variable_set("@#{variable_name}", value)
128
149
  end
129
150
  end
130
151
 
131
- instance_eval(&block) if block_given?
132
- end
133
-
134
- # Returns true if the application is initialized.
135
- def initialized?
136
- @initialized
152
+ instance_eval(&@block) if @block
153
+ self
137
154
  end
138
155
 
139
156
  # Implements call according to the Rack API. It simply
@@ -153,14 +170,13 @@ module Rails
153
170
  def key_generator
154
171
  # number of iterations selected based on consultation with the google security
155
172
  # team. Details at https://github.com/rails/rails/pull/6952#issuecomment-7661220
156
- @caching_key_generator ||= begin
173
+ @caching_key_generator ||=
157
174
  if secrets.secret_key_base
158
175
  key_generator = ActiveSupport::KeyGenerator.new(secrets.secret_key_base, iterations: 1000)
159
176
  ActiveSupport::CachingKeyGenerator.new(key_generator)
160
177
  else
161
- ActiveSupport::LegacyKeyGenerator.new(secrets.secret_token)
178
+ ActiveSupport::LegacyKeyGenerator.new(config.secret_token)
162
179
  end
163
- end
164
180
  end
165
181
 
166
182
  # Returns a message verifier object.
@@ -188,6 +204,38 @@ module Rails
188
204
  end
189
205
  end
190
206
 
207
+ # Convenience for loading config/foo.yml for the current Rails env.
208
+ #
209
+ # Example:
210
+ #
211
+ # # config/exception_notification.yml:
212
+ # production:
213
+ # url: http://127.0.0.1:8080
214
+ # namespace: my_app_production
215
+ # development:
216
+ # url: http://localhost:3001
217
+ # namespace: my_app_development
218
+ #
219
+ # # config/production.rb
220
+ # MyApp::Application.configure do
221
+ # config.middleware.use ExceptionNotifier, config_for(:exception_notification)
222
+ # end
223
+ def config_for(name)
224
+ yaml = Pathname.new("#{paths["config"].existent.first}/#{name}.yml")
225
+
226
+ if yaml.exist?
227
+ require "yaml"
228
+ require "erb"
229
+ (YAML.load(ERB.new(yaml.read).result) || {})[Rails.env] || {}
230
+ else
231
+ raise "Could not load configuration. No such file - #{yaml}"
232
+ end
233
+ rescue Psych::SyntaxError => e
234
+ raise "YAML syntax error occurred while parsing #{yaml}. " \
235
+ "Please note that YAML must be consistently indented using spaces. Tabs are not allowed. " \
236
+ "Error: #{e.message}"
237
+ end
238
+
191
239
  # Stores some of the Rails initial environment parameters which
192
240
  # will be used by middlewares and engines to configure themselves.
193
241
  def env_config
@@ -197,7 +245,7 @@ module Rails
197
245
  super.merge({
198
246
  "action_dispatch.parameter_filter" => config.filter_parameters,
199
247
  "action_dispatch.redirect_filter" => config.filter_redirect,
200
- "action_dispatch.secret_token" => secrets.secret_token,
248
+ "action_dispatch.secret_token" => config.secret_token,
201
249
  "action_dispatch.secret_key_base" => secrets.secret_key_base,
202
250
  "action_dispatch.show_exceptions" => config.action_dispatch.show_exceptions,
203
251
  "action_dispatch.show_detailed_exceptions" => config.consider_all_requests_local,
@@ -208,7 +256,8 @@ module Rails
208
256
  "action_dispatch.signed_cookie_salt" => config.action_dispatch.signed_cookie_salt,
209
257
  "action_dispatch.encrypted_cookie_salt" => config.action_dispatch.encrypted_cookie_salt,
210
258
  "action_dispatch.encrypted_signed_cookie_salt" => config.action_dispatch.encrypted_signed_cookie_salt,
211
- "action_dispatch.cookies_serializer" => config.action_dispatch.cookies_serializer
259
+ "action_dispatch.cookies_serializer" => config.action_dispatch.cookies_serializer,
260
+ "action_dispatch.cookies_digest" => config.action_dispatch.cookies_digest
212
261
  })
213
262
  end
214
263
  end
@@ -316,21 +365,7 @@ module Rails
316
365
  @config = configuration
317
366
  end
318
367
 
319
- # Returns secrets added to config/secrets.yml.
320
- #
321
- # Example:
322
- #
323
- # development:
324
- # secret_key_base: 836fa3665997a860728bcb9e9a1e704d427cfc920e79d847d79c8a9a907b9e965defa4154b2b86bdec6930adbe33f21364523a6f6ce363865724549fdfc08553
325
- # test:
326
- # secret_key_base: 5a37811464e7d378488b0f073e2193b093682e4e21f5d6f3ae0a4e1781e61a351fdc878a843424e81c73fb484a40d23f92c8dafac4870e74ede6e5e174423010
327
- # production:
328
- # secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
329
- # namespace: my_app_production
330
- #
331
- # +Rails.application.secrets.namespace+ returns +my_app_production+ in the
332
- # production environment.
333
- def secrets
368
+ def secrets #:nodoc:
334
369
  @secrets ||= begin
335
370
  secrets = ActiveSupport::OrderedOptions.new
336
371
  yaml = config.paths["config/secrets"].first
@@ -343,8 +378,6 @@ module Rails
343
378
 
344
379
  # Fallback to config.secret_key_base if secrets.secret_key_base isn't set
345
380
  secrets.secret_key_base ||= config.secret_key_base
346
- # Fallback to config.secret_token if secrets.secret_token isn't set
347
- secrets.secret_token ||= config.secret_token
348
381
 
349
382
  secrets
350
383
  end
@@ -381,14 +414,8 @@ module Rails
381
414
  end
382
415
  end
383
416
 
384
- # Return an array of railties respecting the order they're loaded
385
- # and the order specified by the +railties_order+ config.
386
- #
387
- # While when running initializers we need engines in reverse
388
- # order here when copying migrations from railties we need then in the same
389
- # order as given by +railties_order+
390
417
  def migration_railties # :nodoc:
391
- ordered_railties.flatten - [self]
418
+ (ordered_railties & railties_without_main_app).reverse
392
419
  end
393
420
 
394
421
  protected
@@ -421,6 +448,11 @@ module Rails
421
448
  super
422
449
  end
423
450
 
451
+ def railties_without_main_app # :nodoc:
452
+ @railties_without_main_app ||= Rails::Railtie.subclasses.map(&:instance) +
453
+ Rails::Engine.subclasses.map(&:instance)
454
+ end
455
+
424
456
  # Returns the ordered railties for this application considering railties_order.
425
457
  def ordered_railties #:nodoc:
426
458
  @ordered_railties ||= begin
@@ -440,13 +472,13 @@ module Rails
440
472
 
441
473
  index = order.index(:all)
442
474
  order[index] = all
443
- order
475
+ order.reverse.flatten
444
476
  end
445
477
  end
446
478
 
447
479
  def railties_initializers(current) #:nodoc:
448
480
  initializers = []
449
- ordered_railties.reverse.flatten.each do |r|
481
+ ordered_railties.each do |r|
450
482
  if r == self
451
483
  initializers += current
452
484
  else
@@ -474,13 +506,8 @@ module Rails
474
506
  end
475
507
 
476
508
  def validate_secret_key_config! #:nodoc:
477
- if secrets.secret_key_base.blank?
478
- ActiveSupport::Deprecation.warn "You didn't set `secret_key_base`. " +
479
- "Read the upgrade documentation to learn more about this new config option."
480
-
481
- if secrets.secret_token.blank?
482
- raise "Missing `secret_token` and `secret_key_base` for '#{Rails.env}' environment, set these values in `config/secrets.yml`"
483
- end
509
+ if secrets.secret_key_base.blank? && config.secret_token.blank?
510
+ raise "Missing `secret_key_base` for '#{Rails.env}' environment, set this value in `config/secrets.yml`"
484
511
  end
485
512
  end
486
513
  end
@@ -1,6 +1,7 @@
1
1
  require 'active_support/core_ext/kernel/reporting'
2
2
  require 'active_support/file_update_checker'
3
3
  require 'rails/engine/configuration'
4
+ require 'rails/source_annotation_extractor'
4
5
 
5
6
  module Rails
6
7
  class Application
@@ -12,7 +13,7 @@ module Rails
12
13
  :railties_order, :relative_url_root, :secret_key_base, :secret_token,
13
14
  :serve_static_assets, :ssl_options, :static_cache_control, :session_options,
14
15
  :time_zone, :reload_classes_only_on_change,
15
- :beginning_of_week, :filter_redirect
16
+ :beginning_of_week, :filter_redirect, :x
16
17
 
17
18
  attr_writer :log_level
18
19
  attr_reader :encoding
@@ -47,6 +48,7 @@ module Rails
47
48
  @eager_load = nil
48
49
  @secret_token = nil
49
50
  @secret_key_base = nil
51
+ @x = Custom.new
50
52
 
51
53
  @assets = ActiveSupport::OrderedOptions.new
52
54
  @assets.enabled = true
@@ -150,6 +152,26 @@ module Rails
150
152
  end
151
153
  end
152
154
 
155
+ def annotations
156
+ SourceAnnotationExtractor::Annotation
157
+ end
158
+
159
+ private
160
+ class Custom #:nodoc:
161
+ def initialize
162
+ @configurations = Hash.new
163
+ end
164
+
165
+ def method_missing(method, *args)
166
+ if method =~ /=$/
167
+ @configurations[$`.to_sym] = args.first
168
+ else
169
+ @configurations.fetch(method) {
170
+ @configurations[method] = ActiveSupport::OrderedOptions.new
171
+ }
172
+ end
173
+ end
174
+ end
153
175
  end
154
176
  end
155
177
  end
@@ -22,8 +22,6 @@ module Rails
22
22
  initializer :add_builtin_route do |app|
23
23
  if Rails.env.development?
24
24
  app.routes.append do
25
- get '/rails/mailers' => "rails/mailers#index"
26
- get '/rails/mailers/*path' => "rails/mailers#preview"
27
25
  get '/rails/info/properties' => "rails/info#properties"
28
26
  get '/rails/info/routes' => "rails/info#routes"
29
27
  get '/rails/info' => "rails/info#index"
@@ -42,9 +42,11 @@ class CodeStatistics #:nodoc:
42
42
 
43
43
  if File.directory?(path) && (/^\./ !~ file_name)
44
44
  stats.add(calculate_directory_statistics(path, pattern))
45
- elsif file_name =~ pattern
46
- stats.add_by_file_path(path)
47
45
  end
46
+
47
+ next unless file_name =~ pattern
48
+
49
+ stats.add_by_file_path(path)
48
50
  end
49
51
 
50
52
  stats
@@ -20,7 +20,6 @@ The most common rails commands are:
20
20
  new application called MyApp in "./my_app"
21
21
 
22
22
  In addition to those, there are:
23
- application Generate the Rails application code
24
23
  destroy Undo code generated with "generate" (short-cut alias: "d")
25
24
  plugin new Generates skeleton for developing a Rails plugin
26
25
  runner Run a piece of code in the application environment (short-cut alias: "r")
@@ -28,7 +27,7 @@ In addition to those, there are:
28
27
  All commands can be run with -h (or --help) for more information.
29
28
  EOT
30
29
 
31
- COMMAND_WHITELIST = %w(plugin generate destroy console server dbconsole application runner new version help)
30
+ COMMAND_WHITELIST = %w(plugin generate destroy console server dbconsole runner new version help)
32
31
 
33
32
  def initialize(argv)
34
33
  @argv = argv
@@ -87,10 +86,6 @@ EOT
87
86
  Rails::DBConsole.start
88
87
  end
89
88
 
90
- def application
91
- require_command!("application")
92
- end
93
-
94
89
  def runner
95
90
  require_command!("runner")
96
91
  end
@@ -18,7 +18,14 @@ module Rails
18
18
  opt.on("-e", "--environment=name", String,
19
19
  "Specifies the environment to run this console under (test/development/production).",
20
20
  "Default: development") { |v| options[:environment] = v.strip }
21
- opt.on("--debugger", 'Enable the debugger.') { |v| options[:debugger] = v }
21
+ opt.on("--debugger", 'Enable the debugger.') do |v|
22
+ if RUBY_VERSION < '2.0.0'
23
+ options[:debugger] = v
24
+ else
25
+ puts "=> Notice: debugger option is ignored since ruby 2.0 and " \
26
+ "it will be removed in future versions"
27
+ end
28
+ end
22
29
  opt.parse!(arguments)
23
30
  end
24
31
 
@@ -69,12 +76,25 @@ module Rails
69
76
  Rails.env = environment
70
77
  end
71
78
 
72
- def debugger?
73
- options[:debugger]
79
+ if RUBY_VERSION < '2.0.0'
80
+ def debugger?
81
+ options[:debugger]
82
+ end
83
+
84
+ def require_debugger
85
+ require 'debugger'
86
+ puts "=> Debugger enabled"
87
+ rescue LoadError
88
+ puts "You're missing the 'debugger' gem. Add it to your Gemfile, bundle it and try again."
89
+ exit(1)
90
+ end
74
91
  end
75
92
 
76
93
  def start
77
- require_debugger if debugger?
94
+ if RUBY_VERSION < '2.0.0'
95
+ require_debugger if debugger?
96
+ end
97
+
78
98
  set_environment! if environment?
79
99
 
80
100
  if sandbox?
@@ -89,13 +109,5 @@ module Rails
89
109
  end
90
110
  console.start
91
111
  end
92
-
93
- def require_debugger
94
- require 'debugger'
95
- puts "=> Debugger enabled"
96
- rescue LoadError
97
- puts "You're missing the 'debugger' gem. Add it to your Gemfile, bundle it and try again."
98
- exit(1)
99
- end
100
112
  end
101
113
  end