-
-
Save tb/fca3046947a7dc516938 to your computer and use it in GitHub Desktop.
After refactoring #2 - modified
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
var errorize = Ember.Object.extend({ | |
init() { | |
this._super(); | |
this.set('errorsList', {}); | |
}, | |
// test should check various inputs and verify addToErrorsList is called with proper arguments | |
processError(error) { | |
let field = (/\w+$/.exec(error.source.pointer))[0].camelize(); | |
let message = error.detail; | |
this.addToErrorsList(field, message); | |
}, | |
// test should verify adding new field and appending error to existing field | |
addToErrorsList(field, message) { | |
(this.get('errorsList')[field] = this.get('errorsList')[field] || []) | |
.push({message}); | |
}, | |
// test should verify empty and not-empty case | |
serialize() { | |
this.get('errors.responseJSON.errors').forEach(this.processError); | |
return this.get('errorsList'); | |
}, | |
}); | |
export default errorize; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment