2019-04-15 06:17:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
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))
|
2019-01-06 19:00:48 -05:00
|
|
|
allow(controller).to receive(:current_user).and_return(user)
|
2017-08-24 12:17:04 -04:00
|
|
|
|
|
|
|
controller
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
2019-04-19 02:50:54 -04:00
|
|
|
before 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)
|
2019-04-19 02:50:54 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
subject { controller.send(:finder_options).to_h }
|
|
|
|
|
|
|
|
context 'scalar params' do
|
|
|
|
let(:params) do
|
|
|
|
{
|
|
|
|
assignee_id: '1',
|
|
|
|
assignee_username: 'user1',
|
|
|
|
author_id: '2',
|
|
|
|
author_username: 'user2',
|
|
|
|
authorized_only: 'yes',
|
|
|
|
confidential: 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
|
|
|
|
|
|
|
|
it 'only allows whitelisted params' do
|
|
|
|
is_expected.to include({
|
|
|
|
'assignee_id' => '1',
|
|
|
|
'assignee_username' => 'user1',
|
|
|
|
'author_id' => '2',
|
|
|
|
'author_username' => 'user2',
|
|
|
|
'confidential' => true,
|
|
|
|
'label_name' => 'foo',
|
|
|
|
'milestone_title' => 'bar',
|
|
|
|
'my_reaction_emoji' => 'thumbsup',
|
|
|
|
'due_date' => '2017-01-01',
|
|
|
|
'scope' => 'all',
|
|
|
|
'search' => 'baz',
|
|
|
|
'sort' => 'priority',
|
|
|
|
'state' => 'opened'
|
|
|
|
})
|
|
|
|
|
|
|
|
is_expected.not_to include('invalid_param')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'array params' do
|
|
|
|
let(:params) do
|
|
|
|
{
|
|
|
|
assignee_username: %w[user1 user2],
|
|
|
|
label_name: %w[label1 label2],
|
|
|
|
invalid_param: 'invalid_param',
|
|
|
|
invalid_array: ['param']
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'only allows whitelisted params' do
|
|
|
|
is_expected.to include({
|
|
|
|
'label_name' => %w[label1 label2],
|
|
|
|
'assignee_username' => %w[user1 user2]
|
|
|
|
})
|
2017-11-12 23:14:18 -05:00
|
|
|
|
2019-04-19 02:50:54 -04:00
|
|
|
is_expected.not_to include('invalid_param', 'invalid_array')
|
|
|
|
end
|
2017-11-12 23:14:18 -05:00
|
|
|
end
|
2019-06-18 03:45:47 -04:00
|
|
|
|
|
|
|
context 'search using an issue iid' do
|
|
|
|
let(:params) { { search: "#5" } }
|
|
|
|
|
|
|
|
it 'mutates the search into a filter by iid' do
|
|
|
|
is_expected.to include({
|
|
|
|
'iids' => '5',
|
|
|
|
'search' => nil
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
2017-11-12 23:14:18 -05:00
|
|
|
end
|
2017-08-24 12:17:04 -04:00
|
|
|
end
|