allow testing of :foreign_key option for has_one relationships
This commit is contained in:
parent
1b31a064fb
commit
ca8a1e5a8b
|
@ -100,6 +100,11 @@ module Shoulda # :nodoc:
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def with_foreign_key(foreign_key)
|
||||||
|
@options[:foreign_key] = foreign_key
|
||||||
|
self
|
||||||
|
end
|
||||||
|
|
||||||
def validate(validate = true)
|
def validate(validate = true)
|
||||||
@validate = validate
|
@validate = validate
|
||||||
self
|
self
|
||||||
|
@ -261,6 +266,9 @@ module Shoulda # :nodoc:
|
||||||
end
|
end
|
||||||
|
|
||||||
def class_has_foreign_key?(klass)
|
def class_has_foreign_key?(klass)
|
||||||
|
if @options.key?(:foreign_key)
|
||||||
|
reflection.options[:foreign_key] == @options[:foreign_key]
|
||||||
|
else
|
||||||
if klass.column_names.include?(foreign_key)
|
if klass.column_names.include?(foreign_key)
|
||||||
true
|
true
|
||||||
else
|
else
|
||||||
|
@ -268,6 +276,7 @@ module Shoulda # :nodoc:
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def model_class
|
def model_class
|
||||||
@subject.class
|
@subject.class
|
||||||
|
|
Loading…
Reference in New Issue