Skip to content

Commit 6714bb0

Browse files
jwrobesrichmolj
authored andcommitted
Allows for manual scope to be passed (#93)
- Allows for manual scope to be used if passed as option
1 parent a4538a7 commit 6714bb0

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/jsonapi_compliable/base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ def render_jsonapi(scope, opts = {})
288288
opts = default_jsonapi_render_options.merge(opts)
289289
opts = Util::RenderOptions.generate(scope, query_hash, opts)
290290
opts[:expose][:context] = self
291-
opts[:include] = deserialized_params.include_directive if force_includes?
291+
opts[:include] ||= deserialized_params.include_directive if force_includes?
292292
perform_render_jsonapi(opts)
293293
end
294294

spec/jsonapi_compliable_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,5 +124,15 @@ def config(obj)
124124
instance.render_jsonapi(Author.all, scope: false)
125125
end
126126
end
127+
context 'when passing manual scope' do
128+
it 'passes the manually included scope' do
129+
author = Author.create!(first_name: 'Stephen', last_name: 'King')
130+
author.books.create(title: "The Shining", genre: Genre.new(name: 'horror'))
131+
132+
expect(instance).to receive(:perform_render_jsonapi).with(hash_including(include: { foo: {}}))
133+
instance.render_jsonapi(Author.all, { include: { foo: {} }, scope: false, meta: { foo: 'bar' } })
134+
end
135+
end
136+
127137
end
128138
end

0 commit comments

Comments
 (0)