Commit 43467502 authored by Alex Kalderimis's avatar Alex Kalderimis

Merge branch 'jp-epic-index' into 'master'

Cleanup of epics index action

See merge request gitlab-org/gitlab!79818
parents 3cb78825 93f4565c
......@@ -11,7 +11,6 @@ class Groups::EpicsController < Groups::ApplicationController
before_action :check_epics_available!
before_action :epic, except: [:index, :create, :new, :bulk_update]
before_action :set_issuables_index, only: :index
before_action :authorize_update_issuable!, only: :update
before_action :authorize_create_epic!, only: [:create, :new]
before_action :verify_group_bulk_edit_enabled!, only: [:bulk_update]
......@@ -33,12 +32,12 @@ class Groups::EpicsController < Groups::ApplicationController
end
def index
@epics = @issuables
respond_to do |format|
format.html
format.json do
render json: serializer.represent(@epics)
set_issuables_index
render json: serializer.represent(@issuables)
end
end
end
......
......@@ -65,94 +65,6 @@ RSpec.describe Groups::EpicsController do
expect(response).to have_gitlab_http_status(:ok)
end
context 'when there is no logged in user' do
it 'stores sorting param in a cookie' do
group.update!(visibility_level: Gitlab::VisibilityLevel::PUBLIC)
sign_out(user)
get :index, params: { group_id: group, sort: 'start_date_asc' }
expect(cookies['epic_sort']).to eq('start_date_asc')
expect(response).to have_gitlab_http_status(:ok)
end
end
context 'when there is a logged in user' do
context 'when epics_sort is nil' do
it 'stores sorting param in user preferences' do
get :index, params: { group_id: group, sort: 'start_date_asc' }
expect(user.user_preference.epics_sort).to eq('start_date_asc')
expect(response).to have_gitlab_http_status(:ok)
end
end
context 'when epics_sort is present' do
it 'update epics_sort with current value' do
user.user_preference.update!(epics_sort: 'created_desc')
get :index, params: { group_id: group, sort: 'start_date_asc' }
expect(user.reload.user_preference.epics_sort).to eq('start_date_asc')
expect(response).to have_gitlab_http_status(:ok)
end
end
it_behaves_like 'issuable list with anonymous search disabled' do
let(:params) { { group_id: group } }
before do
sign_out(user)
group.update!(visibility_level: Gitlab::VisibilityLevel::PUBLIC)
end
end
end
context 'with page param' do
let(:last_page) { group.epics.page.total_pages }
before do
allow(Kaminari.config).to receive(:default_per_page).and_return(1)
end
it 'redirects to last_page if page number is larger than number of pages' do
get :index, params: { group_id: group, page: (last_page + 1).to_param }
expect(response).to redirect_to(group_epics_path(page: last_page, state: controller.params[:state], scope: controller.params[:scope]))
end
it 'renders the specified page' do
get :index, params: { group_id: group, page: last_page.to_param }
expect(assigns(:epics).current_page).to eq(last_page)
expect(response).to have_gitlab_http_status(:ok)
end
it_behaves_like 'disabled when using an external authorization service' do
subject { get :index, params: { group_id: group } }
end
end
context "when epic has multiple labels" do
render_views
let(:label) { create(:label) }
let!(:labeled_epic) { create(:labeled_epic, group: group, labels: [label]) }
it 'does not cause N+1 queries' do
get :index, params: { group_id: group }
control_count = ActiveRecord::QueryRecorder.new do
get :index, params: { group_id: group }
end
label = create(:label)
create(:labeled_epic, group: group, labels: [label])
expect { get :index, params: { group_id: group } }.not_to exceed_query_limit(control_count)
end
end
context 'when format is JSON' do
before do
allow(Kaminari.config).to receive(:default_per_page).and_return(1)
......
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