@@ -2,8 +2,6 @@ import { expect, sinon, fetchMock } from '../test-helper';
2
2
import { Author , Book , Genre } from '../fixtures' ;
3
3
import uuid from '../../src/util/uuid' ;
4
4
5
- let serverResponse ;
6
-
7
5
const resetMocks = function ( ) {
8
6
fetchMock . restore ( ) ;
9
7
@@ -66,10 +64,6 @@ const resetMocks = function() {
66
64
}
67
65
}
68
66
} ) ;
69
-
70
- fetchMock . post ( 'http://example.com/api/v1/people' , function ( url , payload ) {
71
- return serverResponse ;
72
- } ) ;
73
67
}
74
68
75
69
let instance ;
@@ -97,19 +91,50 @@ describe('validations', function() {
97
91
uuid . generate [ 'restore' ] ( ) ;
98
92
} ) ;
99
93
100
- // todo on next save, remove errs
101
94
it ( 'applies errors to the instance' , function ( done ) {
102
95
instance . save ( { with : { books : 'genre' } } ) . then ( ( success ) => {
103
96
expect ( instance . isPersisted ( ) ) . to . eq ( false ) ;
104
97
expect ( success ) . to . eq ( false ) ;
105
98
expect ( instance . errors ) . to . deep . equal ( {
106
- first_name : 'cannot be blank' ,
107
- last_name : 'cannot be blank'
99
+ firstName : 'cannot be blank' ,
100
+ lastName : 'cannot be blank'
108
101
} ) ;
109
102
done ( ) ;
110
103
} ) ;
111
104
} ) ;
112
105
106
+ describe ( 'when camelizeKeys is false' , function ( ) {
107
+ beforeEach ( function ( ) {
108
+ instance . klass . camelizeKeys = false
109
+ } ) ;
110
+
111
+ afterEach ( function ( ) {
112
+ instance . klass . camelizeKeys = true
113
+ } ) ;
114
+
115
+ it ( 'does not camelize the error keys' , function ( ) {
116
+ instance . save ( { with : { books : 'genre' } } ) . then ( ( success ) => {
117
+ expect ( instance . errors ) . to . deep . equal ( {
118
+ first_name : 'cannot be blank' ,
119
+ last_name : 'cannot be blank'
120
+ } ) ;
121
+ } ) ;
122
+ } ) ;
123
+ } ) ;
124
+
125
+ it ( 'clears errors on save' , function ( done ) {
126
+ fetchMock . restore ( )
127
+ fetchMock . mock ( {
128
+ matcher : '*' ,
129
+ response : { data : { id : '1' , type : 'employees' } }
130
+ } ) ;
131
+ instance . errors = { foo : 'bar' }
132
+ instance . save ( ) . then ( ( ) => {
133
+ expect ( instance . errors ) . to . deep . eq ( { } )
134
+ done ( )
135
+ } ) ;
136
+ } ) ;
137
+
113
138
it ( 'instantiates a new error object instance after save' , function ( done ) {
114
139
let originalErrors = instance . errors = { foo : 'bar' } ;
115
140
let result = instance . save ( { with : { books : 'genre' } } ) ;
0 commit comments