summaryrefslogtreecommitdiff
path: root/spec/controllers/concerns/import_url_params_spec.rb
blob: fc5dfb5263f7ad84c44e2bf901261cc70bfade24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# frozen_string_literal: true

require 'spec_helper'

describe ImportUrlParams do
  let(:import_url_params) do
    controller = OpenStruct.new(params: params).extend(described_class)
    controller.import_url_params
  end

  context 'url and password separately provided' do
    let(:params) do
      ActionController::Parameters.new(project: {
        import_url: 'https://url.com',
        import_url_user: 'user', import_url_password: 'password'
      })
    end

    describe '#import_url_params' do
      it 'returns hash with import_url' do
        expect(import_url_params).to eq(
          import_url: "https://user:password@url.com"
        )
      end
    end
  end

  context 'url with provided empty credentials' do
    let(:params) do
      ActionController::Parameters.new(project: {
        import_url: 'https://user:password@url.com',
        import_url_user: '', import_url_password: ''
      })
    end

    describe '#import_url_params' do
      it 'does not change the url' do
        expect(import_url_params).to eq(
          import_url: "https://user:password@url.com"
        )
      end
    end
  end
end