Commit 258a3366 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'ab-use-factory-prof' into 'master'

Use factory prof to find un-needed db access in tests

See merge request gitlab-org/gitlab!26532
parents 598a7656 4cbbd2e2
...@@ -52,6 +52,13 @@ bundle exec guard ...@@ -52,6 +52,13 @@ bundle exec guard
When using spring and guard together, use `SPRING=1 bundle exec guard` instead to make use of spring. When using spring and guard together, use `SPRING=1 bundle exec guard` instead to make use of spring.
Use [Factory Doctor](https://test-prof.evilmartians.io/#/factory_doctor.md) to find cases on un-necessary database manipulation, which can cause slow tests.
```shell
# run test for path
FDOC=1 bin/rspec spec/[path]/[to]/[spec].rb
```
### General guidelines ### General guidelines
- Use a single, top-level `describe ClassName` block. - Use a single, top-level `describe ClassName` block.
......
...@@ -8,7 +8,7 @@ describe Analytics::CycleAnalytics::ProjectStage do ...@@ -8,7 +8,7 @@ describe Analytics::CycleAnalytics::ProjectStage do
end end
it 'default stages must be valid' do it 'default stages must be valid' do
project = create(:project) project = build(:project)
Gitlab::Analytics::CycleAnalytics::DefaultStages.all.each do |params| Gitlab::Analytics::CycleAnalytics::DefaultStages.all.each do |params|
stage = described_class.new(params.merge(project: project)) stage = described_class.new(params.merge(project: project))
...@@ -17,13 +17,13 @@ describe Analytics::CycleAnalytics::ProjectStage do ...@@ -17,13 +17,13 @@ describe Analytics::CycleAnalytics::ProjectStage do
end end
it_behaves_like 'cycle analytics stage' do it_behaves_like 'cycle analytics stage' do
let(:parent) { create(:project) } let(:parent) { build(:project) }
let(:parent_name) { :project } let(:parent_name) { :project }
end end
context 'relative positioning' do context 'relative positioning' do
it_behaves_like 'a class that supports relative positioning' do it_behaves_like 'a class that supports relative positioning' do
let(:project) { create(:project) } let(:project) { build(:project) }
let(:factory) { :cycle_analytics_project_stage } let(:factory) { :cycle_analytics_project_stage }
let(:default_params) { { project: project } } let(:default_params) { { project: project } }
end end
......
...@@ -573,17 +573,17 @@ describe Clusters::Cluster, :use_clean_rails_memory_store_caching do ...@@ -573,17 +573,17 @@ describe Clusters::Cluster, :use_clean_rails_memory_store_caching do
end end
describe '#allow_user_defined_namespace?' do describe '#allow_user_defined_namespace?' do
let(:cluster) { create(:cluster, :provided_by_gcp) }
subject { cluster.allow_user_defined_namespace? } subject { cluster.allow_user_defined_namespace? }
context 'project type cluster' do context 'project type cluster' do
context 'gitlab managed' do context 'gitlab managed' do
let(:cluster) { build(:cluster, :provided_by_gcp) }
it { is_expected.to be_truthy } it { is_expected.to be_truthy }
end end
context 'not managed' do context 'not managed' do
let(:cluster) { create(:cluster, :provided_by_gcp, managed: false) } let(:cluster) { build(:cluster, :provided_by_gcp, managed: false) }
it { is_expected.to be_truthy } it { is_expected.to be_truthy }
end end
...@@ -591,13 +591,13 @@ describe Clusters::Cluster, :use_clean_rails_memory_store_caching do ...@@ -591,13 +591,13 @@ describe Clusters::Cluster, :use_clean_rails_memory_store_caching do
context 'group type cluster' do context 'group type cluster' do
context 'gitlab managed' do context 'gitlab managed' do
let(:cluster) { create(:cluster, :provided_by_gcp, :group) } let(:cluster) { build(:cluster, :provided_by_gcp, :group) }
it { is_expected.to be_falsey } it { is_expected.to be_falsey }
end end
context 'not managed' do context 'not managed' do
let(:cluster) { create(:cluster, :provided_by_gcp, :group, managed: false) } let(:cluster) { build(:cluster, :provided_by_gcp, :group, managed: false) }
it { is_expected.to be_truthy } it { is_expected.to be_truthy }
end end
...@@ -605,13 +605,13 @@ describe Clusters::Cluster, :use_clean_rails_memory_store_caching do ...@@ -605,13 +605,13 @@ describe Clusters::Cluster, :use_clean_rails_memory_store_caching do
context 'instance type cluster' do context 'instance type cluster' do
context 'gitlab managed' do context 'gitlab managed' do
let(:cluster) { create(:cluster, :provided_by_gcp, :instance) } let(:cluster) { build(:cluster, :provided_by_gcp, :instance) }
it { is_expected.to be_falsey } it { is_expected.to be_falsey }
end end
context 'not managed' do context 'not managed' do
let(:cluster) { create(:cluster, :provided_by_gcp, :instance, managed: false) } let(:cluster) { build(:cluster, :provided_by_gcp, :instance, managed: false) }
it { is_expected.to be_truthy } it { is_expected.to be_truthy }
end end
...@@ -649,18 +649,18 @@ describe Clusters::Cluster, :use_clean_rails_memory_store_caching do ...@@ -649,18 +649,18 @@ describe Clusters::Cluster, :use_clean_rails_memory_store_caching do
end end
describe '#kube_ingress_domain' do describe '#kube_ingress_domain' do
let(:cluster) { create(:cluster, :provided_by_gcp) } let(:cluster) { build(:cluster, :provided_by_gcp) }
subject { cluster.kube_ingress_domain } subject { cluster.kube_ingress_domain }
context 'with domain set in cluster' do context 'with domain set in cluster' do
let(:cluster) { create(:cluster, :provided_by_gcp, :with_domain) } let(:cluster) { build(:cluster, :provided_by_gcp, :with_domain) }
it { is_expected.to eq(cluster.domain) } it { is_expected.to eq(cluster.domain) }
end end
context 'with no domain on cluster' do context 'with no domain on cluster' do
let(:cluster) { create(:cluster, :project, :provided_by_gcp) } let(:cluster) { build(:cluster, :project, :provided_by_gcp) }
let(:project) { cluster.project } let(:project) { cluster.project }
context 'with domain set at instance level' do context 'with domain set at instance level' do
...@@ -754,7 +754,7 @@ describe Clusters::Cluster, :use_clean_rails_memory_store_caching do ...@@ -754,7 +754,7 @@ describe Clusters::Cluster, :use_clean_rails_memory_store_caching do
end end
context 'with no domain' do context 'with no domain' do
let(:cluster) { create(:cluster, :provided_by_gcp, :project) } let(:cluster) { build(:cluster, :provided_by_gcp, :project) }
it 'returns an empty array' do it 'returns an empty array' do
expect(subject.to_hash).to be_empty expect(subject.to_hash).to be_empty
...@@ -782,7 +782,7 @@ describe Clusters::Cluster, :use_clean_rails_memory_store_caching do ...@@ -782,7 +782,7 @@ describe Clusters::Cluster, :use_clean_rails_memory_store_caching do
subject { cluster.status_name } subject { cluster.status_name }
context 'the cluster has a provider' do context 'the cluster has a provider' do
let(:cluster) { create(:cluster, :provided_by_gcp) } let(:cluster) { build(:cluster, :provided_by_gcp) }
let(:provider_status) { :errored } let(:provider_status) { :errored }
before do before do
...@@ -816,7 +816,7 @@ describe Clusters::Cluster, :use_clean_rails_memory_store_caching do ...@@ -816,7 +816,7 @@ describe Clusters::Cluster, :use_clean_rails_memory_store_caching do
end end
context 'there is a cached connection status' do context 'there is a cached connection status' do
let(:cluster) { create(:cluster, :provided_by_user) } let(:cluster) { build(:cluster, :provided_by_user) }
before do before do
allow(cluster).to receive(:connection_status).and_return(:connected) allow(cluster).to receive(:connection_status).and_return(:connected)
...@@ -826,7 +826,7 @@ describe Clusters::Cluster, :use_clean_rails_memory_store_caching do ...@@ -826,7 +826,7 @@ describe Clusters::Cluster, :use_clean_rails_memory_store_caching do
end end
context 'there is no connection status in the cache' do context 'there is no connection status in the cache' do
let(:cluster) { create(:cluster, :provided_by_user) } let(:cluster) { build(:cluster, :provided_by_user) }
before do before do
allow(cluster).to receive(:connection_status).and_return(nil) allow(cluster).to receive(:connection_status).and_return(nil)
......
...@@ -8,7 +8,7 @@ describe ErrorTracking::ProjectErrorTrackingSetting do ...@@ -8,7 +8,7 @@ describe ErrorTracking::ProjectErrorTrackingSetting do
let_it_be(:project) { create(:project) } let_it_be(:project) { create(:project) }
subject(:setting) { create(:project_error_tracking_setting, project: project) } subject(:setting) { build(:project_error_tracking_setting, project: project) }
describe 'Associations' do describe 'Associations' do
it { is_expected.to belong_to(:project) } it { is_expected.to belong_to(:project) }
......
...@@ -276,6 +276,8 @@ describe MergeRequest do ...@@ -276,6 +276,8 @@ describe MergeRequest do
end end
describe 'respond to' do describe 'respond to' do
subject { build(:merge_request) }
it { is_expected.to respond_to(:unchecked?) } it { is_expected.to respond_to(:unchecked?) }
it { is_expected.to respond_to(:checking?) } it { is_expected.to respond_to(:checking?) }
it { is_expected.to respond_to(:can_be_merged?) } it { is_expected.to respond_to(:can_be_merged?) }
......
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