Commit fc54df0f authored by Peter Leitzen's avatar Peter Leitzen Committed by Douglas Barbosa Alexandre

Speed-up project specs for "#feature_available?"

Before

    $ bin/spring rspec ee/spec/models/project_spec.rb -e feature_available
    Finished in 1 minute 31.73 seconds (files took 1.19 seconds to load)
    493 examples, 0 failures

After

    $ bin/spring rspec ee/spec/models/project_spec.rb -e feature_available
    Finished in 19.38 seconds (files took 1.01 seconds to load)
    493 examples, 0 failures
parent 293c97b8
...@@ -376,11 +376,10 @@ describe Project do ...@@ -376,11 +376,10 @@ describe Project do
end end
describe '#feature_available?' do describe '#feature_available?' do
let(:namespace) { create(:namespace) } let(:namespace) { build(:namespace) }
let(:plan_license) { nil } let(:plan_license) { nil }
let!(:gitlab_subscription) { create(:gitlab_subscription, namespace: namespace, hosted_plan: plan_license) } let(:project) { build(:project, namespace: namespace) }
let(:project) { create(:project, namespace: namespace) } let(:user) { build(:user) }
let(:user) { create(:user) }
subject { project.feature_available?(feature, user) } subject { project.feature_available?(feature, user) }
...@@ -402,7 +401,11 @@ describe Project do ...@@ -402,7 +401,11 @@ describe Project do
context 'allowed by Plan License AND Global License' do context 'allowed by Plan License AND Global License' do
let(:allowed_on_global_license) { true } let(:allowed_on_global_license) { true }
let(:plan_license) { create(:gold_plan) } let(:plan_license) { build(:gold_plan) }
before do
allow(namespace).to receive(:plans) { [plan_license] }
end
it 'returns true' do it 'returns true' do
is_expected.to eq(true) is_expected.to eq(true)
...@@ -419,7 +422,7 @@ describe Project do ...@@ -419,7 +422,7 @@ describe Project do
context 'not allowed by Plan License but project and namespace are public' do context 'not allowed by Plan License but project and namespace are public' do
let(:allowed_on_global_license) { true } let(:allowed_on_global_license) { true }
let(:plan_license) { create(:bronze_plan) } let(:plan_license) { build(:bronze_plan) }
it 'returns true' do it 'returns true' do
allow(namespace).to receive(:public?) { true } allow(namespace).to receive(:public?) { true }
...@@ -432,7 +435,7 @@ describe Project do ...@@ -432,7 +435,7 @@ describe Project do
unless License.plan_includes_feature?(License::STARTER_PLAN, feature_sym) unless License.plan_includes_feature?(License::STARTER_PLAN, feature_sym)
context 'not allowed by Plan License' do context 'not allowed by Plan License' do
let(:allowed_on_global_license) { true } let(:allowed_on_global_license) { true }
let(:plan_license) { create(:bronze_plan) } let(:plan_license) { build(:bronze_plan) }
it 'returns false' do it 'returns false' do
is_expected.to eq(false) is_expected.to eq(false)
...@@ -442,7 +445,7 @@ describe Project do ...@@ -442,7 +445,7 @@ describe Project do
context 'not allowed by Global License' do context 'not allowed by Global License' do
let(:allowed_on_global_license) { false } let(:allowed_on_global_license) { false }
let(:plan_license) { create(:gold_plan) } let(:plan_license) { build(:gold_plan) }
it 'returns false' do it 'returns false' do
is_expected.to eq(false) is_expected.to eq(false)
......
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