debian-mirror-gitlab/spec/features/projects/branches_spec.rb

114 lines
3.2 KiB
Ruby
Raw Normal View History

2016-08-24 12:49:21 +05:30
require 'spec_helper'
2017-09-10 17:25:29 +05:30
describe 'Branches' do
let(:user) { create(:user) }
let(:project) { create(:project, :public, :repository) }
2016-08-24 12:49:21 +05:30
let(:repository) { project.repository }
2017-09-10 17:25:29 +05:30
context 'logged in as developer' do
2016-09-29 09:46:39 +05:30
before do
2017-09-10 17:25:29 +05:30
sign_in(user)
2018-03-17 18:26:18 +05:30
project.add_developer(user)
2016-09-29 09:46:39 +05:30
end
2016-08-24 12:49:21 +05:30
2016-09-29 09:46:39 +05:30
describe 'Initial branches page' do
2018-03-17 18:26:18 +05:30
it 'shows all the branches sorted by last updated by default' do
2017-09-10 17:25:29 +05:30
visit project_branches_path(project)
2016-08-24 12:49:21 +05:30
2018-03-17 18:26:18 +05:30
expect(page).to have_content(sorted_branches(repository, count: 20, sort_by: :updated_desc))
2017-09-10 17:25:29 +05:30
end
it 'sorts the branches by name' do
visit project_branches_path(project)
click_button "Last updated" # Open sorting dropdown
click_link "Name"
2018-03-17 18:26:18 +05:30
expect(page).to have_content(sorted_branches(repository, count: 20, sort_by: :name))
2017-09-10 17:25:29 +05:30
end
it 'sorts the branches by oldest updated' do
visit project_branches_path(project)
click_button "Last updated" # Open sorting dropdown
click_link "Oldest updated"
2018-03-17 18:26:18 +05:30
expect(page).to have_content(sorted_branches(repository, count: 20, sort_by: :updated_asc))
2016-09-29 09:46:39 +05:30
end
2017-08-17 22:00:37 +05:30
it 'avoids a N+1 query in branches index' do
2017-09-10 17:25:29 +05:30
control_count = ActiveRecord::QueryRecorder.new { visit project_branches_path(project) }.count
2017-08-17 22:00:37 +05:30
2017-09-10 17:25:29 +05:30
%w(one two three four five).each { |ref| repository.add_branch(user, ref, 'master') }
2017-08-17 22:00:37 +05:30
2017-09-10 17:25:29 +05:30
expect { visit project_branches_path(project) }.not_to exceed_query_limit(control_count)
2017-08-17 22:00:37 +05:30
end
2016-08-24 12:49:21 +05:30
end
2016-09-29 09:46:39 +05:30
describe 'Find branches' do
2018-03-17 18:26:18 +05:30
it 'shows filtered branches', :js do
2017-09-10 17:25:29 +05:30
visit project_branches_path(project)
fill_in 'branch-search', with: 'fix'
find('#branch-search').native.send_keys(:enter)
expect(page).to have_content('fix')
expect(find('.all-branches')).to have_selector('li', count: 1)
end
end
describe 'Delete unprotected branch' do
2018-03-17 18:26:18 +05:30
it 'removes branch after confirmation', :js do
2017-09-10 17:25:29 +05:30
visit project_branches_path(project)
2016-09-29 09:46:39 +05:30
fill_in 'branch-search', with: 'fix'
2017-09-10 17:25:29 +05:30
2016-09-29 09:46:39 +05:30
find('#branch-search').native.send_keys(:enter)
2016-08-24 12:49:21 +05:30
2016-09-29 09:46:39 +05:30
expect(page).to have_content('fix')
expect(find('.all-branches')).to have_selector('li', count: 1)
2018-03-17 18:26:18 +05:30
accept_confirm { find('.js-branch-fix .btn-remove').click }
2017-09-10 17:25:29 +05:30
expect(page).not_to have_content('fix')
expect(find('.all-branches')).to have_selector('li', count: 0)
end
end
end
context 'logged in as master' do
before do
sign_in(user)
2018-03-17 18:26:18 +05:30
project.add_master(user)
2017-09-10 17:25:29 +05:30
end
describe 'Initial branches page' do
it 'shows description for admin' do
visit project_branches_path(project)
expect(page).to have_content("Protected branches can be managed in project settings")
end
end
2016-09-29 09:46:39 +05:30
end
context 'logged out' do
before do
2017-09-10 17:25:29 +05:30
visit project_branches_path(project)
2016-09-29 09:46:39 +05:30
end
2016-08-24 12:49:21 +05:30
2016-09-29 09:46:39 +05:30
it 'does not show merge request button' do
page.within first('.all-branches li') do
expect(page).not_to have_content 'Merge Request'
end
2016-08-24 12:49:21 +05:30
end
end
2018-03-17 18:26:18 +05:30
def sorted_branches(repository, count:, sort_by:)
sorted_branches =
repository.branches_sorted_by(sort_by).first(count).map do |branch|
Regexp.escape(branch.name)
end
Regexp.new(sorted_branches.join('.*'))
end
2016-08-24 12:49:21 +05:30
end