Skip to content
This repository
Browse code

remove AS whiny nil extension and deprecate config.whiny_nils

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

5 notes 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.