2016-12-20 13:52:09 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Dashboard::TodosController do
|
|
|
|
let(:user) { create(:user) }
|
2017-01-16 08:11:08 -05:00
|
|
|
let(:author) { create(:user) }
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project) }
|
2016-12-20 13:52:09 -05:00
|
|
|
let(:todo_service) { TodoService.new }
|
|
|
|
|
2017-01-16 08:11:08 -05:00
|
|
|
before do
|
|
|
|
sign_in(user)
|
2017-12-22 03:18:28 -05:00
|
|
|
project.add_developer(user)
|
2017-01-16 08:11:08 -05:00
|
|
|
end
|
2016-12-20 13:52:09 -05:00
|
|
|
|
2017-01-16 08:11:08 -05:00
|
|
|
describe 'GET #index' do
|
2017-06-13 13:14:14 -04:00
|
|
|
context 'project authorization' do
|
|
|
|
it 'renders 404 when user does not have read access on given project' do
|
2017-08-02 15:55:11 -04:00
|
|
|
unauthorized_project = create(:project, :private)
|
2017-06-13 13:14:14 -04:00
|
|
|
|
2018-12-17 17:52:17 -05:00
|
|
|
get :index, params: { project_id: unauthorized_project.id }
|
2017-06-13 13:14:14 -04:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2017-06-13 13:14:14 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders 404 when given project does not exists' do
|
2018-12-17 17:52:17 -05:00
|
|
|
get :index, params: { project_id: 999 }
|
2017-06-13 13:14:14 -04:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2017-06-13 13:14:14 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders 200 when filtering for "any project" todos' do
|
2018-12-17 17:52:17 -05:00
|
|
|
get :index, params: { project_id: '' }
|
2017-06-13 13:14:14 -04:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2017-06-13 13:14:14 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders 200 when user has access on given project' do
|
2017-08-02 15:55:11 -04:00
|
|
|
authorized_project = create(:project, :public)
|
2017-06-13 13:14:14 -04:00
|
|
|
|
2018-12-17 17:52:17 -05:00
|
|
|
get :index, params: { project_id: authorized_project.id }
|
2017-06-13 13:14:14 -04:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2017-06-13 13:14:14 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-28 13:36:59 -05:00
|
|
|
context 'group authorization' do
|
|
|
|
it 'renders 404 when user does not have read access on given group' do
|
|
|
|
unauthorized_group = create(:group, :private)
|
|
|
|
|
2018-12-17 17:52:17 -05:00
|
|
|
get :index, params: { group_id: unauthorized_group.id }
|
2018-11-28 13:36:59 -05:00
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(404)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-12-20 13:52:09 -05:00
|
|
|
context 'when using pagination' do
|
2017-01-12 15:49:48 -05:00
|
|
|
let(:last_page) { user.todos.page.total_pages }
|
2017-11-09 08:13:48 -05:00
|
|
|
let!(:issues) { create_list(:issue, 3, project: project, assignees: [user]) }
|
2016-12-20 13:52:09 -05:00
|
|
|
|
|
|
|
before do
|
|
|
|
issues.each { |issue| todo_service.new_issue(issue, user) }
|
2017-11-09 08:13:48 -05:00
|
|
|
allow(Kaminari.config).to receive(:default_per_page).and_return(2)
|
2016-12-20 13:52:09 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'redirects to last_page if page number is larger than number of pages' do
|
2018-12-17 17:52:17 -05:00
|
|
|
get :index, params: { page: (last_page + 1).to_param }
|
2016-12-20 13:52:09 -05:00
|
|
|
|
|
|
|
expect(response).to redirect_to(dashboard_todos_path(page: last_page))
|
|
|
|
end
|
|
|
|
|
2017-10-04 12:37:38 -04:00
|
|
|
it 'goes to the correct page' do
|
2018-12-17 17:52:17 -05:00
|
|
|
get :index, params: { page: last_page }
|
2016-12-20 13:52:09 -05:00
|
|
|
|
|
|
|
expect(assigns(:todos).current_page).to eq(last_page)
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-12-20 13:52:09 -05:00
|
|
|
end
|
2017-04-05 18:52:19 -04:00
|
|
|
|
|
|
|
it 'does not redirect to external sites when provided a host field' do
|
|
|
|
external_host = "www.example.com"
|
2018-12-17 17:52:17 -05:00
|
|
|
get :index, params: { page: (last_page + 1).to_param, host: external_host }
|
2017-04-05 18:52:19 -04:00
|
|
|
|
|
|
|
expect(response).to redirect_to(dashboard_todos_path(page: last_page))
|
|
|
|
end
|
2017-10-04 12:37:38 -04:00
|
|
|
|
|
|
|
context 'when providing no filters' do
|
|
|
|
it 'does not perform a query to get the page count, but gets that from the user' do
|
|
|
|
allow(controller).to receive(:current_user).and_return(user)
|
|
|
|
|
|
|
|
expect(user).to receive(:todos_pending_count).and_call_original
|
|
|
|
|
2018-12-17 17:52:17 -05:00
|
|
|
get :index, params: { page: (last_page + 1).to_param, sort: :created_asc }
|
2017-10-04 12:37:38 -04:00
|
|
|
|
|
|
|
expect(response).to redirect_to(dashboard_todos_path(page: last_page, sort: :created_asc))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when providing filters' do
|
|
|
|
it 'performs a query to get the correct page count' do
|
|
|
|
allow(controller).to receive(:current_user).and_return(user)
|
|
|
|
|
|
|
|
expect(user).not_to receive(:todos_pending_count)
|
|
|
|
|
2018-12-17 17:52:17 -05:00
|
|
|
get :index, params: { page: (last_page + 1).to_param, project_id: project.id }
|
2017-10-04 12:37:38 -04:00
|
|
|
|
|
|
|
expect(response).to redirect_to(dashboard_todos_path(page: last_page, project_id: project.id))
|
|
|
|
end
|
|
|
|
end
|
2016-12-20 13:52:09 -05:00
|
|
|
end
|
|
|
|
end
|
2017-01-16 08:11:08 -05:00
|
|
|
|
|
|
|
describe 'PATCH #restore' do
|
|
|
|
let(:todo) { create(:todo, :done, user: user, project: project, author: author) }
|
|
|
|
|
|
|
|
it 'restores the todo to pending state' do
|
2018-12-17 17:52:17 -05:00
|
|
|
patch :restore, params: { id: todo.id }
|
2017-01-16 08:11:08 -05:00
|
|
|
|
|
|
|
expect(todo.reload).to be_pending
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2017-02-22 03:44:01 -05:00
|
|
|
expect(json_response).to eq({ "count" => "1", "done_count" => "0" })
|
2017-01-16 08:11:08 -05:00
|
|
|
end
|
|
|
|
end
|
2017-01-29 04:44:30 -05:00
|
|
|
|
|
|
|
describe 'PATCH #bulk_restore' do
|
|
|
|
let(:todos) { create_list(:todo, 2, :done, user: user, project: project, author: author) }
|
|
|
|
|
|
|
|
it 'restores the todos to pending state' do
|
2018-12-17 17:52:17 -05:00
|
|
|
patch :bulk_restore, params: { ids: todos.map(&:id) }
|
2017-01-29 04:44:30 -05:00
|
|
|
|
|
|
|
todos.each do |todo|
|
|
|
|
expect(todo.reload).to be_pending
|
|
|
|
end
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2017-01-29 04:44:30 -05:00
|
|
|
expect(json_response).to eq({ 'count' => '2', 'done_count' => '0' })
|
|
|
|
end
|
|
|
|
end
|
2016-12-20 13:52:09 -05:00
|
|
|
end
|