diff --git a/addon/mixins/copyable.js b/addon/mixins/copyable.js index 3846966..7812695 100644 --- a/addon/mixins/copyable.js +++ b/addon/mixins/copyable.js @@ -3,14 +3,20 @@ import DS from 'ember-data'; export default Ember.Mixin.create({ copyable: true, - copy: function(options) { + copy: function (options) { + options = options || {}; + + var model = this.constructor; + var copy = this.get('store').createRecord(model.modelName || model.typeKey); + return this.copyTo(copy, options); + }, + copyTo: function(copy, options) { options = options || {}; var _this = this; return new Ember.RSVP.Promise(function(resolve) { var model = _this.constructor; - var copy = _this.get('store').createRecord(model.modelName || model.typeKey); var queue = []; model.eachAttribute(function(attr) { diff --git a/tests/unit/sync-copying-test.js b/tests/unit/sync-copying-test.js index 832c73a..5e17c6e 100644 --- a/tests/unit/sync-copying-test.js +++ b/tests/unit/sync-copying-test.js @@ -27,6 +27,19 @@ test('it excludes attributes', function(assert) { }); }); +test('copies to', function(assert) { + assert.expect(2); + + var foo = store.getById('foo', '1'); + return Ember.run(function() { + assert.equal(foo.get('property'), 'prop1'); + var copy = store.createRecord('foo'); + return foo.copyTo(copy).then(function () { + assert.equal(copy.get('property'), 'prop1'); + }); + }); +}); + test('it shallow copies relation', function(assert) { assert.expect(1);