From 149442a8a8b5e924e4d7980ce46565359441e904 Mon Sep 17 00:00:00 2001 From: Vladimir Shushlin Date: Mon, 11 Mar 2019 12:56:14 +0300 Subject: [PATCH] Remove feature_flag_audit feature flag Remove feature flag and specs for it being turned off --- ee/app/services/feature_flags/base_service.rb | 8 +- .../user_creates_feature_flag_spec.rb | 202 ++++++------------ .../user_updates_feature_flag_spec.rb | 168 +++++---------- .../feature_flags/create_service_spec.rb | 16 -- .../feature_flags/destroy_service_spec.rb | 14 -- .../feature_flags/update_service_spec.rb | 28 --- 6 files changed, 125 insertions(+), 311 deletions(-) diff --git a/ee/app/services/feature_flags/base_service.rb b/ee/app/services/feature_flags/base_service.rb index b5a05900f6e646..fed7fcebb6e051 100644 --- a/ee/app/services/feature_flags/base_service.rb +++ b/ee/app/services/feature_flags/base_service.rb @@ -6,13 +6,7 @@ class BaseService < ::BaseService protected - def audit_enabled? - Feature.enabled?(:feature_flag_audit, project, default_enabled: true) - end - def audit_event(feature_flag) - return unless audit_enabled? - message = audit_message(feature_flag) return if message.blank? @@ -33,7 +27,7 @@ def audit_event(feature_flag) end def save_audit_event(audit_event) - return unless audit_event # feature_flag_audit is disabled or audit_message is blank + return unless audit_event audit_event.security_event end diff --git a/ee/spec/features/projects/feature_flags/user_creates_feature_flag_spec.rb b/ee/spec/features/projects/feature_flags/user_creates_feature_flag_spec.rb index b166affba44e2c..0a3f0a1824062d 100644 --- a/ee/spec/features/projects/feature_flags/user_creates_feature_flag_spec.rb +++ b/ee/spec/features/projects/feature_flags/user_creates_feature_flag_spec.rb @@ -15,182 +15,120 @@ end context 'when creates without changing scopes' do - shared_examples 'succesfully creates feature flag' do - before do - visit(new_project_feature_flag_path(project)) - set_feature_flag_info('ci_live_trace', 'For live trace') - click_button 'Create feature flag' - expect(page).to have_current_path(project_feature_flags_path(project)) - end + before do + visit(new_project_feature_flag_path(project)) + set_feature_flag_info('ci_live_trace', 'For live trace') + click_button 'Create feature flag' + expect(page).to have_current_path(project_feature_flags_path(project)) + end - it 'shows the created feature flag' do - within_feature_flag_row(1) do - expect(page.find('.feature-flag-name')).to have_content('ci_live_trace') - expect(page).to have_css('.js-feature-flag-status .badge-success') + it 'shows the created feature flag' do + within_feature_flag_row(1) do + expect(page.find('.feature-flag-name')).to have_content('ci_live_trace') + expect(page).to have_css('.js-feature-flag-status .badge-success') - within_feature_flag_scopes do - expect(page.find('.badge:nth-child(1)')).to have_content('*') - expect(page.find('.badge:nth-child(1)')['class']).to include('badge-active') - end + within_feature_flag_scopes do + expect(page.find('.badge:nth-child(1)')).to have_content('*') + expect(page.find('.badge:nth-child(1)')['class']).to include('badge-active') end end end - context 'when feature flag audit enabled' do - include_examples 'succesfully creates feature flag' - - it 'records audit event' do - visit(project_audit_events_path(project)) + it 'records audit event' do + visit(project_audit_events_path(project)) - expect(page).to have_text("Created feature flag ci live trace with description \"For live trace\".") - end - end - - context 'when feature flag audit is disabled' do - before do - stub_feature_flags(feature_flag_audit: false) - end - - include_examples 'succesfully creates feature flag' - - it 'does not record audit event' do - visit(project_audit_events_path(project)) - - expect(page).to have_no_text("Created feature flag") - end + expect(page).to have_text("Created feature flag ci live trace with description \"For live trace\".") end end context 'when creates with disabling the default scope' do - shared_examples 'succesfully creates feature flag' do - before do - visit(new_project_feature_flag_path(project)) - set_feature_flag_info('ci_live_trace', 'For live trace') - - within_scope_row(1) do - within_status { find('.project-feature-toggle').click } - end + before do + visit(new_project_feature_flag_path(project)) + set_feature_flag_info('ci_live_trace', 'For live trace') - click_button 'Create feature flag' + within_scope_row(1) do + within_status { find('.project-feature-toggle').click } end - it 'shows the created feature flag' do - within_feature_flag_row(1) do - expect(page.find('.feature-flag-name')).to have_content('ci_live_trace') - expect(page).to have_css('.js-feature-flag-status .badge-danger') - - within_feature_flag_scopes do - expect(page.find('.badge:nth-child(1)')).to have_content('*') - expect(page.find('.badge:nth-child(1)')['class']).to include('badge-inactive') - end - end - end + click_button 'Create feature flag' end - context 'when feature flag audit enabled' do - include_examples 'succesfully creates feature flag' - end + it 'shows the created feature flag' do + within_feature_flag_row(1) do + expect(page.find('.feature-flag-name')).to have_content('ci_live_trace') + expect(page).to have_css('.js-feature-flag-status .badge-danger') - context 'when feature flag audit is disabled' do - before do - stub_feature_flags(feature_flag_audit: false) + within_feature_flag_scopes do + expect(page.find('.badge:nth-child(1)')).to have_content('*') + expect(page.find('.badge:nth-child(1)')['class']).to include('badge-inactive') + end end - - include_examples 'succesfully creates feature flag' end end context 'when creates with an additional scope' do - shared_examples 'succesfully creates feature flag' do - before do - visit(new_project_feature_flag_path(project)) - set_feature_flag_info('mr_train', '') - - within_scope_row(2) do - within_environment_spec do - find('.js-env-input').set("review/*") - find('.js-create-button').click - end - end - - within_scope_row(2) do - within_status { find('.project-feature-toggle').click } + before do + visit(new_project_feature_flag_path(project)) + set_feature_flag_info('mr_train', '') + + within_scope_row(2) do + within_environment_spec do + find('.js-env-input').set("review/*") + find('.js-create-button').click end - - click_button 'Create feature flag' end - it 'shows the created feature flag' do - within_feature_flag_row(1) do - expect(page.find('.feature-flag-name')).to have_content('mr_train') - expect(page).to have_css('.js-feature-flag-status .badge-success') - - within_feature_flag_scopes do - expect(page.find('.badge:nth-child(1)')).to have_content('*') - expect(page.find('.badge:nth-child(1)')['class']).to include('badge-active') - expect(page.find('.badge:nth-child(2)')).to have_content('review/*') - expect(page.find('.badge:nth-child(2)')['class']).to include('badge-active') - end - end + within_scope_row(2) do + within_status { find('.project-feature-toggle').click } end - end - context 'when feature flag audit enabled' do - include_examples 'succesfully creates feature flag' + click_button 'Create feature flag' end - context 'when feature flag audit is disabled' do - before do - stub_feature_flags(feature_flag_audit: false) - end + it 'shows the created feature flag' do + within_feature_flag_row(1) do + expect(page.find('.feature-flag-name')).to have_content('mr_train') + expect(page).to have_css('.js-feature-flag-status .badge-success') - include_examples 'succesfully creates feature flag' + within_feature_flag_scopes do + expect(page.find('.badge:nth-child(1)')).to have_content('*') + expect(page.find('.badge:nth-child(1)')['class']).to include('badge-active') + expect(page.find('.badge:nth-child(2)')).to have_content('review/*') + expect(page.find('.badge:nth-child(2)')['class']).to include('badge-active') + end + end end end context 'when searches an environment name for scope creation' do let!(:environment) { create(:environment, name: 'production', project: project) } - shared_examples 'succesfully creates feature flag' do - before do - visit(new_project_feature_flag_path(project)) - set_feature_flag_info('mr_train', '') + before do + visit(new_project_feature_flag_path(project)) + set_feature_flag_info('mr_train', '') - within_scope_row(2) do - within_environment_spec do - find('.js-env-input').set('prod') - click_button 'production' - end + within_scope_row(2) do + within_environment_spec do + find('.js-env-input').set('prod') + click_button 'production' end - - click_button 'Create feature flag' end - it 'shows the created feature flag' do - within_feature_flag_row(1) do - expect(page.find('.feature-flag-name')).to have_content('mr_train') - expect(page).to have_css('.js-feature-flag-status .badge-success') - - within_feature_flag_scopes do - expect(page.find('.badge:nth-child(1)')).to have_content('*') - expect(page.find('.badge:nth-child(1)')['class']).to include('badge-active') - expect(page.find('.badge:nth-child(2)')).to have_content('production') - expect(page.find('.badge:nth-child(2)')['class']).to include('badge-inactive') - end - end - end + click_button 'Create feature flag' end - context 'when feature flag audit enabled' do - include_examples 'succesfully creates feature flag' - end + it 'shows the created feature flag' do + within_feature_flag_row(1) do + expect(page.find('.feature-flag-name')).to have_content('mr_train') + expect(page).to have_css('.js-feature-flag-status .badge-success') - context 'when feature flag audit is disabled' do - before do - stub_feature_flags(feature_flag_audit: false) + within_feature_flag_scopes do + expect(page.find('.badge:nth-child(1)')).to have_content('*') + expect(page.find('.badge:nth-child(1)')['class']).to include('badge-active') + expect(page.find('.badge:nth-child(2)')).to have_content('production') + expect(page.find('.badge:nth-child(2)')['class']).to include('badge-inactive') + end end - - include_examples 'succesfully creates feature flag' end end diff --git a/ee/spec/features/projects/feature_flags/user_updates_feature_flag_spec.rb b/ee/spec/features/projects/feature_flags/user_updates_feature_flag_spec.rb index a9d908fc6f759e..8516b5e1985a0e 100644 --- a/ee/spec/features/projects/feature_flags/user_updates_feature_flag_spec.rb +++ b/ee/spec/features/projects/feature_flags/user_updates_feature_flag_spec.rb @@ -37,154 +37,94 @@ end context 'when user updates a status of a scope' do - shared_examples 'succesfully updates feature flag' do - before do - within_scope_row(2) do - within_status { find('.project-feature-toggle').click } - end - - click_button 'Save changes' - expect(page).to have_current_path(project_feature_flags_path(project)) + before do + within_scope_row(2) do + within_status { find('.project-feature-toggle').click } end - it 'shows the updated feature flag' do - within_feature_flag_row(1) do - expect(page.find('.feature-flag-name')).to have_content('ci_live_trace') - expect(page).to have_css('.js-feature-flag-status .badge-danger') - - within_feature_flag_scopes do - expect(page.find('.badge:nth-child(1)')).to have_content('*') - expect(page.find('.badge:nth-child(1)')['class']).to include('badge-inactive') - expect(page.find('.badge:nth-child(2)')).to have_content('review/*') - expect(page.find('.badge:nth-child(2)')['class']).to include('badge-inactive') - end - end - end + click_button 'Save changes' + expect(page).to have_current_path(project_feature_flags_path(project)) end - context 'when feature flag audit enabled' do - include_examples 'succesfully updates feature flag' + it 'shows the updated feature flag' do + within_feature_flag_row(1) do + expect(page.find('.feature-flag-name')).to have_content('ci_live_trace') + expect(page).to have_css('.js-feature-flag-status .badge-danger') - it 'records audit event' do - visit(project_audit_events_path(project)) - - expect(page).to( - have_text("Updated feature flag ci live trace. Updated rule review/* active state from true to false.") - ) + within_feature_flag_scopes do + expect(page.find('.badge:nth-child(1)')).to have_content('*') + expect(page.find('.badge:nth-child(1)')['class']).to include('badge-inactive') + expect(page.find('.badge:nth-child(2)')).to have_content('review/*') + expect(page.find('.badge:nth-child(2)')['class']).to include('badge-inactive') + end end end - context 'when feature flag audit is disabled' do - before do - stub_feature_flags(feature_flag_audit: false) - end - - include_examples 'succesfully updates feature flag' + it 'records audit event' do + visit(project_audit_events_path(project)) - it 'does not record audit event' do - visit(project_audit_events_path(project)) - - expect(page).to have_no_text("Updated feature flag") - end + expect(page).to( + have_text("Updated feature flag ci live trace. Updated rule review/* active state from true to false.") + ) end end context 'when user adds a new scope' do - shared_examples 'succesfully updates feature flag' do - before do - within_scope_row(3) do - within_environment_spec do - find('.js-env-input').set('production') - find('.js-create-button').click - end + before do + within_scope_row(3) do + within_environment_spec do + find('.js-env-input').set('production') + find('.js-create-button').click end - - click_button 'Save changes' - expect(page).to have_current_path(project_feature_flags_path(project)) end - it 'shows the newly created scope' do - within_feature_flag_row(1) do - within_feature_flag_scopes do - expect(page.find('.badge:nth-child(3)')).to have_content('production') - expect(page.find('.badge:nth-child(3)')['class']).to include('badge-inactive') - end - end - end + click_button 'Save changes' + expect(page).to have_current_path(project_feature_flags_path(project)) end - context 'when feature flag audit enabled' do - include_examples 'succesfully updates feature flag' - - it 'records audit event' do - visit(project_audit_events_path(project)) - - expect(page).to( - have_text("Updated feature flag ci live trace") - ) + it 'shows the newly created scope' do + within_feature_flag_row(1) do + within_feature_flag_scopes do + expect(page.find('.badge:nth-child(3)')).to have_content('production') + expect(page.find('.badge:nth-child(3)')['class']).to include('badge-inactive') + end end end - context 'when feature flag audit is disabled' do - before do - stub_feature_flags(feature_flag_audit: false) - end - - include_examples 'succesfully updates feature flag' + it 'records audit event' do + visit(project_audit_events_path(project)) - it 'does not record audit event' do - visit(project_audit_events_path(project)) - - expect(page).to have_no_text("Updated feature flag") - end + expect(page).to( + have_text("Updated feature flag ci live trace") + ) end end context 'when user deletes a scope' do - shared_examples 'succesfully updates feature flag' do - before do - within_scope_row(2) do - within_delete { find('.js-delete-scope').click } - end - - click_button 'Save changes' - expect(page).to have_current_path(project_feature_flags_path(project)) + before do + within_scope_row(2) do + within_delete { find('.js-delete-scope').click } end - it 'shows the updated feature flag' do - within_feature_flag_row(1) do - within_feature_flag_scopes do - expect(page).to have_css('.badge:nth-child(1)') - expect(page).not_to have_css('.badge:nth-child(2)') - end - end - end + click_button 'Save changes' + expect(page).to have_current_path(project_feature_flags_path(project)) end - context 'when feature flag audit enabled' do - include_examples 'succesfully updates feature flag' - - it 'records audit event' do - visit(project_audit_events_path(project)) - - expect(page).to( - have_text("Updated feature flag ci live trace") - ) + it 'shows the updated feature flag' do + within_feature_flag_row(1) do + within_feature_flag_scopes do + expect(page).to have_css('.badge:nth-child(1)') + expect(page).not_to have_css('.badge:nth-child(2)') + end end end - context 'when feature flag audit is disabled' do - before do - stub_feature_flags(feature_flag_audit: false) - end + it 'records audit event' do + visit(project_audit_events_path(project)) - include_examples 'succesfully updates feature flag' - - it 'does not record audit event' do - visit(project_audit_events_path(project)) - - expect(page).to have_no_text("Updated feature flag") - end + expect(page).to( + have_text("Updated feature flag ci live trace") + ) end end end diff --git a/ee/spec/services/feature_flags/create_service_spec.rb b/ee/spec/services/feature_flags/create_service_spec.rb index 16c4554527f76c..b089e7bf3cbabc 100644 --- a/ee/spec/services/feature_flags/create_service_spec.rb +++ b/ee/spec/services/feature_flags/create_service_spec.rb @@ -55,22 +55,6 @@ expect { subject }.to change { AuditEvent.count }.by(1) expect(AuditEvent.last.present.action).to eq(expected_message) end - - context 'when feature flag audit is disabled' do - before do - stub_feature_flags(feature_flag_audit: false) - end - - it { expect(subject[:status]).to eq(:success) } - - it 'creates feature flag' do - expect { subject }.to change { Operations::FeatureFlag.count }.by(1) - end - - it 'does not create audit log' do - expect { subject }.not_to change { AuditEvent.count } - end - end end end end diff --git a/ee/spec/services/feature_flags/destroy_service_spec.rb b/ee/spec/services/feature_flags/destroy_service_spec.rb index 302a91b57c4f1d..ce45dd5fa93109 100644 --- a/ee/spec/services/feature_flags/destroy_service_spec.rb +++ b/ee/spec/services/feature_flags/destroy_service_spec.rb @@ -24,20 +24,6 @@ expect(audit_event_message).to eq("Deleted feature flag #{feature_flag.name.tr('_', ' ')}.") end - context 'when feature flag audit is disabled' do - before do - stub_feature_flags(feature_flag_audit: false) - end - - it 'works successfully' do - expect(subject[:status]).to eq(:success) - end - - it 'does not create audit event' do - expect { subject }.not_to change { AuditEvent.count } - end - end - context 'when feature flag can not be destroyed' do before do allow(feature_flag).to receive(:destroy).and_return(false) diff --git a/ee/spec/services/feature_flags/update_service_spec.rb b/ee/spec/services/feature_flags/update_service_spec.rb index fcb951fcb0bc1e..aa6c7348715b89 100644 --- a/ee/spec/services/feature_flags/update_service_spec.rb +++ b/ee/spec/services/feature_flags/update_service_spec.rb @@ -29,24 +29,6 @@ ) end - shared_examples 'disabled feature flag audit' do - context 'when feature flag audit is disabled' do - before do - stub_feature_flags(feature_flag_audit: false) - end - - it 'returns success status' do - expect(subject[:status]).to eq(:success) - end - - it 'does not create audit event' do - expect { subject }.not_to change { AuditEvent.count } - end - end - end - - include_examples 'disabled feature flag audit' - context 'with invalid params' do let(:params) { { name: nil } } @@ -85,8 +67,6 @@ " to \"new description\".") ) end - - include_examples 'disabled feature flag audit' end context 'when active state is changed' do @@ -103,8 +83,6 @@ "from true to false.") ) end - - include_examples 'disabled feature flag audit' end context 'when scope is renamed' do @@ -123,8 +101,6 @@ ) end - include_examples 'disabled feature flag audit' - context 'when scope can not be updated' do let(:params) do { @@ -159,8 +135,6 @@ expect(audit_event_message).to include("Deleted rule review.") end - include_examples 'disabled feature flag audit' - context 'when scope can not be deleted' do RSpec::Matchers.define_negated_matcher :not_change, :change @@ -191,8 +165,6 @@ ) end - include_examples 'disabled feature flag audit' - context 'when scope can not be created' do let(:new_environment_scope) { '' } -- GitLab