Skip to content

#290 fix passing relationships on create #320

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

Merged

Conversation

senid231
Copy link
Member

@senid231 senid231 commented Nov 8, 2018

  • fix passing relationships on create
  • fix false positive tests

related issues #290
related PR #317 #319 #318

Copy link
Collaborator

@gaorlov gaorlov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks solid overall. There's a few changes that look like whitespace only: can you please confirm that i'm not missing anything.

Request: can you push the change summary into changelog under Unreleased, please?

Thanks for the work!

}
}
}
}.to_json)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this only whitespace changes, or am i missing something subtle here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it's only whitespace. My IDE has different notation. will fix it shortly

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no worries. Just making sure i'm not missing anything : D

@@ -18,35 +18,35 @@ def after_create_method
class Author < TestResource
end

def setup
super
def stub_simple_creation
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the thinking behind moving this out of setup? does this stub interfere with other tests?

Copy link
Member Author

@senid231 senid231 Nov 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when this code were in setup in cause false positive test #test_create_with_relationships_in_payload
because in this test create request has different payload (and different stub) but it pass because stub from #setup aws matched instead of stub written in test itself.

I move stub into separate method and use it only in tests that relies on it. it will save us from future false positive tests.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. I figured it was something like that, but wasn't sure. Thanks!

}
]
}
},
attributes: {
title: 'Rails is Omakase'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this whitespace only?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no
key order in Hash is changed because it affects key order in json body
stub will not be matched without this change

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah. 👍

@@ -303,7 +307,7 @@ def test_create_with_relationships_in_payload
}
}.to_json)

article = Article.new(title: 'Rails is Omakase', relationships: {comments: [Comment.new(id: 2)]})
article = Article.new(title: 'Rails is Omakase', relationships: {comments: [Comment.new(id: '2')]})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this a significant behavior change? will id: 2 still work?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not significant behavior change because this test never actually work without bug that I'm trying to fix.
current behavior it that if you add id as integer to relationship it will be added to payload as is.

I think we should convert all ids into strings because JSONAPI spec says that id MUST be a string
but it's an idea of different PR. this PR fixes another problem

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we cast .to_s as to avoid interface changes? Won't this break everyone who is upgrading from an older version?

@@ -23,21 +23,21 @@ def after_save_method
end
end

def setup
super
def stub_simple_fetch
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as aboev: what's the thinking behind moving this out of setup?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same that I said in above comment - to prevent false positive tests pass in future

title: "Rails is Omakase"
}
}
}.to_json)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this whitespace only?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeap. going to fix that

also fix false positive tests
@senid231 senid231 force-pushed the 290-fix-passing-relationship-on-create branch from 231a88b to ce8963c Compare November 9, 2018 14:03
@senid231
Copy link
Member Author

senid231 commented Nov 9, 2018

@gaorlov done with reverting whitespace unnecessary changes and answering your questions
please take a look

@gaorlov
Copy link
Collaborator

gaorlov commented Nov 9, 2018

This looks good. My only concern is whether making ids strings now will break backwards compatibility and make it hard to upgrade from previous versions.

@senid231
Copy link
Member Author

it doesn't concern current PR
but for future PR - if we will convert id to string it's more a bugfix then breaking logic. Current implementation allows to send invalid requests because they violates JSONAPI spec.
Production code will not be broken if server implementation respects JSONAPI specification.
Only tests could be broken in this case.

@gaorlov
Copy link
Collaborator

gaorlov commented Nov 12, 2018

Ohhh, i see. The int was always invalid, but we just let it, right?

@senid231
Copy link
Member Author

@gaorlov yeap

@senid231 senid231 merged commit d7634d1 into JsonApiClient:master Nov 13, 2018
senid231 added a commit to senid231/json_api_client that referenced this pull request Nov 13, 2018
add JsonApiClient#315 and JsonApiClient#320 to unreleased section of CHANGELOG.md
@senid231 senid231 mentioned this pull request Nov 13, 2018
@senid231
Copy link
Member Author

forgot to add changelog
added in #321

@gaorlov
Copy link
Collaborator

gaorlov commented Nov 13, 2018

huzzah! thanks, @senid231

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants