diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-12-11 14:38:27 -0800 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-12-11 14:38:27 -0800 |
commit | c9b8ca97481fd88534cbe11c45181f3043a560ec (patch) | |
tree | 5313810bfcf98cfd0c7cd0590edadba7550f8902 /activerecord/lib/active_record/dynamic_matchers.rb | |
parent | 6deb0a09c1e9b2d7c1d603978d26fd13aec50c83 (diff) | |
parent | 23ce3e5fde42d0af9b77ad014bde8f36401fa3b6 (diff) | |
download | rails-c9b8ca97481fd88534cbe11c45181f3043a560ec.tar.gz rails-c9b8ca97481fd88534cbe11c45181f3043a560ec.tar.bz2 rails-c9b8ca97481fd88534cbe11c45181f3043a560ec.zip |
Merge pull request #13264 from laurocaetano/fix_dynamic_finder_with_reserved_words
Prevent invalid code when using dynamic finders with reserved ruby word.
Diffstat (limited to 'activerecord/lib/active_record/dynamic_matchers.rb')
-rw-r--r-- | activerecord/lib/active_record/dynamic_matchers.rb | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/dynamic_matchers.rb b/activerecord/lib/active_record/dynamic_matchers.rb index e650ebcf64..5caab09038 100644 --- a/activerecord/lib/active_record/dynamic_matchers.rb +++ b/activerecord/lib/active_record/dynamic_matchers.rb @@ -84,13 +84,18 @@ module ActiveRecord "#{finder}(#{attributes_hash})" end + # The parameters in the signature may have reserved Ruby words, in order + # to prevent errors, we start each param name with `_`. + # # Extended in activerecord-deprecated_finders def signature - attribute_names.join(', ') + attribute_names.map { |name| "_#{name}" }.join(', ') end + # Given that the parameters starts with `_`, the finder needs to use the + # same parameter name. def attributes_hash - "{" + attribute_names.map { |name| ":#{name} => #{name}" }.join(',') + "}" + "{" + attribute_names.map { |name| ":#{name} => _#{name}" }.join(',') + "}" end def finder |