Permalink
Browse files

Hardwire `to_json` implementation.

  • Loading branch information...
1 parent faba4e0 commit 61633294c2de117d6d105f31652eae5a07b7165b @lucasmazza lucasmazza committed Jun 12, 2012
Showing with 11 additions and 0 deletions.
  1. +6 −0 lib/i18n_alchemy/proxy.rb
  2. +5 −0 test/i18n_alchemy/proxy_test.rb
@@ -27,6 +27,12 @@ def to_param
@target.to_param
end
+ # Override to_json to always call +to_json+ on the target object, instead of
+ # serializing the proxy object, that may issue circular references on Ruby 1.8.
+ def to_json(options = nil)
+ @target.to_json(options)
+ end
+
# Override to_model to always return the proxy, otherwise it returns the
# target object. This allows us to integrate with action view.
def to_model
@@ -26,6 +26,11 @@ def test_does_not_localize_primary_key
assert_equal 1, @localized.id
end
+ def test_to_json
+ @supplier.products << @product
+ assert_equal @supplier.to_json, @supplier_localized.to_json
+ end
+
def test_to_param
assert_equal @product.to_param, @localized.to_param
end

0 comments on commit 6163329

Please sign in to comment.