railties 4.1.0 → 4.2.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +229 -197
  3. data/RDOC_MAIN.rdoc +1 -1
  4. data/README.rdoc +6 -2
  5. data/lib/rails/all.rb +1 -0
  6. data/lib/rails/api/task.rb +7 -0
  7. data/lib/rails/app_rails_loader.rb +5 -3
  8. data/lib/rails/application/bootstrap.rb +15 -1
  9. data/lib/rails/application/configuration.rb +65 -8
  10. data/lib/rails/application/default_middleware_stack.rb +6 -2
  11. data/lib/rails/application/finisher.rb +0 -2
  12. data/lib/rails/application.rb +119 -24
  13. data/lib/rails/backtrace_cleaner.rb +9 -4
  14. data/lib/rails/code_statistics.rb +3 -4
  15. data/lib/rails/commands/commands_tasks.rb +2 -7
  16. data/lib/rails/commands/console.rb +24 -12
  17. data/lib/rails/commands/dbconsole.rb +20 -5
  18. data/lib/rails/commands/destroy.rb +2 -0
  19. data/lib/rails/commands/generate.rb +2 -0
  20. data/lib/rails/commands/plugin.rb +1 -1
  21. data/lib/rails/commands/server.rb +32 -21
  22. data/lib/rails/configuration.rb +2 -2
  23. data/lib/rails/engine/configuration.rb +1 -1
  24. data/lib/rails/engine.rb +15 -12
  25. data/lib/rails/gem_version.rb +2 -2
  26. data/lib/rails/generators/actions/create_migration.rb +4 -3
  27. data/lib/rails/generators/actions.rb +33 -12
  28. data/lib/rails/generators/app_base.rb +63 -55
  29. data/lib/rails/generators/base.rb +2 -2
  30. data/lib/rails/generators/erb/mailer/mailer_generator.rb +25 -2
  31. data/lib/rails/generators/erb/mailer/templates/layout.html.erb +5 -0
  32. data/lib/rails/generators/erb/mailer/templates/layout.text.erb +1 -0
  33. data/lib/rails/generators/erb/scaffold/templates/_form.html.erb +1 -6
  34. data/lib/rails/generators/erb/scaffold/templates/edit.html.erb +1 -1
  35. data/lib/rails/generators/erb/scaffold/templates/index.html.erb +3 -1
  36. data/lib/rails/generators/erb/scaffold/templates/new.html.erb +1 -1
  37. data/lib/rails/generators/generated_attribute.rb +28 -4
  38. data/lib/rails/generators/model_helpers.rb +28 -0
  39. data/lib/rails/generators/named_base.rb +10 -1
  40. data/lib/rails/generators/rails/app/app_generator.rb +34 -2
  41. data/lib/rails/generators/rails/app/templates/Gemfile +22 -7
  42. data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +2 -2
  43. data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css +1 -1
  44. data/lib/rails/generators/rails/app/templates/bin/rails +1 -1
  45. data/lib/rails/generators/rails/app/templates/bin/setup +28 -0
  46. data/lib/rails/generators/rails/app/templates/config/application.rb +8 -1
  47. data/lib/rails/generators/rails/app/templates/config/boot.rb +1 -2
  48. data/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml +1 -3
  49. data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml +1 -1
  50. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +4 -0
  51. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +14 -20
  52. data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +5 -2
  53. data/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +11 -0
  54. data/lib/rails/generators/rails/app/templates/config/initializers/cookies_serializer.rb +1 -1
  55. data/lib/rails/generators/rails/app/templates/config/initializers/to_time_preserves_timezone.rb +10 -0
  56. data/lib/rails/generators/rails/app/templates/config.ru +1 -1
  57. data/lib/rails/generators/rails/app/templates/gitignore +4 -1
  58. data/lib/rails/generators/rails/app/templates/test/test_helper.rb +0 -3
  59. data/lib/rails/generators/rails/controller/USAGE +0 -1
  60. data/lib/rails/generators/rails/controller/controller_generator.rb +8 -4
  61. data/lib/rails/generators/rails/helper/USAGE +0 -4
  62. data/lib/rails/generators/rails/model/USAGE +12 -3
  63. data/lib/rails/generators/rails/model/model_generator.rb +4 -0
  64. data/lib/rails/generators/rails/plugin/plugin_generator.rb +23 -1
  65. data/lib/rails/generators/rails/plugin/templates/%name%.gemspec +3 -3
  66. data/lib/rails/generators/rails/plugin/templates/Gemfile +14 -6
  67. data/lib/rails/generators/rails/plugin/templates/MIT-LICENSE +1 -1
  68. data/lib/rails/generators/rails/plugin/templates/Rakefile +4 -0
  69. data/lib/rails/generators/rails/plugin/templates/app/controllers/%name%/application_controller.rb.tt +1 -0
  70. data/lib/rails/generators/rails/plugin/templates/rails/application.rb +1 -1
  71. data/lib/rails/generators/rails/plugin/templates/rails/javascripts.js +2 -2
  72. data/lib/rails/generators/rails/plugin/templates/rails/stylesheets.css +1 -1
  73. data/lib/rails/generators/rails/plugin/templates/test/integration/navigation_test.rb +0 -4
  74. data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb +13 -3
  75. data/lib/rails/generators/rails/resource_route/resource_route_generator.rb +4 -2
  76. data/lib/rails/generators/rails/scaffold/USAGE +7 -1
  77. data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +1 -0
  78. data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb +1 -1
  79. data/lib/rails/generators/resource_helpers.rb +2 -11
  80. data/lib/rails/generators/test_unit/controller/templates/functional_test.rb +6 -0
  81. data/lib/rails/generators/test_unit/helper/helper_generator.rb +1 -5
  82. data/lib/rails/generators/test_unit/job/job_generator.rb +13 -0
  83. data/lib/rails/generators/test_unit/job/templates/unit_test.rb.erb +9 -0
  84. data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +9 -0
  85. data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb +4 -1
  86. data/lib/rails/generators/testing/assertions.rb +3 -1
  87. data/lib/rails/generators/testing/behaviour.rb +18 -1
  88. data/lib/rails/generators.rb +66 -15
  89. data/lib/rails/info.rb +8 -24
  90. data/lib/rails/info_controller.rb +1 -1
  91. data/lib/rails/mailers_controller.rb +20 -14
  92. data/lib/rails/paths.rb +3 -3
  93. data/lib/rails/rack/log_tailer.rb +4 -0
  94. data/lib/rails/rack/logger.rb +1 -1
  95. data/lib/rails/rack.rb +1 -1
  96. data/lib/rails/railtie.rb +3 -3
  97. data/lib/rails/ruby_version_check.rb +1 -1
  98. data/lib/rails/source_annotation_extractor.rb +25 -19
  99. data/lib/rails/tasks/framework.rake +2 -2
  100. data/lib/rails/tasks/statistics.rake +9 -2
  101. data/lib/rails/tasks.rb +3 -2
  102. data/lib/rails/templates/rails/mailers/email.html.erb +22 -4
  103. data/lib/rails/templates/rails/mailers/index.html.erb +2 -2
  104. data/lib/rails/templates/rails/mailers/mailer.html.erb +1 -1
  105. data/lib/rails/templates/rails/welcome/index.html.erb +23 -7
  106. data/lib/rails/test_help.rb +1 -0
  107. data/lib/rails/test_unit/sub_test_task.rb +2 -2
  108. data/lib/rails/test_unit/testing.rake +23 -5
  109. data/lib/rails.rb +7 -1
  110. metadata +17 -12
  111. data/lib/rails/commands/update.rb +0 -9
  112. data/lib/rails/generators/test_unit/helper/templates/helper_test.rb +0 -6
  113. data/lib/rails/rubyprof_ext.rb +0 -35
