summaryrefslogtreecommitdiff
path: root/spec/tasks/gitlab/users_rake_spec.rb
blob: 972670e7f913a6580c290b0be57e2fe6fb529756 (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
require 'spec_helper'
require 'rake'

describe 'gitlab:users namespace rake task' do
  let(:enable_registry) { true }

  before :all do
    Rake.application.rake_require 'tasks/gitlab/helpers'
    Rake.application.rake_require 'tasks/gitlab/users'

    # empty task as env is already loaded
    Rake::Task.define_task :environment
  end

  def run_rake_task(task_name)
    Rake::Task[task_name].reenable
    Rake.application.invoke_task task_name
  end

  describe 'clear_all_authentication_tokens' do
    before do
      # avoid writing task output to spec progress
      allow($stdout).to receive :write
    end

    context 'gitlab version' do
      it 'clears the authentication token for all users' do
        create_list(:user, 2)

        expect(User.pluck(:authentication_token)).to all(be_present)

        run_rake_task('gitlab:users:clear_all_authentication_tokens')

        expect(User.pluck(:authentication_token)).to all(be_nil)
      end
    end
  end
end