2016-07-07 12:19:21 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-06-29 00:13:10 -04:00
|
|
|
describe 'Branches' do
|
2017-06-19 22:06:13 -04:00
|
|
|
let(:user) { create(:user) }
|
2017-07-24 18:51:14 -04:00
|
|
|
let(:project) { create(:project, :public, :repository) }
|
2016-07-07 12:19:21 -04:00
|
|
|
let(:repository) { project.repository }
|
|
|
|
|
2017-05-08 03:41:58 -04:00
|
|
|
context 'logged in as developer' do
|
2016-09-02 09:33:24 -04:00
|
|
|
before do
|
2017-06-19 22:06:13 -04:00
|
|
|
sign_in(user)
|
|
|
|
project.team << [user, :developer]
|
2016-09-02 09:33:24 -04:00
|
|
|
end
|
2016-07-07 12:19:21 -04:00
|
|
|
|
2016-09-02 09:33:24 -04:00
|
|
|
describe 'Initial branches page' do
|
2017-09-15 07:25:12 -04:00
|
|
|
it 'shows all the branches sorted by last updated by default' do
|
2017-06-29 13:06:35 -04:00
|
|
|
visit project_branches_path(project)
|
2016-07-07 12:19:21 -04:00
|
|
|
|
2017-09-15 07:25:12 -04:00
|
|
|
expect(page).to have_content(sorted_branches(repository, count: 20, sort_by: :updated_desc))
|
2016-09-02 09:33:24 -04:00
|
|
|
end
|
2017-03-13 12:00:07 -04:00
|
|
|
|
2017-06-28 15:38:00 -04:00
|
|
|
it 'sorts the branches by name' do
|
2017-06-29 13:06:35 -04:00
|
|
|
visit project_branches_path(project)
|
2017-06-28 15:38:00 -04:00
|
|
|
|
2017-07-28 12:52:40 -04:00
|
|
|
click_button "Last updated" # Open sorting dropdown
|
2017-06-28 15:38:00 -04:00
|
|
|
click_link "Name"
|
|
|
|
|
2017-09-15 07:25:12 -04:00
|
|
|
expect(page).to have_content(sorted_branches(repository, count: 20, sort_by: :name))
|
2017-06-28 15:38:00 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'sorts the branches by oldest updated' do
|
2017-06-29 13:06:35 -04:00
|
|
|
visit project_branches_path(project)
|
2017-06-28 15:38:00 -04:00
|
|
|
|
2017-07-28 12:52:40 -04:00
|
|
|
click_button "Last updated" # Open sorting dropdown
|
2017-06-28 15:38:00 -04:00
|
|
|
click_link "Oldest updated"
|
|
|
|
|
2017-09-15 07:25:12 -04:00
|
|
|
expect(page).to have_content(sorted_branches(repository, count: 20, sort_by: :updated_asc))
|
2016-09-02 09:33:24 -04:00
|
|
|
end
|
2017-03-13 12:00:07 -04:00
|
|
|
|
|
|
|
it 'avoids a N+1 query in branches index' do
|
2017-06-29 13:06:35 -04:00
|
|
|
control_count = ActiveRecord::QueryRecorder.new { visit project_branches_path(project) }.count
|
2017-03-13 12:00:07 -04:00
|
|
|
|
2017-06-19 22:06:13 -04:00
|
|
|
%w(one two three four five).each { |ref| repository.add_branch(user, ref, 'master') }
|
2017-03-13 12:00:07 -04:00
|
|
|
|
2017-06-29 13:06:35 -04:00
|
|
|
expect { visit project_branches_path(project) }.not_to exceed_query_limit(control_count)
|
2017-03-13 12:00:07 -04:00
|
|
|
end
|
2016-09-02 09:33:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'Find branches' do
|
2017-10-03 04:35:01 -04:00
|
|
|
it 'shows filtered branches', :js do
|
2017-06-29 13:06:35 -04:00
|
|
|
visit project_branches_path(project)
|
2016-09-02 09:33:24 -04:00
|
|
|
|
|
|
|
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
|
2016-07-07 12:19:21 -04:00
|
|
|
end
|
2017-05-08 03:41:58 -04:00
|
|
|
|
|
|
|
describe 'Delete unprotected branch' do
|
2017-10-03 04:35:01 -04:00
|
|
|
it 'removes branch after confirmation', :js do
|
2017-06-29 13:06:35 -04:00
|
|
|
visit project_branches_path(project)
|
2017-05-08 03:41:58 -04:00
|
|
|
|
|
|
|
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)
|
2017-11-02 15:04:27 -04:00
|
|
|
accept_confirm { find('.js-branch-fix .btn-remove').click }
|
2017-05-08 03:41:58 -04:00
|
|
|
|
|
|
|
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
|
2017-06-19 22:06:13 -04:00
|
|
|
sign_in(user)
|
|
|
|
project.team << [user, :master]
|
2017-05-08 03:41:58 -04:00
|
|
|
end
|
|
|
|
|
2017-07-18 12:55:48 -04:00
|
|
|
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-07-07 12:19:21 -04:00
|
|
|
end
|
|
|
|
|
2016-09-02 09:33:24 -04:00
|
|
|
context 'logged out' do
|
|
|
|
before do
|
2017-06-29 13:06:35 -04:00
|
|
|
visit project_branches_path(project)
|
2016-09-02 09:33:24 -04:00
|
|
|
end
|
2016-07-07 12:19:21 -04:00
|
|
|
|
2016-09-02 09:33:24 -04:00
|
|
|
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-07-07 12:19:21 -04:00
|
|
|
end
|
|
|
|
end
|
2017-09-15 07:25:12 -04:00
|
|
|
|
|
|
|
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-07-07 12:19:21 -04:00
|
|
|
end
|