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

90 lines
2.6 KiB
Ruby
Raw Normal View History

2016-08-24 12:49:21 +05:30
require 'spec_helper'
describe BranchesFinder do
let(:user) { create(:user) }
2017-08-17 22:00:37 +05:30
let(:project) { create(:project, :repository) }
2016-08-24 12:49:21 +05:30
let(:repository) { project.repository }
describe '#execute' do
context 'sort only' do
it 'sorts by name' do
branches_finder = described_class.new(repository, {})
result = branches_finder.execute
expect(result.first.name).to eq("'test'")
end
it 'sorts by recently_updated' do
2016-09-13 17:45:13 +05:30
branches_finder = described_class.new(repository, { sort: 'updated_desc' })
2016-08-24 12:49:21 +05:30
result = branches_finder.execute
2016-09-13 17:45:13 +05:30
recently_updated_branch = repository.branches.max do |a, b|
2016-11-24 13:41:30 +05:30
repository.commit(a.dereferenced_target).committed_date <=> repository.commit(b.dereferenced_target).committed_date
2016-09-13 17:45:13 +05:30
end
expect(result.first.name).to eq(recently_updated_branch.name)
2016-08-24 12:49:21 +05:30
end
it 'sorts by last_updated' do
2016-09-13 17:45:13 +05:30
branches_finder = described_class.new(repository, { sort: 'updated_asc' })
2016-08-24 12:49:21 +05:30
result = branches_finder.execute
expect(result.first.name).to eq('feature')
end
end
context 'filter only' do
it 'filters branches by name' do
branches_finder = described_class.new(repository, { search: 'fix' })
result = branches_finder.execute
expect(result.first.name).to eq('fix')
2018-03-17 18:26:18 +05:30
expect(result.count).to eq(1)
end
it 'filters branches by name ignoring letter case' do
branches_finder = described_class.new(repository, { search: 'FiX' })
result = branches_finder.execute
expect(result.first.name).to eq('fix')
2016-08-24 12:49:21 +05:30
expect(result.count).to eq(1)
end
it 'does not find any branch with that name' do
branches_finder = described_class.new(repository, { search: 'random' })
result = branches_finder.execute
expect(result.count).to eq(0)
end
end
context 'filter and sort' do
it 'filters branches by name and sorts by recently_updated' do
2016-09-13 17:45:13 +05:30
params = { sort: 'updated_desc', search: 'feature' }
2016-08-24 12:49:21 +05:30
branches_finder = described_class.new(repository, params)
result = branches_finder.execute
expect(result.first.name).to eq('feature_conflict')
expect(result.count).to eq(2)
end
it 'filters branches by name and sorts by last_updated' do
2016-09-13 17:45:13 +05:30
params = { sort: 'updated_asc', search: 'feature' }
2016-08-24 12:49:21 +05:30
branches_finder = described_class.new(repository, params)
result = branches_finder.execute
expect(result.first.name).to eq('feature')
expect(result.count).to eq(2)
end
end
end
end