TESTS: Remove `URL_FIXTURES` constant for pretender
This commit is contained in:
parent
6eb478f5fa
commit
3c66e48573
|
@ -9,9 +9,6 @@
|
|||
window.Discourse = Ember.Application.createWithMixins(Discourse.Ajax, {
|
||||
rootElement: '#main',
|
||||
|
||||
// Helps with integration tests
|
||||
URL_FIXTURES: {},
|
||||
|
||||
getURL: function(url) {
|
||||
// If it's a non relative URL, return it.
|
||||
if (url.indexOf('http') === 0) return url;
|
||||
|
|
|
@ -40,12 +40,6 @@ Discourse.Ajax = Em.Mixin.create({
|
|||
Ember.Logger.error("DEPRECATION: Discourse.ajax should use promises, received 'error' callback");
|
||||
}
|
||||
|
||||
// If we have URL_FIXTURES, load from there instead (testing)
|
||||
var fixture = Discourse.URL_FIXTURES && Discourse.URL_FIXTURES[url];
|
||||
if (fixture) {
|
||||
return Ember.RSVP.resolve(fixture);
|
||||
}
|
||||
|
||||
var performAjax = function(promise) {
|
||||
var oldSuccess = args.success;
|
||||
args.success = function(xhr) {
|
||||
|
|
|
@ -7,13 +7,8 @@ task 'integration:create_fixtures' => :environment do
|
|||
discovery: ["/latest.json", "/categories.json", "/category/bug/l/latest.json"],
|
||||
topic: ["/t/280.json"],
|
||||
user: ["/users/eviltrout.json",
|
||||
"/user_actions.json?offset=0&username=eviltrout",
|
||||
"/topics/created-by/eviltrout.json",
|
||||
"/user_actions.json?offset=0&username=eviltrout&filter=5",
|
||||
"/user_actions.json?offset=0&username=eviltrout&filter=6,7,9",
|
||||
"/user_actions.json?offset=0&username=eviltrout&filter=1",
|
||||
"/user_actions.json?offset=0&username=eviltrout&filter=2",
|
||||
"/user_actions.json?offset=0&username=eviltrout&filter=11"],
|
||||
"/user_actions.json",
|
||||
"/topics/created-by/eviltrout.json"]
|
||||
static: ["/faq", '/tos', '/privacy'],
|
||||
unknown: ['/404-body']
|
||||
}
|
||||
|
@ -22,7 +17,7 @@ task 'integration:create_fixtures' => :environment do
|
|||
|
||||
filename = "#{Rails.root}/test/javascripts/fixtures/#{type}_fixtures.js"
|
||||
|
||||
content = "/*jshint maxlen:10000000 */\n"
|
||||
content = "/*jshint maxlen:10000000 */\nexport default {\n"
|
||||
urls.each do |url|
|
||||
|
||||
http_result = fake_xhr("http://localhost:3000#{url}")
|
||||
|
@ -33,9 +28,10 @@ task 'integration:create_fixtures' => :environment do
|
|||
rescue
|
||||
http_result = http_result.to_json
|
||||
end
|
||||
content << "Discourse.URL_FIXTURES[\"#{url}\"] = #{http_result};\n"
|
||||
content << "\"#{url}\": #{http_result},\n"
|
||||
|
||||
end
|
||||
content << "};\n"
|
||||
|
||||
File.write(filename, content)
|
||||
end
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1,2 +0,0 @@
|
|||
/*jshint maxlen:10000000 */
|
||||
Discourse.URL_FIXTURES["/draft.json"] = {};
|
|
@ -1,2 +0,0 @@
|
|||
/*jshint maxlen:10000000 */
|
||||
Discourse.URL_FIXTURES["/notifications"] = [ { notification_type: 2, read: true, post_number: 2, topic_id: 1234, slug: "a-slug", data: { topic_title: "some title", display_username: "velesin" } } ];
|
|
@ -0,0 +1,2 @@
|
|||
/*jshint maxlen:10000000 */
|
||||
export default {"/notifications": [ { notification_type: 2, read: true, post_number: 2, topic_id: 1234, slug: "a-slug", data: { topic_title: "some title", display_username: "velesin" } } ] };
|
|
@ -1,2 +0,0 @@
|
|||
/*jshint maxlen:10000000 */
|
||||
Discourse.URL_FIXTURES["/search"] = [ { type: "topic", more: true, results: [ { url: "some-url" } ] } ];
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1,2 +0,0 @@
|
|||
/*jshint maxlen:10000000 */
|
||||
Discourse.URL_FIXTURES["/404-body"] = "\n\u003Ch1 class=\"page-not-found\"\u003EThe page you requested doesn\u0026#39;t exist or is private.\u003C/h1\u003E\n\n\u003Cdiv class=\"row\"\u003E\n \u003Cdiv class=\"span8\"\u003E\n \u003Ch2 class=\"popular-topics-title\"\u003EPopular topics\u003C/h2\u003E\n \u003Ca href=\"/t/is-it-better-for-discourse-to-use-javascript-or-coffeescript/3153\"\u003EIs it better for Discourse to use JavaScript or CoffeeScript?\u003C/a\u003E\u003Cbr/\u003E\n \u003Ca href=\"/t/tuning-ruby-and-rails-for-discourse/4126\"\u003ETuning Ruby and Rails for Discourse\u003C/a\u003E\u003Cbr/\u003E\n \u003Ca href=\"/t/welcome-to-meta-discourse-org/1\"\u003EWelcome to meta.discourse.org\u003C/a\u003E\u003Cbr/\u003E\n \u003Ca href=\"/t/what-is-wrong-with-phpbb/3763\"\u003EWhat is wrong with PHPBB?\u003C/a\u003E\u003Cbr/\u003E\n \u003Ca href=\"/t/what-is-a-onebox/4546\"\u003EWhat is a onebox?\u003C/a\u003E\u003Cbr/\u003E\n \u003Ca href=\"/t/so-you-want-to-help-out-with-discourse/3823\"\u003ESo, you want to help out with Discourse\u003C/a\u003E\u003Cbr/\u003E\n \u003Ca href=\"/t/please-visit-our-discourse-forum-directory/3102\"\u003EPlease visit our Discourse Forum! (Directory)\u003C/a\u003E\u003Cbr/\u003E\n \u003Ca href=\"/t/why-is-discourse-so-slow-on-android/8823\"\u003EWhy is Discourse so slow on Android?\u003C/a\u003E\u003Cbr/\u003E\n \u003Ca href=\"/t/what-i-love-about-wordpress-plugins/5697\"\u003EWhat I love about WordPress plugins\u003C/a\u003E\u003Cbr/\u003E\n \u003Ca href=\"/t/anyone-got-this-running-on-heroku-yet/625\"\u003EAnyone got this running on Heroku yet?\u003C/a\u003E\u003Cbr/\u003E\n \u003Cbr/\u003E\n \u003Ca href=\"/latest\" class=\"btn\"\u003ESee More\u0026hellip;\u003C/a\u003E\n \u003C/div\u003E\n \u003Cdiv class=\"span8\"\u003E\n \u003Ch2 class=\"recent-topics-title\"\u003ERecent topics\u003C/h2\u003E\n \u003Ca href=\"/t/making-external-api-call-after-logging-in/15160\"\u003EMaking external API call after logging in\u003C/a\u003E\u003Cbr/\u003E\n \u003Ca href=\"/t/upload-maximum-value/15159\"\u003EUpload maximum value\u003C/a\u003E\u003Cbr/\u003E\n \u003Ca href=\"/t/people-with-experience-bitnami-vs-discoursehosting-com-s/15156\"\u003EPeople with experience, Bitnami vs DiscourseHosting.com? :S\u003C/a\u003E\u003Cbr/\u003E\n \u003Ca href=\"/t/support-docker-v0-9-1-and-up/15154\"\u003ESupport Docker v0.9.1 and up\u003C/a\u003E\u003Cbr/\u003E\n \u003Ca href=\"/t/how-to-rearrange-participants-list/15152\"\u003EHow to rearrange participants list?\u003C/a\u003E\u003Cbr/\u003E\n \u003Ca href=\"/t/how-to-use-category-color-as-background-color/15151\"\u003EHow to use category color as background color?\u003C/a\u003E\u003Cbr/\u003E\n \u003Ca href=\"/t/roadmap-for-styling-email-digest/15150\"\u003ERoadmap for styling email digest\u003C/a\u003E\u003Cbr/\u003E\n \u003Ca href=\"/t/undefined-on-latest-link/15148\"\u003EUndefined on latest link\u003C/a\u003E\u003Cbr/\u003E\n \u003Ca href=\"/t/performance-through-the-roof-since-docker-izing/15147\"\u003EPerformance through the roof since docker-izing\u003C/a\u003E\u003Cbr/\u003E\n \u003Ca href=\"/t/a-image-slider-possible/15139\"\u003EA Image Slider? Possible?\u003C/a\u003E\u003Cbr/\u003E\n \u003Cbr/\u003E\n \u003Ca href=\"/latest\" class=\"btn\"\u003ESee More\u0026hellip;\u003C/a\u003E\n \u003C/div\u003E\n\u003C/div\u003E\n\n";
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -17,6 +17,35 @@ function response(code, obj) {
|
|||
|
||||
export default function() {
|
||||
var server = new Pretender(function() {
|
||||
|
||||
// Load any fixtures automatically
|
||||
var self = this;
|
||||
Ember.keys(require._eak_seen).forEach(function(entry) {
|
||||
if (/^fixtures/.test(entry)) {
|
||||
var fixture = require(entry, null, null, true);
|
||||
if (fixture && fixture.default) {
|
||||
var obj = fixture.default;
|
||||
Ember.keys(obj).forEach(function(url) {
|
||||
self.get(url, function() {
|
||||
return response(obj[url]);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
this.get("/404-body", function() {
|
||||
return [200, {"Content-Type": "text/html"}, "<div class='page-not-found'>not found</div>"];
|
||||
});
|
||||
|
||||
this.get("/search", function() {
|
||||
return response([ { type: "topic", more: true, results: [ { url: "some-url" } ] } ]);
|
||||
});
|
||||
|
||||
this.get('/draft.json', function() {
|
||||
return response({});
|
||||
});
|
||||
|
||||
this.post('/session', function(request) {
|
||||
var data = parsePostData(request.requestBody);
|
||||
|
||||
|
@ -55,6 +84,7 @@ export default function() {
|
|||
if (body && typeof body === "object") {
|
||||
return JSON.stringify(body);
|
||||
}
|
||||
return body;
|
||||
};
|
||||
|
||||
server.unhandledRequest = function(verb, path) {
|
||||
|
|
Loading…
Reference in New Issue