-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5369 from dwickern/fix-create-duplicate
[BUGFIX beta] Fix createRecord creating two records
- Loading branch information
Showing
3 changed files
with
35 additions
and
6 deletions.
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
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
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 |
---|---|---|
|
@@ -1452,3 +1452,35 @@ test("Rollbacking attributes of a created record works correctly when the belong | |
assert.equal(user.get('accounts.length'), 0, "User does not have the account anymore"); | ||
assert.equal(account.get('user'), null, 'Account does not have the user anymore'); | ||
}); | ||
|
||
test("createRecord updates inverse record array which has observers", function(assert) { | ||
|
||
env.adapter.findAll = () => { | ||
return { | ||
data: [{ | ||
id: '2', | ||
type: 'user', | ||
attributes: { | ||
name: 'Stanley' | ||
} | ||
}] | ||
} | ||
}; | ||
|
||
return store.findAll('user').then(users => { | ||
assert.equal(users.get('length'), 1, 'Exactly 1 user'); | ||
|
||
let user = users.get('firstObject'); | ||
assert.equal(user.get('messages.length'), 0, 'Record array is initially empty'); | ||
|
||
// set up an observer | ||
user.addObserver('[email protected]', () => {}); | ||
user.get('messages.firstObject'); | ||
|
||
let message = run(() => store.createRecord('message', { user, title: 'EmberFest was great' })); | ||
assert.equal(user.get('messages.length'), 1, 'The message is added to the record array'); | ||
|
||
let messageFromArray = user.get('messages.firstObject'); | ||
assert.equal(message, messageFromArray, 'Only one message should be created'); | ||
}); | ||
}); |