mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
Pass fields down from constructor
This commit is contained in:
parent
cd9689683c
commit
be01fc8ee7
@ -3,6 +3,7 @@ module ActiveModelSerializers
|
||||
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
|
||||
|
||||
@ -84,6 +84,20 @@ module ActiveModelSerializers
|
||||
|
||||
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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user