mirror of
https://github.com/discourse/discourse.git
synced 2025-05-25 00:32:52 +08:00
TESTS: Reset the preload store for testing
This commit is contained in:
@ -98,8 +98,16 @@ Discourse.Singleton = Em.Mixin.create({
|
|||||||
} else {
|
} else {
|
||||||
return instance.get(property);
|
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) {
|
remove: function(key) {
|
||||||
if (this.data[key]) delete this.data[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) {
|
if (lifecycle && lifecycle.setup) {
|
||||||
lifecycle.setup.call(this);
|
lifecycle.setup.call(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (lifecycle && lifecycle.user) {
|
||||||
|
Discourse.User.resetCurrent(Discourse.User.create(lifecycle.user));
|
||||||
|
}
|
||||||
Discourse.reset();
|
Discourse.reset();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -1,17 +1,7 @@
|
|||||||
integration("Header", {
|
integration("Header as Staff", {
|
||||||
setup: function() {
|
user: { username: 'test',
|
||||||
var originalUser = Discourse.User.current();
|
staff: true,
|
||||||
sandbox.stub(Discourse.User, "current").returns(originalUser);
|
site_flagged_posts_count: 1 }
|
||||||
Discourse.User.current.returns(Ember.Object.create({
|
|
||||||
username: 'test',
|
|
||||||
staff: true,
|
|
||||||
site_flagged_posts_count: 1
|
|
||||||
}));
|
|
||||||
},
|
|
||||||
|
|
||||||
teardown: function() {
|
|
||||||
Discourse.User.current.restore();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("header", function() {
|
test("header", function() {
|
||||||
|
@ -24,6 +24,7 @@ test("uploading one file", function() {
|
|||||||
|
|
||||||
test("new user cannot upload images", function() {
|
test("new user cannot upload images", function() {
|
||||||
Discourse.SiteSettings.newuser_max_images = 0;
|
Discourse.SiteSettings.newuser_max_images = 0;
|
||||||
|
Discourse.User.resetCurrent(Discourse.User.create());
|
||||||
sandbox.stub(bootbox, "alert");
|
sandbox.stub(bootbox, "alert");
|
||||||
|
|
||||||
not(validUpload([{name: "image.png"}]), 'the upload is not valid');
|
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() {
|
test("new user cannot upload attachments", function() {
|
||||||
Discourse.SiteSettings.newuser_max_attachments = 0;
|
Discourse.SiteSettings.newuser_max_attachments = 0;
|
||||||
sandbox.stub(bootbox, "alert");
|
sandbox.stub(bootbox, "alert");
|
||||||
|
Discourse.User.resetCurrent(Discourse.User.create());
|
||||||
|
|
||||||
not(validUpload([{name: "roman.txt"}]));
|
not(validUpload([{name: "roman.txt"}]));
|
||||||
ok(bootbox.alert.calledWith(I18n.t('post.errors.attachment_upload_not_allowed_for_new_user')));
|
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() {
|
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 };
|
var image = { name: "image.png", size: 10 * 1024 };
|
||||||
Discourse.SiteSettings.max_image_size_kb = 5;
|
Discourse.SiteSettings.max_image_size_kb = 5;
|
||||||
Discourse.User.currentProp("trust_level", 1);
|
Discourse.User.currentProp("trust_level", 1);
|
||||||
@ -69,6 +72,7 @@ var dummyBlob = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
test("allows valid uploads to go through", function() {
|
test("allows valid uploads to go through", function() {
|
||||||
|
Discourse.User.resetCurrent(Discourse.User.create());
|
||||||
Discourse.User.currentProp("trust_level", 1);
|
Discourse.User.currentProp("trust_level", 1);
|
||||||
Discourse.SiteSettings.max_image_size_kb = 15;
|
Discourse.SiteSettings.max_image_size_kb = 15;
|
||||||
sandbox.stub(bootbox, "alert");
|
sandbox.stub(bootbox, "alert");
|
||||||
|
@ -98,6 +98,8 @@ QUnit.testStart(function(ctx) {
|
|||||||
Discourse.SiteSettings = jQuery.extend(true, {}, Discourse.SiteSettingsOriginal);
|
Discourse.SiteSettings = jQuery.extend(true, {}, Discourse.SiteSettingsOriginal);
|
||||||
Discourse.BaseUri = "/";
|
Discourse.BaseUri = "/";
|
||||||
Discourse.BaseUrl = "";
|
Discourse.BaseUrl = "";
|
||||||
|
Discourse.User.resetCurrent();
|
||||||
|
PreloadStore.reset();
|
||||||
|
|
||||||
window.sandbox = sinon.sandbox.create();
|
window.sandbox = sinon.sandbox.create();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user