ember-data-source 2.1.0.beta.1 → 2.1.0.beta.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 42a7133babf76842ad69f869acf49924e5778386
4
- data.tar.gz: b68ec9a80f7078159afb73ef4939ef884759ab3d
3
+ metadata.gz: a39d5bf4d490e8b7016bd7269d40d929e1bad580
4
+ data.tar.gz: a5b548fd610bd42723fe91d0d898a3d6b713598c
5
5
  SHA512:
6
- metadata.gz: de202a28d55bad5e3d376bd2f34c504d34e9a4714081dfb4aa8d11a0979e7d49e63b5d59d5aeb26ea7a7eab4a0ea1fd57eaa243d6658702e98f6155bcb0f8337
7
- data.tar.gz: 9bf21e5c777c62986a361444cf653701e9a9f38fe429633a40b0b4ac765f86174d89c872ce57bf00defffaafd914a9142dd92019aa022e57d7c625dc07c73a0c
6
+ metadata.gz: 481f1b778c86e2d6bb0d216a009f9d96f1aa2ee9545208f06a3db7a8b509092452f398b57ffb0eccb6e6517e898cfc0f7a3ace5830c815d9aa3c3ad809d81fab
7
+ data.tar.gz: add81a1b8505b77e8fe1c6c0dfef0720c8dab0482500d21f1b7c82e35af906f81d748f92fd4e708ed8cfaa14d2178feaf27980bdbedb4fa67200dd54fb401fe7
@@ -18273,6 +18273,36 @@ define(
18273
18273
  }
18274
18274
  });
18275
18275
 
18276
+ test("serialize doesn't include ID when includeId is false", function () {
18277
+ run(function () {
18278
+ post = env.store.createRecord('post', { title: 'Rails is omakase' });
18279
+ });
18280
+ var json = {};
18281
+
18282
+ json = env.serializer.serialize(post._createSnapshot(), { includeId: false });
18283
+
18284
+ deepEqual(json, {
18285
+ title: "Rails is omakase",
18286
+ comments: []
18287
+ });
18288
+ });
18289
+
18290
+ test("serialize includes id when includeId is true", function () {
18291
+ run(function () {
18292
+ post = env.store.createRecord('post', { title: 'Rails is omakase' });
18293
+ post.set('id', 'test');
18294
+ });
18295
+ var json = {};
18296
+
18297
+ json = env.serializer.serialize(post._createSnapshot(), { includeId: true });
18298
+
18299
+ deepEqual(json, {
18300
+ id: 'test',
18301
+ title: 'Rails is omakase',
18302
+ comments: []
18303
+ });
18304
+ });
18305
+
18276
18306
  test("serializeAttribute", function () {
18277
18307
  run(function () {
18278
18308
  post = env.store.createRecord('post', { title: "Rails is omakase" });
@@ -23469,6 +23499,28 @@ define("ember-data/tests/unit/model-test", ["exports"], function(__exports__) {
23469
23499
  return store.createRecord('person');
23470
23500
  });
23471
23501
  });
23502
+
23503
+ test('setting the id after model creation should correctly update the id', function () {
23504
+ expect(2);
23505
+ var Person = DS.Model.extend({
23506
+ name: DS.attr('string')
23507
+ });
23508
+
23509
+ var env = setupStore({
23510
+ person: Person
23511
+ });
23512
+ var store = env.store;
23513
+
23514
+ run(function () {
23515
+ var person = store.createRecord('person');
23516
+
23517
+ equal(person.get('id'), null, 'initial created model id should be null');
23518
+
23519
+ person.set('id', 'john');
23520
+
23521
+ equal(person.get('id'), 'john', 'new id should be correctly set.');
23522
+ });
23523
+ });
23472
23524
  });
23473
23525
 
23474
23526
 
@@ -29953,13 +30005,6 @@ QUnit.test('ember-data/lib/adapters/errors.js should pass jshint', function(asse
29953
30005
  assert.ok(true, 'ember-data/lib/adapters/errors.js should pass jshint.');
29954
30006
  });
29955
30007
 
