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
|
||||
end
|
||||
|
||||
def with_foreign_key(foreign_key)
|
||||
@options[:foreign_key] = foreign_key
|
||||
self
|
||||
end
|
||||
|
||||
def validate(validate = true)
|
||||
@validate = validate
|
||||
self
|
||||
|
@ -261,6 +266,9 @@ module Shoulda # :nodoc:
|
|||
end
|
||||
|
||||
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)
|
||||
true
|
||||
else
|
||||
|
@ -268,6 +276,7 @@ module Shoulda # :nodoc:
|
|||
false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def model_class
|
||||
@subject.class
|
||||
|
|
Loading…
Reference in New Issue