Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

remove AS whiny nil extension and deprecate config.whiny_nils

  • Loading branch information...
commit 4f6af26a886630c97865a2e5023a9560692e6aa4 1 parent 667d7aa
Sergey Nartimov lest authored
6 activesupport/lib/active_support/railtie.rb
View
@@ -5,12 +5,6 @@ module ActiveSupport
class Railtie < Rails::Railtie
config.active_support = ActiveSupport::OrderedOptions.new
- # Loads support for "whiny nil" (noisy warnings when methods are invoked
- # on +nil+ values) if Configuration#whiny_nils is true.
- initializer "active_support.initialize_whiny_nils" do |app|
- require 'active_support/whiny_nil' if app.config.whiny_nils
- end
-
initializer "active_support.deprecation_behavior" do |app|
if deprecation = app.config.active_support.deprecation
ActiveSupport::Deprecation.behavior = deprecation
22 activesupport/lib/active_support/whiny_nil.rb
View
@@ -1,22 +0,0 @@
-# Extensions to +nil+ which allow for more helpful error messages for people who
-# are new to Rails.
-#
-# NilClass#id exists in Ruby 1.8 (though it is deprecated). Since +id+ is a fundamental
-# method of Active Record models NilClass#id is redefined as well to raise a RuntimeError
-# and warn the user. She probably wanted a model database identifier and the 4
-# returned by the original method could result in obscure bugs.
-#
-# The flag <tt>config.whiny_nils</tt> determines whether this feature is enabled.
-# By default it is on in development and test modes, and it is off in production
-# mode.
-class NilClass
- def self.add_whiner(klass)
- ActiveSupport::Deprecation.warn "NilClass.add_whiner is deprecated and this functionality is " \
- "removed from Rails versions as it affects Ruby 1.9 performance.", caller
- end
-
- # Raises a RuntimeError when you attempt to call +id+ on +nil+.
- def id
- raise RuntimeError, "Called id for nil, which would mistakenly be #{object_id} -- if you really wanted the id of nil, use object_id", caller
- end
-end
11 activesupport/test/whiny_nil_test.rb
View
@@ -1,11 +0,0 @@
-require 'abstract_unit'
-require 'active_support/whiny_nil'
-
-class WhinyNilTest < Test::Unit::TestCase
- def test_id
- nil.id
- rescue RuntimeError => nme
- assert_no_match(/nil:NilClass/, nme.message)
- assert_match(Regexp.new(nil.object_id.to_s), nme.message)
- end
-end
7 railties/lib/rails/application/configuration.rb
View
@@ -12,7 +12,7 @@ class Configuration < ::Rails::Engine::Configuration
:force_ssl, :helpers_paths, :logger, :log_tags, :preload_frameworks,
:railties_order, :relative_url_root, :reload_plugins, :secret_token,
:serve_static_assets, :ssl_options, :static_cache_control, :session_options,
- :time_zone, :reload_classes_only_on_change, :whiny_nils
+ :time_zone, :reload_classes_only_on_change
attr_writer :log_level
attr_reader :encoding
@@ -145,6 +145,11 @@ def session_store(*args)
@session_options = args.shift || {}
end
end
+
+ def whiny_nils=(*)
+ ActiveSupport::Deprecation.warn "config.whiny_nils option " \
+ "is deprecated and no longer works", caller
+ end
end
end
end
3  railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt
View
@@ -6,9 +6,6 @@
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
- # Log error messages when you accidentally call methods on nil.
- config.whiny_nils = true
-
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
3  railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt
View
@@ -11,9 +11,6 @@
config.serve_static_assets = true
config.static_cache_control = "public, max-age=3600"
- # Log error messages when you accidentally call methods on nil
- config.whiny_nils = true
-
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_controller.perform_caching = false

5 comments on commit 4f6af26

Kieran Pilkington

So now when you mistakenly call nil.id in tests, it'll give back an ID and appear to have worked?

Seems like a step back to me. I'm sure you have good reason for it though?

Guillermo Iguaran
irb(main):001:0> nil.id
NoMethodError: undefined method `id' for nil:NilClass
    from (irb):1
    from /Users/guille/.rbenv/versions/1.9.3-p0/bin/irb:12:in `<main>'
Kieran Pilkington

Thanks Guillermo. Makes much sense now.

Sam Soffes

@guilleiguaran is that new in 1.9? I know at one point the renamed id to object_id

Jared Beck

The 1.9.3 docs say "Object#object_id ... replaces the deprecated Object#id."

Please sign in to comment.
Something went wrong with that request. Please try again.