diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-01-15 18:32:07 +0400 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-01-15 18:32:07 +0400 |
commit | 4a5e4b18f5470eedc0fb8af9a135edc609d167f6 (patch) | |
tree | 253db61e1f60810f4ed377127a51bd0050b93cc5 /spec | |
parent | 6153aa136007daa4b5c592190b72de389de8b032 (diff) |
Specs for FilteringService
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'spec')
-rw-r--r-- | spec/services/filtering_service_spec.rb | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/spec/services/filtering_service_spec.rb b/spec/services/filtering_service_spec.rb new file mode 100644 index 00000000000..596601264b3 --- /dev/null +++ b/spec/services/filtering_service_spec.rb @@ -0,0 +1,65 @@ +require 'spec_helper' + +describe FilteringService do + let(:user) { create :user } + let(:user2) { create :user } + let(:project1) { create(:project) } + let(:project2) { create(:project) } + let(:merge_request1) { create(:merge_request, author: user, source_project: project1, target_project: project2) } + let(:merge_request2) { create(:merge_request, author: user, source_project: project2, target_project: project1) } + let(:merge_request3) { create(:merge_request, author: user, source_project: project2, target_project: project2) } + let(:issue1) { create(:issue, assignee: user, project: project1) } + let(:issue2) { create(:issue, assignee: user, project: project2) } + let(:issue3) { create(:issue, assignee: user2, project: project2) } + + before do + project1.team << [user, :master] + project2.team << [user, :developer] + end + + describe 'merge requests' do + before :each do + merge_request1 + merge_request2 + merge_request3 + end + + it 'should filter by scope' do + params = { scope: 'authored', state: 'opened' } + merge_requests = FilteringService.new.execute(MergeRequest, user, params) + merge_requests.size.should == 3 + end + + it 'should filter by project' do + params = { project_id: project1.id, scope: 'authored', state: 'opened' } + merge_requests = FilteringService.new.execute(MergeRequest, user, params) + merge_requests.size.should == 1 + end + end + + describe 'issues' do + before :each do + issue1 + issue2 + issue3 + end + + it 'should filter by all' do + params = { scope: "all", state: 'opened' } + issues = FilteringService.new.execute(Issue, user, params) + issues.size.should == 3 + end + + it 'should filter by assignee' do + params = { scope: "assigned-to-me", state: 'opened' } + issues = FilteringService.new.execute(Issue, user, params) + issues.size.should == 2 + end + + it 'should filter by project' do + params = { scope: "assigned-to-me", state: 'opened', project_id: project1.id } + issues = FilteringService.new.execute(Issue, user, params) + issues.size.should == 1 + end + end +end |