Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/jsonapi-serializers/serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@ def self.serialize(objects, options = {})
namespace: options[:namespace],
include: includes,
fields: fields,
base_url: options[:base_url]
base_url: options[:base_url],
skip_included_check: options[:skip_included_check]
}

if !options[:skip_collection_check] && options[:is_collection] && !objects.respond_to?(:each)
Expand Down Expand Up @@ -470,7 +471,7 @@ def self.find_recursive_relationships(root_object, root_inclusion_tree, results,
object = serializer.has_many_relationship(unformatted_attr_name, attr_data)
end

if !is_valid_attr
if !options[:skip_included_check] && !is_valid_attr
raise JSONAPI::Serializer::InvalidIncludeError.new(
"'#{attribute_name}' is not a valid include.")
end
Expand Down
12 changes: 12 additions & 0 deletions spec/serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,18 @@ def read_attribute_for_validation(attr)
expect do
JSONAPI::Serializer.serialize(create(:underscore_test), include: 'tagged_posts');
end.not_to raise_error

expect do
JSONAPI::Serializer.serialize([create(:post)], include: 'fake', is_collection: true);
end.to raise_error(JSONAPI::Serializer::InvalidIncludeError)
end

context 'when skip_included_check is true' do
it "doesn't raise an exception when join character is invalid" do
expect do
JSONAPI::Serializer.serialize([create(:post)], include: 'fake', is_collection: true, skip_included_check: true);
end.not_to raise_error(JSONAPI::Serializer::InvalidIncludeError)
end
end
end

Expand Down