Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add test for a composed_of converter that can accept two argument [cl…

…oses #364]
  • Loading branch information...
commit e15109202876565f3af13a986c4d6948dc709730 1 parent fbe012e
@franckverrot authored
View
6 activerecord/test/cases/aggregations_test.rb
@@ -119,6 +119,12 @@ def test_custom_converter
assert_equal 'Barnoit GUMBLEAU', customers(:barney).fullname.to_s
assert_kind_of Fullname, customers(:barney).fullname
end
+
+ def test_custom_converter_with_arity_of_2
+ customers(:barney).fullname = 'Franck Verrot'
+ customers(:barney).location = %w(Lyon France)
+ assert_equal 'Franck VERROT from Lyon, France', customers(:barney).location.to_s
+ end
end
class OverridingAggregationsTest < ActiveRecord::TestCase
View
16 activerecord/test/models/customer.rb
@@ -3,6 +3,7 @@ class Customer < ActiveRecord::Base
composed_of :balance, :class_name => "Money", :mapping => %w(balance amount), :converter => Proc.new { |balance| balance.to_money }
composed_of :gps_location, :allow_nil => true
composed_of :fullname, :mapping => %w(name to_s), :constructor => Proc.new { |name| Fullname.parse(name) }, :converter => :parse
+ composed_of :location, :class_name => "Location", :mapping => [ %w(address_city city), %w(address_country country) ], :converter => :convert_location
end
class Address
@@ -35,6 +36,21 @@ def exchange_to(other_currency)
end
end
+class Location
+ attr_reader :city, :country, :who
+ def initialize(city, country, who = "")
+ @city, @country, @who = city, country, who
+ end
+
+ def self.convert_location(customer, values)
+ new(values.first, values.last, customer.fullname)
+ end
+
+ def to_s
+ "#{who} from #{city}, #{country}"
+ end
+end
+
class GpsLocation
attr_reader :gps_location
Please sign in to comment.
Something went wrong with that request. Please try again.