Skip to content

Commit

Permalink
Merge branch 'vasilakisfil-feat/fields_from_constructor'
Browse files Browse the repository at this point in the history
  • Loading branch information
bf4 committed Jun 9, 2016
2 parents cd96896 + be01fc8 commit 848479b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/active_model_serializers/adapter/attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module Adapter
class Attributes < Base
def serializable_hash(options = nil)
options = serialization_options(options)
options[:fields] ||= instance_options[:fields]
serializer.serializable_hash(instance_options, options, self)
end
end
Expand Down
14 changes: 14 additions & 0 deletions test/adapter/json/collection_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,20 @@ def test_include_option

assert_equal(expected, actual)
end

def test_fields_with_no_associations_include_option
actual = ActiveModelSerializers::SerializableResource.new(
[@first_post, @second_post], adapter: :json, fields: [:id], include: []
).as_json

expected = { posts: [{
id: 1
}, {
id: 2
}] }

assert_equal(expected, actual)
end
end
end
end
Expand Down

0 comments on commit 848479b

Please sign in to comment.