diff options
author | Robert Speicher <rspeicher@gmail.com> | 2021-01-20 13:34:23 -0600 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2021-01-20 13:34:23 -0600 |
commit | 6438df3a1e0fb944485cebf07976160184697d72 (patch) | |
tree | 00b09bfd170e77ae9391b1a2f5a93ef6839f2597 /spec/models/onboarding_progress_spec.rb | |
parent | 42bcd54d971da7ef2854b896a7b34f4ef8601067 (diff) | |
download | gitlab-ce-6438df3a1e0fb944485cebf07976160184697d72.tar.gz |
Add latest changes from gitlab-org/gitlab@13-8-stable-eev13.8.0-rc42
Diffstat (limited to 'spec/models/onboarding_progress_spec.rb')
-rw-r--r-- | spec/models/onboarding_progress_spec.rb | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/spec/models/onboarding_progress_spec.rb b/spec/models/onboarding_progress_spec.rb new file mode 100644 index 00000000000..bd951846bb8 --- /dev/null +++ b/spec/models/onboarding_progress_spec.rb @@ -0,0 +1,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 |