From 5e51bdda59c9ba8e5faf86294e3e431bd45f1830 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 29 Aug 2014 15:32:24 -0700 Subject: We tenderized the wrong method! Object#try already had the yield option, just needed some tenderloving instance_eval to fit the bill --- activesupport/test/core_ext/object/blank_test.rb | 10 ---------- activesupport/test/core_ext/object/try_test.rb | 4 ++++ 2 files changed, 4 insertions(+), 10 deletions(-) (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/object/blank_test.rb b/activesupport/test/core_ext/object/blank_test.rb index 4deac4b0aa..d6c69bd582 100644 --- a/activesupport/test/core_ext/object/blank_test.rb +++ b/activesupport/test/core_ext/object/blank_test.rb @@ -28,14 +28,4 @@ class BlankTest < ActiveSupport::TestCase BLANK.each { |v| assert_equal false, v.present?, "#{v.inspect} should not be present" } NOT.each { |v| assert_equal true, v.present?, "#{v.inspect} should be present" } end - - def test_presence - BLANK.each { |v| assert_equal nil, v.presence, "#{v.inspect}.presence should return nil" } - NOT.each { |v| assert_equal v, v.presence, "#{v.inspect}.presence should return self" } - end - - def test_presence_with_a_block - assert_equal "THIS WAS TENDERLOVE'S IDEA", "this was tenderlove's idea".presence { upcase } || "Nobody" - assert_equal "Nobody", nil.presence { upcase } || "Nobody" - end end diff --git a/activesupport/test/core_ext/object/try_test.rb b/activesupport/test/core_ext/object/try_test.rb index 8b754ced53..225c20fa36 100644 --- a/activesupport/test/core_ext/object/try_test.rb +++ b/activesupport/test/core_ext/object/try_test.rb @@ -65,6 +65,10 @@ class ObjectTryTest < ActiveSupport::TestCase assert_equal false, ran end + def test_try_with_instance_eval_block + assert_equal @string.reverse, @string.try { reverse } + end + def test_try_with_private_method_bang klass = Class.new do private -- cgit v1.2.3