Commit 479f03cf authored by Jan Provaznik's avatar Jan Provaznik

Add requirements index action

This action will be used by FE to setup Vue objects for
Requirements UI.
parent d0ce09be
# frozen_string_literal: true
class Projects::RequirementsController < Projects::ApplicationController
before_action :authorize_read_requirement!
before_action :verify_requirements_management_flag!
before_action do
push_frontend_feature_flag(:requirements_management, project)
end
def index
respond_to do |format|
format.html
end
end
private
def verify_requirements_management_flag!
render_404 unless Feature.enabled?(:requirements_management, project)
end
end
......@@ -11,6 +11,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
# Begin of the /-/ scope.
# Use this scope for all new project routes.
scope '-' do
resources :requirements, only: [:index]
resources :packages, only: [:index, :show, :destroy], module: :packages
resources :package_files, only: [], module: :packages do
member do
......
# frozen_string_literal: true
require 'spec_helper'
describe Projects::RequirementsController do
let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user) }
subject { get :index, params: { namespace_id: project.namespace, project_id: project } }
describe 'GET #index' do
context 'with authorized user' do
before do
project.add_developer(user)
sign_in(user)
end
context 'when feature is available' do
before do
stub_licensed_features(requirements: true)
end
it 'renders the index template' do
subject
expect(response).to have_gitlab_http_status(:ok)
expect(response).to render_template(:index)
end
context 'when requirements_management flag is disabled' do
before do
stub_feature_flags(requirements_management: false)
end
it 'returns 404' do
subject
expect(response).to have_gitlab_http_status(:not_found)
end
end
end
context 'when feature is not available' do
before do
stub_licensed_features(requirements: false)
end
it 'returns 404' do
subject
expect(response).to have_gitlab_http_status(:not_found)
end
end
end
context 'with unauthorized user' do
before do
sign_in(user)
end
context 'when feature is available' do
before do
stub_licensed_features(requirements: true)
end
it 'returns 404' do
subject
expect(response).to have_gitlab_http_status(:not_found)
end
end
end
context 'with anonymous user' do
it 'returns 302' do
subject
expect(response).to have_gitlab_http_status(:found)
expect(response).to redirect_to(new_user_session_path)
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