2017-08-24 12:17:04 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe IssuableCollections do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
let(:controller) do
|
|
|
|
klass = Class.new do
|
|
|
|
def self.helper_method(name); end
|
|
|
|
|
|
|
|
include IssuableCollections
|
2018-02-20 07:33:49 -05:00
|
|
|
|
|
|
|
def finder_type
|
|
|
|
IssuesFinder
|
|
|
|
end
|
2017-08-24 12:17:04 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
controller = klass.new
|
|
|
|
|
2017-11-12 23:14:18 -05:00
|
|
|
allow(controller).to receive(:params).and_return(ActionController::Parameters.new(params))
|
2017-08-24 12:17:04 -04:00
|
|
|
|
|
|
|
controller
|
|
|
|
end
|
|
|
|
|
2018-08-30 16:39:56 -04:00
|
|
|
describe '#set_set_order_from_cookie' do
|
|
|
|
describe 'when sort param given' do
|
|
|
|
let(:cookies) { {} }
|
|
|
|
let(:params) { { sort: 'downvotes_asc' } }
|
|
|
|
|
|
|
|
it 'sets the cookie with the right values and flags' do
|
|
|
|
allow(controller).to receive(:cookies).and_return(cookies)
|
|
|
|
|
|
|
|
controller.send(:set_sort_order_from_cookie)
|
|
|
|
|
|
|
|
expect(cookies['issue_sort']).to eq({ value: 'popularity', secure: false, httponly: false })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'when cookie exists' do
|
|
|
|
let(:cookies) { { 'issue_sort' => 'id_asc' } }
|
|
|
|
let(:params) { {} }
|
|
|
|
|
|
|
|
it 'sets the cookie with the right values and flags' do
|
|
|
|
allow(controller).to receive(:cookies).and_return(cookies)
|
|
|
|
|
|
|
|
controller.send(:set_sort_order_from_cookie)
|
|
|
|
|
|
|
|
expect(cookies['issue_sort']).to eq({ value: 'created_asc', secure: false, httponly: false })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-24 12:17:04 -04:00
|
|
|
describe '#page_count_for_relation' do
|
2017-11-12 23:14:18 -05:00
|
|
|
let(:params) { { state: 'opened' } }
|
|
|
|
|
2017-08-24 12:17:04 -04:00
|
|
|
it 'returns the number of pages' do
|
|
|
|
relation = double(:relation, limit_value: 20)
|
|
|
|
pages = controller.send(:page_count_for_relation, relation, 28)
|
|
|
|
|
|
|
|
expect(pages).to eq(2)
|
|
|
|
end
|
|
|
|
end
|
2017-11-12 23:14:18 -05:00
|
|
|
|
2018-11-09 09:29:45 -05:00
|
|
|
describe '#finder_options' do
|
2017-11-12 23:14:18 -05:00
|
|
|
let(:params) do
|
|
|
|
{
|
|
|
|
assignee_id: '1',
|
|
|
|
assignee_username: 'user1',
|
|
|
|
author_id: '2',
|
|
|
|
author_username: 'user2',
|
|
|
|
authorized_only: 'true',
|
|
|
|
due_date: '2017-01-01',
|
|
|
|
group_id: '3',
|
|
|
|
iids: '4',
|
|
|
|
label_name: 'foo',
|
|
|
|
milestone_title: 'bar',
|
|
|
|
my_reaction_emoji: 'thumbsup',
|
|
|
|
non_archived: 'true',
|
|
|
|
project_id: '5',
|
|
|
|
scope: 'all',
|
|
|
|
search: 'baz',
|
|
|
|
sort: 'priority',
|
|
|
|
state: 'opened',
|
|
|
|
invalid_param: 'invalid_param'
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2018-11-09 09:29:45 -05:00
|
|
|
it 'only allows whitelisted params' do
|
2017-11-12 23:14:18 -05:00
|
|
|
allow(controller).to receive(:cookies).and_return({})
|
2018-12-03 07:46:47 -05:00
|
|
|
allow(controller).to receive(:current_user).and_return(nil)
|
2017-11-12 23:14:18 -05:00
|
|
|
|
2018-11-09 09:29:45 -05:00
|
|
|
finder_options = controller.send(:finder_options)
|
2017-11-12 23:14:18 -05:00
|
|
|
|
2018-11-09 09:29:45 -05:00
|
|
|
expect(finder_options).to eq({
|
2017-11-12 23:14:18 -05:00
|
|
|
'assignee_id' => '1',
|
|
|
|
'assignee_username' => 'user1',
|
|
|
|
'author_id' => '2',
|
|
|
|
'author_username' => 'user2',
|
|
|
|
'label_name' => 'foo',
|
|
|
|
'milestone_title' => 'bar',
|
|
|
|
'my_reaction_emoji' => 'thumbsup',
|
2018-11-09 09:29:45 -05:00
|
|
|
'due_date' => '2017-01-01',
|
2017-11-12 23:14:18 -05:00
|
|
|
'scope' => 'all',
|
|
|
|
'search' => 'baz',
|
|
|
|
'sort' => 'priority',
|
|
|
|
'state' => 'opened'
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
2017-08-24 12:17:04 -04:00
|
|
|
end
|