Commit 8502eb4a authored by Jarka Kadlecova's avatar Jarka Kadlecova

Implement epics index action

parent b97bce0a
...@@ -143,6 +143,8 @@ module IssuableCollections ...@@ -143,6 +143,8 @@ module IssuableCollections
'Issue' 'Issue'
when MergeRequestsFinder when MergeRequestsFinder
'MergeRequest' 'MergeRequest'
when EpicsFinder
'Epic'
end end
end end
...@@ -155,6 +157,8 @@ module IssuableCollections ...@@ -155,6 +157,8 @@ module IssuableCollections
:source_project, :target_project, :author, :assignee, :labels, :milestone, :source_project, :target_project, :author, :assignee, :labels, :milestone,
head_pipeline: :project, target_project: :namespace, merge_request_diff: :merge_request_diff_commits head_pipeline: :project, target_project: :namespace, merge_request_diff: :merge_request_diff_commits
] ]
when 'Epic'
[:group, :author]
end end
end end
end end
...@@ -40,6 +40,7 @@ module Gitlab ...@@ -40,6 +40,7 @@ module Gitlab
config.eager_load_paths.push(*%W[ config.eager_load_paths.push(*%W[
#{config.root}/ee/lib #{config.root}/ee/lib
#{config.root}/ee/app/controllers #{config.root}/ee/app/controllers
#{config.root}/ee/app/finders
#{config.root}/ee/app/helpers #{config.root}/ee/app/helpers
#{config.root}/ee/app/mailers #{config.root}/ee/app/mailers
#{config.root}/ee/app/models #{config.root}/ee/app/models
......
class Groups::EpicsController < Groups::ApplicationController class Groups::EpicsController < Groups::ApplicationController
include IssuableActions include IssuableActions
include IssuableCollections
before_action :epic before_action :epic, except: :index
before_action :set_issuables_index, only: :index
before_action :authorize_update_issuable!, only: :update before_action :authorize_update_issuable!, only: :update
skip_before_action :labels skip_before_action :labels
def index
@epics = @issuables
respond_to do |format|
format.html do
render 'groups/ee/epics/index'
end
format.json do
render json: {
html: view_to_html_string("groups/ee/epics/_epics")
}
end
end
end
private private
def epic def epic
...@@ -41,4 +58,8 @@ class Groups::EpicsController < Groups::ApplicationController ...@@ -41,4 +58,8 @@ class Groups::EpicsController < Groups::ApplicationController
def show_view def show_view
'groups/ee/epics/show' 'groups/ee/epics/show'
end end
def finder_type
EpicsFinder
end
end end
class EpicsFinder < IssuableFinder
def klass
Epic
end
def execute
raise ArgumentError, 'group_id argument is missing' unless group
items = init_collection
items = by_created_at(items)
items = by_search(items)
items = by_author(items)
items = by_iids(items)
sort(items)
end
def row_count
execute.count
end
def group
return nil unless params[:group_id]
return @group if defined?(@group)
group = Group.find(params[:group_id])
group = nil unless Ability.allowed?(current_user, :read_epic, group)
@group = group
end
def init_collection
group.epics
end
end
%ul.content-list.issues-list.issuable-list
...@@ -9,6 +9,42 @@ describe Groups::EpicsController do ...@@ -9,6 +9,42 @@ describe Groups::EpicsController do
sign_in(user) sign_in(user)
end end
describe "GET #index" do
let!(:epic_list) { create_list(:epic, 2, group: group) }
before do
sign_in(user)
group.add_developer(user)
end
it "returns index" do
get :index, group_id: group
expect(response).to have_gitlab_http_status(200)
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, 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, group_id: group, page: last_page.to_param
expect(assigns(:epics).current_page).to eq(last_page)
expect(response).to have_gitlab_http_status(200)
end
end
end
describe 'GET #show' do describe 'GET #show' do
def show_epic(format = :html) def show_epic(format = :html)
get :show, group_id: group, id: epic.to_param, format: format get :show, group_id: group, id: epic.to_param, format: format
......
require 'spec_helper'
describe EpicsFinder do
let(:user) { create(:user) }
let(:search_user) { create(:user) }
let(:group) { create(:group, :private) }
let(:another_group) { create(:group) }
let!(:epic1) { create(:epic, group: group, title: 'This is awesome epic', created_at: 1.week.ago) }
let!(:epic2) { create(:epic, group: group, created_at: 4.days.ago, author: user) }
let!(:epic3) { create(:epic, group: group, description: 'not so awesome') }
let!(:epic4) { create(:epic, group: another_group) }
describe '#execute' do
def epics(params = {})
params[:group_id] = group.id
described_class.new(search_user, params).execute
end
context 'without param' do
it 'raises an error when group_id param is missing' do
expect { described_class.new(search_user).execute }.to raise_error { ArgumentError }
end
end
context 'when user can not read epics of a group' do
it 'raises an error when group_id param is missing' do
expect { epics }.to raise_error { ArgumentError }
end
end
context 'wtih correct params' do
before do
group.add_developer(search_user)
end
it 'returns all epics that belong to the given group' do
expect(epics).to contain_exactly(epic1, epic2, epic3)
end
context 'by created_at' do
it 'returns all epics created before the given date' do
expect(epics(created_before: 2.days.ago)).to contain_exactly(epic1, epic2)
end
it 'returns all epics created after the given date' do
expect(epics(created_after: 2.days.ago)).to contain_exactly(epic3)
end
it 'returns all epics created within the given interval' do
expect(epics(created_after: 5.days.ago, created_before: 1.day.ago)).to contain_exactly(epic2)
end
end
context 'by search' do
it 'returns all epics that match the search' do
expect(epics(search: 'awesome')).to contain_exactly(epic1, epic3)
end
end
context 'by author' do
it 'returns all epics authored by the given user' do
expect(epics(author_id: user.id)).to contain_exactly(epic2)
end
end
context 'by iids' do
it 'returns all epics by the given iids' do
expect(epics(iids: [epic1.iid, epic3.iid])).to contain_exactly(epic1, epic3)
end
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