From de6a067078ade6d4c9775ebd9d05ebb94b3a6b54 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 30 Apr 2012 15:55:50 -0700 Subject: return value of block is returned --- activerecord/test/cases/base_test.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'activerecord/test/cases') diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index 02d5320d9d..da4dfb4b33 100644 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -180,9 +180,17 @@ class BasicsTest < ActiveRecord::TestCase found = nil Topic.find_by_id(t.id) { |f| found = f } assert_equal t, found + end + def test_finder_block_nothing_found bad_id = Topic.maximum(:id) + 1 - Topic.find_by_id(bad_id) { |f| raise } + assert_nil Topic.find_by_id(bad_id) { |f| raise } + end + + def test_find_returns_block_value + t = Topic.first + x = Topic.find_by_id(t.id) { |f| "hi mom!" } + assert_equal "hi mom!", x end def test_preserving_date_objects -- cgit v1.2.3