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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe OnboardingProgress do
let(:namespace) { create(:namespace) }
let(:action) { :subscription_created }
describe 'associations' do
it { is_expected.to belong_to(:namespace).required }
end
describe 'validations' do
describe 'namespace_is_root_namespace' do
subject(:onboarding_progress) { build(:onboarding_progress, namespace: namespace)}
context 'when associated namespace is root' do
it { is_expected.to be_valid }
end
context 'when associated namespace is not root' do
let(:namespace) { build(:group, :nested) }
it 'is invalid' do
expect(onboarding_progress).to be_invalid
expect(onboarding_progress.errors[:namespace]).to include('must be a root namespace')
end
end
end
end
describe '.onboard' do
subject(:onboard) { described_class.onboard(namespace) }
it 'adds a record for the namespace' do
expect { onboard }.to change(described_class, :count).from(0).to(1)
end
context 'when not given a namespace' do
let(:namespace) { nil }
it 'does not add a record for the namespace' do
expect { onboard }.not_to change(described_class, :count).from(0)
end
end
context 'when not given a root namespace' do
let(:namespace) { create(:namespace, parent: build(:namespace)) }
it 'does not add a record for the namespace' do
expect { onboard }.not_to change(described_class, :count).from(0)
end
end
end
describe '.register' do
subject(:register_action) { described_class.register(namespace, action) }
context 'when the namespace was onboarded' do
before do
described_class.onboard(namespace)
end
it 'registers the action for the namespace' do
expect { register_action }.to change { described_class.completed?(namespace, action) }.from(false).to(true)
end
context 'when the action does not exist' do
let(:action) { :foo }
it 'does not register the action for the namespace' do
expect { register_action }.not_to change { described_class.completed?(namespace, action) }.from(nil)
end
end
end
context 'when the namespace was not onboarded' do
it 'does not register the action for the namespace' do
expect { register_action }.not_to change { described_class.completed?(namespace, action) }.from(false)
end
end
end
describe '.completed?' do
subject { described_class.completed?(namespace, action) }
context 'when the namespace has not yet been onboarded' do
it { is_expected.to eq(false) }
end
context 'when the namespace has been onboarded but not registered the action yet' do
before do
described_class.onboard(namespace)
end
it { is_expected.to eq(false) }
context 'when the action has been registered' do
before do
described_class.register(namespace, action)
end
it { is_expected.to eq(true) }
end
end
end
end
|