Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Two tests for committing records with an updated child-parent relationship #381

Closed
wants to merge 1 commit into from

3 participants

Luke Melia Peter Wagenet Sylvain MINA
Luke Melia
Collaborator

In both cases, the successful commit should result in the parent record no longer being in a dirty state. Currently, one fails and one passes. The difference is whether the response includes a hash representation of the child record.

Both @wagenet and I have run into this recently in real-world apps.

Luke Melia lukemelia Two tests for committing records with an updated child-parent relatio…
…nship.

In both cases, the successful commit should result in the parent record no longer being in a dirty state. Currently, one fails and one passes. The difference is whether the response includes a hash representation of the child record.
207959c
Peter Wagenet
Owner

@lukemelia Can you rebase this?

Sylvain MINA
Collaborator

@wagenet I wonder if this is related to #412

Peter Wagenet
Owner

I think this is probably resolved now.

Peter Wagenet wagenet closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 10, 2012
  1. Luke Melia

    Two tests for committing records with an updated child-parent relatio…

    lukemelia authored
    …nship.
    
    In both cases, the successful commit should result in the parent record no longer being in a dirty state. Currently, one fails and one passes. The difference is whether the response includes a hash representation of the child record.
This page is out of date. Refresh to see the latest.
Showing with 42 additions and 4 deletions.
  1. +42 −4 packages/ember-data/tests/unit/rest_adapter_test.js
46 packages/ember-data/tests/unit/rest_adapter_test.js
View
@@ -89,13 +89,15 @@ var expectData = function(hash) {
deepEqual(hash, ajaxHash.data, "the hash was passed along");
};
-var expectState = function(state, value, p) {
- p = p || person;
+var expectState = function(state, value, record) {
+ record = record || person;
if (value === undefined) { value = true; }
- var flag = "is" + state.charAt(0).toUpperCase() + state.substr(1);
- equal(get(p, flag), value, "the person is " + (value === false ? "not " : "") + state);
+ var flag = "is" + state.charAt(0).toUpperCase() + state.substr(1),
+ recordFriendlyType = record.constructor.toString().replace(/^App\./,'');
+ recordFriendlyType = recordFriendlyType.charAt(0).toLowerCase() + recordFriendlyType.substr(1);
+ equal(get(record, flag), value, "the " + recordFriendlyType + " is " + (value === false ? "not " : "") + state);
};
var expectStates = function(state, value) {
@@ -174,6 +176,42 @@ test("updating a person makes a PUT to /people/:id with the data hash", function
equal(get(person, 'name'), "Brohuda Brokatz", "the hash should be updated");
});
+test("committing an update to a person's group leaves the group in a clean state (update returns hash)", function() {
+ store.load(Person, { id: 1, name: "Yehuda Katz" });
+ store.load(Group, { id: 1, name: "Emberenos" });
+
+ person = store.find(Person, 1);
+ group = store.find(Group, 1);
+
+ set(person, 'group', group);
+
+ expectState('dirty', true, person);
+ expectState('dirty', true, group);
+ store.commit();
+
+ ajaxHash.success({ person: { id: 1, name: "Yehuda Katz", groupId: 1 } });
+ expectState('dirty', false, person);
+ expectState('dirty', false, group);
+});
+
+test("committing an update to a person's group leaves the group in a clean state (update does not return hash)", function() {
+ store.load(Person, { id: 1, name: "Yehuda Katz" });
+ store.load(Group, { id: 1, name: "Emberenos" });
+
+ person = store.find(Person, 1);
+ group = store.find(Group, 1);
+
+ set(person, 'group', group);
+
+ expectState('dirty', true, person);
+ expectState('dirty', true, group);
+ store.commit();
+
+ ajaxHash.success({});
+ expectState('dirty', false, person);
+ expectState('dirty', false, group);
+});
+
test("updates are not required to return data", function() {
store.load(Person, { id: 1, name: "Yehuda Katz" });
Something went wrong with that request. Please try again.