Skip to content
This repository

Preventing from dirtying internals while creating a record with an existing id #770

Merged
merged 1 commit into from over 1 year ago

2 participants

Cyril Fluck Tom Dale
Cyril Fluck

[Fixes #768]

Cyril Fluck

I have added a test.

Tom Dale tomdale merged commit 902e87f into from
Tom Dale tomdale closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Mar 04, 2013
Cyril Fluck Cyril-sf Preventing from dirtying internals while creating a record with an ex…
…isting id

[Fixes #768]
278bfd9
This page is out of date. Refresh to see the latest.
2  packages/ember-data/lib/system/store.js
@@ -1626,6 +1626,8 @@ DS.Store = Ember.Object.extend(DS._Mappable, {
1626 1626 clientIds = typeMap.clientIds,
1627 1627 cidToData = this.clientIdToData;
1628 1628
  1629 + Ember.assert('The id ' + id + ' has already been used with another record of type ' + type.toString() + '.', !id || !idToClientIdMap[id]);
  1630 +
1629 1631 var clientId = ++this.clientIdCounter;
1630 1632
1631 1633 cidToData[clientId] = data;
19 packages/ember-data/tests/unit/store_test.js
@@ -414,6 +414,25 @@ test("a new record of a particular type is created via store.createRecord(type)"
414 414 equal(get(person, 'name'), "Braaahm Dale", "Even if no hash is supplied, `set` still worked");
415 415 });
416 416
  417 +test("a new record with a specific id can't be created if this id is already used in the store", function() {
  418 + var store = DS.Store.create();
  419 + var Person = DS.Model.extend({
  420 + name: DS.attr('string'),
  421 + });
  422 + Person.reopenClass({
  423 + toString: function() {
  424 + return 'Person';
  425 + }
  426 + });
  427 + store.createRecord(Person, {id: 5});
  428 +
  429 + raises(
  430 + function() { store.createRecord(Person, {id: 5}); },
  431 + /The id 5 has already been used with another record of type Person/,
  432 + "Creating a record with an if an id already in used in the store is disallowed"
  433 + );
  434 +});
  435 +
417 436 test("an initial data hash can be provided via store.createRecord(type, hash)", function() {
418 437 expect(6);
419 438 var store = DS.Store.create();

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.