debian-mirror-gitlab/spec/finders/issues_finder_spec.rb

102 lines
3.5 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
require 'spec_helper'
describe IssuesFinder do
let(:user) { create :user }
let(:user2) { create :user }
let(:project1) { create(:project) }
let(:project2) { create(:project) }
2015-04-26 12:48:37 +05:30
let(:milestone) { create(:milestone, project: project1) }
2015-10-24 18:46:33 +05:30
let(:label) { create(:label, project: project2) }
2015-04-26 12:48:37 +05:30
let(:issue1) { create(:issue, author: user, assignee: user, project: project1, milestone: milestone) }
let(:issue2) { create(:issue, author: user, assignee: user, project: project2) }
let(:issue3) { create(:issue, author: user2, assignee: user2, project: project2) }
2015-10-24 18:46:33 +05:30
let!(:label_link) { create(:label_link, label: label, target: issue2) }
2014-09-02 18:07:02 +05:30
before do
project1.team << [user, :master]
project2.team << [user, :developer]
project2.team << [user2, :developer]
end
describe :execute do
before :each do
issue1
issue2
issue3
end
2015-04-26 12:48:37 +05:30
context 'scope: all' do
it 'should filter by all' do
params = { scope: "all", state: 'opened' }
2015-09-11 14:41:01 +05:30
issues = IssuesFinder.new(user, params).execute
2015-04-26 12:48:37 +05:30
expect(issues.size).to eq(3)
end
2014-09-02 18:07:02 +05:30
2015-04-26 12:48:37 +05:30
it 'should filter by assignee id' do
params = { scope: "all", assignee_id: user.id, state: 'opened' }
2015-09-11 14:41:01 +05:30
issues = IssuesFinder.new(user, params).execute
2015-04-26 12:48:37 +05:30
expect(issues.size).to eq(2)
end
2014-09-02 18:07:02 +05:30
2015-04-26 12:48:37 +05:30
it 'should filter by author id' do
params = { scope: "all", author_id: user2.id, state: 'opened' }
2015-09-11 14:41:01 +05:30
issues = IssuesFinder.new(user, params).execute
2015-04-26 12:48:37 +05:30
expect(issues).to eq([issue3])
end
2014-09-02 18:07:02 +05:30
2015-04-26 12:48:37 +05:30
it 'should filter by milestone id' do
2015-09-11 14:41:01 +05:30
params = { scope: "all", milestone_title: milestone.title, state: 'opened' }
issues = IssuesFinder.new(user, params).execute
2015-04-26 12:48:37 +05:30
expect(issues).to eq([issue1])
end
2015-10-24 18:46:33 +05:30
it 'should filter by no milestone id' do
params = { scope: "all", milestone_title: Milestone::None.title, state: 'opened' }
issues = IssuesFinder.new(user, params).execute
expect(issues).to match_array([issue2, issue3])
end
it 'should filter by label name' do
params = { scope: "all", label_name: label.title, state: 'opened' }
issues = IssuesFinder.new(user, params).execute
expect(issues).to eq([issue2])
end
it 'should filter by no label name' do
params = { scope: "all", label_name: Label::None.title, state: 'opened' }
issues = IssuesFinder.new(user, params).execute
expect(issues).to match_array([issue1, issue3])
end
2015-04-26 12:48:37 +05:30
it 'should be empty for unauthorized user' do
params = { scope: "all", state: 'opened' }
2015-09-11 14:41:01 +05:30
issues = IssuesFinder.new(nil, params).execute
2015-04-26 12:48:37 +05:30
expect(issues.size).to be_zero
end
it 'should not include unauthorized issues' do
params = { scope: "all", state: 'opened' }
2015-09-11 14:41:01 +05:30
issues = IssuesFinder.new(user2, params).execute
2015-04-26 12:48:37 +05:30
expect(issues.size).to eq(2)
expect(issues).not_to include(issue1)
expect(issues).to include(issue2)
expect(issues).to include(issue3)
end
2014-09-02 18:07:02 +05:30
end
2015-04-26 12:48:37 +05:30
context 'personal scope' do
it 'should filter by assignee' do
params = { scope: "assigned-to-me", state: 'opened' }
2015-09-11 14:41:01 +05:30
issues = IssuesFinder.new(user, params).execute
2015-04-26 12:48:37 +05:30
expect(issues.size).to eq(2)
end
it 'should filter by project' do
params = { scope: "assigned-to-me", state: 'opened', project_id: project1.id }
2015-09-11 14:41:01 +05:30
issues = IssuesFinder.new(user, params).execute
2015-04-26 12:48:37 +05:30
expect(issues.size).to eq(1)
end
2014-09-02 18:07:02 +05:30
end
end
end