Skip to content

Commit

Permalink
Merge pull request #243 from crossroads/master
Browse files Browse the repository at this point in the history
#MayRelease2
  • Loading branch information
namrataukirde authored May 18, 2018
2 parents 57c9b9d + fcad257 commit 7273493
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 20 deletions.
41 changes: 21 additions & 20 deletions app/controllers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,28 @@ export default Ember.Controller.extend({
saveUser(){
var store = this.store;
var user = this.get("model");
var loadingView = getOwner(this).lookup('component:loading').append();
if(this.get('selectedRoleIds.length')){
user.set('userRoleIds', this.get('selectedRoleIds'));
} else {
user.set('userRoleIds',[]);
}
user.save()
.then(function(data){
data.get('userRoles').toArray().forEach(userRole => {
if(userRole && !data.get('userRoleIds').includes([userRole.get('roleId')].map(String))){
store.unloadRecord(userRole);
}
});
loadingView.destroy();
})
.catch(error => {
user.rollbackAttributes();
loadingView.destroy();
throw error;
var self = this;
var loadingView = getOwner(this).lookup('component:loading').append();
if(this.get('selectedRoleIds.length')){
user.set('userRoleIds', this.get('selectedRoleIds'));
} else {
user.set('userRoleIds',[]);
}
user.save()
.then(function(data){
data.get('userRoles').toArray().forEach(userRole => {
if(userRole && !data.get('userRoleIds').includes([userRole.get('roleId')].map(String))){
store.unloadRecord(userRole);
}
});
// }
loadingView.destroy();
self.transitionToRoute('users');
})
.catch(error => {
user.rollbackAttributes();
loadingView.destroy();
throw error;
});
}
}
});
Expand Down
60 changes: 60 additions & 0 deletions tests/acceptance/user-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import Ember from 'ember';
import startApp from '../helpers/start-app';
import '../helpers/custom-helpers';
import FactoryGuy from 'ember-data-factory-guy';
import TestHelper from 'ember-data-factory-guy/factory-guy-test-helper';
import { module, test } from 'qunit';

var App, user, role, userRole, userRole1;

module('Users', {
beforeEach: function() {
App = startApp({}, 1);
TestHelper.setup();

role = FactoryGuy.make("role");
$.mockjax({url: '/api/v1/role*', type: 'GET', status: 200,responseText: {
roles: [role.toJSON({includeId: true})]
}
});

user = FactoryGuy.make("user");
$.mockjax({url: '/api/v1/users', type: 'GET', status: 200,responseText: {
users: [user.toJSON({includeId: true})]
}
});
},
afterEach: function() {
Em.run(function() { TestHelper.teardown(); });
Ember.run(App, 'destroy');
}
});

test("redirect to users page after role save", function(assert) {
assert.expect(3);
userRole = FactoryGuy.make('user_role');
userRole1 = FactoryGuy.make('user_role');
$.mockjax({url: '/api/v1/user_role*', type: 'GET', status: 200,responseText: {
user_roles: [userRole.toJSON({includeId: true}), userRole1.toJSON({includeId: true})]
}
});

$.mockjax({url: '/api/v1/user*', type: 'PUT', status: 200,responseText: {
user: [user.toJSON({includeId: true})]
}
});

visit("/users");

andThen(function(){
assert.equal(currentURL(), '/users');
click("ul.list li:first a");
andThen(function(){
assert.equal(currentURL(), '/users/' + user.id);
click("button.expand");
andThen(function(){
assert.equal(currentURL(), '/users');
});
});
});
});

0 comments on commit 7273493

Please sign in to comment.