@@ -1,5 +1,6 @@
1
1
  require "active_support/notifications"
2
2
  require "active_support/dependencies"
3
+ require "active_support/deprecation"
3
4
  require "active_support/descendants_tracker"
4
5
 
5
6
  module Rails
@@ -47,12 +48,25 @@ INFO
47
48
  logger = ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDERR))
48
49
  logger.level = ActiveSupport::Logger::WARN
49
50
  logger.warn(
50
- "Rails Error: Unable to access log file. Please ensure that #{path} exists and is chmod 0666. " +
51
+ "Rails Error: Unable to access log file. Please ensure that #{path} exists and is writable " +
52
+ "(ie, make it writable for user and group: chmod 0664 #{path}). " +
51
53
  "The log level has been raised to WARN and the output directed to STDERR until the problem is fixed."
52
54
  )
53
55
  logger
54
56
  end
55
57
 
58
+ if Rails.env.production? && !config.has_explicit_log_level?
59
+ ActiveSupport::Deprecation.warn \
60
+ "You did not specify a `log_level` in `production.rb`. Currently, " \
61
+ "the default value for `log_level` is `:info` for the production " \
62
+ "environment and `:debug` in all other environments. In Rails 5 " \
63
+ "the default value will be unified to `:debug` across all " \
64
+ "environments. To preserve the current setting, add the following " \
65
+ "line to your `production.rb`:\n" \
66
+ "\n" \
67
+ " config.log_level = :info\n\n"
68
+ end
69
+
56
70
  Rails.logger.level = ActiveSupport::Logger.const_get(config.log_level.to_s.upcase)
