aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/aggregations_test.rb
diff options
context:
space:
mode:
authorRob Anderton <rob.anderton@thewebfellas.com>2008-08-18 19:13:01 +0100
committerMichael Koziarski <michael@koziarski.com>2008-09-10 18:28:47 +0200
commit2cee51d5c1d143f6fe0096ba6cbd1db1ecbe2d90 (patch)
tree69385e859aef550418365d4553bebe5a4af5cb77 /activerecord/test/cases/aggregations_test.rb
parent7c9851dbb6f841ffbf3ebd16e9f57c04319d3a39 (diff)
downloadrails-2cee51d5c1d143f6fe0096ba6cbd1db1ecbe2d90.tar.gz
rails-2cee51d5c1d143f6fe0096ba6cbd1db1ecbe2d90.tar.bz2
rails-2cee51d5c1d143f6fe0096ba6cbd1db1ecbe2d90.zip
Added :constructor and :converter options to composed_of and deprecated the conversion block
Signed-off-by: Michael Koziarski <michael@koziarski.com>
Diffstat (limited to 'activerecord/test/cases/aggregations_test.rb')
-rw-r--r--activerecord/test/cases/aggregations_test.rb35
1 files changed, 35 insertions, 0 deletions
diff --git a/activerecord/test/cases/aggregations_test.rb b/activerecord/test/cases/aggregations_test.rb
index 75d1f27e07..b6656c8631 100644
--- a/activerecord/test/cases/aggregations_test.rb
+++ b/activerecord/test/cases/aggregations_test.rb
@@ -107,6 +107,41 @@ class AggregationsTest < ActiveRecord::TestCase
customers(:david).gps_location = nil
assert_equal nil, customers(:david).gps_location
end
+
+ def test_custom_constructor
+ assert_equal 'Barney GUMBLE', customers(:barney).fullname.to_s
+ assert_kind_of Fullname, customers(:barney).fullname
+ end
+
+ def test_custom_converter
+ customers(:barney).fullname = 'Barnoit Gumbleau'
+ assert_equal 'Barnoit GUMBLEAU', customers(:barney).fullname.to_s
+ assert_kind_of Fullname, customers(:barney).fullname
+ end
+end
+
+class DeprecatedAggregationsTest < ActiveRecord::TestCase
+ class Person < ActiveRecord::Base; end
+
+ def test_conversion_block_is_deprecated
+ assert_deprecated 'conversion block has been deprecated' do
+ Person.composed_of(:balance, :class_name => "Money", :mapping => %w(balance amount)) { |balance| balance.to_money }
+ end
+ end
+
+ def test_conversion_block_used_when_converter_option_is_nil
+ Person.composed_of(:balance, :class_name => "Money", :mapping => %w(balance amount)) { |balance| balance.to_money }
+ assert_raise(NoMethodError) { Person.new.balance = 5 }
+ end
+
+ def test_converter_option_overrides_conversion_block
+ Person.composed_of(:balance, :class_name => "Money", :mapping => %w(balance amount), :converter => Proc.new { |balance| Money.new(balance) }) { |balance| balance.to_money }
+
+ person = Person.new
+ assert_nothing_raised { person.balance = 5 }
+ assert_equal 5, person.balance.amount
+ assert_kind_of Money, person.balance
+ end
end
class OverridingAggregationsTest < ActiveRecord::TestCase