2014-01-15 09:32:07 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2014-02-25 12:21:53 -05:00
|
|
|
describe IssuesFinder do
|
2014-01-15 09:32:07 -05:00
|
|
|
let(:user) { create :user }
|
|
|
|
let(:user2) { create :user }
|
|
|
|
let(:project1) { create(:project) }
|
|
|
|
let(:project2) { create(:project) }
|
2014-12-05 10:25:22 -05:00
|
|
|
let(:milestone) { create(:milestone, project: project1) }
|
|
|
|
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) }
|
2014-01-15 09:32:07 -05:00
|
|
|
|
|
|
|
before do
|
|
|
|
project1.team << [user, :master]
|
|
|
|
project2.team << [user, :developer]
|
2014-02-10 08:23:19 -05:00
|
|
|
project2.team << [user2, :developer]
|
2014-01-15 09:32:07 -05:00
|
|
|
end
|
|
|
|
|
2014-02-25 12:21:53 -05:00
|
|
|
describe :execute do
|
2014-01-15 09:32:07 -05:00
|
|
|
before :each do
|
|
|
|
issue1
|
|
|
|
issue2
|
|
|
|
issue3
|
|
|
|
end
|
|
|
|
|
2014-12-05 10:25:22 -05:00
|
|
|
context 'scope: all' do
|
|
|
|
it 'should filter by all' do
|
|
|
|
params = { scope: "all", state: 'opened' }
|
|
|
|
issues = IssuesFinder.new.execute(user, params)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(issues.size).to eq(3)
|
2014-12-05 10:25:22 -05:00
|
|
|
end
|
2014-01-15 09:32:07 -05:00
|
|
|
|
2014-12-05 10:25:22 -05:00
|
|
|
it 'should filter by assignee id' do
|
|
|
|
params = { scope: "all", assignee_id: user.id, state: 'opened' }
|
|
|
|
issues = IssuesFinder.new.execute(user, params)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(issues.size).to eq(2)
|
2014-12-05 10:25:22 -05:00
|
|
|
end
|
2014-01-15 09:32:07 -05:00
|
|
|
|
2014-12-05 10:25:22 -05:00
|
|
|
it 'should filter by author id' do
|
|
|
|
params = { scope: "all", author_id: user2.id, state: 'opened' }
|
|
|
|
issues = IssuesFinder.new.execute(user, params)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(issues).to eq([issue3])
|
2014-12-05 10:25:22 -05:00
|
|
|
end
|
2014-02-10 08:23:19 -05:00
|
|
|
|
2014-12-05 10:25:22 -05:00
|
|
|
it 'should filter by milestone id' do
|
|
|
|
params = { scope: "all", milestone_id: milestone.id, state: 'opened' }
|
|
|
|
issues = IssuesFinder.new.execute(user, params)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(issues).to eq([issue1])
|
2014-12-05 10:25:22 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be empty for unauthorized user' do
|
|
|
|
params = { scope: "all", state: 'opened' }
|
|
|
|
issues = IssuesFinder.new.execute(nil, params)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(issues.size).to be_zero
|
2014-12-05 10:25:22 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not include unauthorized issues' do
|
|
|
|
params = { scope: "all", state: 'opened' }
|
|
|
|
issues = IssuesFinder.new.execute(user2, params)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(issues.size).to eq(2)
|
|
|
|
expect(issues).not_to include(issue1)
|
|
|
|
expect(issues).to include(issue2)
|
|
|
|
expect(issues).to include(issue3)
|
2014-12-05 10:25:22 -05:00
|
|
|
end
|
2014-02-10 08:23:19 -05:00
|
|
|
end
|
|
|
|
|
2014-12-05 10:25:22 -05:00
|
|
|
context 'personal scope' do
|
|
|
|
it 'should filter by assignee' do
|
|
|
|
params = { scope: "assigned-to-me", state: 'opened' }
|
|
|
|
issues = IssuesFinder.new.execute(user, params)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(issues.size).to eq(2)
|
2014-12-05 10:25:22 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should filter by project' do
|
|
|
|
params = { scope: "assigned-to-me", state: 'opened', project_id: project1.id }
|
|
|
|
issues = IssuesFinder.new.execute(user, params)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(issues.size).to eq(1)
|
2014-12-05 10:25:22 -05:00
|
|
|
end
|
2014-02-10 08:23:19 -05:00
|
|
|
end
|
2014-01-15 09:32:07 -05:00
|
|
|
end
|
|
|
|
end
|