Permalink
Browse files

Merge pull request #1344 from jmileham/serialization_includes

AR Serialization shouldn't fall back to base opts for includes
  • Loading branch information...
2 parents 5083d70 + 043b624 commit d341d166774dba12508abbfb848bcde49d3cdf07 @josevalim josevalim committed May 26, 2011
@@ -31,9 +31,6 @@ def serializable_hash(options = nil)
def serializable_add_includes(options = {})
return unless include_associations = options.delete(:include)
- base_only_or_except = { :except => options[:except],
- :only => options[:only] }
-
include_has_options = include_associations.is_a?(Hash)
associations = include_has_options ? include_associations.keys : Array.wrap(include_associations)
@@ -46,9 +43,8 @@ def serializable_add_includes(options = {})
end
if records
- association_options = include_has_options ? include_associations[association] : base_only_or_except
- opts = options.merge(association_options)
- yield(association, records, opts)
+ association_options = include_has_options ? include_associations[association] : {}
+ yield(association, records, association_options)
end
end
@@ -161,6 +161,15 @@ def test_includes_fetches_nth_level_associations
assert_match %r{"tag":\{"name":"General"\}}, json
end
+ def test_includes_doesnt_merge_opts_from_base
+ json = @david.to_json(
+ :only => :id,
+ :include => :posts
+ )
+
+ assert_match %{"title":"Welcome to the weblog"}, json
+ end
+
def test_should_not_call_methods_on_associations_that_dont_respond
def @david.favorite_quote; "Constraints are liberating"; end
json = @david.to_json(:include => :posts, :methods => :favorite_quote)

0 comments on commit d341d16

Please sign in to comment.