-
Notifications
You must be signed in to change notification settings - Fork 5
Add disable_feature and enable_feature to TestUtilitiesController #963
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+243
−131
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,6 +37,9 @@ namespace :test_seeds do | |
| school_ids = [school_id, teacher_signup_school_id].compact | ||
| School.where(id: school_ids).destroy_all | ||
|
|
||
| # Clear any feature flags that may have been set | ||
| Flipper.features.each(&:remove) | ||
|
|
||
| Rails.logger.info 'Done...' | ||
| end | ||
| end | ||
|
|
@@ -52,8 +55,6 @@ namespace :test_seeds do | |
| teacher_id = ENV.fetch('SEEDING_TEACHER_ID', TEST_USERS[:john_doe]) | ||
|
|
||
| school = create_school(creator_id, TEST_SCHOOL) | ||
| Flipper.enable_actor :cat_mode, school | ||
| Flipper.enable_actor :student_sso, school | ||
|
Comment on lines
-55
to
-56
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hopefully these changes mean that we no longer need to hard-code features. And I think |
||
|
|
||
| verify_school(school) | ||
| assign_a_teacher(teacher_id, school) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,204 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'rails_helper' | ||
|
|
||
| RSpec.describe TestUtilitiesController do | ||
| let(:headers) { { 'X-RESEED-API-KEY' => ENV.fetch('RESEED_API_KEY', nil) } } | ||
|
|
||
| before do | ||
| host! 'test-editor-api.raspberrypi.org' | ||
| ENV['RESEED_API_KEY'] = 'my_test_api_key' | ||
| end | ||
|
|
||
| after do | ||
| ENV.delete('RESEED_API_KEY') | ||
| end | ||
|
|
||
| describe 'POST /test/reseed' do | ||
| subject(:request) { post('/test/reseed', headers:) } | ||
|
|
||
| before do | ||
| allow(Rake::Task['test_seeds:destroy']).to receive(:execute) | ||
| allow(Rake::Task['test_seeds:create']).to receive(:execute) | ||
| end | ||
|
|
||
| around do |example| | ||
| DatabaseCleaner.clean_with(:truncation) | ||
| DatabaseCleaner.strategy = :transaction | ||
|
|
||
| DatabaseCleaner.cleaning do | ||
| Rake::Task.tasks.each(&:reenable) | ||
| example.run | ||
| ensure | ||
| Rake::Task.tasks.each(&:reenable) | ||
| end | ||
| end | ||
|
|
||
| it 'returns OK' do | ||
| request | ||
| expect(response).to be_ok | ||
| end | ||
|
|
||
| it 'destroys the test seeds' do | ||
| request | ||
| expect(Rake::Task['test_seeds:destroy']).to have_received(:execute) | ||
| end | ||
|
|
||
| it 'recreates the test seeds' do | ||
| request | ||
| expect(Rake::Task['test_seeds:create']).to have_received(:execute) | ||
| end | ||
|
|
||
| context 'when the host is not allowed' do | ||
| before do | ||
| host! 'editor-api.raspberrypi.org' | ||
| end | ||
|
|
||
| it 'returns not found' do | ||
| request | ||
| expect(response).to be_not_found | ||
| end | ||
|
|
||
| it 'does not destroy test seeds' do | ||
| request | ||
| expect(Rake::Task['test_seeds:destroy']).not_to have_received(:execute) | ||
| end | ||
|
|
||
| it 'does not recreate test seeds' do | ||
| request | ||
| expect(Rake::Task['test_seeds:create']).not_to have_received(:execute) | ||
| end | ||
| end | ||
|
|
||
| context 'when the RESEED_API_KEY is not set in the environment' do | ||
| let(:headers) { { 'X-RESEED-API-KEY' => '' } } | ||
|
|
||
| before do | ||
| ENV.delete('RESEED_API_KEY') | ||
| end | ||
|
|
||
| it 'returns not found' do | ||
| request | ||
| expect(response).to be_not_found | ||
| end | ||
|
|
||
| it 'does not destroy test seeds' do | ||
| request | ||
| expect(Rake::Task['test_seeds:destroy']).not_to have_received(:execute) | ||
| end | ||
|
|
||
| it 'does not recreate test seeds' do | ||
| request | ||
| expect(Rake::Task['test_seeds:create']).not_to have_received(:execute) | ||
| end | ||
| end | ||
|
|
||
| context 'when the X-RESEED_API_KEY is incorrect' do | ||
| let(:headers) { { 'X-RESEED-API-KEY' => 'my_dodgy_api_key' } } | ||
|
|
||
| it 'returns not found' do | ||
| request | ||
| expect(response).to be_not_found | ||
| end | ||
|
|
||
| it 'does not destroy test seeds' do | ||
| request | ||
| expect(Rake::Task['test_seeds:destroy']).not_to have_received(:execute) | ||
| end | ||
|
|
||
| it 'does not recreate test seeds' do | ||
| request | ||
| expect(Rake::Task['test_seeds:create']).not_to have_received(:execute) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| describe 'feature toggle endpoints' do | ||
| let(:school) { create(:school) } | ||
| let(:feature_key) { :flipper_feature } | ||
| let(:params) do | ||
| { | ||
| feature_key: | ||
| } | ||
| end | ||
|
|
||
| shared_examples 'a rejected feature toggle request' do | ||
| it 'returns not found' do | ||
| request | ||
| expect(response).to be_not_found | ||
| end | ||
|
|
||
| it 'does not change the feature' do | ||
| expect { request }.not_to(change { Flipper.enabled?(feature_key, school) }) | ||
| end | ||
| end | ||
|
|
||
| shared_examples 'a feature toggle endpoint' do | ||
| it 'returns no content' do | ||
| request | ||
| expect(response).to be_no_content | ||
| end | ||
|
|
||
| context 'when the feature_key param is missing' do | ||
| let(:params) { {} } | ||
|
|
||
| it 'returns bad request' do | ||
| request | ||
| expect(response).to be_bad_request | ||
| end | ||
|
|
||
| it 'does not change the feature' do | ||
| expect { request }.not_to(change { Flipper.enabled?(feature_key, school) }) | ||
| end | ||
| end | ||
|
|
||
| context 'when the host is not allowed' do | ||
| before { host! 'editor-api.raspberrypi.org' } | ||
|
|
||
| it_behaves_like 'a rejected feature toggle request' | ||
| end | ||
|
|
||
| context 'when the RESEED_API_KEY is not set in the environment' do | ||
| let(:headers) { { 'X-RESEED-API-KEY' => '' } } | ||
|
|
||
| before { ENV.delete('RESEED_API_KEY') } | ||
|
|
||
| it_behaves_like 'a rejected feature toggle request' | ||
| end | ||
|
|
||
| context 'when the X-RESEED-API-KEY is incorrect' do | ||
| let(:headers) { { 'X-RESEED-API-KEY' => 'my_dodgy_api_key' } } | ||
|
|
||
| it_behaves_like 'a rejected feature toggle request' | ||
| end | ||
| end | ||
|
|
||
| describe 'POST /test/enable_feature' do | ||
| subject(:request) { post('/test/enable_feature', headers:, params:) } | ||
|
|
||
| before do | ||
| Flipper.disable(feature_key) | ||
| end | ||
|
|
||
| it 'universally enables the feature' do | ||
| expect { request }.to change { Flipper.enabled?(feature_key, school) }.from(false).to(true) | ||
| end | ||
|
|
||
| it_behaves_like 'a feature toggle endpoint' | ||
| end | ||
|
|
||
| describe 'POST /test/disable_feature' do | ||
| subject(:request) { post('/test/disable_feature', headers:, params:) } | ||
|
|
||
| before do | ||
| Flipper.enable_actor(feature_key, school) | ||
| end | ||
|
|
||
| it 'universally disables the feature' do | ||
| expect { request }.to change { Flipper.enabled?(feature_key, school) }.from(true).to(false) | ||
| end | ||
|
|
||
| it_behaves_like 'a feature toggle endpoint' | ||
| end | ||
| end | ||
| end |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.