29956
- }
29957
- if (!QUnit.urlParams.nojshint) {
29958
- QUnit.module('JSHint - ember-data/lib/adapters');
29959
- QUnit.test('ember-data/lib/adapters/fixture-adapter.js should pass jshint', function(assert) {
29960
- assert.ok(true, 'ember-data/lib/adapters/fixture-adapter.js should pass jshint.');
29961
- });
29962
-
29963
30008
  }
29964
30009
  if (!QUnit.urlParams.nojshint) {
29965
30010
  QUnit.module('JSHint - ember-data/lib/adapters');
@@ -881,340 +881,6 @@
881
881
  });
882
882
 
883
883
  var ember$data$lib$system$adapter$$default = ember$data$lib$system$adapter$$Adapter;
884
-
885
- /**
886
- `DS.FixtureAdapter` is an adapter that loads records from memory.
887
- It's primarily used for development and testing. You can also use
888
- `DS.FixtureAdapter` while working on the API but is not ready to
889
- integrate yet. It is a fully functioning adapter. All CRUD methods
890
- are implemented. You can also implement query logic that a remote
891
- system would do. It's possible to develop your entire application
892
- with `DS.FixtureAdapter`.
893
-
894
- For information on how to use the `FixtureAdapter` in your
895
- application please see the [FixtureAdapter
896
- guide](/guides/models/the-fixture-adapter/).
897
-
898
- @class FixtureAdapter
899
- @namespace DS
900
- @extends DS.Adapter
901
- */
902
- /**
903
- @module ember-data
904
- */
905
- var ember$data$lib$adapters$fixture$adapter$$get = Ember.get;
906
- var ember$data$lib$adapters$fixture$adapter$$fmt = Ember.String.fmt;
907
-
908
- var ember$data$lib$adapters$fixture$adapter$$counter = 0;
909
-
910
- var ember$data$lib$adapters$fixture$adapter$$default = ember$data$lib$system$adapter$$default.extend({
911
- // by default, fixtures are already in normalized form
912
- serializer: null,
913
- // The fixture adapter does not support coalesceFindRequests
914
- coalesceFindRequests: false,
915
-
916
- /**
917
- If `simulateRemoteResponse` is `true` the `FixtureAdapter` will
918
- wait a number of milliseconds before resolving promises with the
919
- fixture values. The wait time can be configured via the `latency`
920
- property.
921
- @property simulateRemoteResponse
922
- @type {Boolean}
923
- @default true
924
- */
925
- simulateRemoteResponse: true,
926
-
927
- /**
928
- By default the `FixtureAdapter` will simulate a wait of the
929
- `latency` milliseconds before resolving promises with the fixture
930
- values. This behavior can be turned off via the
931
- `simulateRemoteResponse` property.
932
- @property latency
933
- @type {Number}
934
- @default 50
935
- */
936
- latency: 50,
937
-
938
- /**
939
- Implement this method in order to provide data associated with a type
940
- @method fixturesForType
941
- @param {DS.Model} typeClass
942
- @return {Array}
943
- */
944
- fixturesForType: function (typeClass) {
945
- if (typeClass.FIXTURES) {
946
- return typeClass.FIXTURES.map(function (fixture) {
947
- var fixtureIdType = typeof fixture.id;
948
- if (fixtureIdType !== "number" && fixtureIdType !== "string") {
949
- throw new Error(ember$data$lib$adapters$fixture$adapter$$fmt('the id property must be defined as a number or string for fixture %@', [fixture]));
950
- }
951
- fixture.id = fixture.id + '';
952
- return fixture;
953
- });
954
- }
955
- return null;
956
- },
957
-
958
- /**
959
- Implement this method in order to query fixtures data
960
- @method queryFixtures
961
- @param {Array} fixtures
962
- @param {Object} query
963
- @param {DS.Model} typeClass
964
- @return {(Promise|Array)}
965
- */
966
- queryFixtures: function (fixtures, query, typeClass) {
967
- Ember.assert('Not implemented: You must override the DS.FixtureAdapter::queryFixtures method to support querying the fixture store.');
968
- },
969
-
970
- /**
971
- @method updateFixtures
972
- @param {DS.Model} typeClass
973
- @param {Array} fixture
974
- */
975
- updateFixtures: function (typeClass, fixture) {
976
- if (!typeClass.FIXTURES) {
977
- typeClass.FIXTURES = [];
978
- }
979
-
980
- var fixtures = typeClass.FIXTURES;
981
-
982
- this.deleteLoadedFixture(typeClass, fixture);
983
-
984
- fixtures.push(fixture);
985
- },
986
-
987
- /**
988
- Implement this method in order to provide json for CRUD methods
989
- @method mockJSON
990
- @param {DS.Store} store
991
- @param {DS.Model} typeClass
992
- @param {DS.Snapshot} snapshot
993
- */
994
- mockJSON: function (store, typeClass, snapshot) {
995
- return store.serializerFor(snapshot.modelName).serialize(snapshot, { includeId: true });
996
- },
997
-
998
- /**
999
- @method generateIdForRecord
1000
- @param {DS.Store} store
1001
- @return {String} id
1002
- */
1003
- generateIdForRecord: function (store) {
1004
- return "fixture-" + ember$data$lib$adapters$fixture$adapter$$counter++;
1005
- },
1006
-
1007
- /**
1008
- @method find
1009
- @param {DS.Store} store
1010
- @param {DS.Model} typeClass
1011
- @param {String} id
1012
- @param {DS.Snapshot} snapshot
1013
- @return {Promise} promise
1014
- */
1015
- find: function (store, typeClass, id, snapshot) {
1016
- var fixtures = this.fixturesForType(typeClass);
1017
- var fixture;
1018
-
1019
- Ember.assert("Unable to find fixtures for model type " + typeClass.toString() + ". If you're defining your fixtures using `Model.FIXTURES = ...`, please change it to `Model.reopenClass({ FIXTURES: ... })`.", fixtures);
1020
-
1021
- if (fixtures) {
1022
- fixture = Ember.A(fixtures).findBy('id', id);
1023
- }
1024
-
1025
- if (fixture) {
1026
- return this.simulateRemoteCall(function () {
1027
- return fixture;
1028
- });
1029
- }
1030
- },
1031
-
1032
- /**
1033
- @method findMany
1034
- @param {DS.Store} store
1035
- @param {DS.Model} typeClass
1036
- @param {Array} ids
1037
- @param {Array} snapshots
1038
- @return {Promise} promise
1039
- */
1040
- findMany: function (store, typeClass, ids, snapshots) {
1041
- var fixtures = this.fixturesForType(typeClass);
1042
-
1043
- Ember.assert("Unable to find fixtures for model type " + typeClass.toString(), fixtures);
1044
-
1045
- if (fixtures) {
1046
- fixtures = fixtures.filter(function (item) {
1047
- return ids.indexOf(item.id) !== -1;
1048
- });
1049
- }
1050
-
1051
- if (fixtures) {
1052
- return this.simulateRemoteCall(function () {
1053
- return fixtures;
1054
- });
1055
- }
1056
- },
1057
-
1058
- /**
1059
- @private
1060
- @method findAll
1061
- @param {DS.Store} store
1062
- @param {DS.Model} typeClass
1063
- @return {Promise} promise
1064
- */
1065
- findAll: function (store, typeClass) {
1066
- var fixtures = this.fixturesForType(typeClass);
1067
-
1068
- Ember.assert("Unable to find fixtures for model type " + typeClass.toString(), fixtures);
1069
-
1070
- return this.simulateRemoteCall(function () {
1071
- return fixtures;
1072
- });
1073
- },
1074
-
1075
- /**
1076
- @private
1077
- @method findQuery
1078
- @param {DS.Store} store
1079
- @param {DS.Model} typeClass
1080
- @param {Object} query
1081
- @param {DS.AdapterPopulatedRecordArray} array
1082
- @return {Promise} promise
1083
- */
1084
- findQuery: function (store, typeClass, query, array) {
1085
- var fixtures = this.fixturesForType(typeClass);
1086
-
1087
- Ember.assert("Unable to find fixtures for model type " + typeClass.toString(), fixtures);
1088
-
1089
- fixtures = this.queryFixtures(fixtures, query, typeClass);
1090
-
1091
- if (fixtures) {
1092
- return this.simulateRemoteCall(function () {
1093
- return fixtures;
1094
- });
1095
- }
1096
- },
1097
-
1098
- /**
1099
- @method createRecord
1100
- @param {DS.Store} store
1101
- @param {DS.Model} typeClass
1102
- @param {DS.Snapshot} snapshot
1103
- @return {Promise} promise
1104
- */
1105
- createRecord: function (store, typeClass, snapshot) {
1106
- var fixture = this.mockJSON(store, typeClass, snapshot);
1107
-
1108
- this.updateFixtures(typeClass, fixture);
1109
-
1110
- return this.simulateRemoteCall(function () {
1111
- return fixture;
1112
- });
1113
- },
1114
-
1115
- /**
1116
- @method updateRecord
1117
- @param {DS.Store} store
1118
- @param {DS.Model} typeClass
1119
- @param {DS.Snapshot} snapshot
1120
- @return {Promise} promise
1121
- */
1122
- updateRecord: function (store, typeClass, snapshot) {
1123
- var fixture = this.mockJSON(store, typeClass, snapshot);
1124
-
1125
- this.updateFixtures(typeClass, fixture);
1126
-
1127
- return this.simulateRemoteCall(function () {
1128
- return fixture;
1129
- });
1130
- },
1131
-
1132
- /**
1133
- @method deleteRecord
1134
- @param {DS.Store} store
1135
- @param {DS.Model} typeClass
1136
- @param {DS.Snapshot} snapshot
1137
- @return {Promise} promise
1138
- */
1139
- deleteRecord: function (store, typeClass, snapshot) {
1140
- this.deleteLoadedFixture(typeClass, snapshot);
1141
-
1142
- return this.simulateRemoteCall(function () {
1143
- return null;
1144
- });
1145
- },
1146
-
1147
- /*
1148
- @method deleteLoadedFixture
1149
- @private
1150
- @param typeClass
1151
- @param snapshot
1152
- */
1153
- deleteLoadedFixture: function (typeClass, snapshot) {
1154
- var existingFixture = this.findExistingFixture(typeClass, snapshot);
1155
-
1156
- if (existingFixture) {
1157
- var index = typeClass.FIXTURES.indexOf(existingFixture);
1158
- typeClass.FIXTURES.splice(index, 1);
1159
- return true;
1160
- }
1161
- },
1162
-
1163
- /*
1164
- @method findExistingFixture
1165
- @private
1166
- @param typeClass
1167
- @param snapshot
1168
- */
1169
- findExistingFixture: function (typeClass, snapshot) {
1170
- var fixtures = this.fixturesForType(typeClass);
1171
- var id = snapshot.id;
1172
-
1173
- return this.findFixtureById(fixtures, id);
1174
- },
1175
-
1176
- /*
1177
- @method findFixtureById
1178
- @private
1179
- @param fixtures
1180
- @param id
1181
- */
1182
- findFixtureById: function (fixtures, id) {
1183
- return Ember.A(fixtures).find(function (r) {
1184
- if ('' + ember$data$lib$adapters$fixture$adapter$$get(r, 'id') === '' + id) {
1185
- return true;
1186
- } else {
1187
- return false;
1188
- }
1189
- });
1190
- },
1191
-
1192
- /*
1193
- @method simulateRemoteCall
1194
- @private
1195
- @param callback
1196
- @param context
1197
- */
1198
- simulateRemoteCall: function (callback, context) {
1199
- var adapter = this;
1200
-
1201
- return new Ember.RSVP.Promise(function (resolve) {
1202
- var value = Ember.copy(callback.call(context), true);
1203
- if (ember$data$lib$adapters$fixture$adapter$$get(adapter, 'simulateRemoteResponse')) {
1204
- // Schedule with setTimeout
1205
- Ember.run.later(function () {
1206
- return resolve(value);
1207
- }, ember$data$lib$adapters$fixture$adapter$$get(adapter, 'latency'));
1208
- } else {
1209
- // Asynchronous, but at the of the runloop with zero latency
1210
- Ember.run.schedule('actions', null, function () {
1211
- return resolve(value);
1212
- });
1213
- }
1214
- }, "DS: FixtureAdapter#simulateRemoteCall");
1215
- }
1216
- });
1217
-
1218
884
  var ember$data$lib$system$map$$Map = Ember.Map;
