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

current_organization_spec.rb « organization « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ffd37ac4de9eea71cf72f8fc8e6d6f40963f0745 (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Organization::CurrentOrganization, feature_category: :organization do
  include described_class

  after do
    # Wipe thread variables between specs.
    Thread.current[described_class::CURRENT_ORGANIZATION_THREAD_VAR] = nil
  end

  describe '.current_organization' do
    subject { current_organization }

    context 'when current organization is set' do
      let(:some_organization) { create(:organization) }

      before do
        self.current_organization = some_organization
      end

      it { is_expected.to eq some_organization }
    end

    context 'when organization is not set' do
      it { is_expected.to be_nil }
    end
  end

  describe '.current_organization=' do
    subject(:setter) { self.current_organization = some_organization }

    let(:some_organization) { create(:organization) }

    it 'sets current organization' do
      expect { setter }.to change { current_organization }.from(nil).to(some_organization)
    end
  end

  describe '.with_current_organization' do
    let(:some_organization) { create(:organization) }

    it 'sets current organization within block' do
      expect(current_organization).to be_nil
      with_current_organization(some_organization) do
        expect(current_organization).to eq some_organization
      end
      expect(current_organization).to be_nil
    end

    context 'when an error is raised' do
      it 'resets current organization' do
        begin
          with_current_organization(some_organization) do
            raise StandardError
          end
        rescue StandardError
          nil
        end

        expect(current_organization).to be_nil
      end
    end
  end
end