mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Merge pull request #1344 from jmileham/serialization_includes
AR Serialization shouldn't fall back to base opts for includes
This commit is contained in:
@@ -31,9 +31,6 @@ module ActiveRecord #:nodoc:
|
||||
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 @@ module ActiveRecord #:nodoc:
|
||||
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 @@ class DatabaseConnectedJsonEncodingTest < ActiveRecord::TestCase
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user