Permalink
Browse files

Change class_name to assert on the real class name

  • Loading branch information...
cbandy authored and mxie committed Dec 21, 2012
1 parent 2d2d299 commit d5af9bb8c04d0ced44ca29ec161245b7a6812cc0
@@ -4,7 +4,7 @@ module ActiveRecord # :nodoc:
# Ensure that the belongs_to relationship exists.
#
# Options:
- # * <tt>:class_name</tt> - tests that the association makes use of the class_name option.
+ # * <tt>:class_name</tt> - tests that the association resolves to class_name.
# * <tt>:validate</tt> - tests that the association makes use of the validate
# option.
#
@@ -23,7 +23,7 @@ def belong_to(name)
# * <tt>through</tt> - association name for <tt>has_many :through</tt>
# * <tt>dependent</tt> - tests that the association makes use of the
# dependent option.
- # * <tt>:class_name</tt> - tests that the association makes use of the class_name option.
+ # * <tt>:class_name</tt> - tests that the association resoves to class_name.
# * <tt>:validate</tt> - tests that the association makes use of the validate
# option.
#
@@ -43,7 +43,7 @@ def have_many(name)
# Options:
# * <tt>:dependent</tt> - tests that the association makes use of the
# dependent option.
- # * <tt>:class_name</tt> - tests that the association makes use of the class_name option.
+ # * <tt>:class_name</tt> - tests that the association resolves to class_name.
# * <tt>:validate</tt> - tests that the association makes use of the validate
# option.
#
@@ -58,6 +58,7 @@ def have_one(name)
# the join table is in place.
#
# Options:
+ # * <tt>:class_name</tt> - tests that the association resolves to class_name.
# * <tt>:validate</tt> - tests that the association makes use of the validate
# option.
#
@@ -209,10 +210,10 @@ def dependent_correct?
def class_name_correct?
if @options.key?(:class_name)
- if @options[:class_name].to_s == reflection.options[:class_name].to_s
+ if @options[:class_name].to_s == reflection.klass.to_s
true
else
- @missing = "#{@name} should have #{@options[:class_name]} as class_name"
+ @missing = "#{@name} should resolve to #{@options[:class_name]} for class_name"
false
end
else
@@ -64,6 +64,10 @@
Child.new.should_not belong_to(:parent).conditions(:adopter => true)
end
+ it 'accepts an association without a :class_name option' do
+ belonging_to_parent.should belong_to(:parent).class_name('Parent')
+ end
+
it 'accepts an association with a valid :class_name option' do
define_model :tree_parent
define_model :child, :parent_id => :integer do
@@ -234,6 +238,10 @@ def belonging_to_parent(options = {})
Parent.new.should_not have_many(:children).conditions(:adopted => true)
end
+ it 'accepts an association without a :class_name option' do
+ having_many_children.should have_many(:children).class_name('Child')
+ end
+
it 'accepts an association with a valid :class_name option' do
define_model :node, :parent_id => :integer
define_model :parent do
@@ -374,6 +382,10 @@ def having_many_children(options = {})
Person.new.should_not have_one(:detail).conditions(:disabled => true)
end
+ it 'accepts an association without a :class_name option' do
+ having_one_detail.should have_one(:detail).class_name('Detail')
+ end
+
it 'accepts an association with a valid :class_name option' do
define_model :person_detail, :person_id => :integer
define_model :person do
@@ -490,6 +502,11 @@ def having_one_detail(options = {})
Person.new.should_not have_and_belong_to_many(:relatives).conditions(:adopted => true)
end
+ it 'accepts an association without a :class_name option' do
+ having_and_belonging_to_many_relatives.
+ should have_and_belong_to_many(:relatives).class_name('Relative')
+ end
+
it 'accepts an association with a valid :class_name option' do
define_model :person_relative, :adopted => :boolean
define_model :person do

0 comments on commit d5af9bb

Please sign in to comment.