Permalink
Browse files

Fix for dynamic finder methods with bang !

  • Loading branch information...
1 parent 9a7c892 commit b771fb87d3dda4a78cfe294da1fab7df266e72c9 @j15e j15e committed with parndt Aug 7, 2012
Showing with 9 additions and 2 deletions.
  1. +3 −2 lib/globalize/active_record/class_methods.rb
  2. +6 −0 test/globalize3/dynamic_finders_test.rb
View
5 lib/globalize/active_record/class_methods.rb
@@ -102,8 +102,9 @@ def method_missing(method_id, *arguments, &block)
if match.instantiator? and scope.blank?
return scope.find_or_instantiator_by_attributes match, attribute_names, *arguments, &block
end
-
- return scope.send(match.finder).tap do |found|
+ match_finder_method = match.finder.to_s
+ match_finder_method << "!" if match.bang?
+ return scope.send(match_finder_method).tap do |found|
found.is_a?(Array) ? found.map { |f| f.translations.reload } : found.translations.reload unless found.nil?
end
end
View
6 test/globalize3/dynamic_finders_test.rb
@@ -50,6 +50,12 @@ class DynamicFindersTest < Test::Unit::TestCase
assert_equal [], Post.find_all_by_title('non existing')
end
+ test "dynamic finders do work with bangs" do
+ assert_raise ActiveRecord::RecordNotFound do
+ Post.find_by_title!('non existing')
+ end
+ end
+
# https://github.com/svenfuchs/globalize3/issues#issue/5
test "simple dynamic finders retruns results from current locale and fallbacks" do
en, de, he = 'title', 'titel', 'שם'

0 comments on commit b771fb8

Please sign in to comment.