TESTS: Integration tests for login_required

This commit is contained in:
Robin Ward 2014-07-31 17:59:52 -04:00
parent e63cdc50bb
commit adea5b36a0
4 changed files with 27 additions and 10 deletions

View File

@ -94,7 +94,7 @@ window.Discourse = Ember.Application.createWithMixins(Discourse.Ajax, {
loginRequired: function() {
return Discourse.SiteSettings.login_required && !Discourse.User.current();
}.property(),
}.property().volatile(),
redirectIfLoginRequired: function(route) {
if(this.get('loginRequired')) { route.transitionTo('login'); }

View File

@ -46,6 +46,10 @@ export default function() {
this.post('/users', function() {
return response({success: true});
});
this.get('/login.html', function() {
return [200, {}, 'LOGIN PAGE'];
});
});

View File

@ -1,22 +1,28 @@
/* global asyncTest */
/* exported integration, testController, controllerFor, asyncTestDiscourse, fixture */
function integration(name, lifecycle) {
function integration(name, options) {
module("Integration: " + name, {
setup: function() {
Ember.run(Discourse, Discourse.advanceReadiness);
if (lifecycle && lifecycle.setup) {
lifecycle.setup.call(this);
}
if (options) {
if (options.setup) {
options.setup.call(this);
}
if (lifecycle && lifecycle.user) {
Discourse.User.resetCurrent(Discourse.User.create(lifecycle.user));
if (options.user) {
Discourse.User.resetCurrent(Discourse.User.create(options.user));
}
if (options.settings) {
Discourse.SiteSettings = jQuery.extend(true, Discourse.SiteSettings, options.settings);
}
}
Discourse.reset();
},
teardown: function() {
if (lifecycle && lifecycle.teardown) {
lifecycle.teardown.call(this);
if (options && options.teardown) {
options.teardown.call(this);
}
Discourse.reset();

View File

@ -1,21 +1,28 @@
integration("Static");
test("Static Pages", function() {
expect(4);
visit("/faq");
andThen(function() {
ok(exists(".body-page"), "The content is present");
});
visit("/guidelines");
andThen(function() {
ok(exists(".body-page"), "The content is present");
});
visit("/tos");
andThen(function() {
ok(exists(".body-page"), "The content is present");
});
visit("/privacy");
andThen(function() {
ok(exists(".body-page"), "The content is present");
});
visit("/login");
andThen(function() {
equal(currentPath(), "discovery.latest", "it redirects them to latest unless `login_required`");
});
});