should_have_one expects association to be plural
Reported by gary.tsang (at gmail) | February 18th, 2008 @ 04:00 PM
active record has_one macro expects association to be singular.
contrary, should_have_one expects association to be in the pluralized form.
for example:
should_have_one :address
tests "*Addres*" instead of Address.
I've included a patch and a reference from Rails Code for has_one association.
===== reflection.rb ======
AssociationReflection
def derive_class_name
# get the class_name of the belongs_to association of the through reflection
if through_reflection
options[:source_type] || source_reflection.class_name
else
class_name = name.to_s.camelize
class_name = class_name.singularize if [ :has_many, :has_and_belongs_to_many ].include?(macro)
class_name
end
end
Comments and changes to this ticket
-
Tammer Saleh February 28th, 2008 @ 04:35 PM
- → State changed from new to resolved
Hi Gary,
Thanks for the patch. I've merged it into shoulda. I've also added an Address model with a polymorphic relationship to the User model in order to test it:
class AddressTest < Test::Unit::TestCase should_belong_to :addressable endclass UserTest < Test::Unit::TestCase should_have_one :address endCheers,
Tammer
-

gary.tsang (at gmail) February 29th, 2008 @ 08:43 PM
thanks tammer for all your work on this extremely useful plugin.
Best,
Gary
Please Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
