Permalink
Browse files

Remove deprecated block usage in composed_of.

  • Loading branch information...
1 parent 7710a8c commit fdb7f84eb10c5e59490764a1a259aa00a1fcfe5f @miloops miloops committed Jun 24, 2010
Showing with 2 additions and 32 deletions.
  1. +2 −4 activerecord/lib/active_record/aggregations.rb
  2. +0 −28 activerecord/test/cases/aggregations_test.rb
@@ -190,7 +190,7 @@ module ClassMethods
# :constructor => Proc.new { |ip| IPAddr.new(ip, Socket::AF_INET) },
# :converter => Proc.new { |ip| ip.is_a?(Integer) ? IPAddr.new(ip, Socket::AF_INET) : IPAddr.new(ip.to_s) }
#
- def composed_of(part_id, options = {}, &block)
+ def composed_of(part_id, options = {})
options.assert_valid_keys(:class_name, :mapping, :allow_nil, :constructor, :converter)
name = part_id.id2name
@@ -199,9 +199,7 @@ def composed_of(part_id, options = {}, &block)
mapping = [ mapping ] unless mapping.first.is_a?(Array)
allow_nil = options[:allow_nil] || false
constructor = options[:constructor] || :new
- converter = options[:converter] || block
-
- ActiveSupport::Deprecation.warn('The conversion block has been deprecated, use the :converter option instead.', caller) if block_given?
+ converter = options[:converter]
reader_method(name, class_name, mapping, allow_nil, constructor)
writer_method(name, class_name, mapping, allow_nil, converter)
@@ -121,34 +121,6 @@ def test_custom_converter
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
- assert_deprecated 'conversion block has been deprecated' do
- Person.composed_of(:balance, :class_name => "Money", :mapping => %w(balance amount)) { |balance| balance.to_money }
- end
- assert_raise(NoMethodError) { Person.new.balance = 5 }
- end
-
- def test_converter_option_overrides_conversion_block
- assert_deprecated 'conversion block has been deprecated' do
- Person.composed_of(:balance, :class_name => "Money", :mapping => %w(balance amount), :converter => Proc.new { |balance| Money.new(balance) }) { |balance| balance.to_money }
- end
-
- 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
class Name; end
class DifferentName; end

0 comments on commit fdb7f84

Please sign in to comment.