57
71
  end
58
72
 
@@ -1,6 +1,9 @@
1
1
  require 'active_support/core_ext/kernel/reporting'
2
+ require 'active_support/core_ext/string/filters'
2
3
  require 'active_support/file_update_checker'
4
+ require 'active_support/deprecation'
3
5
  require 'rails/engine/configuration'
6
+ require 'rails/source_annotation_extractor'
4
7
 
5
8
  module Rails
6
9
  class Application
@@ -10,11 +13,10 @@ module Rails
10
13
  :eager_load, :exceptions_app, :file_watcher, :filter_parameters,
11
14
  :force_ssl, :helpers_paths, :logger, :log_formatter, :log_tags,
12
15
  :railties_order, :relative_url_root, :secret_key_base, :secret_token,
13
- :serve_static_assets, :ssl_options, :static_cache_control, :session_options,
16
+ :serve_static_files, :ssl_options, :static_cache_control, :session_options,
14
17
  :time_zone, :reload_classes_only_on_change,
15
- :beginning_of_week, :filter_redirect
18
+ :beginning_of_week, :filter_redirect, :x
16
19
 
17
- attr_writer :log_level
18
20
  attr_reader :encoding
19
21
 
20
22
  def initialize(*)
@@ -25,7 +27,7 @@ module Rails
25
27
  @filter_parameters = []
26
28
  @filter_redirect = []
27
29
  @helpers_paths = []
28
- @serve_static_assets = true
30
+ @serve_static_files = true
29
31
  @static_cache_control = nil
30
32
  @force_ssl = false
31
33
  @ssl_options = {}
@@ -33,6 +35,7 @@ module Rails
33
35
  @session_options = {}
34
36
  @time_zone = "UTC"
35
37
  @beginning_of_week = :monday
38
+ @has_explicit_log_level = false
36
39
  @log_level = nil
37
40
  @middleware = app_middleware
38
41
  @generators = app_generators
@@ -47,6 +50,7 @@ module Rails
47
50
  @eager_load = nil
48
51
  @secret_token = nil
49
52
  @secret_key_base = nil
53
+ @x = Custom.new
50
54
 
51
55
  @assets = ActiveSupport::OrderedOptions.new
52
56
  @assets.enabled = true
@@ -91,9 +95,10 @@ module Rails
91
95
  # Loads and returns the entire raw configuration of database from
92
96
  # values stored in `config/database.yml`.
93
97
  def database_configuration
94
- yaml = Pathname.new(paths["config/database"].first || "")
98
+ path = paths["config/database"].existent.first
99
+ yaml = Pathname.new(path) if path
95
100
 
96
- config = if yaml.exist?
101
+ config = if yaml && yaml.exist?
97
102
  require "yaml"
98
103
  require "erb"
99
104
  YAML.load(ERB.new(yaml.read).result) || {}
@@ -102,7 +107,7 @@ module Rails
102
107
  # by Active Record.
103
108
  {}
104
109
  else
