Skip to content
This repository was archived by the owner on Jan 31, 2019. It is now read-only.

A model that is not "dirty" can't transition to "uncommitted".#14

Merged
bcardarella merged 2 commits intoDavyJonesLocker:masterfrom
diogomafra:validate_dirty
Apr 21, 2013
Merged

A model that is not "dirty" can't transition to "uncommitted".#14
bcardarella merged 2 commits intoDavyJonesLocker:masterfrom
diogomafra:validate_dirty

Conversation

@diogomafra
Copy link
Copy Markdown
Contributor

When a ember-data model is validated, the validator changes its state to 'uncommitted', but it fails silently when the model is not dirty. It does not show any error because the deferred is not catching the errors.

You can see the problem adding this code on line 83 of mixin.js: .then(null, function(err){alert(err);}); . The could should look like this:

// Line: 71
return Ember.RSVP.all(deferreds).then(function() {
  if (object.get('stateManager')) {
    if (Object.keys(object.errors).length === 0) {
      object.get('stateManager').transitionTo('uncommitted');
    } else {
      object.get('stateManager').transitionTo('invalid');
    }
  } else {
    object.set('isValid', Object.keys(object.errors).length === 0);
  }
}).then(null, function(err){alert(err);});

And then, just try to validate a model that is not dirty: App.MyModel.find(1).validate().

It throws this error: Error: assertion failed: Could not find state for path: "uncommitted".

@bcardarella
Copy link
Copy Markdown
Contributor

Could we get a test case for this? How the validations are being handled will probably be refactored eventually to match whatever happens in ember-data and I wouldn't want this to regress

@diogomafra
Copy link
Copy Markdown
Contributor Author

OK, I will create a test case!

@bcardarella
Copy link
Copy Markdown
Contributor

@diogomafra any updates on this?

@diogomafra
Copy link
Copy Markdown
Contributor Author

I was busy this week and could not create the test. I will try to finish it today.

@diogomafra
Copy link
Copy Markdown
Contributor Author

I added a test, it's similar to a test that already exists, checking the behavior using the stateManager. This test is very 'artificial', because we're just simulating the ember-data behavior, and not really using it.

When ember-data becomes more stable, would be nice to have some integration tests.

@bcardarella
Copy link
Copy Markdown
Contributor

Yes I agree

bcardarella added a commit that referenced this pull request Apr 21, 2013
A model that is not "dirty" can't transition to "uncommitted".
@bcardarella bcardarella merged commit fbea7ea into DavyJonesLocker:master Apr 21, 2013
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants