diff options
author | winniehell <git@winniehell.de> | 2016-11-19 22:59:32 +0100 |
---|---|---|
committer | winniehell <git@winniehell.de> | 2016-11-25 11:03:35 +0100 |
commit | 918bc207c680bed46e82bef996aea027ac72b38d (patch) | |
tree | 7071bcd73dc85df1318e3b61819aebe232aaf903 | |
parent | d100f843d784b64b1b73ad8090b855e2ffd985dd (diff) | |
download | gitlab-ce-918bc207c680bed46e82bef996aea027ac72b38d.tar.gz |
Use Rails test host name for frontend fixtures
-rw-r--r-- | spec/javascripts/build_spec.js.es6 | 20 | ||||
-rw-r--r-- | spec/javascripts/issue_spec.js | 2 | ||||
-rw-r--r-- | spec/javascripts/spec_helper.js | 5 | ||||
-rw-r--r-- | spec/support/javascript_fixtures_helpers.rb | 4 |
4 files changed, 17 insertions, 14 deletions
diff --git a/spec/javascripts/build_spec.js.es6 b/spec/javascripts/build_spec.js.es6 index c9a314d2a82..50411695925 100644 --- a/spec/javascripts/build_spec.js.es6 +++ b/spec/javascripts/build_spec.js.es6 @@ -10,6 +10,7 @@ //= require turbolinks describe('Build', () => { + const BUILD_URL = `${gl.TEST_HOST}/namespace1/project1/builds/1`; // see spec/factories/ci/builds.rb const BUILD_TRACE = 'BUILD TRACE'; // see lib/ci/ansi2html.rb @@ -39,8 +40,8 @@ describe('Build', () => { }); it('copies build options', function () { - expect(this.build.pageUrl).toBe('http://test.host/namespace1/project1/builds/1'); - expect(this.build.buildUrl).toBe('http://test.host/namespace1/project1/builds/1.json'); + expect(this.build.pageUrl).toBe(BUILD_URL); + expect(this.build.buildUrl).toBe(`${BUILD_URL}.json`); expect(this.build.buildStatus).toBe('success'); expect(this.build.buildStage).toBe('test'); expect(this.build.state).toBe(INITIAL_BUILD_TRACE_STATE); @@ -79,7 +80,7 @@ describe('Build', () => { it('displays the initial build trace', function () { expect($.ajax.calls.count()).toBe(1); 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(success).toEqual(jasmine.any(Function)); @@ -100,8 +101,7 @@ describe('Build', () => { beforeEach(function () { $('.js-build-options').data('buildStatus', 'running'); this.build = new Build(); - spyOn(this.build, 'location') - .and.returnValue('http://test.host/namespace1/project1/builds/1'); + spyOn(this.build, 'location').and.returnValue(BUILD_URL); }); it('updates the build trace on an interval', function () { @@ -110,7 +110,7 @@ describe('Build', () => { expect($.ajax.calls.count()).toBe(2); let [{ url, dataType, success, context }] = $.ajax.calls.argsFor(1); 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(success).toEqual(jasmine.any(Function)); @@ -129,9 +129,7 @@ describe('Build', () => { expect($.ajax.calls.count()).toBe(3); [{ url, dataType, success, context }] = $.ajax.calls.argsFor(2); - expect(url).toBe( - 'http://test.host/namespace1/project1/builds/1/trace.json?state=newstate' - ); + expect(url).toBe(`${BUILD_URL}/trace.json?state=newstate`); expect(dataType).toBe('json'); expect(success).toEqual(jasmine.any(Function)); @@ -180,9 +178,7 @@ describe('Build', () => { append: true, }); - expect(Turbolinks.visit).toHaveBeenCalledWith( - 'http://test.host/namespace1/project1/builds/1' - ); + expect(Turbolinks.visit).toHaveBeenCalledWith(BUILD_URL); }); }); }); diff --git a/spec/javascripts/issue_spec.js b/spec/javascripts/issue_spec.js index beef46122ab..ab92bdf01fd 100644 --- a/spec/javascripts/issue_spec.js +++ b/spec/javascripts/issue_spec.js @@ -74,7 +74,7 @@ it('submits an ajax request on tasklist:changed', function() { spyOn(jQuery, 'ajax').and.callFake(function(req) { 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); }); diff --git a/spec/javascripts/spec_helper.js b/spec/javascripts/spec_helper.js index 8a64de4dd43..831dfada952 100644 --- a/spec/javascripts/spec_helper.js +++ b/spec/javascripts/spec_helper.js @@ -41,3 +41,8 @@ }).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'; diff --git a/spec/support/javascript_fixtures_helpers.rb b/spec/support/javascript_fixtures_helpers.rb index adc3f48b434..7e066aa115d 100644 --- a/spec/support/javascript_fixtures_helpers.rb +++ b/spec/support/javascript_fixtures_helpers.rb @@ -1,3 +1,4 @@ +require 'action_dispatch/testing/test_request' require 'fileutils' require 'gitlab/popen' @@ -36,7 +37,8 @@ module JavaScriptFixturesHelpers fixture = doc.to_html # replace relative links - fixture.gsub!(%r{="/}, '="https://fixture.invalid/') + test_host = ActionDispatch::TestRequest::DEFAULT_ENV['HTTP_HOST'] + fixture.gsub!(%r{="/}, "=\"http://#{test_host}/") end FileUtils.mkdir_p(File.dirname(fixture_file_name)) |