105
- raise "Could not load database configuration. No such file - #{yaml}"
110
+ raise "Could not load database configuration. No such file - #{paths["config/database"].instance_variable_get(:@paths)}"
106
111
  end
107
112
 
108
113
  config
@@ -114,8 +119,17 @@ module Rails
114
119
  raise e, "Cannot load `Rails.application.database_configuration`:\n#{e.message}", e.backtrace
115
120
  end
116
121
 
122
+ def has_explicit_log_level? # :nodoc:
123
+ @has_explicit_log_level
124
+ end
125
+
126
+ def log_level=(level)
127
+ @has_explicit_log_level = !!(level)
128
+ @log_level = level
129
+ end
130
+
117
131
  def log_level
118
- @log_level ||= Rails.env.production? ? :info : :debug
132
+ @log_level ||= (Rails.env.production? ? :info : :debug)
119
133
  end
120
134
 
121
135
  def colorize_logging
@@ -127,6 +141,25 @@ module Rails
127
141
  self.generators.colorize_logging = val
128
142
  end
129
143
 
144
+ # :nodoc:
145
+ SERVE_STATIC_ASSETS_DEPRECATION_MESSAGE = <<-MSG.squish
146
+ The configuration option `config.serve_static_assets` has been renamed
147
+ to `config.serve_static_files` to clarify its role (it merely enables
148
+ serving everything in the `public` folder and is unrelated to the asset
149
+ pipeline). The `serve_static_assets` alias will be removed in Rails 5.0.
150
+ Please migrate your configuration files accordingly.
151
+ MSG
152
+
153
+ def serve_static_assets
154
+ ActiveSupport::Deprecation.warn SERVE_STATIC_ASSETS_DEPRECATION_MESSAGE
155
+ serve_static_files
156
+ end
157
+
158
+ def serve_static_assets=(value)
159
+ ActiveSupport::Deprecation.warn SERVE_STATIC_ASSETS_DEPRECATION_MESSAGE
160
+ self.serve_static_files = value
161
+ end
162
+
130
163
  def session_store(*args)
131
164
  if args.empty?
132
165
  case @session_store
@@ -150,6 +183,30 @@ module Rails
150
183
  end
151
184
  end
152
185
 
