Commit 95cf5004 authored by Gabriel Mazetto's avatar Gabriel Mazetto

Merge branch 'fix-elasticsearch-indexed-containers-specs' into 'master'

Refactor Elasticsearch Indexed Containers specs to support parent strategy

See merge request gitlab-org/gitlab!41764
parents 93a9fce9 e25aff9f
......@@ -18,8 +18,13 @@ RSpec.describe ElasticsearchIndexedNamespace do
end
it_behaves_like 'an elasticsearch indexed container' do
let_it_be(:namespace) { create(:namespace) }
let(:container) { :elasticsearch_indexed_namespace }
let(:attribute) { :namespace_id }
let(:container_attributes) { { namespace: namespace } }
let(:required_attribute) { :namespace_id }
let(:index_action) do
expect(ElasticNamespaceIndexerWorker).to receive(:perform_async).with(subject.namespace_id, :index)
end
......
......@@ -8,8 +8,13 @@ RSpec.describe ElasticsearchIndexedProject do
end
it_behaves_like 'an elasticsearch indexed container' do
let_it_be(:project) { create(:project) }
let(:container) { :elasticsearch_indexed_project }
let(:attribute) { :project_id }
let(:container_attributes) { { project: project } }
let(:required_attribute) { :project_id }
let(:index_action) do
expect(Elastic::ProcessBookkeepingService).to receive(:track!).with(subject.project)
end
......
......@@ -254,7 +254,9 @@ RSpec.describe GitlabSubscription do
describe 'callbacks' do
context 'after_commit :index_namespace' do
let(:gitlab_subscription) { build(:gitlab_subscription, plan) }
let_it_be(:namespace) { create(:namespace) }
let(:gitlab_subscription) { build(:gitlab_subscription, plan, namespace: namespace) }
let(:dev_env_or_com) { true }
let(:expiration_date) { Date.today + 10 }
let(:plan) { :bronze }
......@@ -271,7 +273,7 @@ RSpec.describe GitlabSubscription do
end
context 'when it is a trial' do
let(:gitlab_subscription) { build(:gitlab_subscription, :active_trial) }
let(:gitlab_subscription) { build(:gitlab_subscription, :active_trial, namespace: namespace) }
it 'indexes the namespace' do
expect(ElasticsearchIndexedNamespace).to receive(:safe_find_or_create_by!).with(namespace_id: gitlab_subscription.namespace_id)
......
......@@ -2,15 +2,15 @@
RSpec.shared_examples 'an elasticsearch indexed container' do
describe 'validations' do
subject { create container }
subject { create(container, container_attributes) }
it 'validates uniqueness of main attribute' do
is_expected.to validate_uniqueness_of(attribute)
is_expected.to validate_uniqueness_of(required_attribute)
end
end
describe 'callbacks' do
subject { build container }
subject { build(container, container_attributes) }
describe 'on save' do
it 'triggers index_project' do
......@@ -27,7 +27,7 @@ RSpec.shared_examples 'an elasticsearch indexed container' do
end
describe 'on destroy' do
subject { create container }
subject { create(container, container_attributes) }
it 'triggers delete_from_index' do
is_expected.to receive(:delete_from_index)
......
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