From 141d864e0ec1098176141e6cb6aef3eaf07e830f Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 29 Aug 2014 14:58:36 -0700 Subject: Added yield to Object#presence --- activesupport/test/core_ext/object/blank_test.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'activesupport/test/core_ext/object') diff --git a/activesupport/test/core_ext/object/blank_test.rb b/activesupport/test/core_ext/object/blank_test.rb index 246bc7fa61..7b3f10b4da 100644 --- a/activesupport/test/core_ext/object/blank_test.rb +++ b/activesupport/test/core_ext/object/blank_test.rb @@ -33,4 +33,9 @@ class BlankTest < ActiveSupport::TestCase 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 "SALLY", "sally".presence(&:upcase) || "Nobody" + assert_equal "Nobody", nil.presence(&:upcase) || "Nobody" + end end -- cgit v1.2.3 From 961945046848492ddc541700419cf553e7817c94 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 29 Aug 2014 15:19:32 -0700 Subject: Use instance_eval on @tenderlove's suggestion :trollface: --- activesupport/test/core_ext/object/blank_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activesupport/test/core_ext/object') diff --git a/activesupport/test/core_ext/object/blank_test.rb b/activesupport/test/core_ext/object/blank_test.rb index 7b3f10b4da..34d10c6981 100644 --- a/activesupport/test/core_ext/object/blank_test.rb +++ b/activesupport/test/core_ext/object/blank_test.rb @@ -35,7 +35,7 @@ class BlankTest < ActiveSupport::TestCase end def test_presence_with_a_block - assert_equal "SALLY", "sally".presence(&:upcase) || "Nobody" - assert_equal "Nobody", nil.presence(&:upcase) || "Nobody" + assert_equal "SALLY", "sally".presence { upcase } || "Nobody" + assert_equal "Nobody", nil.presence { upcase } || "Nobody" end end -- cgit v1.2.3 From 39691ba2f5664aa83720fa3c2a1ca14937d29009 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 29 Aug 2014 15:24:36 -0700 Subject: Clarify the origin of this great addition to Rails :trollface: :trollface :trollface: --- activesupport/test/core_ext/object/blank_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/test/core_ext/object') diff --git a/activesupport/test/core_ext/object/blank_test.rb b/activesupport/test/core_ext/object/blank_test.rb index 34d10c6981..4deac4b0aa 100644 --- a/activesupport/test/core_ext/object/blank_test.rb +++ b/activesupport/test/core_ext/object/blank_test.rb @@ -35,7 +35,7 @@ class BlankTest < ActiveSupport::TestCase end def test_presence_with_a_block - assert_equal "SALLY", "sally".presence { upcase } || "Nobody" + assert_equal "THIS WAS TENDERLOVE'S IDEA", "this was tenderlove's idea".presence { upcase } || "Nobody" assert_equal "Nobody", nil.presence { upcase } || "Nobody" end end -- cgit v1.2.3 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/core_ext/object') 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 From c67c5e6ba0fd098d25094810ac7243b73a140be1 Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Fri, 29 Aug 2014 21:51:32 -0700 Subject: Bring back the test cases for `presence` This was removed by mistake in 5e51bdd --- activesupport/test/core_ext/object/blank_test.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'activesupport/test/core_ext/object') diff --git a/activesupport/test/core_ext/object/blank_test.rb b/activesupport/test/core_ext/object/blank_test.rb index d6c69bd582..246bc7fa61 100644 --- a/activesupport/test/core_ext/object/blank_test.rb +++ b/activesupport/test/core_ext/object/blank_test.rb @@ -28,4 +28,9 @@ 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 end -- cgit v1.2.3 From fdc5e768ca29e3ad4288dcd8a8c7147cea8a1f97 Mon Sep 17 00:00:00 2001 From: Peter Jaros Date: Wed, 3 Sep 2014 16:00:06 -0400 Subject: Methods are not duplicable. --- activesupport/test/core_ext/object/duplicable_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/test/core_ext/object') diff --git a/activesupport/test/core_ext/object/duplicable_test.rb b/activesupport/test/core_ext/object/duplicable_test.rb index 84512380cf..34679cb362 100644 --- a/activesupport/test/core_ext/object/duplicable_test.rb +++ b/activesupport/test/core_ext/object/duplicable_test.rb @@ -4,7 +4,7 @@ require 'active_support/core_ext/object/duplicable' require 'active_support/core_ext/numeric/time' class DuplicableTest < ActiveSupport::TestCase - RAISE_DUP = [nil, false, true, :symbol, 1, 2.3, 5.seconds] + RAISE_DUP = [nil, false, true, :symbol, 1, 2.3, 5.seconds, method(:puts)] ALLOW_DUP = ['1', Object.new, /foo/, [], {}, Time.now, Class.new, Module.new] # Needed to support Ruby 1.9.x, as it doesn't allow dup on BigDecimal, instead -- cgit v1.2.3