Skip to content

Commit

Permalink
Actually camelize the error keys
Browse files Browse the repository at this point in the history
Error keys were arriving on models with underscores e.g.

    human.errors.first_name

Addresses the test which was incorrectly passing
  • Loading branch information
Ben Holmes committed Apr 27, 2015
1 parent e928355 commit c947e25
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/activemodel-adapter/lib/system/active-model-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {pluralize} from "ember-inflector";
@module ember-data
*/

var camelize = Ember.String.camelize;
var decamelize = Ember.String.decamelize;
var underscore = Ember.String.underscore;

Expand Down Expand Up @@ -143,6 +144,16 @@ var ActiveModelAdapter = RESTAdapter.extend({
if (jqXHR && jqXHR.status === 422) {
var response = Ember.$.parseJSON(jqXHR.responseText);
var errors = response.errors ? response.errors : response;

for (var underscoredError in errors) {
var camelizedError = camelize(underscoredError);

if (camelizedError !== underscoredError) {
errors[camelizedError] = errors[underscoredError];
delete errors[underscoredError];
}
}

return new InvalidError(errors);
} else {
return error;
Expand Down

0 comments on commit c947e25

Please sign in to comment.