diff options
Diffstat (limited to 'spec/requests/api/features_spec.rb')
-rw-r--r-- | spec/requests/api/features_spec.rb | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/spec/requests/api/features_spec.rb b/spec/requests/api/features_spec.rb index 4ad5b4f9d49..59a9ed2f77d 100644 --- a/spec/requests/api/features_spec.rb +++ b/spec/requests/api/features_spec.rb @@ -2,11 +2,12 @@ require 'spec_helper' -describe API::Features do +describe API::Features, stub_feature_flags: false do let_it_be(:user) { create(:user) } let_it_be(:admin) { create(:admin) } before do + Feature.reset Flipper.unregister_groups Flipper.register(:perf_team) do |actor| actor.respond_to?(:admin) && actor.admin? @@ -38,9 +39,9 @@ describe API::Features do end before do - Feature.get('feature_1').enable - Feature.get('feature_2').disable - Feature.get('feature_3').enable Feature.group(:perf_team) + Feature.enable('feature_1') + Feature.disable('feature_2') + Feature.enable('feature_3', Feature.group(:perf_team)) end it 'returns a 401 for anonymous users' do @@ -226,10 +227,8 @@ describe API::Features do end context 'when the feature exists' do - let(:feature) { Feature.get(feature_name) } - before do - feature.disable # This also persists the feature on the DB + Feature.disable(feature_name) # This also persists the feature on the DB end context 'when passed value=true' do @@ -272,8 +271,8 @@ describe API::Features do context 'when feature is enabled and value=false is passed' do it 'disables the feature' do - feature.enable - expect(feature).to be_enabled + Feature.enable(feature_name) + expect(Feature.enabled?(feature_name)).to eq(true) post api("/features/#{feature_name}", admin), params: { value: 'false' } @@ -285,8 +284,8 @@ describe API::Features do end it 'disables the feature for the given Flipper group when passed feature_group=perf_team' do - feature.enable(Feature.group(:perf_team)) - expect(Feature.get(feature_name).enabled?(admin)).to be_truthy + Feature.enable(feature_name, Feature.group(:perf_team)) + expect(Feature.enabled?(feature_name, admin)).to be_truthy post api("/features/#{feature_name}", admin), params: { value: 'false', feature_group: 'perf_team' } @@ -298,8 +297,8 @@ describe API::Features do end it 'disables the feature for the given user when passed user=username' do - feature.enable(user) - expect(Feature.get(feature_name).enabled?(user)).to be_truthy + Feature.enable(feature_name, user) + expect(Feature.enabled?(feature_name, user)).to be_truthy post api("/features/#{feature_name}", admin), params: { value: 'false', user: user.username } @@ -313,7 +312,7 @@ describe API::Features do context 'with a pre-existing percentage of time value' do before do - feature.enable_percentage_of_time(50) + Feature.enable_percentage_of_time(feature_name, 50) end it 'updates the percentage of time if passed an integer' do @@ -332,7 +331,7 @@ describe API::Features do context 'with a pre-existing percentage of actors value' do before do - feature.enable_percentage_of_actors(42) + Feature.enable_percentage_of_actors(feature_name, 42) end it 'updates the percentage of actors if passed an integer' do @@ -377,14 +376,17 @@ describe API::Features do context 'when the gate value was set' do before do - Feature.get(feature_name).enable + Feature.enable(feature_name) end it 'deletes an enabled feature' do - delete api("/features/#{feature_name}", admin) + expect do + delete api("/features/#{feature_name}", admin) + Feature.reset + end.to change { Feature.persisted_name?(feature_name) } + .and change { Feature.enabled?(feature_name) } expect(response).to have_gitlab_http_status(:no_content) - expect(Feature.get(feature_name)).not_to be_enabled end end end |