186
+ def annotations
187
+ SourceAnnotationExtractor::Annotation
188
+ end
189
+
190
+ private
191
+ class Custom #:nodoc:
192
+ def initialize
193
+ @configurations = Hash.new
194
+ end
195
+
196
+ def method_missing(method, *args)
197
+ if method =~ /=$/
198
+ @configurations[$`.to_sym] = args.first
199
+ else
200
+ @configurations.fetch(method) {
201
+ @configurations[method] = ActiveSupport::OrderedOptions.new
202
+ }
203
+ end
204
+ end
205
+
206
+ def respond_to_missing?(symbol, *)
207
+ true
208
+ end
209
+ end
153
210
  end
154
211
  end
155
212
  end
@@ -17,7 +17,7 @@ module Rails
17
17
 
18
18
  middleware.use ::Rack::Sendfile, config.action_dispatch.x_sendfile_header
19
19
 
20
- if config.serve_static_assets
20
+ if config.serve_static_files
21
21
  middleware.use ::ActionDispatch::Static, paths["public"].first, config.static_cache_control
22
22
  end
23
23
 
@@ -66,7 +66,11 @@ module Rails
66
66
  end
67
67
 
68
68
  def allow_concurrency?
69
- config.allow_concurrency.nil? ? config.cache_classes : config.allow_concurrency
69
+ if config.allow_concurrency.nil?
70
+ config.cache_classes && config.eager_load
71
+ else
72
+ config.allow_concurrency
73
+ end
70
74
  end
71
75
 
72
76
  def load_rack_cache
@@ -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"
@@ -1,4 +1,5 @@
1
1
  require 'fileutils'
2
+ require 'yaml'
2
3
  require 'active_support/core_ext/hash/keys'
3
4
  require 'active_support/core_ext/object/blank'
4
5
  require 'active_support/key_generator'
@@ -87,7 +88,21 @@ module Rails
87
88
  class << self
88
89
  def inherited(base)
89
90
  super
90
- base.instance
91
+ Rails.app_class = base
92
+ add_lib_to_load_path!(find_root(base.called_from))
93
+ ActiveSupport.run_load_hooks(:before_configuration, base)
94
+ end
95
+
96
+ def instance
97
+ super.run_load_hooks!
98
+ end
99
+
100
+ def create(initial_variable_values = {}, &block)
101
+ new(initial_variable_values, &block).run_load_hooks!
102
+ end
103
+
104
+ def find_root(from)
105
+ find_root_with_flag "config.ru", from, Dir.pwd
91
106
  end
92
107
 
93
108
  # Makes the +new+ method public.
@@ -116,24 +131,30 @@ module Rails
116
131
  @ordered_railties = nil
117
132
  @railties = nil
118
133
  @message_verifiers = {}
134
+ @ran_load_hooks = false
119
135
 
120
- Rails.application ||= self
136
+ # are these actually used?
137
+ @initial_variable_values = initial_variable_values
138
+ @block = block
139
+ end
121
140
 
122
- add_lib_to_load_path!
123
- ActiveSupport.run_load_hooks(:before_configuration, self)
141
+ # Returns true if the application is initialized.
142
+ def initialized?
143
+ @initialized
144
+ end
145
+
146
+ def run_load_hooks! # :nodoc:
147
+ return self if @ran_load_hooks
148
+ @ran_load_hooks = true
124
149
 
125
- initial_variable_values.each do |variable_name, value|
150
+ @initial_variable_values.each do |variable_name, value|
126
151
  if INITIAL_VARIABLES.include?(variable_name)
127
152
  instance_variable_set("@#{variable_name}", value)
128
153
  end
129
154
  end
130
155
 
131
- instance_eval(&block) if block_given?
132
- end
133
-
134
- # Returns true if the application is initialized.
135
- def initialized?
136
- @initialized
156
+ instance_eval(&@block) if @block
157
+ self
137
158
  end
138
159
 
139
160
  # Implements call according to the Rack API. It simply
@@ -153,14 +174,13 @@ module Rails
153
174
  def key_generator
154
175
  # number of iterations selected based on consultation with the google security
155
176
  # team. Details at https://github.com/rails/rails/pull/6952#issuecomment-7661220
156
- @caching_key_generator ||= begin
177
+ @caching_key_generator ||=
157
178
  if secrets.secret_key_base
158
179
  key_generator = ActiveSupport::KeyGenerator.new(secrets.secret_key_base, iterations: 1000)
159
180
  ActiveSupport::CachingKeyGenerator.new(key_generator)
160
181
  else
161
- ActiveSupport::LegacyKeyGenerator.new(config.secret_token)
182
+ ActiveSupport::LegacyKeyGenerator.new(secrets.secret_token)
162
183
  end
163
- end
164
184
  end
165
185
 
166
186
  # Returns a message verifier object.
@@ -188,6 +208,37 @@ module Rails
188
208
  end
189
209
  end
190
210
 
211
+ # Convenience for loading config/foo.yml for the current Rails env.
212
+ #
213
+ # Example:
214
+ #
215
+ # # config/exception_notification.yml:
216
+ # production:
217
+ # url: http://127.0.0.1:8080
218
+ # namespace: my_app_production
219
+ # development:
220
+ # url: http://localhost:3001
221
+ # namespace: my_app_development
222
+ #
223
+ # # config/production.rb
224
+ # Rails.application.configure do
225
+ # config.middleware.use ExceptionNotifier, config_for(:exception_notification)
226
+ # end
227
+ def config_for(name)
228
+ yaml = Pathname.new("#{paths["config"].existent.first}/#{name}.yml")
229
+
230
+ if yaml.exist?
231
+ require "erb"
232
+ (YAML.load(ERB.new(yaml.read).result) || {})[Rails.env] || {}
233
+ else
234
+ raise "Could not load configuration. No such file - #{yaml}"
235
+ end
236
+ rescue Psych::SyntaxError => e
237
+ raise "YAML syntax error occurred while parsing #{yaml}. " \
238
+ "Please note that YAML must be consistently indented using spaces. Tabs are not allowed. " \
239
+ "Error: #{e.message}"
240
+ end
241
+
191
242
  # Stores some of the Rails initial environment parameters which
192
243
  # will be used by middlewares and engines to configure themselves.
193
244
  def env_config
@@ -197,7 +248,7 @@ module Rails
197
248
  super.merge({
198
249
  "action_dispatch.parameter_filter" => config.filter_parameters,
199
250
  "action_dispatch.redirect_filter" => config.filter_redirect,
200
- "action_dispatch.secret_token" => config.secret_token,
251
+ "action_dispatch.secret_token" => secrets.secret_token,
201
252
  "action_dispatch.secret_key_base" => secrets.secret_key_base,
202
253
  "action_dispatch.show_exceptions" => config.action_dispatch.show_exceptions,
203
254
  "action_dispatch.show_detailed_exceptions" => config.consider_all_requests_local,
@@ -208,7 +259,8 @@ module Rails
208
259
  "action_dispatch.signed_cookie_salt" => config.action_dispatch.signed_cookie_salt,
209
260
  "action_dispatch.encrypted_cookie_salt" => config.action_dispatch.encrypted_cookie_salt,
210
261
  "action_dispatch.encrypted_signed_cookie_salt" => config.action_dispatch.encrypted_signed_cookie_salt,
211
- "action_dispatch.cookies_serializer" => config.action_dispatch.cookies_serializer
262
+ "action_dispatch.cookies_serializer" => config.action_dispatch.cookies_serializer,
263
+ "action_dispatch.cookies_digest" => config.action_dispatch.cookies_digest
212
264
  })
213
265
  end
214
266
  end
@@ -232,6 +284,18 @@ module Rails
232
284
  self.class.runner(&blk)
233
285
  end
234
286
 
287
+ # Sends any console called in the instance of a new application up
288
+ # to the +console+ method defined in Rails::Railtie.
289
+ def console(&blk)
290
+ self.class.console(&blk)
291
+ end
292
+
293
+ # Sends any generators called in the instance of a new application up
294
+ # to the +generators+ method defined in Rails::Railtie.
295
+ def generators(&blk)
296
+ self.class.generators(&blk)
297
+ end
298
+
235
299
  # Sends the +isolate_namespace+ method up to the class method.
236
300
  def isolate_namespace(mod)
237
301
  self.class.isolate_namespace(mod)
@@ -252,8 +316,8 @@ module Rails
252
316
  # are changing config.root inside your application definition or having a custom
253
317
  # Rails application, you will need to add lib to $LOAD_PATH on your own in case
254
318
  # you need to load files in lib/ during the application configuration as well.
255
- def add_lib_to_load_path! #:nodoc:
256
- path = File.join config.root, 'lib'
319
+ def self.add_lib_to_load_path!(root) #:nodoc:
320
+ path = File.join root, 'lib'
257
321
  if File.exist?(path) && !$LOAD_PATH.include?(path)
258
322
  $LOAD_PATH.unshift(path)
259
323
  end
@@ -297,14 +361,28 @@ module Rails
297
361
  end
298
362
 
299
363
  def config #:nodoc:
300
- @config ||= Application::Configuration.new(find_root_with_flag("config.ru", Dir.pwd))
364
+ @config ||= Application::Configuration.new(self.class.find_root(self.class.called_from))
301
365
  end
302
366
 
303
367
  def config=(configuration) #:nodoc:
304
368
  @config = configuration
305
369
  end
306
370
 
307
- def secrets #:nodoc:
371
+ # Returns secrets added to config/secrets.yml.
372
+ #
373
+ # Example:
374
+ #
375
+ # development:
376
+ # secret_key_base: 836fa3665997a860728bcb9e9a1e704d427cfc920e79d847d79c8a9a907b9e965defa4154b2b86bdec6930adbe33f21364523a6f6ce363865724549fdfc08553
377
+ # test:
378
+ # secret_key_base: 5a37811464e7d378488b0f073e2193b093682e4e21f5d6f3ae0a4e1781e61a351fdc878a843424e81c73fb484a40d23f92c8dafac4870e74ede6e5e174423010
379
+ # production:
380
+ # secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
381
+ # namespace: my_app_production
382
+ #
383
+ # +Rails.application.secrets.namespace+ returns +my_app_production+ in the
384
+ # production environment.
385
+ def secrets
308
386
  @secrets ||= begin
309
387
  secrets = ActiveSupport::OrderedOptions.new
310
388
  yaml = config.paths["config/secrets"].first
@@ -317,6 +395,8 @@ module Rails
317
395
 
318
396
  # Fallback to config.secret_key_base if secrets.secret_key_base isn't set
319
397
  secrets.secret_key_base ||= config.secret_key_base
398
+ # Fallback to config.secret_token if secrets.secret_token isn't set
399
+ secrets.secret_token ||= config.secret_token
320
400
 
321
401
  secrets
322
402
  end
@@ -353,6 +433,16 @@ module Rails
353
433
  end
354
434
  end
355
435
 
436
+ # Return an array of railties respecting the order they're loaded
437
+ # and the order specified by the +railties_order+ config.
438
+ #
439
+ # While when running initializers we need engines in reverse
440
+ # order here when copying migrations from railties we need then in the same
441
+ # order as given by +railties_order+
442
+ def migration_railties # :nodoc:
443
+ ordered_railties.flatten - [self]
444
+ end
445
+
356
446
  protected
357
447
 
358
448
  alias :build_middleware_stack :app
@@ -402,13 +492,13 @@ module Rails
402
492
 
403
493
  index = order.index(:all)
404
494
  order[index] = all
405
- order.reverse.flatten
495
+ order
406
496
  end
407
497
  end
408
498
 
409
499
  def railties_initializers(current) #:nodoc:
410
500
  initializers = []
411
- ordered_railties.each do |r|
501
+ ordered_railties.reverse.flatten.each do |r|
412
502
  if r == self
413
503
  initializers += current
414
504
  else
@@ -436,8 +526,13 @@ module Rails
436
526
  end
437
527
 
438
528
  def validate_secret_key_config! #:nodoc:
439
- if secrets.secret_key_base.blank? && config.secret_token.blank?
440
- raise "Missing `secret_key_base` for '#{Rails.env}' environment, set this value in `config/secrets.yml`"
529
+ if secrets.secret_key_base.blank?
530
+ ActiveSupport::Deprecation.warn "You didn't set `secret_key_base`. " +
531
+ "Read the upgrade documentation to learn more about this new config option."
532
+
533
+ if secrets.secret_token.blank?
534
+ raise "Missing `secret_token` and `secret_key_base` for '#{Rails.env}' environment, set these values in `config/secrets.yml`"
535
+ end
441
536
  end
442
537
  end
443
538
  end
@@ -4,12 +4,16 @@ module Rails
4
4
  class BacktraceCleaner < ActiveSupport::BacktraceCleaner
5
5
  APP_DIRS_PATTERN = /^\/?(app|config|lib|test)/
6
6
  RENDER_TEMPLATE_PATTERN = /:in `_render_template_\w*'/
7
+ EMPTY_STRING = ''.freeze
8
+ SLASH = '/'.freeze
9
+ DOT_SLASH = './'.freeze
7
10
 
8
11
  def initialize
9
12
  super
10
- add_filter { |line| line.sub("#{Rails.root}/", '') }
11
- add_filter { |line| line.sub(RENDER_TEMPLATE_PATTERN, '') }
12
- add_filter { |line| line.sub('./', '/') } # for tests
13
+ @root = "#{Rails.root}/".freeze
14
+ add_filter { |line| line.sub(@root, EMPTY_STRING) }
15
+ add_filter { |line| line.sub(RENDER_TEMPLATE_PATTERN, EMPTY_STRING) }
16
+ add_filter { |line| line.sub(DOT_SLASH, SLASH) } # for tests
13
17
 
14
18
  add_gem_filters
15
19
  add_silencer { |line| line !~ APP_DIRS_PATTERN }
@@ -21,7 +25,8 @@ module Rails
21
25
  return if gems_paths.empty?
22
26
 
23
27
  gems_regexp = %r{(#{gems_paths.join('|')})/gems/([^/]+)-([\w.]+)/(.*)}
24
- add_filter { |line| line.sub(gems_regexp, '\2 (\3) \4') }
28
+ gems_result = '\2 (\3) \4'.freeze
29
+ add_filter { |line| line.sub(gems_regexp, gems_result) }
25
30
  end
26
31
  end
27
32
  end
@@ -6,6 +6,7 @@ class CodeStatistics #:nodoc:
6
6
  'Helper tests',
7
7
  'Model tests',
8
8
  'Mailer tests',
9
+ 'Job tests',
9
10
  'Integration tests',
10
11
  'Functional tests (old)',
11
12
  'Unit tests (old)']
@@ -42,11 +43,9 @@ class CodeStatistics #:nodoc:
42
43
 
43
44
  if File.directory?(path) && (/^\./ !~ file_name)
44
45
  stats.add(calculate_directory_statistics(path, pattern))
46
+ elsif file_name =~ pattern
47
+ stats.add_by_file_path(path)
45
48
  end
46
-
47
- next unless file_name =~ pattern
48
-
49
- stats.add_by_file_path(path)
50
49
  end
51
50
 
52
51
  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
@@ -132,7 +127,7 @@ EOT
132
127
  require 'rails/generators'
133
128
  require_application_and_environment!
134
129
  Rails.application.load_generators
135
- require "rails/commands/#{command}"
130
+ require_command!(command)
136
131
  end
137
132
 
138
133
  # Change to the application's path if there is no config.ru file in current directory.
@@ -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", 'Enables 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
@@ -20,7 +20,7 @@ module Rails
20
20
  ENV['RAILS_ENV'] = options[:environment] || environment
21
21
 
22
22
  case config["adapter"]
23
- when /^mysql/
23
+ when /^(jdbc)?mysql/
24
24
  args = {
25
25
  'host' => '--host',
26
26
  'port' => '--port',
@@ -30,7 +30,7 @@ module Rails
30
30
  'sslca' => '--ssl-ca',
31
31
  'sslcert' => '--ssl-cert',
32
32
  'sslcapath' => '--ssl-capath',
33
- 'sslcipher' => '--ssh-cipher',
33
+ 'sslcipher' => '--ssl-cipher',
34
34
  'sslkey' => '--ssl-key'
35
35
  }.map { |opt, arg| "#{arg}=#{config[opt]}" if config[opt] }.compact
36
36
 
@@ -44,7 +44,7 @@ module Rails
44
44
 
45
45
  find_cmd_and_exec(['mysql', 'mysql5'], *args)
46
46
 
47
- when "postgresql", "postgres", "postgis"
47
+ when /^postgres|^postgis/
48
48
  ENV['PGUSER'] = config["username"] if config["username"]
49
49
  ENV['PGHOST'] = config["host"] if config["host"]
50
50
  ENV['PGPORT'] = config["port"].to_s if config["port"]
@@ -74,8 +74,23 @@ module Rails
74
74
 
75
75
  find_cmd_and_exec('sqlplus', logon)
76
76
 
77
+ when "sqlserver"
78
+ args = []
79
+
80
+ args += ["-D", "#{config['database']}"] if config['database']
81
+ args += ["-U", "#{config['username']}"] if config['username']
82
+ args += ["-P", "#{config['password']}"] if config['password']
83
+
84
+ if config['host']
85
+ host_arg = "#{config['host']}"
86
+ host_arg << ":#{config['port']}" if config['port']
87
+ args += ["-S", host_arg]
88
+ end
89
+
90
+ find_cmd_and_exec("sqsh", *args)
91
+
77
92
  else
78
- abort "Unknown command-line client for #{config['database']}. Submit a Rails patch to add support!"
93
+ abort "Unknown command-line client for #{config['database']}."
79
94
  end
80
95
  end
81
96
 
@@ -163,7 +178,7 @@ module Rails
163
178
  found = commands.detect do |cmd|
164
179
  dirs_on_path.detect do |path|
165
180
  full_path_command = File.join(path, cmd)
166
- File.executable? full_path_command
181
+ File.file?(full_path_command) && File.executable?(full_path_command)
167
182
  end
168
183
  end
169
184