debian-mirror-gitlab/spec/lib/event_filter_spec.rb

59 lines
3 KiB
Ruby
Raw Normal View History

2016-11-03 12:29:30 +05:30
require 'spec_helper'
2017-09-10 17:25:29 +05:30
describe EventFilter do
2016-11-03 12:29:30 +05:30
describe '#apply_filter' do
let(:source_user) { create(:user) }
2017-09-10 17:25:29 +05:30
let!(:public_project) { create(:project, :public) }
2017-08-17 22:00:37 +05:30
2017-09-10 17:25:29 +05:30
let!(:push_event) { create(:push_event, project: public_project, author: source_user) }
2017-08-17 22:00:37 +05:30
let!(:merged_event) { create(:event, :merged, project: public_project, target: public_project, author: source_user) }
let!(:created_event) { create(:event, :created, project: public_project, target: public_project, author: source_user) }
let!(:updated_event) { create(:event, :updated, project: public_project, target: public_project, author: source_user) }
let!(:closed_event) { create(:event, :closed, project: public_project, target: public_project, author: source_user) }
let!(:reopened_event) { create(:event, :reopened, project: public_project, target: public_project, author: source_user) }
let!(:comments_event) { create(:event, :commented, project: public_project, target: public_project, author: source_user) }
let!(:joined_event) { create(:event, :joined, project: public_project, target: public_project, author: source_user) }
let!(:left_event) { create(:event, :left, project: public_project, target: public_project, author: source_user) }
2016-11-03 12:29:30 +05:30
it 'applies push filter' do
2017-09-10 17:25:29 +05:30
events = described_class.new(described_class.push).apply_filter(Event.all)
2016-11-03 12:29:30 +05:30
expect(events).to contain_exactly(push_event)
end
it 'applies merged filter' do
2017-09-10 17:25:29 +05:30
events = described_class.new(described_class.merged).apply_filter(Event.all)
2016-11-03 12:29:30 +05:30
expect(events).to contain_exactly(merged_event)
end
2017-08-17 22:00:37 +05:30
it 'applies issue filter' do
2017-09-10 17:25:29 +05:30
events = described_class.new(described_class.issue).apply_filter(Event.all)
2017-08-17 22:00:37 +05:30
expect(events).to contain_exactly(created_event, updated_event, closed_event, reopened_event)
end
2016-11-03 12:29:30 +05:30
it 'applies comments filter' do
2017-09-10 17:25:29 +05:30
events = described_class.new(described_class.comments).apply_filter(Event.all)
2016-11-03 12:29:30 +05:30
expect(events).to contain_exactly(comments_event)
end
it 'applies team filter' do
2017-09-10 17:25:29 +05:30
events = described_class.new(described_class.team).apply_filter(Event.all)
2016-11-03 12:29:30 +05:30
expect(events).to contain_exactly(joined_event, left_event)
end
it 'applies all filter' do
2017-09-10 17:25:29 +05:30
events = described_class.new(described_class.all).apply_filter(Event.all)
2017-08-17 22:00:37 +05:30
expect(events).to contain_exactly(push_event, merged_event, created_event, updated_event, closed_event, reopened_event, comments_event, joined_event, left_event)
2016-11-03 12:29:30 +05:30
end
it 'applies no filter' do
2017-09-10 17:25:29 +05:30
events = described_class.new(nil).apply_filter(Event.all)
2017-08-17 22:00:37 +05:30
expect(events).to contain_exactly(push_event, merged_event, created_event, updated_event, closed_event, reopened_event, comments_event, joined_event, left_event)
2016-11-03 12:29:30 +05:30
end
it 'applies unknown filter' do
2017-09-10 17:25:29 +05:30
events = described_class.new('').apply_filter(Event.all)
2017-08-17 22:00:37 +05:30
expect(events).to contain_exactly(push_event, merged_event, created_event, updated_event, closed_event, reopened_event, comments_event, joined_event, left_event)
2016-11-03 12:29:30 +05:30
end
end
end