phxdatasec/model-factory — pull request #15 by juristr (2014-12-02 07:29:47+00:00)
Title: adds failing test demonstrating a bug with cloned models

I added this test which is failing as of now.

```javascript
it('on a copied model it should sent back the copied model data', function(){
var newModel = new PersonModel({
name: 'Juri'
});

var copied = angular.copy(newModel);
copied.name = 'Austin'; //change something in the clone

$httpBackend.expectPOST('/api/people', JSON.stringify(copied)).respond(200, '');

copied.$save();
$httpBackend.flush();
});
```

When executing this test I get

![image](https://cloud.githubusercontent.com/assets/542458/5259173/991038bc-79fc-11e4-8cfe-9feb5cfabec6.png)

**The scenario** is the following. Take the this simple master-detail editing UI:

![image](https://cloud.githubusercontent.com/assets/542458/5230577/7b9d025a-7728-11e4-8cca-c0f5f742a284.gif)

When clicking on an item to start editing I want to update the list entry **only after the user clicked the save button and everything has been stored successfully on the server**, rather than the auto-updating scenario due to the live binding.

As such, I create a copy of the model using `angular.copy(...)` which I'm currently editing, for then merging it back into the original one once `$save()` succeeded. When doing so, I notice that `.copy(...)` does not work properly, at least not when then invoking `$save()` on the copied model as it will always take the data from original one rather than the newly copied.

I suspect it has something to do with [this line](https://github.com/phxdatasec/model-factory/blob/master/src/modelFactory.js#L335) as the data is somehow gathered from some internal variable.

@amcdnl Any idea on this? Or how we could fix it?