@@ -2,8 +2,6 @@ import { expect, sinon, fetchMock } from '../test-helper';
22import { Author , Book , Genre } from '../fixtures' ;
33import uuid from '../../src/util/uuid' ;
44
5- let serverResponse ;
6-
75const resetMocks = function ( ) {
86 fetchMock . restore ( ) ;
97
@@ -66,10 +64,6 @@ const resetMocks = function() {
6664 }
6765 }
6866 } ) ;
69-
70- fetchMock . post ( 'http://example.com/api/v1/people' , function ( url , payload ) {
71- return serverResponse ;
72- } ) ;
7367}
7468
7569let instance ;
@@ -97,19 +91,50 @@ describe('validations', function() {
9791 uuid . generate [ 'restore' ] ( ) ;
9892 } ) ;
9993
100- // todo on next save, remove errs
10194 it ( 'applies errors to the instance' , function ( done ) {
10295 instance . save ( { with : { books : 'genre' } } ) . then ( ( success ) => {
10396 expect ( instance . isPersisted ( ) ) . to . eq ( false ) ;
10497 expect ( success ) . to . eq ( false ) ;
10598 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'
108101 } ) ;
109102 done ( ) ;
110103 } ) ;
111104 } ) ;
112105
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+
113138 it ( 'instantiates a new error object instance after save' , function ( done ) {
114139 let originalErrors = instance . errors = { foo : 'bar' } ;
115140 let result = instance . save ( { with : { books : 'genre' } } ) ;
0 commit comments