ember-data-source 2.2.0.beta.3 → 2.2.0.beta.4

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: 2d695118e77e0fbd0ad07b41815ac70e0b58a657
4
- data.tar.gz: 31a8706ad29a3d96b880a619a209c5a58e02c3af
3
+ metadata.gz: 5f1c0fd651f2cf27ef8c54dd3780fff36c3b8f1a
4
+ data.tar.gz: f06e467af8bcfdddbac5709b9d8323fa80afcf79
5
5
  SHA512:
6
- metadata.gz: 6c77c7fe0bb6537c531743d11dd599272aeaa6a1cd6d0d6d8576afddbd13411e19b5b2bbbe942d477184c9b1337bbefba42c5ac685e477bb13f3a34b8108291f
7
- data.tar.gz: 2d3659c9b6f8b36a5c5077a1fbe7b2b2e182523dff89261eccf10c85c5c080799a1ae6bc9a54bfdb8bac7aca306a199ca4c4d67f0fd52dd40d30d1cf3e988f62
6
+ metadata.gz: ccde9c59e715d43a26aa55d17d67936f56af5985001f804ae57daef6751aba9a6f69494de190086a7ecd4822b9d22e012e970f6aef6d58ecb783b04d8baffda9
7
+ data.tar.gz: 50424402422532c96ba1033f5da08c913f169bbb20509b4393d221e2d96c5f8596b949ab0063f716e4c1454f7e4833803bccc4129af28c3f36914ea3bbe31b52
@@ -17874,6 +17874,54 @@ define(
17874
17874
  });
17875
17875
  });
17876
17876
 
