forked from emberjs/data
/
create_record_test.js
93 lines (76 loc) · 2.53 KB
/
create_record_test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
var store, container, Record;
var run = Ember.run;
module("unit/store/createRecord - Store creating records", {
setup: function() {
store = createStore({ adapter: DS.Adapter.extend()});
Record = DS.Model.extend({
title: DS.attr('string')
});
}
});
test("doesn't modify passed in properties hash", function(){
var attributes = { foo: 'bar' };
run(function(){
store.createRecord(Record, attributes);
store.createRecord(Record, attributes);
});
deepEqual(attributes, { foo: 'bar' }, "The properties hash is not modified");
});
module("unit/store/createRecord - Store with models by dash", {
setup: function() {
var env = setupStore({
'some-thing': DS.Model.extend({ foo: DS.attr('string') })
});
store = env.store;
container = env.container;
env.replaceContainerNormalize(function(key){
return Ember.String.dasherize(key);
});
}
});
test("creating a record by camel-case string finds the model", function(){
var attributes = { foo: 'bar' };
var record;
run(function(){
record = store.createRecord('someThing', attributes);
});
equal(record.get('foo'), attributes.foo, "The record is created");
equal(store.modelFor('someThing').typeKey, 'someThing');
});
test("creating a record by dasherize string finds the model", function(){
var attributes = { foo: 'bar' };
var record;
run(function(){
record = store.createRecord('some-thing', attributes);
});
equal(record.get('foo'), attributes.foo, "The record is created");
equal(store.modelFor('some-thing').typeKey, 'someThing');
});
module("unit/store/createRecord - Store with models by camelCase", {
setup: function() {
var env = setupStore({
'someThing': DS.Model.extend({ foo: DS.attr('string') })
});
store = env.store;
container = env.container;
env.replaceContainerNormalize(Ember.String.camelize);
}
});
test("creating a record by camel-case string finds the model", function(){
var attributes = { foo: 'bar' };
var record;
run(function(){
record = store.createRecord('someThing', attributes);
});
equal(record.get('foo'), attributes.foo, "The record is created");
equal(store.modelFor('someThing').typeKey, 'someThing');
});
test("creating a record by dasherize string finds the model", function(){
var attributes = { foo: 'bar' };
var record;
run(function(){
record = store.createRecord('some-thing', attributes);
});
equal(record.get('foo'), attributes.foo, "The record is created");
equal(store.modelFor('some-thing').typeKey, 'someThing');
});