1219
885
  var ember$data$lib$system$map$$MapWithDefault = Ember.MapWithDefault;
1220
886
 
@@ -2167,7 +1833,7 @@
2167
1833
  });
2168
1834
 
2169
1835
  var ember$data$lib$core$$DS = Ember.Namespace.create({
2170
- VERSION: '2.1.0-beta.1'
1836
+ VERSION: '2.1.0-beta.2'
2171
1837
  });
2172
1838
 
2173
1839
  if (Ember.libraries) {
@@ -2721,10 +2387,7 @@
2721
2387
  @uses Ember.Evented
2722
2388
  */
2723
2389
  var ember$data$lib$system$model$model$$Model = Ember.Object.extend(Ember.Evented, {
2724
- _recordArrays: undefined,
2725
- _relationships: undefined,
2726
2390
  _internalModel: null,
2727
-
2728
2391
  store: null,
2729
2392
 
2730
2393
  /**
@@ -2935,7 +2598,6 @@
2935
2598
  @property id
2936
2599
  @type {String}
2937
2600
  */
2938
- id: null,
2939
2601
 
2940
2602
  /**
2941
2603
  @property currentState
@@ -3370,6 +3032,7 @@
3370
3032
  willMergeMixin: function (props) {
3371
3033
  var constructor = this.constructor;
3372
3034
  Ember.assert('`' + ember$data$lib$system$model$model$$intersection(Object.keys(props), ember$data$lib$system$model$model$$RESERVED_MODEL_PROPS)[0] + '` is a reserved property name on DS.Model objects. Please choose a different property name for ' + constructor.toString(), !ember$data$lib$system$model$model$$intersection(Object.keys(props), ember$data$lib$system$model$model$$RESERVED_MODEL_PROPS)[0]);
3035
+ Ember.assert("You may not set `id` as an attribute on your model. Please remove any lines that look like: `id: DS.attr('<type>')` from " + constructor.toString(), Object.keys(props).indexOf('id') === -1);
3373
3036
  },
3374
3037
 
3375
3038
  attr: function () {
@@ -3435,6 +3098,19 @@
3435
3098
  modelName: null
3436
3099
  });
3437
3100
 
3101
+ Object.defineProperty(ember$data$lib$system$model$model$$Model.prototype, 'id', {
3102
+ configurable: true,
3103
+ enumerable: false,
3104
+ set: function (id) {
3105
+ if (this._internalModel) {
3106
+ this._internalModel.setId(id);
3107
+ }
3108
+ },
3109
+ get: function () {
3110
+ return this._internalModel.id;
3111
+ }
3112
+ });
3113
+
3438
3114
  var ember$data$lib$system$model$model$$default = ember$data$lib$system$model$model$$Model;
3439
3115
 
3440
3116
  var ember$data$lib$system$store$serializer$response$$get = Ember.get;
@@ -6689,6 +6365,7 @@
6689
6365
  this._attributes = new ember$data$lib$system$empty$object$$default();
6690
6366
  this._inFlightAttributes = new ember$data$lib$system$empty$object$$default();
6691
6367
  this._relationships = new ember$data$lib$system$relationships$state$create$$default(this);
6368
+ this._recordArrays = undefined;
6692
6369
  this.currentState = ember$data$lib$system$model$states$$default.empty;
6693
6370
  this.isReloading = false;
6694
6371
  this.isError = false;
@@ -6735,7 +6412,6 @@
6735
6412
  // lookupFactory should really return an object that creates
6736
6413
  // instances with the injections applied
6737
6414
  this.record = this.type._create({
6738
- id: this.id,
6739
6415
  store: this.store,
6740
6416
  container: this.container,
6741
6417
  _internalModel: this,
@@ -7171,9 +6847,8 @@
7171
6847
  },
7172
6848
 
7173
6849
  setId: function (id) {
6850
+ Ember.assert('A record\'s id cannot be changed once it is in the loaded state', this.id === null || this.id === id || this.isNew());
7174
6851
  this.id = id;
7175
- //TODO figure out whether maybe we should proxy
7176
- ember$data$lib$system$model$internal$model$$set(this.record, 'id', id);
7177
6852
  },
7178
6853
 
7179
6854
  didError: function (error) {
@@ -7457,7 +7132,7 @@
7457
7132
 
7458
7133
  Define your application's store like this:
7459
7134
 
7460
- ```app/stores/application.js
7135
+ ```app/services/store.js
7461
7136
  import DS from 'ember-data';
7462
7137
 
7463
7138
  export default DS.Store.extend({
@@ -10603,8 +10278,8 @@
10603
10278
  var ember$inflector$lib$lib$system$inflector$$capitalize = ember$lib$main$$default.String.capitalize;
10604
10279
 
10605
10280
  var ember$inflector$lib$lib$system$inflector$$BLANK_REGEX = /^\s*$/;
10606
- var ember$inflector$lib$lib$system$inflector$$LAST_WORD_DASHED_REGEX = /([\w/-]+[_/-\s])([a-z\d]+$)/;
10607
- var ember$inflector$lib$lib$system$inflector$$LAST_WORD_CAMELIZED_REGEX = /([\w/-\s]+)([A-Z][a-z\d]*$)/;
10281
+ var ember$inflector$lib$lib$system$inflector$$LAST_WORD_DASHED_REGEX = /([\w/-]+[_/\s-])([a-z\d]+$)/;
10282
+ var ember$inflector$lib$lib$system$inflector$$LAST_WORD_CAMELIZED_REGEX = /([\w/\s-]+)([A-Z][a-z\d]*$)/;
10608
10283
  var ember$inflector$lib$lib$system$inflector$$CAMELIZED_REGEX = /[A-Z][a-z\d]*$/;
10609
10284
 
10610
10285
  function ember$inflector$lib$lib$system$inflector$$loadUncountable(rules, uncountable) {
@@ -12375,7 +12050,6 @@
12375
12050
  }
12376
12051
  },
12377
12052
  set: function (key, value) {
12378
- Ember.assert("You may not set `id` as an attribute on your model. Please remove any lines that look like: `id: DS.attr('<type>')` from " + this.constructor.toString(), key !== 'id');
12379
12053
  var internalModel = this._internalModel;
12380
12054
  var oldValue = ember$data$lib$system$model$attributes$$getValue(internalModel, key);
12381
12055
 
@@ -14331,23 +14005,6 @@
14331
14005
  value: ember$data$lib$system$normalize$model$name$$default
14332
14006
  });
14333
14007
 
14334
- var ember$data$lib$main$$_FixtureAdapter = ember$data$lib$adapters$fixture$adapter$$default;
14335
-
14336
- Object.defineProperty(ember$data$lib$core$$default, 'FixtureAdapter', {
14337
- get: function () {
14338
- if (ember$data$lib$main$$_FixtureAdapter === ember$data$lib$adapters$fixture$adapter$$default) {
14339
- Ember.deprecate('DS.FixtureAdapter has been deprecated and moved into an unsupported addon: https://github.com/emberjs/ember-data-fixture-adapter/tree/master', false, {
14340
- id: 'ds.adapter.fixture-adapter-deprecated',
14341
- until: '2.0.0'
14342
- });
14343
- }
14344
- return ember$data$lib$main$$_FixtureAdapter;
14345
- },
14346
- set: function (FixtureAdapter) {
14347
- ember$data$lib$main$$_FixtureAdapter = FixtureAdapter;
14348
- }
14349
- });
14350
-
14351
14008
  Ember.lookup.DS = ember$data$lib$core$$default;
14352
14009
 
14353
14010
  var ember$data$lib$main$$default = ember$data$lib$core$$default;