aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/models
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2016-08-05 09:39:46 -0400
committerSean Griffin <sean@thoughtbot.com>2016-08-05 09:52:09 -0400
commitb63d532f1ed0770e00183894a9efd7450d8cde82 (patch)
tree2eb02d5093170d6371c5e2624b742cd7637570b8 /activerecord/test/models
parent320d40123ab0befe248373aab8ac2e2a3dec33cd (diff)
downloadrails-b63d532f1ed0770e00183894a9efd7450d8cde82.tar.gz
rails-b63d532f1ed0770e00183894a9efd7450d8cde82.tar.bz2
rails-b63d532f1ed0770e00183894a9efd7450d8cde82.zip
Don't assume all hashes are from multiparameter assignment in `composed_of`
So this bug is kinda funky. The code path is basically "if we weren't passed an instance of the class we compose to, and we have a converter, call that". Ignoring the hash case for a moment, everything after that was roughly intended to be the "else" clause, meaning that we are expected to have an instance of the class we compose to. Really, we should be blowing up in that case, as we can give a much better error message than what they user will likely get (e.g. `NameError: No method first for String` or something). Still, Ruby is duck typed, so if the object you're assigning responds to the same methods as the type you compose to, knock yourself out. The hash case was added in 36e9be8 to remove a bunch of special cased code from multiparameter assignment. I wrongly assumed that the only time we'd get a hash there is in that case. Multiparameter assignment will construct a very specific hash though, where the keys are integers, and we will have a set of keys covering `1..part.size` exactly. I'm pretty sure this could actually be passed around as an array, but that's a different story. Really I should convert this to something like `class MultiParameterAssignment < Hash; end`, which I might do soon. However for a change that I'm willing to backport to 4-2-stable, this is what I want to go with for the time being. Fixes #25978
Diffstat (limited to 'activerecord/test/models')
-rw-r--r--activerecord/test/models/customer.rb1
1 files changed, 1 insertions, 0 deletions
diff --git a/activerecord/test/models/customer.rb b/activerecord/test/models/customer.rb
index 3338aaf7e1..d464759430 100644
--- a/activerecord/test/models/customer.rb
+++ b/activerecord/test/models/customer.rb
@@ -7,6 +7,7 @@ class Customer < ActiveRecord::Base
composed_of :non_blank_gps_location, :class_name => "GpsLocation", :allow_nil => true, :mapping => %w(gps_location gps_location),
:converter => lambda { |gps| self.gps_conversion_was_run = true; gps.blank? ? nil : GpsLocation.new(gps)}
composed_of :fullname, :mapping => %w(name to_s), :constructor => Proc.new { |name| Fullname.parse(name) }, :converter => :parse
+ composed_of :fullname_no_converter, :mapping => %w(name to_s), class_name: "Fullname"
end
class Address