diff --git a/app/mixins/delete-model.js b/app/mixins/delete-model.js new file mode 100644 index 0000000..e16fb76 --- /dev/null +++ b/app/mixins/delete-model.js @@ -0,0 +1,15 @@ +import Ember from 'ember'; + +const { Mixin } = Ember; + +export default Mixin.create({ + transitionRoute: null, + + actions: { + delete: function() { + this.get('model').destroyRecord().then(() => { + this.transitionToRoute(this.get('transitionRoute')); + }); + }, + }, +}); diff --git a/app/pods/protected/species/show/controller.js b/app/pods/protected/species/show/controller.js index 684673b..4a659e0 100644 --- a/app/pods/protected/species/show/controller.js +++ b/app/pods/protected/species/show/controller.js @@ -1,14 +1,9 @@ import Ember from 'ember'; +import DeleteModel from '../../../../mixins/delete-model'; const { Controller } = Ember; -export default Controller.extend({ - actions: { - delete: function() { - this.get('model').destroyRecord().then(() => { - this.transitionToRoute('protected.species.index'); - }); - }, - }, - +export default Controller.extend(DeleteModel, { + // Required for DeleteModel mixin + transitionRoute: 'protected.species.index', }); diff --git a/tests/unit/mixins/delete-model-test.js b/tests/unit/mixins/delete-model-test.js new file mode 100644 index 0000000..b49b132 --- /dev/null +++ b/tests/unit/mixins/delete-model-test.js @@ -0,0 +1,12 @@ +import Ember from 'ember'; +import DeleteModelMixin from '../../../mixins/delete-model'; +import { module, test } from 'qunit'; + +module('Unit | Mixin | delete model'); + +// Replace this with your real tests. +test('it works', function(assert) { + var DeleteModelObject = Ember.Object.extend(DeleteModelMixin); + var subject = DeleteModelObject.create(); + assert.ok(subject); +});