Welcome to mirror list, hosted at ThFree Co, Russian Federation.

20200728182311_add_o_auth_paths_to_protected_paths_spec.rb « migrations « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5c65d45c6e011c14f8c16df25b7bbe207e961619 (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
45
46
47
48
49
50
51
52
# frozen_string_literal: true

require 'spec_helper'
require_migration!('add_o_auth_paths_to_protected_paths')

RSpec.describe AddOAuthPathsToProtectedPaths do
  subject(:migration) { described_class.new }

  let(:application_settings) { table(:application_settings) }
  let(:new_paths) do
    [
      '/oauth/authorize',
      '/oauth/token'
    ]
  end

  it 'appends new OAuth paths' do
    application_settings.create!

    protected_paths_before = application_settings.first.protected_paths
    protected_paths_after = protected_paths_before + new_paths

    expect { migrate! }.to change { application_settings.first.protected_paths }.from(protected_paths_before).to(protected_paths_after)
  end

  it 'new default includes new paths' do
    settings_before = application_settings.create!

    expect(settings_before.protected_paths).not_to include(*new_paths)

    migrate!

    application_settings.reset_column_information
    settings_after = application_settings.create!

    expect(settings_after.protected_paths).to include(*new_paths)
  end

  it 'does not change the value when the new paths are already included' do
    application_settings.create!(protected_paths: %w(/users/sign_in /users/password) + new_paths)

    expect { migrate! }.not_to change { application_settings.first.protected_paths }
  end

  it 'adds one value when the other is already present' do
    application_settings.create!(protected_paths: %W(/users/sign_in /users/password #{new_paths.first}))

    migrate!

    expect(application_settings.first.protected_paths).to include(new_paths.second)
  end
end