ember-data-source 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2eb4cb649c5ee137f864ad0f1e1f3016d2e40fe1
4
- data.tar.gz: e0165c6093acdae51c9b85ee4bfba0a9ac639dfd
3
+ metadata.gz: 99cbb3e7aeb8402514a2c16df64ff6fa3dddbdbe
4
+ data.tar.gz: 0074152bef6776110c690b11c710f2989be1dc1a
5
5
  SHA512:
6
- metadata.gz: 2d4456415e2c4da997c488d60bfdbd0b18b61992af101acf90956c07ebb7613f3b22d8b496030c24cc61d45a34aeca088f840e1941333a725d8241a2b4441724
7
- data.tar.gz: eb1453c7da01d62be09739a8871518166ba999c569446d68dd8c4ffb78d78f6b7d3cf7804cee55b6ad5a64733b1596303df33507b57b34dbe5c564703ca9b7c2
6
+ metadata.gz: 7572751098acad398e2e478038b22093031aa42c227e1445547902a3cb08476a3a642c15ef77076545003950c27f3a9a3cf0eede684e7d0bc41ac384047e3066
7
+ data.tar.gz: e98bbfa7a24ce04ad082a26df0e616f93777b0db980ad7814cceb64e655722172b7ed639e77c2a7398a5dc149ba7537aff8bd281d05d6348e58d079cfe0148f7
@@ -4287,7 +4287,7 @@ define(
4287
4287
  var run = Ember.run;
4288
4288
  var Person, Dog, env, store, adapter;
4289
4289
 
4290
- module("integration/adapter/store_adapter - DS.Store and DS.Adapter integration test", {
4290
+ module("integration/adapter/store-adapter - DS.Store and DS.Adapter integration test", {
4291
4291
  setup: function () {
4292
4292
  Person = DS.Model.extend({
4293
4293
  updatedAt: DS.attr('string'),
@@ -4731,7 +4731,13 @@ define(
4731
4731
  equal(type, Person, "the type is correct");
4732
4732
 
4733
4733
  if (snapshot.attr('name').indexOf('Bro') === -1) {
4734
- return Ember.RSVP.reject(new DS.InvalidError({ name: ['common... name requires a "bro"'] }));
4734
+ return Ember.RSVP.reject(new DS.InvalidError([{
4735
+ title: 'Invalid Attribute',
4736
+ detail: 'common... name requires a "bro"',
4737
+ source: {
4738
+ pointer: '/data/attributes/name'
4739
+ }
4740
+ }]));
4735
4741
  } else {
4736
4742
  return Ember.RSVP.resolve();
4737
4743
  }
@@ -4770,7 +4776,13 @@ define(
4770
4776
  test("allows errors on arbitrary properties on create", function () {
4771
4777
  adapter.createRecord = function (store, type, snapshot) {
4772
4778
  if (snapshot.attr('name').indexOf('Bro') === -1) {
4773
- return Ember.RSVP.reject(new DS.InvalidError({ base: ['is a generally unsavoury character'] }));
4779
+ return Ember.RSVP.reject(new DS.InvalidError([{
4780
+ title: "Invalid Attribute",
4781
+ detail: "is a generally unsavoury character",
4782
+ source: {
4783
+ pointer: "/data/attributes/base"
4784
+ }
4785
+ }]));
4774
4786
  } else {
4775
4787
  return Ember.RSVP.resolve();
4776
4788
  }
@@ -4816,7 +4828,13 @@ define(
4816
4828
  saveCount++;
4817
4829
 
4818
4830
  if (snapshot.attr('name').indexOf('Bro') === -1) {
4819
- return Ember.RSVP.reject(new DS.InvalidError({ name: ['common... name requires a "bro"'] }));
4831
+ return Ember.RSVP.reject(new DS.InvalidError([{
4832
+ title: 'Invalid Attribute',
4833
+ detail: 'common... name requires a "bro"',
4834
+ source: {
4835
+ pointer: '/data/attributes/name'
4836
+ }
4837
+ }]));
4820
4838
  } else {
4821
4839
  return Ember.RSVP.resolve();
4822
4840
  }
@@ -4880,7 +4898,13 @@ define(
4880
4898
  equal(type, Person, "the type is correct");
4881
4899
 
4882
4900
  if (snapshot.attr('name').indexOf('Bro') === -1) {
4883
- return Ember.RSVP.reject(new DS.InvalidError({ name: ['common... name requires a "bro"'] }));
4901
+ return Ember.RSVP.reject(new DS.InvalidError([{
4902
+ title: 'Invalid Attribute',
4903
+ detail: 'common... name requires a "bro"',
4904
+ source: {
4905
+ pointer: '/data/attributes/name'
4906
+ }
4907
+ }]));
4884
4908
  } else {
4885
4909
  return Ember.RSVP.resolve();
4886
4910
  }
@@ -4935,7 +4959,13 @@ define(
4935
4959
  };
4936
4960
  adapter.updateRecord = function (store, type, snapshot) {
4937
4961
  if (snapshot.attr('name').indexOf('Bro') === -1) {
4938
- return Ember.RSVP.reject(new DS.InvalidError({ base: ['is a generally unsavoury character'] }));
4962
+ return Ember.RSVP.reject(new DS.InvalidError([{
4963
+ title: "Invalid Attribute",
4964
+ detail: "is a generally unsavoury character",
4965
+ source: {
4966
+ pointer: "/data/attributes/base"
4967
+ }
4968
+ }]));
4939
4969
  } else {
4940
4970
  return Ember.RSVP.resolve();
4941
4971
  }
@@ -4997,7 +5027,13 @@ define(
4997
5027
  equal(type, Person, "the type is correct");
4998
5028
  saveCount++;
4999
5029
  if (snapshot.attr('name').indexOf('Bro') === -1) {
5000
- return Ember.RSVP.reject(new DS.InvalidError({ name: ['common... name requires a "bro"'] }));
5030
+ return Ember.RSVP.reject(new DS.InvalidError([{
5031
+ title: 'Invalid Attribute',
5032
+ detail: 'common... name requires a "bro"',
5033
+ source: {
5034
+ pointer: '/data/attributes/name'
5035
+ }
5036
+ }]));
5001
5037
  } else {
5002
5038
  return Ember.RSVP.resolve();
5003
5039
  }
@@ -9993,6 +10029,128 @@ define(
9993
10029
  ok(user._internalModel._relationships.has('favouriteMessage'), "Newly created record with relationships in params passed in its constructor should have relationships");
9994
10030
  });
9995
10031
  });
10032
+
10033
+ test("Related link should be fetched when no local data is present", function () {
10034
+ expect(3);
10035
+
10036
+ Book.reopen({
10037
+ author: DS.belongsTo('author', { async: true })
10038
+ });
10039
+
10040
+ env.adapter.findBelongsTo = function (store, snapshot, url, relationship) {
10041
+ equal(url, 'author', 'url is correct');
10042
+ ok(true, "The adapter's findBelongsTo method should be called");
10043
+ return Ember.RSVP.resolve({ id: 1, name: 'This is author' });
10044
+ };
10045
+
10046
+ run(function () {
10047
+ var book = env.store.push({
10048
+ data: {
10049
+ type: 'book',
10050
+ id: '1',
10051
+ relationships: {
10052
+ author: {
10053
+ links: {
10054
+ related: 'author'
10055
+ }
10056
+ }
10057
+ }
10058
+ }
10059
+ });
10060
+ book.get('author').then(function (author) {
10061
+ equal(author.get('name'), 'This is author', 'author name is correct');
10062
+ });
10063
+ });
10064
+ });
10065
+
10066
+ test("Local data should take precedence over related link", function () {
10067
+ expect(1);
10068
+
10069
+ Book.reopen({
10070
+ author: DS.belongsTo('author', { async: true })
10071
+ });
10072
+
10073
+ env.adapter.findBelongsTo = function (store, snapshot, url, relationship) {
10074
+ ok(false, "The adapter's findBelongsTo method should not be called");
10075
+ };
10076
+
10077
+ env.adapter.findRecord = function (store, type, id, snapshot) {
10078
+ return Ember.RSVP.resolve({ id: 1, name: 'This is author' });
10079
+ };
10080
+
10081
+ run(function () {
10082
+ var book = env.store.push({
10083
+ data: {
10084
+ type: 'book',
10085
+ id: '1',
10086
+ relationships: {
10087
+ author: {
10088
+ links: {
10089
+ related: 'author'
10090
+ },
10091
+ data: { type: 'author', id: '1' }
10092
+ }
10093
+ }
10094
+ }
10095
+ });
10096
+ book.get('author').then(function (author) {
10097
+ equal(author.get('name'), 'This is author', 'author name is correct');
10098
+ });
10099
+ });
10100
+ });
10101
+
10102
+ test("Updated related link should take precedence over local data", function () {
10103
+ expect(3);
10104
+
10105
+ Book.reopen({
10106
+ author: DS.belongsTo('author', { async: true })
10107
+ });
10108
+
10109
+ env.adapter.findBelongsTo = function (store, snapshot, url, relationship) {
10110
+ equal(url, 'author-updated-link', 'url is correct');
10111
+ ok(true, "The adapter's findBelongsTo method should be called");
10112
+ return Ember.RSVP.resolve({ id: 1, name: 'This is author' });
10113
+ };
10114
+
10115
+ env.adapter.findRecord = function (store, type, id, snapshot) {
10116
+ ok(false, "The adapter's findRecord method should not be called");
10117
+ };
10118
+
10119
+ run(function () {
10120
+ var book = env.store.push({
10121
+ data: {
10122
+ type: 'book',
10123
+ id: '1',
10124
+ relationships: {
10125
+ author: {
10126
+ links: {
10127
+ related: 'author'
10128
+ },
10129
+ data: { type: 'author', id: '1' }
10130
+ }
10131
+ }
10132
+ }
10133
+ });
10134
+
10135
+ env.store.push({
10136
+ data: {
10137
+ type: 'book',
10138
+ id: '1',
10139
+ relationships: {
10140
+ author: {
10141
+ links: {
10142
+ related: 'author-updated-link'
10143
+ }
10144
+ }
10145
+ }
10146
+ }
10147
+ });
10148
+
10149
+ book.get('author').then(function (author) {
10150
+ equal(author.get('name'), 'This is author', 'author name is correct');
10151
+ });
10152
+ });
10153
+ });
9996
10154
  }
9997
10155
  );
9998
10156
 
@@ -12224,6 +12382,128 @@ define(
12224
12382
  });
12225
12383
  });
12226
12384
  });
12385
+
12386
+ test("Related link should be fetched when no local data is present", function () {
12387
+ expect(3);
12388
+
12389
+ Post.reopen({
12390
+ comments: DS.hasMany('comment', { async: true })
12391
+ });
12392
+
12393
+ env.adapter.findHasMany = function (store, snapshot, url, relationship) {
12394
+ equal(url, 'comments', 'url is correct');
12395
+ ok(true, "The adapter's findHasMany method should be called");
12396
+ return Ember.RSVP.resolve([{ id: 1, body: 'This is comment' }]);
12397
+ };
12398
+
12399
+ run(function () {
12400
+ var post = env.store.push({
12401
+ data: {
12402
+ type: 'post',
12403
+ id: '1',
12404
+ relationships: {
12405
+ comments: {
12406
+ links: {
12407
+ related: 'comments'
12408
+ }
12409
+ }
12410
+ }
12411
+ }
12412
+ });
12413
+ post.get('comments').then(function (comments) {
12414
+ equal(comments.get('firstObject.body'), 'This is comment', 'comment body is correct');
12415
+ });
12416
+ });
12417
+ });
12418
+
12419
+ test("Local data should take precedence over related link", function () {
12420
+ expect(1);
12421
+
12422
+ Post.reopen({
12423
+ comments: DS.hasMany('comment', { async: true })
12424
+ });
12425
+
12426
+ env.adapter.findHasMany = function (store, snapshot, url, relationship) {
12427
+ ok(false, "The adapter's findHasMany method should not be called");
12428
+ };
12429
+
12430
+ env.adapter.findRecord = function (store, type, id, snapshot) {
12431
+ return Ember.RSVP.resolve({ id: 1, body: 'This is comment' });
12432
+ };
12433
+
12434
+ run(function () {
12435
+ var post = env.store.push({
12436
+ data: {
12437
+ type: 'post',
12438
+ id: '1',
12439
+ relationships: {
12440
+ comments: {
12441
+ links: {
12442
+ related: 'comments'
12443
+ },
12444
+ data: [{ type: 'comment', id: '1' }]
12445
+ }
12446
+ }
12447
+ }
12448
+ });
12449
+ post.get('comments').then(function (comments) {
12450
+ equal(comments.get('firstObject.body'), 'This is comment', 'comment body is correct');
12451
+ });
12452
+ });
12453
+ });
12454
+
12455
+ test("Updated related link should take precedence over local data", function () {
12456
+ expect(3);
12457
+
12458
+ Post.reopen({
12459
+ comments: DS.hasMany('comment', { async: true })
12460
+ });
12461
+
12462
+ env.adapter.findHasMany = function (store, snapshot, url, relationship) {
12463
+ equal(url, 'comments-updated-link', 'url is correct');
12464
+ ok(true, "The adapter's findHasMany method should be called");
12465
+ return Ember.RSVP.resolve([{ id: 1, body: 'This is comment' }]);
12466
+ };
12467
+
12468
+ env.adapter.findRecord = function (store, type, id, snapshot) {
12469
+ ok(false, "The adapter's findRecord method should not be called");
12470
+ };
12471
+
12472
+ run(function () {
12473
+ var post = env.store.push({
12474
+ data: {
12475
+ type: 'post',
12476
+ id: '1',
12477
+ relationships: {
12478
+ comments: {
12479
+ links: {
12480
+ related: 'comments'
12481
+ },
12482
+ data: [{ type: 'comment', id: '1' }]
12483
+ }
12484
+ }
12485
+ }
12486
+ });
12487
+
12488
+ env.store.push({
12489
+ data: {
12490
+ type: 'post',
12491
+ id: '1',
12492
+ relationships: {
12493
+ comments: {
12494
+ links: {
12495
+ related: 'comments-updated-link'
12496
+ }
12497
+ }
12498
+ }
12499
+ }
12500
+ });
12501
+
12502
+ post.get('comments').then(function (comments) {
12503
+ equal(comments.get('firstObject.body'), 'This is comment', 'comment body is correct');
12504
+ });
12505
+ });
12506
+ });
12227
12507
  }
12228
12508
  );
12229
12509
 
@@ -21451,7 +21731,7 @@ define(
21451
21731
  __exports__[name] = value;
21452
21732
  }
21453
21733
 
21454
- module("unit/adapter/errors - DS.AdapterError");
21734
+ module("unit/adapter-errors - DS.AdapterError");
21455
21735
 
21456
21736
  test("DS.AdapterError", function () {
21457
21737
  var error = new DS.AdapterError();
@@ -21514,18 +21794,12 @@ define(
21514
21794
  deepEqual(result, { name: ['error message'] });
21515
21795
  });
21516
21796
 
21517
- test("DS.InvalidError will normalize errors hash with deprecation", function () {
21797
+ test("DS.InvalidError will normalize errors hash will assert", function () {
21518
21798
  var error;
21519
21799
 
21520
- expectDeprecation(function () {
21800
+ expectAssertion(function () {
21521
21801
  error = new DS.InvalidError({ name: ['is invalid'] });
21522
21802
  }, /expects json-api formatted errors/);
21523
-
21524
- deepEqual(error.errors, [{
21525
- title: 'Invalid Attribute',
21526
- detail: 'is invalid',
21527
- source: { pointer: '/data/attributes/name' }
21528
- }]);
21529
21803
  });
21530
21804
  }
21531
21805
  );
@@ -23881,7 +24155,13 @@ define(
23881
24155
  updateRecord: function (store, type, snapshot) {
23882
24156
  equal(callCount, 0, "becameInvalid callback was not called until recordWasInvalid is called");
23883
24157
 
23884
- return Ember.RSVP.reject(new DS.InvalidError({ bar: 'error' }));
24158
+ return Ember.RSVP.reject(new DS.InvalidError([{
24159
+ title: "Invalid Attribute",
24160
+ detail: "error",
24161
+ source: {
24162
+ pointer: "/data/attributes/bar"
24163
+ }
24164
+ }]));
23885
24165
  }
23886
24166
  });
23887
24167
 
@@ -26893,18 +27173,21 @@ define(
26893
27173
  var get = Ember.get;
26894
27174
  var set = Ember.set;
26895
27175
  var resolve = Ember.RSVP.resolve;
26896
- var TestAdapter, store, person;
27176
+ var TestAdapter, store, person, oldFilterEnabled;
26897
27177
  var run = Ember.run;
26898
27178
 
26899
27179
  module("unit/store/adapter-interop - DS.Store working with a DS.Adapter", {
26900
27180
  setup: function () {
26901
27181
  TestAdapter = DS.Adapter.extend();
27182
+ oldFilterEnabled = Ember.ENV.ENABLE_DS_FILTER;
27183
+ Ember.ENV.ENABLE_DS_FILTER = false;
26902
27184
  },
26903
27185
  teardown: function () {
26904
27186
  run(function () {
26905
27187
  if (store) {
26906
27188
  store.destroy();
26907
27189
  }
27190
+ Ember.ENV.ENABLE_DS_FILTER = oldFilterEnabled;
26908
27191
  });
26909
27192
  }
26910
27193
  });
@@ -28113,6 +28396,38 @@ define(
28113
28396
  equal(store.peekRecord('person', 1).get('name'), 'Tom');
28114
28397
  });
28115
28398
 
28399
+ test("store should assert of the user tries to call store.filter", function () {
28400
+ expect(1);
28401
+
28402
+ var Person = DS.Model.extend({
28403
+ name: DS.attr('string')
28404
+ });
28405
+
28406
+ store = createStore({
28407
+ person: Person
28408
+ });
28409
+
28410
+ expectAssertion(function () {
28411
+ run(function () {
28412
+ store.filter('person', {});
28413
+ });
28414
+ }, /The filter API has been moved to a plugin/);
28415
+ });
28416
+
28417
+ test("Calling adapterFor with a model class should assert", function () {
28418
+ var Person = DS.Model.extend({
28419
+ name: DS.attr('string')
28420
+ });
28421
+
28422
+ store = createStore({
28423
+ person: Person
28424
+ });
28425
+
28426
+ expectAssertion(function () {
28427
+ store.adapterFor(Person);
28428
+ }, /Passing classes to store.adapterFor has been removed/);
28429
+ });
28430
+
28116
28431
  module("unit/store/adapter_interop - find preload deprecations", {
28117
28432
  setup: function () {
28118
28433
  var Person = DS.Model.extend({
@@ -29379,12 +29694,13 @@ define(
29379
29694
  __exports__[name] = value;
29380
29695
  }
29381
29696
 
29382
- var container, store, registry;
29697
+ var container, store, registry, Person;
29383
29698
  var run = Ember.run;
29384
29699
 
29385
29700
  module("unit/store/serializer_for - DS.Store#serializerFor", {
29386
29701
  setup: function () {
29387
- var env = setupStore({ person: DS.Model.extend() });
29702
+ Person = DS.Model.extend({});
29703
+ var env = setupStore({ person: Person });
29388
29704
  store = env.store;
29389
29705
  container = store.container;
29390
29706
  registry = env.registry;
@@ -29417,6 +29733,12 @@ define(
29417
29733
  test("Calling serializerFor with a type that has not been registered and in an application that does not have an ApplicationSerializer looks up the default Ember Data serializer", function () {
29418
29734
  ok(store.serializerFor('person') instanceof DS.JSONSerializer, "serializer returned from serializerFor is an instance of DS.JSONSerializer");
29419
29735
  });
29736
+
29737
+ test("Calling serializerFor with a model class should assert", function () {
29738
+ expectAssertion(function () {
29739
+ store.serializerFor(Person);
29740
+ }, /Passing classes to store.serializerFor has been removed/);
29741
+ });
29420
29742
  }
29421
29743
  );
29422
29744