17877
+ test("serialize with embedded object (polymorphic belongsTo relationship)", function () {
17878
+ env.registry.register('serializer:super-villain', DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, {
17879
+ attrs: {
17880
+ secretLab: { embedded: 'always' }
17881
+ }
17882
+ }));
17883
+
17884
+ SuperVillain.reopen({
17885
+ secretLab: DS.belongsTo('secret-lab', { polymorphic: true })
17886
+ });
17887
+
17888
+ var json, tom;
17889
+ run(function () {
17890
+ tom = env.store.createRecord('super-villain', {
17891
+ id: "1",
17892
+ firstName: "Tom",
17893
+ lastName: "Dale",
17894
+ secretLab: env.store.createRecord('bat-cave', {
17895
+ id: "101",
17896
+ minionCapacity: 5000,
17897
+ vicinity: "California, USA",
17898
+ infiltrated: true
17899
+ }),
17900
+ homePlanet: env.store.createRecord('home-planet', {
17901
+ id: "123",
17902
+ name: "Villain League"
17903
+ })
17904
+ });
17905
+ });
17906
+
17907
+ run(function () {
17908
+ json = tom.serialize();
17909
+ });
17910
+
17911
+ deepEqual(json, {
17912
+ firstName: get(tom, "firstName"),
17913
+ lastName: get(tom, "lastName"),
17914
+ homePlanet: get(tom, "homePlanet").get("id"),
17915
+ secretLabType: 'batCave',
17916
+ secretLab: {
17917
+ id: get(tom, "secretLab").get("id"),
17918
+ minionCapacity: get(tom, "secretLab").get("minionCapacity"),
17919
+ vicinity: get(tom, "secretLab").get("vicinity"),
17920
+ infiltrated: true
17921
+ }
17922
+ });
17923
+ });
17924
+
17877
17925
  test("serialize with embedded object (belongsTo relationship) works with different primaryKeys", function () {
17878
17926
  env.registry.register('serializer:super-villain', DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, {
17879
17927
  primaryKey: '_id',
@@ -17947,6 +17995,102 @@ define(
17947
17995
  });
17948
17996
  });
17949
17997
 
17998
+ test("serialize with embedded object (polymorphic belongsTo relationship) supports serialize:ids", function () {
17999
+ SuperVillain.reopen({
18000
+ secretLab: DS.belongsTo('secret-lab', { polymorphic: true })
18001
+ });
18002
+
18003
+ env.registry.register('serializer:super-villain', DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, {
18004
+ attrs: {
18005
+ secretLab: { serialize: 'ids' }
18006
+ }
18007
+ }));
18008
+
18009
+ var tom, json;
18010
+ run(function () {
18011
+ tom = env.store.createRecord('super-villain', { firstName: "Tom", lastName: "Dale", id: "1",
18012
+ secretLab: env.store.createRecord('bat-cave', { minionCapacity: 5000, vicinity: "California, USA", id: "101" }),
18013
+ homePlanet: env.store.createRecord('home-planet', { name: "Villain League", id: "123" })
18014
+ });
18015
+ });
18016
+
18017
+ run(function () {
18018
+ json = tom.serialize();
18019
+ });
18020
+
18021
+ deepEqual(json, {
18022
+ firstName: get(tom, "firstName"),
18023
+ lastName: get(tom, "lastName"),
18024
+ homePlanet: get(tom, "homePlanet").get("id"),
18025
+ secretLab: get(tom, "secretLab").get("id"),
18026
+ secretLabType: 'batCave'
18027
+ });
18028
+ });
18029
+
18030
+ test("serialize with embedded object (belongsTo relationship) supports serialize:id", function () {
18031
+ SuperVillain.reopen({
18032
+ secretLab: DS.belongsTo('secret-lab', { polymorphic: true })
18033
+ });
18034
+
18035
+ env.registry.register('serializer:super-villain', DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, {
18036
+ attrs: {
18037
+ secretLab: { serialize: 'id' }
18038
+ }
18039
+ }));
18040
+
18041
+ var tom, json;
18042
+ run(function () {
18043
+ tom = env.store.createRecord('super-villain', { firstName: "Tom", lastName: "Dale", id: "1",
18044
+ secretLab: env.store.createRecord('bat-cave', { minionCapacity: 5000, vicinity: "California, USA", id: "101" }),
18045
+ homePlanet: env.store.createRecord('home-planet', { name: "Villain League", id: "123" })
18046
+ });
18047
+ });
18048
+
18049
+ run(function () {
18050
+ json = tom.serialize();
18051
+ });
18052
+
18053
+ deepEqual(json, {
18054
+ firstName: get(tom, "firstName"),
18055
+ lastName: get(tom, "lastName"),
18056
+ homePlanet: get(tom, "homePlanet").get("id"),
18057
+ secretLab: get(tom, "secretLab").get("id"),
18058
+ secretLabType: 'batCave'
18059
+ });
18060
+ });
18061
+
18062
+ test("serialize with embedded object (belongsTo relationship) supports serialize:id in conjunction with deserialize:records", function () {
18063
+ SuperVillain.reopen({
18064
+ secretLab: DS.belongsTo('secret-lab', { polymorphic: true })
18065
+ });
18066
+
18067
+ env.registry.register('serializer:super-villain', DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, {
18068
+ attrs: {
18069
+ secretLab: { serialize: 'id', deserialize: 'records' }
18070
+ }
18071
+ }));
18072
+
18073
+ var tom, json;
18074
+ run(function () {
18075
+ tom = env.store.createRecord('super-villain', { firstName: "Tom", lastName: "Dale", id: "1",
18076
+ secretLab: env.store.createRecord('bat-cave', { minionCapacity: 5000, vicinity: "California, USA", id: "101" }),
18077
+ homePlanet: env.store.createRecord('home-planet', { name: "Villain League", id: "123" })
18078
+ });
18079
+ });
18080
+
18081
+ run(function () {
18082
+ json = tom.serialize();
18083
+ });
18084
+
18085
+ deepEqual(json, {
18086
+ firstName: get(tom, "firstName"),
18087
+ lastName: get(tom, "lastName"),
18088
+ homePlanet: get(tom, "homePlanet").get("id"),
18089
+ secretLab: get(tom, "secretLab").get("id"),
18090
+ secretLabType: 'batCave'
18091
+ });
18092
+ });
18093
+
17950
18094
  test("serialize with embedded object (belongsTo relationship) supports serialize:ids", function () {
17951
18095
  env.registry.register('serializer:super-villain', DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, {
17952
18096
  attrs: {
@@ -18671,7 +18815,7 @@ define(
18671
18815
  var get = Ember.get;
18672
18816
  var run = Ember.run;
18673
18817
 
18674
- var User, Handle, GithubHandle, TwitterHandle, Company;
18818
+ var User, Handle, GithubHandle, TwitterHandle, Company, Project;
18675
18819
 
18676
18820
  module('integration/serializers/json-api-serializer - JSONAPISerializer', {
18677
18821
  setup: function () {
@@ -18700,6 +18844,10 @@ define(
18700
18844
  employees: DS.hasMany('user', { async: true })
18701
18845
  });
18702
18846
 
18847
+ Project = DS.Model.extend({
18848
+ 'company-name': DS.attr('string')
18849
+ });
18850
+
18703
18851
  env = setupStore({
18704
18852
  adapter: DS.JSONAPIAdapter,
18705
18853
 
@@ -18707,7 +18855,8 @@ define(
18707
18855
  handle: Handle,
18708
18856
  'github-handle': GithubHandle,
18709
18857
  'twitter-handle': TwitterHandle,
18710
- company: Company
18858
+ company: Company,
18859
+ project: Project
18711
18860
  });
18712
18861
 
18713
18862
  store = env.store;
@@ -18790,6 +18939,7 @@ define(
18790
18939
  test('Serializer should respect the attrs hash when extracting attributes and relationships', function () {
18791
18940
  env.registry.register("serializer:user", DS.JSONAPISerializer.extend({
18792
18941
  attrs: {
18942
+ firstName: 'firstname_attribute_key',
18793
18943
  title: "title_attribute_key",
18794
18944
  company: { key: 'company_relationship_key' }
18795
18945
  }
@@ -18800,6 +18950,7 @@ define(
18800
18950
  type: 'users',
18801
18951
  id: '1',
18802
18952
  attributes: {
18953
+ 'firstname_attribute_key': 'Yehuda',
18803
18954
  'title_attribute_key': 'director'
18804
18955
  },
18805
18956
  relationships: {
@@ -18819,6 +18970,7 @@ define(
18819
18970
 
18820
18971
  var user = env.store.serializerFor("user").normalizeResponse(env.store, User, jsonHash, '1', 'findRecord');
18821
18972
 
18973
+ equal(user.data.attributes.firstName, 'Yehuda');
18822
18974
  equal(user.data.attributes.title, "director");
18823
18975
  deepEqual(user.data.relationships.company.data, { id: "2", type: "company" });
18824
18976
  });
@@ -18826,6 +18978,7 @@ define(
18826
18978
  test('Serializer should respect the attrs hash when serializing attributes and relationships', function () {
18827
18979
  env.registry.register("serializer:user", DS.JSONAPISerializer.extend({
18828
18980
  attrs: {
18981
+ firstName: 'firstname_attribute_key',
18829
18982
  title: "title_attribute_key",
18830
18983
  company: { key: 'company_relationship_key' }
18831
18984
  }
@@ -18849,8 +19002,48 @@ define(
18849
19002
  var payload = env.store.serializerFor("user").serialize(user._createSnapshot());
18850
19003
 
18851
19004
  equal(payload.data.relationships['company_relationship_key'].data.id, "1");
19005
+ equal(payload.data.attributes['firstname_attribute_key'], 'Yehuda');
18852
19006
  equal(payload.data.attributes['title_attribute_key'], "director");
18853
19007
  });
19008
+
19009
+ test('Serializer should respect the attrs hash when extracting attributes with not camelized keys', function () {
19010
+ env.registry.register('serializer:project', DS.JSONAPISerializer.extend({
19011
+ attrs: {
19012
+ 'company-name': 'company_name'
19013
+ }
19014
+ }));
19015
+
19016
+ var jsonHash = {
19017
+ data: {
19018
+ type: 'projects',
19019
+ id: '1',
19020
+ attributes: {
19021
+ 'company_name': 'Tilde Inc.'
19022
+ }
19023
+ }
19024
+ };
19025
+
19026
+ var project = env.store.serializerFor('project').normalizeResponse(env.store, User, jsonHash, '1', 'findRecord');
19027
+
19028
+ equal(project.data.attributes['company-name'], 'Tilde Inc.');
19029
+ });
19030
+
19031
+ test('Serializer should respect the attrs hash when serializing attributes with not camelized keys', function () {
19032
+ env.registry.register('serializer:project', DS.JSONAPISerializer.extend({
19033
+ attrs: {
19034
+ 'company-name': 'company_name'
19035
+ }
19036
+ }));
19037
+ var project;
19038
+
19039
+ run(function () {
19040
+ project = env.store.createRecord('project', { 'company-name': 'Tilde Inc.' });
19041
+ });
19042
+
19043
+ var payload = env.store.serializerFor('project').serialize(project._createSnapshot());
19044
+
19045
+ equal(payload.data.attributes['company_name'], 'Tilde Inc.');
19046
+ });
18854
19047
  }
18855
19048
  );
18856
19049
 
@@ -19151,6 +19344,30 @@ define(
19151
19344
  deepEqual(post.data.relationships.comments.data, [{ id: "1", type: "comment" }, { id: "2", type: "comment" }]);
19152
19345
  });
19153
19346
 
19347
+ test('Serializer should map `attrs` attributes directly when keyForAttribute also has a transform', function () {
19348
+ Post = DS.Model.extend({
19349
+ authorName: DS.attr('string')
19350
+ });
19351
+ env = setupStore({
19352
+ post: Post
19353
+ });
19354
+ env.registry.register("serializer:post", DS.JSONSerializer.extend({
19355
+ keyForAttribute: Ember.String.underscore,
19356
+ attrs: {
19357
+ authorName: 'author_name_key'
19358
+ }
19359
+ }));
19360
+
19361
+ var jsonHash = {
19362
+ id: "1",
19363
+ author_name_key: "DHH"
19364
+ };
19365
+
19366
+ var post = env.store.serializerFor("post").normalizeResponse(env.store, Post, jsonHash, '1', 'findRecord');
19367
+
19368
+ equal(post.data.attributes.authorName, "DHH");
19369
+ });
19370
+
19154
19371
  test('Serializer should respect the attrs hash when serializing records', function () {
19155
19372
  Post.reopen({
19156
19373
  parentPost: DS.belongsTo('post', { inverse: null, async: true })
@@ -20113,6 +20330,28 @@ define(
20113
20330
  equal(array.data[0].relationships.superVillain.data.id, 1);
20114
20331
  });
20115
20332
 
20333
+ test('normalize should allow for different levels of normalization - attributes', function () {
20334
+ env.registry.register('serializer:application', DS.RESTSerializer.extend({
20335
+ attrs: {
20336
+ name: 'full_name'
20337
+ },
20338
+ keyForAttribute: function (attr) {
20339
+ return Ember.String.decamelize(attr);
20340
+ }
20341
+ }));
20342
+
20343
+ var jsonHash = {
20344
+ evilMinions: [{ id: "1", full_name: "Tom Dale" }]
20345
+ };
20346
+ var array;
20347
+
20348
+ run(function () {
20349
+ array = env.restSerializer.normalizeResponse(env.store, EvilMinion, jsonHash, null, 'findAll');
20350
+ });
20351
+
20352
+ equal(array.data[0].attributes.name, 'Tom Dale');
20353
+ });
20354
+
20116
20355
  test("serializeIntoHash", function () {
20117
20356
  run(function () {
20118
20357
  league = env.store.createRecord('home-planet', { name: "Umber", id: "123" });
@@ -22495,11 +22734,30 @@ define(
22495
22734
  source: { pointer: '/data/attributes/age' }
22496
22735
  }];
22497
22736
 
22737
+ var errorsPrimaryHash = {
22738
+ base: ['is invalid', 'error message']
22739
+ };
22740
+
22741
+ var errorsPrimaryArray = [{
22742
+ title: 'Invalid Document',
22743
+ detail: 'is invalid',
22744
+ source: { pointer: '/data' }
22745
+ }, {
22746
+ title: 'Invalid Document',
22747
+ detail: 'error message',
22748
+ source: { pointer: '/data' }
22749
+ }];
22750
+
22498
22751
  test("errorsHashToArray", function () {
22499
22752
  var result = DS.errorsHashToArray(errorsHash);
22500
22753
  deepEqual(result, errorsArray);
22501
22754
  });
22502
22755
 
22756
+ test("errorsHashToArray for primary data object", function () {
22757
+ var result = DS.errorsHashToArray(errorsPrimaryHash);
22758
+ deepEqual(result, errorsPrimaryArray);
22759
+ });
22760
+
22503
22761
  test("errorsArrayToHash", function () {
22504
22762
  var result = DS.errorsArrayToHash(errorsArray);
22505
22763
  deepEqual(result, errorsHash);
@@ -22513,6 +22771,11 @@ define(
22513
22771
  deepEqual(result, { name: ['error message'] });
22514
22772
  });
22515
22773
 
22774
+ test("errorsArrayToHash for primary data object", function () {
22775
+ var result = DS.errorsArrayToHash(errorsPrimaryArray);
22776
+ deepEqual(result, errorsPrimaryHash);
22777
+ });
22778
+
22516
22779
  test("DS.InvalidError will normalize errors hash will assert", function () {
22517
22780
  var error;
22518
22781
 
@@ -24659,16 +24922,17 @@ define(
24659
24922
 
24660
24923
  module("unit/model/internal-model - Internal Model");
24661
24924
 
24662
- var mockModelFactory = {
24663
- _create: function () {
24664
- return { trigger: function () {} };
24665
- },
24925
+ function MockModelFactory() {}
24666
24926
 
24667
- eachRelationship: function () {}
24927
+ MockModelFactory._create = function () {
24928
+ return { trigger: function () {} };
24668
24929
  };
24930
+
24931
+ MockModelFactory.eachRelationship = function () {};
24932
+
24669
24933
  test("Materializing a model twice errors out", function () {
24670
24934
  expect(1);
24671
- var internalModel = new DS.InternalModel(mockModelFactory, null, null, null);
24935
+ var internalModel = new DS.InternalModel(MockModelFactory, null, {}, null);
24672
24936
 
24673
24937
  internalModel.materializeRecord();
24674
24938
  expectAssertion(function () {
@@ -29681,7 +29945,7 @@ define(
29681
29945
  "blog.post": DS.Model.extend()
29682
29946
  });
29683
29947
  store = env.store;
29684
- container = store.container;
29948
+ container = env.container;
29685
29949
  registry = env.registry;
29686
29950
  },
29687
29951
 
@@ -29832,6 +30096,50 @@ define(
29832
30096
  }
29833
30097
  });
29834
30098
 
30099
+ test('Changed attributes are reset when matching data is pushed', function (assert) {
30100
+ var person;
30101
+
30102
+ run(function () {
30103
+ person = store.push({
30104
+ data: {
30105
+ type: 'person',
30106
+ id: 1,
30107
+ attributes: {
30108
+ firstName: 'original first name'
30109
+ }
30110
+ }
30111
+ });
30112
+ });
30113
+
30114
+ assert.equal(person.get('firstName'), 'original first name');
30115
+ assert.equal(person.get('currentState.stateName'), 'root.loaded.saved');
30116
+
30117
+ run(function () {
30118
+ person.set('firstName', 'updated first name');
30119
+ });
30120
+
30121
+ assert.equal(person.get('firstName'), 'updated first name');
30122
+ assert.equal(person.get('lastName'), undefined);
30123
+ assert.equal(person.get('currentState.stateName'), 'root.loaded.updated.uncommitted');
30124
+ deepEqual(person.changedAttributes().firstName, ['original first name', 'updated first name']);
30125
+
30126
+ run(function () {
30127
+ store.push({
30128
+ data: {
30129
+ type: 'person',
30130
+ id: 1,
30131
+ attributes: {
30132
+ firstName: 'updated first name'
30133
+ }
30134
+ }
30135
+ });
30136
+ });
30137
+
30138
+ assert.equal(person.get('firstName'), 'updated first name');
30139
+ assert.equal(person.get('currentState.stateName'), 'root.loaded.saved');
30140
+ assert.ok(!person.changedAttributes().firstName);
30141
+ });
30142
+
29835
30143
  test("Calling push with a normalized hash returns a record", function () {
29836
30144
  expect(2);
29837
30145
  env.adapter.shouldBackgroundReloadRecord = function () {
@@ -30519,7 +30827,7 @@ define(
30519
30827
  Person = DS.Model.extend({});
30520
30828
  var env = setupStore({ person: Person });
30521
30829
  store = env.store;
30522
- container = store.container;
30830
+ container = env.container;
30523
30831
  registry = env.registry;
30524
30832
  },
30525
30833