-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[BUGFIX release] fix relationship merging #5147
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
148 changes: 148 additions & 0 deletions
148
tests/integration/relationships/nested-relationship-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
import setupStore from 'dummy/tests/helpers/store'; | ||
import Ember from 'ember'; | ||
|
||
import {module, test} from 'qunit'; | ||
|
||
import DS from 'ember-data'; | ||
|
||
const { get, run } = Ember; | ||
const { attr, hasMany, belongsTo } = DS; | ||
|
||
let env, store, serializer, Elder, MiddleAger, Kid; | ||
|
||
module('integration/relationships/nested_relationships_test - Nested relationships', { | ||
beforeEach() { | ||
Elder = DS.Model.extend({ | ||
name: attr('string'), | ||
middleAgers: hasMany('middle-ager') | ||
}); | ||
|
||
MiddleAger = DS.Model.extend({ | ||
name: attr('string'), | ||
elder: belongsTo('elder'), | ||
kids: hasMany('kid') | ||
}); | ||
|
||
Kid = DS.Model.extend({ | ||
name: attr('string'), | ||
middleAger: belongsTo('middle-ager') | ||
}); | ||
|
||
env = setupStore({ | ||
elder: Elder, | ||
'middle-ager': MiddleAger, | ||
kid: Kid, | ||
adapter: DS.JSONAPIAdapter | ||
}); | ||
|
||
store = env.store; | ||
serializer = env.serializer; | ||
}, | ||
|
||
afterEach() { | ||
run(env.container, 'destroy'); | ||
} | ||
}); | ||
|
||
/* | ||
Server loading tests | ||
*/ | ||
|
||
test('Sideloaded nested relationships load correctly', function(assert) { | ||
run(() => { | ||
serializer.pushPayload(store, { | ||
data: [ | ||
{ | ||
id: '1', | ||
type: 'kids', | ||
links: { | ||
self: '/kids/1' | ||
}, | ||
attributes: { | ||
name: 'Kid 1' | ||
}, | ||
relationships: { | ||
'middle-ager': { | ||
links: { | ||
self: '/kids/1/relationships/middle-ager', | ||
related: '/kids/1/middle-ager' | ||
}, | ||
data:{ | ||
type: 'middle-agers', | ||
id: '1' | ||
} | ||
} | ||
} | ||
} | ||
], | ||
included: [ | ||
{ | ||
id: '1', | ||
type: 'middle-agers', | ||
links: { | ||
self: '/middle-ager/1' | ||
}, | ||
attributes: { | ||
name: 'Middle Ager 1' | ||
}, | ||
relationships: { | ||
elder: { | ||
links: { | ||
self: '/middle-agers/1/relationships/elder', | ||
related: '/middle-agers/1/elder' | ||
}, | ||
data: { | ||
type: 'elders', | ||
id: '1' | ||
} | ||
}, | ||
kids: { | ||
links: { | ||
self: '/middle-agers/1/relationships/kids', | ||
related: '/middle-agers/1/kids' | ||
} | ||
} | ||
} | ||
}, | ||
|
||
{ | ||
id: '1', | ||
type: 'elders', | ||
links: { | ||
self: '/elders/1' | ||
}, | ||
attributes: { | ||
name: 'Elder 1' | ||
}, | ||
relationships: { | ||
'middle-agers': { | ||
links: { | ||
self: '/elders/1/relationships/middle-agers', | ||
related: '/elders/1/middle-agers' | ||
} | ||
} | ||
} | ||
} | ||
] | ||
}); | ||
}); | ||
|
||
return run(() => { | ||
let kid = store.peekRecord('kid', 1); | ||
|
||
return kid.get('middleAger').then(middleAger => { | ||
assert.ok(middleAger, 'MiddleAger relationship was set up correctly'); | ||
|
||
let middleAgerName = get(middleAger, 'name'); | ||
assert.equal(middleAgerName, 'Middle Ager 1', 'MiddleAger name is there'); | ||
assert.ok(middleAger.get('kids').includes(kid)); | ||
|
||
return middleAger.get('elder').then(elder => { | ||
assert.notEqual(elder, null, 'Elder relationship was set up correctly'); | ||
let elderName = get(elder, 'name'); | ||
assert.equal(elderName, 'Elder 1', 'Elder name is there'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Do we need this at all?
Can't we minimize the test to only have
middle-ager
andelder
?I think now that we've figured out the root cause the kid relationship adds noise to the test.