mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-02-17 04:01:29 -05:00
TESTS: Reset the preload store for testing
This commit is contained in:
parent
c3e1dd4707
commit
c5b5db48cf
6 changed files with 31 additions and 15 deletions
|
@ -98,8 +98,16 @@ Discourse.Singleton = Em.Mixin.create({
|
|||
} else {
|
||||
return instance.get(property);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
Resets the current singleton. Useful in testing.
|
||||
|
||||
@method resetCurrent
|
||||
**/
|
||||
resetCurrent: function(val) {
|
||||
this._current = val;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
|
|
@ -77,6 +77,14 @@ window.PreloadStore = {
|
|||
**/
|
||||
remove: function(key) {
|
||||
if (this.data[key]) delete this.data[key];
|
||||
},
|
||||
|
||||
/**
|
||||
Resets the contents of the store. Used in testing.
|
||||
|
||||
**/
|
||||
reset: function() {
|
||||
this.data = {};
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -7,6 +7,10 @@ function integration(name, lifecycle) {
|
|||
if (lifecycle && lifecycle.setup) {
|
||||
lifecycle.setup.call(this);
|
||||
}
|
||||
|
||||
if (lifecycle && lifecycle.user) {
|
||||
Discourse.User.resetCurrent(Discourse.User.create(lifecycle.user));
|
||||
}
|
||||
Discourse.reset();
|
||||
},
|
||||
|
||||
|
|
|
@ -1,17 +1,7 @@
|
|||
integration("Header", {
|
||||
setup: function() {
|
||||
var originalUser = Discourse.User.current();
|
||||
sandbox.stub(Discourse.User, "current").returns(originalUser);
|
||||
Discourse.User.current.returns(Ember.Object.create({
|
||||
username: 'test',
|
||||
staff: true,
|
||||
site_flagged_posts_count: 1
|
||||
}));
|
||||
},
|
||||
|
||||
teardown: function() {
|
||||
Discourse.User.current.restore();
|
||||
}
|
||||
integration("Header as Staff", {
|
||||
user: { username: 'test',
|
||||
staff: true,
|
||||
site_flagged_posts_count: 1 }
|
||||
});
|
||||
|
||||
test("header", function() {
|
||||
|
|
|
@ -24,6 +24,7 @@ test("uploading one file", function() {
|
|||
|
||||
test("new user cannot upload images", function() {
|
||||
Discourse.SiteSettings.newuser_max_images = 0;
|
||||
Discourse.User.resetCurrent(Discourse.User.create());
|
||||
sandbox.stub(bootbox, "alert");
|
||||
|
||||
not(validUpload([{name: "image.png"}]), 'the upload is not valid');
|
||||
|
@ -33,6 +34,7 @@ test("new user cannot upload images", function() {
|
|||
test("new user cannot upload attachments", function() {
|
||||
Discourse.SiteSettings.newuser_max_attachments = 0;
|
||||
sandbox.stub(bootbox, "alert");
|
||||
Discourse.User.resetCurrent(Discourse.User.create());
|
||||
|
||||
not(validUpload([{name: "roman.txt"}]));
|
||||
ok(bootbox.alert.calledWith(I18n.t('post.errors.attachment_upload_not_allowed_for_new_user')));
|
||||
|
@ -48,6 +50,7 @@ test("ensures an authorized upload", function() {
|
|||
});
|
||||
|
||||
test("prevents files that are too big from being uploaded", function() {
|
||||
Discourse.User.resetCurrent(Discourse.User.create());
|
||||
var image = { name: "image.png", size: 10 * 1024 };
|
||||
Discourse.SiteSettings.max_image_size_kb = 5;
|
||||
Discourse.User.currentProp("trust_level", 1);
|
||||
|
@ -69,6 +72,7 @@ var dummyBlob = function() {
|
|||
};
|
||||
|
||||
test("allows valid uploads to go through", function() {
|
||||
Discourse.User.resetCurrent(Discourse.User.create());
|
||||
Discourse.User.currentProp("trust_level", 1);
|
||||
Discourse.SiteSettings.max_image_size_kb = 15;
|
||||
sandbox.stub(bootbox, "alert");
|
||||
|
|
|
@ -98,6 +98,8 @@ QUnit.testStart(function(ctx) {
|
|||
Discourse.SiteSettings = jQuery.extend(true, {}, Discourse.SiteSettingsOriginal);
|
||||
Discourse.BaseUri = "/";
|
||||
Discourse.BaseUrl = "";
|
||||
Discourse.User.resetCurrent();
|
||||
PreloadStore.reset();
|
||||
|
||||
window.sandbox = sinon.sandbox.create();
|
||||
|
||||
|
|
Loading…
Reference in a new issue