Redirect setup if authenticated

closes #3145
- added beforeModel redirect
- added test
This commit is contained in:
Sebastian Gierlinger 2014-07-01 12:57:44 +02:00
parent 9214f25dee
commit b332e8c158
3 changed files with 40 additions and 2 deletions

View File

@ -2,7 +2,12 @@ import styleBody from 'ghost/mixins/style-body';
import loadingIndicator from 'ghost/mixins/loading-indicator';
var SetupRoute = Ember.Route.extend(styleBody, loadingIndicator, {
classNames: ['ghost-setup']
classNames: ['ghost-setup'],
beforeModel: function () {
if (this.get('session').isAuthenticated) {
this.transitionTo(Ember.SimpleAuth.routeAfterAuthentication);
}
}
});
export default SetupRoute;

View File

@ -100,6 +100,10 @@ screens = {
'setup': {
url: 'ghost/setup/',
selector: '.button-add'
},
'setup-authenticated': {
url: 'ghost/setup/',
selector: '#main-menu .content.active'
}
};

View File

@ -31,4 +31,33 @@ CasperTest.begin('Ghost setup fails properly', 5, function suite(test) {
}, function onTimeout() {
test.assert(false, 'No error notification :(');
});
}, true);
}, true);
CasperTest.begin('Authenticated user is redirected', 8, function suite(test) {
casper.thenOpenAndWaitForPageLoad('signin', function testTitleAndUrl() {
test.assertTitle('Ghost Admin', 'Ghost admin has no title');
test.assertUrlMatch(/ghost\/signin\/$/, 'Landed on the correct URL');
});
casper.waitForOpaque('.login-box', function then() {
this.fillAndSave('#login', user);
});
casper.wait(2000);
casper.waitForResource(/posts/, function testForDashboard() {
test.assertUrlMatch(/ghost\/\d+\/$/, 'Landed on the correct URL');
test.assertExists('#global-header', 'Global admin header is present');
test.assertExists('.manage', 'We\'re now on content');
}, function onTimeOut() {
test.fail('Failed to signin');
});
casper.thenOpenAndWaitForPageLoad('setup-authenticated', function testTitleAndUrl() {
test.assertUrlMatch(/ghost\/\d+\/$/, 'Landed on the correct URL');
test.assertExists('#global-header', 'Global admin header is present');
test.assertExists('.manage', 'We\'re now on content');
}, function onTimeOut() {
test.fail('Failed to redirect');
});
}, true);