Skip to content
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

Feature/persistence #17

Merged
merged 3 commits into from
Mar 18, 2015
Merged

Conversation

danelowe
Copy link

This is changing the way jsonapi-consumer decides if an object is persisted or not. It no longer checks for the existence of an ID attribute and instead sets flags when an object is loaded. I tried to draw inspiration from how ActiveRecord does it, but its a much simpler implementation.

The reasoning behind this change is that I read the JSONAPI spec as almost encouraging the use of client-supplied IDs. If jsonapi-consumer assumes that a new record with an ID is persisted, then the wrong actions would be taken.

I'm not completely happy with adding another parameter to the initialise method, but it seemed like the path of least resistance for now.

In the query classes, I've added methods that signify whether the query type is to be used for a new record or for an existing record (e.g. create vs update query). This I see as a pragmatic way of influencing how the path is built during the instantiation of the query.

To simulate a persisted object in a spec, one would pass false as the second parameter (new_record) when instantiating the object, e.g.

persisted_object = test_class.new({name: 'jsonapi.example', id: '1'}, false)

Dane Lowe added 3 commits February 25, 2015 13:20
So that client provided GUIDs can be used.
I don't beleive a create query should ever use the Client Supplied ID in the request path, but should provide it in the body if available.
@@ -17,11 +18,47 @@
end
end

describe '#persisted?' do
it 'uses the primary key to decide' do
describe '#new_record? / #peristed?' do
Copy link
Owner

Choose a reason for hiding this comment

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

Got a typo here but I'll fix it up.

jsmestad added a commit that referenced this pull request Mar 18, 2015
Better persistence check via a hard variable.
@jsmestad jsmestad merged commit 559f911 into jsmestad:develop Mar 18, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants