diff options
author | Stan Hu <stanhu@gmail.com> | 2018-03-12 18:00:50 +0300 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2018-03-13 18:46:19 +0300 |
commit | da15e7329affe3d7f4169ce4b558d2066434eb8f (patch) | |
tree | 66a4e25f979145b52f396cfd199daf585b951459 /spec/lib | |
parent | 17823b144ac745395286825272d0c3b4e4e52f50 (diff) |
Merge branch 'tc-api-fix-expose_url' into 'master'
Respect the protocol in `expose_url`
Closes gitlab-ee#5217
See merge request gitlab-org/gitlab-ce!17681
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/api/helpers/related_resources_helpers_spec.rb | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/spec/lib/api/helpers/related_resources_helpers_spec.rb b/spec/lib/api/helpers/related_resources_helpers_spec.rb new file mode 100644 index 00000000000..b918301f1cb --- /dev/null +++ b/spec/lib/api/helpers/related_resources_helpers_spec.rb @@ -0,0 +1,41 @@ +require 'spec_helper' + +describe API::Helpers::RelatedResourcesHelpers do + subject(:helpers) do + Class.new.include(described_class).new + end + + describe '#expose_url' do + let(:path) { '/api/v4/awesome_endpoint' } + subject(:url) { helpers.expose_url(path) } + + def stub_default_url_options(protocol: 'http', host: 'example.com', port: nil) + expect(Gitlab::Application.routes).to receive(:default_url_options) + .and_return(protocol: protocol, host: host, port: port) + end + + it 'respects the protocol if it is HTTP' do + stub_default_url_options(protocol: 'http') + + is_expected.to start_with('http://') + end + + it 'respects the protocol if it is HTTPS' do + stub_default_url_options(protocol: 'https') + + is_expected.to start_with('https://') + end + + it 'accepts port to be nil' do + stub_default_url_options(port: nil) + + is_expected.to start_with('http://example.com/') + end + + it 'includes port if provided' do + stub_default_url_options(port: 8080) + + is_expected.to start_with('http://example.com:8080/') + end + end +end |