-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent loading association when include_data is set to false #1710
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,8 @@ class Serializer | |
module Adapter | ||
class JsonApi | ||
class RelationshipTest < ActiveSupport::TestCase | ||
RelationshipAuthor = Class.new(::Model) | ||
class RelationshipAuthor < ::Model; end | ||
|
||
class RelationshipAuthorSerializer < ActiveModel::Serializer | ||
has_one :bio do | ||
link :self, '//example.com/link_author/relationships/bio' | ||
|
@@ -71,7 +72,6 @@ def cached_roles | |
|
||
def setup | ||
@post = Post.new(id: 1337, comments: [], author: nil) | ||
@blog = Blog.new(id: 1337, name: 'extra') | ||
@bio = Bio.new(id: 1337) | ||
@like = Like.new(id: 1337) | ||
@role = Role.new(id: 'from-record') | ||
|
@@ -82,7 +82,6 @@ def setup | |
@author = RelationshipAuthor.new( | ||
id: 1337, | ||
posts: [@post], | ||
blog: @blog, | ||
reviewer: @reviewer, | ||
bio: @bio, | ||
likes: [@like], | ||
|
@@ -158,10 +157,16 @@ def test_relationship_meta | |
end | ||
|
||
def test_relationship_not_including_data | ||
@author.define_singleton_method(:read_attribute_for_serialization) do |attr| | ||
fail 'should not be called' if attr == :blog | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this test needs to change as well. It shouldn't be raising a runtime error and is hard to read and why do we even need the define_singleton_method? 😦 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also don't understand why this test was changed, why blog was removed from the setup There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In any case, this test file is basically garbage. See #1857 would be better to do an 'integration' test |
||
super(attr) | ||
end | ||
expected = { | ||
links: { self: '//example.com/link_author/relationships/blog' } | ||
} | ||
assert_relationship(:blog, expected) | ||
assert_nothing_raised do | ||
assert_relationship(:blog, expected) | ||
end | ||
end | ||
|
||
def test_relationship_including_data_explicit | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when is
@_include_data
present?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about the question but it is set to
true
by default so includes the relationshipdata
by default. The point of the PR is to prevent calling the relationship ifinclude_data
is set tofalse
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aight, I guess we'll document _include_data at a later date
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's already documented but the behavior added in this PR is not though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@NullVoxPopuli please don't merge code with missing
else
clauses. I was going to say it was a bug and raise a ❗ but then I realized that it was the feature of the PR. 😱 :(There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense.