Commit 7e3a1eb9 authored by Alex Buijs's avatar Alex Buijs

Remove NamespaceOnboardingAction model

Because it is no longer needed
parent db82a385
......@@ -28,7 +28,6 @@ class Namespace < ApplicationRecord
has_many :runner_namespaces, inverse_of: :namespace, class_name: 'Ci::RunnerNamespace'
has_many :runners, through: :runner_namespaces, source: :runner, class_name: 'Ci::Runner'
has_many :namespace_onboarding_actions
has_one :onboarding_progress
# This should _not_ be `inverse_of: :namespace`, because that would also set
......
# frozen_string_literal: true
class NamespaceOnboardingAction < ApplicationRecord
belongs_to :namespace, optional: false
validates :action, presence: true
ACTIONS = {
subscription_created: 1,
git_write: 2,
merge_request_created: 3,
git_read: 4,
pipeline_created: 5,
user_added: 6
}.freeze
# The monitoring window prevents the recording of a namespace_onboarding_action if a namespace is created before this
# time span. We are not interested in older namspaces, because the purpose of this table is to monitor and act on the
# progress of newly created namespaces or namespaces that already have at least one recorded action.
MONITORING_WINDOW = 90.days
enum action: ACTIONS
class << self
def completed?(namespace, action)
where(namespace: namespace, action: action).exists?
end
def create_action(namespace, action)
return unless namespace.root?
return if namespace.created_at < MONITORING_WINDOW.ago && !namespace.namespace_onboarding_actions.exists?
NamespaceOnboardingAction.safe_find_or_create_by(namespace: namespace, action: action)
end
end
end
# frozen_string_literal: true
FactoryBot.define do
factory :namespace_onboarding_action do
namespace
action { :subscription_created }
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe NamespaceOnboardingAction do
let(:namespace) { create(:namespace) }
describe 'associations' do
it { is_expected.to belong_to(:namespace).required }
end
describe 'validations' do
it { is_expected.to validate_presence_of(:action) }
end
describe '.completed?' do
let(:action) { :subscription_created }
subject { described_class.completed?(namespace, action) }
context 'action created for the namespace' do
before do
create(:namespace_onboarding_action, namespace: namespace, action: action)
end
it { is_expected.to eq(true) }
end
context 'action created for another namespace' do
before do
create(:namespace_onboarding_action, namespace: build(:namespace), action: action)
end
it { is_expected.to eq(false) }
end
end
describe '.create_action' do
let(:action) { :subscription_created }
subject(:create_action) { described_class.create_action(namespace, action) }
it 'creates the action for the namespace just once' do
expect { create_action }.to change { count_namespace_actions }.by(1)
expect { create_action }.to change { count_namespace_actions }.by(0)
end
context 'when the namespace is created outside the monitoring window' do
let(:namespace) { create(:namespace, created_at: (NamespaceOnboardingAction::MONITORING_WINDOW + 1.day).ago) }
it 'does not create an action for the namespace' do
expect { create_action }.not_to change { count_namespace_actions }
end
context 'when an action has already been recorded for the namespace' do
before do
described_class.create!(namespace: namespace, action: :git_write)
end
it 'creates an action for the namespace' do
expect { create_action }.to change { count_namespace_actions }.by(1)
end
end
end
context 'when the namespace is not a root' do
let(:namespace) { create(:namespace, parent: build(:namespace)) }
it 'does not create an action for the namespace' do
expect { create_action }.not_to change { count_namespace_actions }
end
end
def count_namespace_actions
described_class.where(namespace: namespace, action: action).count
end
end
end
......@@ -19,7 +19,6 @@ RSpec.describe Namespace do
it { is_expected.to have_one :aggregation_schedule }
it { is_expected.to have_one :namespace_settings }
it { is_expected.to have_many :custom_emoji }
it { is_expected.to have_many :namespace_onboarding_actions }
it { is_expected.to have_one :package_setting_relation }
it { is_expected.to have_one :onboarding_progress }
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment