Commit 918bc207 authored by winniehell's avatar winniehell

Use Rails test host name for frontend fixtures

parent d100f843
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
//= require turbolinks //= require turbolinks
describe('Build', () => { describe('Build', () => {
const BUILD_URL = `${gl.TEST_HOST}/namespace1/project1/builds/1`;
// see spec/factories/ci/builds.rb // see spec/factories/ci/builds.rb
const BUILD_TRACE = 'BUILD TRACE'; const BUILD_TRACE = 'BUILD TRACE';
// see lib/ci/ansi2html.rb // see lib/ci/ansi2html.rb
...@@ -39,8 +40,8 @@ describe('Build', () => { ...@@ -39,8 +40,8 @@ describe('Build', () => {
}); });
it('copies build options', function () { it('copies build options', function () {
expect(this.build.pageUrl).toBe('http://test.host/namespace1/project1/builds/1'); expect(this.build.pageUrl).toBe(BUILD_URL);
expect(this.build.buildUrl).toBe('http://test.host/namespace1/project1/builds/1.json'); expect(this.build.buildUrl).toBe(`${BUILD_URL}.json`);
expect(this.build.buildStatus).toBe('success'); expect(this.build.buildStatus).toBe('success');
expect(this.build.buildStage).toBe('test'); expect(this.build.buildStage).toBe('test');
expect(this.build.state).toBe(INITIAL_BUILD_TRACE_STATE); expect(this.build.state).toBe(INITIAL_BUILD_TRACE_STATE);
...@@ -79,7 +80,7 @@ describe('Build', () => { ...@@ -79,7 +80,7 @@ describe('Build', () => {
it('displays the initial build trace', function () { it('displays the initial build trace', function () {
expect($.ajax.calls.count()).toBe(1); expect($.ajax.calls.count()).toBe(1);
const [{ url, dataType, success, context }] = $.ajax.calls.argsFor(0); const [{ url, dataType, success, context }] = $.ajax.calls.argsFor(0);
expect(url).toBe('http://test.host/namespace1/project1/builds/1.json'); expect(url).toBe(`${BUILD_URL}.json`);
expect(dataType).toBe('json'); expect(dataType).toBe('json');
expect(success).toEqual(jasmine.any(Function)); expect(success).toEqual(jasmine.any(Function));
...@@ -100,8 +101,7 @@ describe('Build', () => { ...@@ -100,8 +101,7 @@ describe('Build', () => {
beforeEach(function () { beforeEach(function () {
$('.js-build-options').data('buildStatus', 'running'); $('.js-build-options').data('buildStatus', 'running');
this.build = new Build(); this.build = new Build();
spyOn(this.build, 'location') spyOn(this.build, 'location').and.returnValue(BUILD_URL);
.and.returnValue('http://test.host/namespace1/project1/builds/1');
}); });
it('updates the build trace on an interval', function () { it('updates the build trace on an interval', function () {
...@@ -110,7 +110,7 @@ describe('Build', () => { ...@@ -110,7 +110,7 @@ describe('Build', () => {
expect($.ajax.calls.count()).toBe(2); expect($.ajax.calls.count()).toBe(2);
let [{ url, dataType, success, context }] = $.ajax.calls.argsFor(1); let [{ url, dataType, success, context }] = $.ajax.calls.argsFor(1);
expect(url).toBe( expect(url).toBe(
`http://test.host/namespace1/project1/builds/1/trace.json?state=${encodeURIComponent(INITIAL_BUILD_TRACE_STATE)}` `${BUILD_URL}/trace.json?state=${encodeURIComponent(INITIAL_BUILD_TRACE_STATE)}`
); );
expect(dataType).toBe('json'); expect(dataType).toBe('json');
expect(success).toEqual(jasmine.any(Function)); expect(success).toEqual(jasmine.any(Function));
...@@ -129,9 +129,7 @@ describe('Build', () => { ...@@ -129,9 +129,7 @@ describe('Build', () => {
expect($.ajax.calls.count()).toBe(3); expect($.ajax.calls.count()).toBe(3);
[{ url, dataType, success, context }] = $.ajax.calls.argsFor(2); [{ url, dataType, success, context }] = $.ajax.calls.argsFor(2);
expect(url).toBe( expect(url).toBe(`${BUILD_URL}/trace.json?state=newstate`);
'http://test.host/namespace1/project1/builds/1/trace.json?state=newstate'
);
expect(dataType).toBe('json'); expect(dataType).toBe('json');
expect(success).toEqual(jasmine.any(Function)); expect(success).toEqual(jasmine.any(Function));
...@@ -180,9 +178,7 @@ describe('Build', () => { ...@@ -180,9 +178,7 @@ describe('Build', () => {
append: true, append: true,
}); });
expect(Turbolinks.visit).toHaveBeenCalledWith( expect(Turbolinks.visit).toHaveBeenCalledWith(BUILD_URL);
'http://test.host/namespace1/project1/builds/1'
);
}); });
}); });
}); });
......
...@@ -74,7 +74,7 @@ ...@@ -74,7 +74,7 @@
it('submits an ajax request on tasklist:changed', function() { it('submits an ajax request on tasklist:changed', function() {
spyOn(jQuery, 'ajax').and.callFake(function(req) { spyOn(jQuery, 'ajax').and.callFake(function(req) {
expect(req.type).toBe('PATCH'); expect(req.type).toBe('PATCH');
expect(req.url).toBe('https://fixture.invalid/namespace3/project3/issues/1.json'); expect(req.url).toBe(gl.TEST_HOST + '/namespace3/project3/issues/1.json');
expect(req.data.issue.description).not.toBe(null); expect(req.data.issue.description).not.toBe(null);
}); });
......
...@@ -41,3 +41,8 @@ ...@@ -41,3 +41,8 @@
}).call(this); }).call(this);
// defined in ActionDispatch::TestRequest
// see https://github.com/rails/rails/blob/v4.2.7.1/actionpack/lib/action_dispatch/testing/test_request.rb#L7
window.gl = window.gl || {};
gl.TEST_HOST = 'http://test.host';
require 'action_dispatch/testing/test_request'
require 'fileutils' require 'fileutils'
require 'gitlab/popen' require 'gitlab/popen'
...@@ -36,7 +37,8 @@ module JavaScriptFixturesHelpers ...@@ -36,7 +37,8 @@ module JavaScriptFixturesHelpers
fixture = doc.to_html fixture = doc.to_html
# replace relative links # replace relative links
fixture.gsub!(%r{="/}, '="https://fixture.invalid/') test_host = ActionDispatch::TestRequest::DEFAULT_ENV['HTTP_HOST']
fixture.gsub!(%r{="/}, "=\"http://#{test_host}/")
end end
FileUtils.mkdir_p(File.dirname(fixture_file_name)) FileUtils.mkdir_p(File.dirname(fixture_file_name))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment