Skip to content

Commit

Permalink
Merge pull request #127 from richmolj/defer_sideload
Browse files Browse the repository at this point in the history
Defer serializer relationships when eager loading
  • Loading branch information
richmolj authored Apr 17, 2019
2 parents 10f2188 + 5d4204a commit 97bec78
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
1 change: 0 additions & 1 deletion lib/graphiti/resource/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ def serializer=(val)
if val
if super(Class.new(val))
apply_attributes_to_serializer
apply_sideloads_to_serializer
end
else
super
Expand Down
28 changes: 28 additions & 0 deletions spec/resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,34 @@
expect(klass.relationships_writable_by_default).to eq(true)
end

context 'when rails' do
before do
rails = double \
application: double(config: double(eager_load: eager_load))
stub_const('Rails', rails)
end

context 'and eager loading' do
let(:eager_load) { true }

it 'does NOT assign relationships to the serializer' do
klass.has_many :positions, resource: PORO::PositionResource
expect(klass.serializer.relationship_blocks).to be_blank
Graphiti.setup!
expect(klass.serializer.relationship_blocks).to_not be_blank
end
end

context 'and NOT eager loading' do
let(:eager_load) { false }

it 'assigns relationships to the serializer' do
klass.has_many :positions, resource: PORO::PositionResource
expect(klass.serializer.relationship_blocks).to_not be_blank
end
end
end

context "when assigning new adapter" do
let(:adapter) do
Class.new(Graphiti::Adapters::Abstract) do
Expand Down

0 comments on commit 97bec78

Please sign in to comment.