Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixed foreign key determination (http://tammer.lighthouseapp.com/proj…

…ects/5807/tickets/8)

git-svn-id: https://svn.thoughtbot.com/plugins/shoulda/trunk@287 7bbfaf0e-4d1d-0410-9690-a8bb5f8ef2aa
  • Loading branch information...
commit b5251e9f2b641c75de16c04e732ee00791672ace 1 parent 46f8ff2
tsaleh authored
Showing with 7 additions and 2 deletions.
  1. +5 −0 .autotest
  2. +2 −2 lib/shoulda/active_record_helpers.rb
View
5 .autotest
@@ -1,8 +1,13 @@
Autotest.add_hook :initialize do |at|
+ at.add_mapping(%r{^lib/\w.*\.rb}) do
+ at.files_matching(%r{^test/*/\w.*_test\.rb})
+ end
+
at.add_mapping(%r{^test/rails_root/\w.*}) do
at.files_matching(%r{^test/*/\w.*_test\.rb})
end
at.add_exception(%r{.svn})
at.add_exception(%r{.log$})
+ at.add_exception(%r{^.autotest$})
end
View
4 lib/shoulda/active_record_helpers.rb
@@ -302,7 +302,7 @@ def should_have_many(*associations)
elsif reflection.options[:as]
fk = reflection.options[:as].to_s.foreign_key
else
- fk = klass.name.foreign_key
+ fk = reflection.primary_key_name
end
associated_klass = (reflection.options[:class_name] || association.to_s.classify).constantize
assert associated_klass.column_names.include?(fk.to_s), "#{associated_klass.name} does not have a #{fk} foreign key."
@@ -367,7 +367,7 @@ def should_belong_to(*associations)
unless reflection.options[:polymorphic]
associated_klass = (reflection.options[:class_name] || association.to_s.classify).constantize
- fk = reflection.options[:foreign_key] || associated_klass.name.foreign_key
+ fk = reflection.options[:foreign_key] || reflection.primary_key_name
assert klass.column_names.include?(fk.to_s), "#{klass.name} does not have a #{fk} foreign key."
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.