2013-07-04 15:19:59 -05:00
|
|
|
require 'open-uri'
|
|
|
|
|
|
|
|
desc 'Creates the integration fixtures. Requires a development instance running.'
|
|
|
|
task 'integration:create_fixtures' => :environment do
|
|
|
|
|
|
|
|
fixtures = {
|
2015-01-06 17:56:03 -06:00
|
|
|
discovery: ["/latest.json", "/categories.json", "/c/bug/l/latest.json"],
|
2013-07-04 15:19:59 -05:00
|
|
|
topic: ["/t/280.json"],
|
2017-03-28 13:27:54 -05:00
|
|
|
user: ["/u/eviltrout.json",
|
2014-08-01 16:26:43 -05:00
|
|
|
"/user_actions.json",
|
2014-08-01 16:29:20 -05:00
|
|
|
"/topics/created-by/eviltrout.json"],
|
2014-04-29 14:29:01 -05:00
|
|
|
static: ["/faq", '/tos', '/privacy'],
|
|
|
|
unknown: ['/404-body']
|
2013-07-04 15:19:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fixtures.each do |type, urls|
|
|
|
|
|
|
|
|
filename = "#{Rails.root}/test/javascripts/fixtures/#{type}_fixtures.js"
|
|
|
|
|
2014-08-01 16:26:43 -05:00
|
|
|
content = "/*jshint maxlen:10000000 */\nexport default {\n"
|
2013-07-04 15:19:59 -05:00
|
|
|
urls.each do |url|
|
|
|
|
|
|
|
|
http_result = fake_xhr("http://localhost:3000#{url}")
|
|
|
|
|
|
|
|
# If the result is not JSON, convert it to JSON
|
|
|
|
begin
|
|
|
|
parsed = ::JSON.parse(http_result)
|
|
|
|
rescue
|
|
|
|
http_result = http_result.to_json
|
|
|
|
end
|
2014-08-01 16:26:43 -05:00
|
|
|
content << "\"#{url}\": #{http_result},\n"
|
2013-07-04 15:19:59 -05:00
|
|
|
|
|
|
|
end
|
2014-08-01 16:26:43 -05:00
|
|
|
content << "};\n"
|
2013-07-04 15:19:59 -05:00
|
|
|
|
|
|
|
File.write(filename, content)
|
|
|
|
end
|
2014-01-14 11:48:57 -06:00
|
|
|
|
2013-07-04 15:19:59 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def fake_xhr(url)
|
|
|
|
uri = URI(url)
|
|
|
|
|
|
|
|
result = nil
|
|
|
|
Net::HTTP.start(uri.host, uri.port) do |http|
|
|
|
|
request = Net::HTTP::Get.new uri
|
|
|
|
request.add_field "X-Requested-With", "XMLHttpRequest"
|
|
|
|
response = http.request(request)
|
|
|
|
result = response.body.force_encoding("UTF-8")
|
|
|
|
end
|
|
|
|
|
|
|
|
result
|
|
|
|
|
2014-01-14 11:48:57 -06:00
|
|
|
end
|