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-01-25 16:44:33 -05:00
|
|
|
let(:project) { create(:empty_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)
|
|
|
|
project.team << [user, :developer]
|
|
|
|
end
|
2016-12-20 13:52:09 -05:00
|
|
|
|
2017-01-16 08:11:08 -05:00
|
|
|
describe 'GET #index' do
|
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-05-04 08:11:15 -04:00
|
|
|
let!(:issues) { create_list(:issue, 2, project: project, assignees: [user]) }
|
2016-12-20 13:52:09 -05:00
|
|
|
|
|
|
|
before do
|
|
|
|
issues.each { |issue| todo_service.new_issue(issue, user) }
|
2016-12-21 10:02:05 -05:00
|
|
|
allow(Kaminari.config).to receive(:default_per_page).and_return(1)
|
2016-12-20 13:52:09 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'redirects to last_page if page number is larger than number of pages' do
|
|
|
|
get :index, page: (last_page + 1).to_param
|
|
|
|
|
|
|
|
expect(response).to redirect_to(dashboard_todos_path(page: last_page))
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'redirects to correspondent page' do
|
|
|
|
get :index, page: last_page
|
|
|
|
|
|
|
|
expect(assigns(:todos).current_page).to eq(last_page)
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
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"
|
|
|
|
get :index, page: (last_page + 1).to_param, host: external_host
|
|
|
|
|
|
|
|
expect(response).to redirect_to(dashboard_todos_path(page: last_page))
|
|
|
|
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
|
|
|
|
patch :restore, id: todo.id
|
|
|
|
|
|
|
|
expect(todo.reload).to be_pending
|
|
|
|
expect(response).to have_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
|
|
|
|
patch :bulk_restore, ids: todos.map(&:id)
|
|
|
|
|
|
|
|
todos.each do |todo|
|
|
|
|
expect(todo.reload).to be_pending
|
|
|
|
end
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
expect(json_response).to eq({ 'count' => '2', 'done_count' => '0' })
|
|
|
|
end
|
|
|
|
end
|
2016-12-20 13:52:09 -05:00
|
|
|
end
|