Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Replace fix_condition (spcioal globalize method) by sanitize_sql (rai…

…ls method). Globalize work now with Hash condition. All test pass with rails trunk.
  • Loading branch information...
commit e0c4823896f78f4a97c6e3fcd88e66bb1d32bbb6 1 parent 4775bdf
@yannlugrin yannlugrin authored
View
25 lib/globalize/localization/db_translate.rb
@@ -725,7 +725,7 @@ def find_every(options)
return results
end
- options[:conditions] = fix_conditions(options[:conditions]) if options[:conditions]
+ options[:conditions] = sanitize_sql(options[:conditions]) if options[:conditions]
# there will at least be an +id+ field here
select_clause = untranslated_fields.map {|f| "#{table_name}.#{f}" }.join(", ")
@@ -838,29 +838,6 @@ def find_every(options)
return results
end
-
- # properly scope conditions to table
- def fix_conditions(conditions)
- if conditions.kind_of? Array
- is_array = true
- sql = conditions.shift
- else
- is_array = false
- sql = conditions
- end
-
- column_names.each do |column_name|
- sql.gsub!( /(^|([^\.\w"'`]+))(["'`]?)#{column_name}(?!\w)/,
- '\1' + "#{table_name}." + '\3' + "#{column_name}" )
- end
-
- if is_array
- [ sql ] + conditions
- else
- sql
- end
- end
-
end
end
View
33 test/db_translation_test.rb
@@ -323,22 +323,23 @@ def test_destroy_class_method
assert_nil tr
end
- def test_fix_conditions
- assert_equal 'globalize_products.name="test"',
- Product.class_eval { fix_conditions('name="test"') }
- assert_equal '(globalize_products.name="test" OR globalize_products.name = "test2")',
- Product.class_eval { fix_conditions('(name="test" OR name = "test2")') }
- assert_equal 'globalize_products.name = globalize_translations.name',
- Product.class_eval { fix_conditions('globalize_products.name = globalize_translations.name') }
- assert_equal ' globalize_products.name = globalize_translations.name',
- Product.class_eval { fix_conditions(' name = globalize_translations.name') }
- assert_equal ' globalize_products."name" = globalize_translations.name',
- Product.class_eval { fix_conditions(' "name" = globalize_translations.name') }
- assert_equal ' globalize_products.\'name\' = globalize_translations.name',
- Product.class_eval { fix_conditions(' \'name\' = globalize_translations.name') }
- assert_equal ' globalize_products.`name` = globalize_translations.name',
- Product.class_eval { fix_conditions(' `name` = globalize_translations.name') }
- end
+# Function is removed, Globalite work fine without.
+# def test_fix_conditions
+# assert_equal 'globalize_products.name="test"',
+# Product.class_eval { fix_conditions('name="test"') }
+# assert_equal '(globalize_products.name="test" OR globalize_products.name = "test2")',
+# Product.class_eval { fix_conditions('(name="test" OR name = "test2")') }
+# assert_equal 'globalize_products.name = globalize_translations.name',
+# Product.class_eval { fix_conditions('globalize_products.name = globalize_translations.name') }
+# assert_equal ' globalize_products.name = globalize_translations.name',
+# Product.class_eval { fix_conditions(' name = globalize_translations.name') }
+# assert_equal ' globalize_products."name" = globalize_translations.name',
+# Product.class_eval { fix_conditions(' "name" = globalize_translations.name') }
+# assert_equal ' globalize_products.\'name\' = globalize_translations.name',
+# Product.class_eval { fix_conditions(' \'name\' = globalize_translations.name') }
+# assert_equal ' globalize_products.`name` = globalize_translations.name',
+# Product.class_eval { fix_conditions(' `name` = globalize_translations.name') }
+# end
def test_native_name
heb = Globalize::Language.pick('he')
Please sign in to comment.
Something went wrong with that request. Please try again.