Commit fcc5da4f authored by Vitali Tatarintev's avatar Vitali Tatarintev

Refactor specs for FeatureFlagsController

* Use RSpec one-liner syntax where possible
* Use `have_gitlab_http_status` instead of `be_ok`
parent c274e589
...@@ -26,36 +26,24 @@ describe Projects::FeatureFlagsController do ...@@ -26,36 +26,24 @@ describe Projects::FeatureFlagsController do
subject { get(:index, params: view_params) } subject { get(:index, params: view_params) }
context 'when there is no feature flags' do context 'when there is no feature flags' do
before do it 'responds with success' do
subject is_expected.to have_gitlab_http_status(:ok)
end
it 'renders page' do
expect(response).to be_ok
end end
end end
context 'for a list of feature flags' do context 'for a list of feature flags' do
let!(:feature_flags) { create_list(:operations_feature_flag, 50, project: project) } let!(:feature_flags) { create_list(:operations_feature_flag, 50, project: project) }
before do it 'responds with success' do
subject is_expected.to have_gitlab_http_status(:ok)
end
it 'renders page' do
expect(response).to have_gitlab_http_status(:ok)
end end
end end
context 'when feature is not available' do context 'when feature is not available' do
let(:feature_enabled) { false } let(:feature_enabled) { false }
before do it 'responds with not found' do
subject is_expected.to have_gitlab_http_status(:not_found)
end
it 'shows not found' do
expect(subject).to have_gitlab_http_status(:not_found)
end end
end end
end end
...@@ -102,9 +90,7 @@ describe Projects::FeatureFlagsController do ...@@ -102,9 +90,7 @@ describe Projects::FeatureFlagsController do
end end
it 'matches json schema' do it 'matches json schema' do
subject is_expected.to match_response_schema('feature_flags', dir: 'ee')
expect(response).to match_response_schema('feature_flags', dir: 'ee')
end end
it 'returns false for active when the feature flag is inactive even if it has an active scope' do it 'returns false for active when the feature flag is inactive even if it has an active scope' do
...@@ -228,9 +214,7 @@ describe Projects::FeatureFlagsController do ...@@ -228,9 +214,7 @@ describe Projects::FeatureFlagsController do
subject { get(:new, params: view_params) } subject { get(:new, params: view_params) }
it 'renders the form' do it 'renders the form' do
subject is_expected.to have_gitlab_http_status(:ok)
expect(response).to be_ok
end end
end end
...@@ -257,9 +241,7 @@ describe Projects::FeatureFlagsController do ...@@ -257,9 +241,7 @@ describe Projects::FeatureFlagsController do
end end
it 'matches json schema' do it 'matches json schema' do
subject is_expected.to match_response_schema('feature_flag', dir: 'ee')
expect(response).to match_response_schema('feature_flag', dir: 'ee')
end end
context 'when feature flag is not found' do context 'when feature flag is not found' do
...@@ -274,9 +256,7 @@ describe Projects::FeatureFlagsController do ...@@ -274,9 +256,7 @@ describe Projects::FeatureFlagsController do
end end
it 'returns 404' do it 'returns 404' do
subject is_expected.to have_gitlab_http_status(:not_found)
expect(response).to have_gitlab_http_status(:not_found)
end end
end end
...@@ -284,9 +264,7 @@ describe Projects::FeatureFlagsController do ...@@ -284,9 +264,7 @@ describe Projects::FeatureFlagsController do
let(:user) { reporter } let(:user) { reporter }
it 'returns 404' do it 'returns 404' do
subject is_expected.to have_gitlab_http_status(:not_found)
expect(response).to have_gitlab_http_status(:not_found)
end end
end end
...@@ -346,9 +324,7 @@ describe Projects::FeatureFlagsController do ...@@ -346,9 +324,7 @@ describe Projects::FeatureFlagsController do
end end
it 'returns 200' do it 'returns 200' do
subject is_expected.to have_gitlab_http_status(:ok)
expect(response).to have_gitlab_http_status(:ok)
end end
it 'creates a new feature flag' do it 'creates a new feature flag' do
...@@ -367,9 +343,7 @@ describe Projects::FeatureFlagsController do ...@@ -367,9 +343,7 @@ describe Projects::FeatureFlagsController do
end end
it 'matches json schema' do it 'matches json schema' do
subject is_expected.to match_response_schema('feature_flag', dir: 'ee')
expect(response).to match_response_schema('feature_flag', dir: 'ee')
end end
context 'when the same named feature flag has already existed' do context 'when the same named feature flag has already existed' do
...@@ -378,9 +352,7 @@ describe Projects::FeatureFlagsController do ...@@ -378,9 +352,7 @@ describe Projects::FeatureFlagsController do
end end
it 'returns 400' do it 'returns 400' do
subject is_expected.to have_gitlab_http_status(:bad_request)
expect(response).to have_gitlab_http_status(:bad_request)
end end
it 'returns an error message' do it 'returns an error message' do
...@@ -415,9 +387,7 @@ describe Projects::FeatureFlagsController do ...@@ -415,9 +387,7 @@ describe Projects::FeatureFlagsController do
let(:user) { reporter } let(:user) { reporter }
it 'returns 404' do it 'returns 404' do
subject is_expected.to have_gitlab_http_status(:not_found)
expect(response).to have_gitlab_http_status(:not_found)
end end
end end
...@@ -549,9 +519,7 @@ describe Projects::FeatureFlagsController do ...@@ -549,9 +519,7 @@ describe Projects::FeatureFlagsController do
end end
it 'returns 200' do it 'returns 200' do
subject is_expected.to have_gitlab_http_status(:ok)
expect(response).to have_gitlab_http_status(:ok)
end end
it 'deletes one feature flag' do it 'deletes one feature flag' do
...@@ -563,18 +531,14 @@ describe Projects::FeatureFlagsController do ...@@ -563,18 +531,14 @@ describe Projects::FeatureFlagsController do
end end
it 'matches json schema' do it 'matches json schema' do
subject is_expected.to match_response_schema('feature_flag', dir: 'ee')
expect(response).to match_response_schema('feature_flag', dir: 'ee')
end end
context 'when user is reporter' do context 'when user is reporter' do
let(:user) { reporter } let(:user) { reporter }
it 'returns 404' do it 'returns 404' do
subject is_expected.to have_gitlab_http_status(:not_found)
expect(response).to have_gitlab_http_status(:not_found)
end end
end end
...@@ -609,9 +573,7 @@ describe Projects::FeatureFlagsController do ...@@ -609,9 +573,7 @@ describe Projects::FeatureFlagsController do
end end
it 'returns 200' do it 'returns 200' do
subject is_expected.to have_gitlab_http_status(:ok)
expect(response).to have_gitlab_http_status(:ok)
end end
it 'updates the name of the feature flag name' do it 'updates the name of the feature flag name' do
...@@ -621,9 +583,7 @@ describe Projects::FeatureFlagsController do ...@@ -621,9 +583,7 @@ describe Projects::FeatureFlagsController do
end end
it 'matches json schema' do it 'matches json schema' do
subject is_expected.to match_response_schema('feature_flag', dir: 'ee')
expect(response).to match_response_schema('feature_flag', dir: 'ee')
end end
context 'when updates active' do context 'when updates active' do
...@@ -672,9 +632,7 @@ describe Projects::FeatureFlagsController do ...@@ -672,9 +632,7 @@ describe Projects::FeatureFlagsController do
let(:user) { reporter } let(:user) { reporter }
it 'returns 404' do it 'returns 404' do
subject is_expected.to have_gitlab_http_status(:not_found)
expect(response).to have_gitlab_http_status(:not_found)
end end
end end
...@@ -711,9 +669,7 @@ describe Projects::FeatureFlagsController do ...@@ -711,9 +669,7 @@ describe Projects::FeatureFlagsController do
end end
it 'returns 400' do it 'returns 400' do
subject is_expected.to have_gitlab_http_status(:bad_request)
expect(response).to have_gitlab_http_status(:bad_request)
end end
end end
...@@ -761,9 +717,7 @@ describe Projects::FeatureFlagsController do ...@@ -761,9 +717,7 @@ describe Projects::FeatureFlagsController do
end end
it 'returns 400' do it 'returns 400' do
subject is_expected.to have_gitlab_http_status(:bad_request)
expect(response).to have_gitlab_http_status(:bad_request)
end end
end end
......
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