Permalink
Browse files

Prefer #foreign_key to #primary_key_name when possible for Associatio…

…nMatcher#foreign_key

Fixes deprecation warning added in Rails 3.1:
https://github.com/rails/rails/blob/v3.1.0.beta1/activerecord/lib/active_record/reflection.rb#L201-208

Closes: #9
  • Loading branch information...
1 parent 574461c commit 6b4035c11783a0588e78d3705bb9425b9b5f45b8 @joelmoss joelmoss committed with jasonm May 19, 2011
Showing with 1 addition and 1 deletion.
  1. +1 −1 lib/shoulda/matchers/active_record/association_matcher.rb
@@ -191,7 +191,7 @@ def associated_class
end
def foreign_key
- reflection.primary_key_name
+ reflection.respond_to?(:foreign_key) ? reflection.foreign_key : reflection.primary_key_name
end
def through?

9 comments on commit 6b4035c

Any way this can get released?... It's december and I'm still manually changing this line to remove deprecation warnings. :(

+1 for this fix release. Please !

chip replied Jan 12, 2012

+1

+1 Please

3den replied Jan 16, 2012

+1

Member

Isn't this in 1.0.0?

Owner

@gabebw yes, it is.

3den replied Jan 16, 2012

@gabebw @joshuaclayton the problem is because shoulda.gemspec still loading old version of shoulda matchers https://github.com/thoughtbot/shoulda/blob/master/shoulda.gemspec

3den replied Jan 16, 2012

I sent a PR to fix this thoughtbot/shoulda#198

Please sign in to comment.