diff options
author | Takuya Noguchi <takninnovationresearch@gmail.com> | 2017-11-15 23:56:36 +0900 |
---|---|---|
committer | Takuya Noguchi <takninnovationresearch@gmail.com> | 2018-03-06 21:28:14 +0900 |
commit | 580d8953636266e40802fd8ea525c4908ebc8b9f (patch) | |
tree | b643fc68bbb40643c8932f8b456173669a334a81 /spec | |
parent | 65348cf07bafef5efc1c9665d3efdb5a1bdd7128 (diff) | |
download | gitlab-ce-580d8953636266e40802fd8ea525c4908ebc8b9f.tar.gz |
Add overview of branches and a filter for active/stale branches
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/projects/branches_controller_spec.rb | 33 | ||||
-rw-r--r-- | spec/features/projects/branches/download_buttons_spec.rb | 2 | ||||
-rw-r--r-- | spec/features/projects/branches_spec.rb | 137 | ||||
-rw-r--r-- | spec/features/projects/environments/environment_spec.rb | 2 | ||||
-rw-r--r-- | spec/features/projects/merge_request_button_spec.rb | 4 | ||||
-rw-r--r-- | spec/lib/gitlab/git/branch_spec.rb | 64 |
6 files changed, 226 insertions, 16 deletions
diff --git a/spec/controllers/projects/branches_controller_spec.rb b/spec/controllers/projects/branches_controller_spec.rb index 734396ddf7b..3b9e06cb5ad 100644 --- a/spec/controllers/projects/branches_controller_spec.rb +++ b/spec/controllers/projects/branches_controller_spec.rb @@ -407,10 +407,43 @@ describe Projects::BranchesController do get :index, namespace_id: project.namespace, project_id: project, + state: 'all', format: :html expect(response).to have_gitlab_http_status(200) end end + + context 'when depreated sort/search/page parameters are specified' do + it 'returns with a status 301 when sort specified' do + get :index, + namespace_id: project.namespace, + project_id: project, + sort: 'updated_asc', + format: :html + + expect(response).to redirect_to project_branches_filtered_path(project, state: 'all') + end + + it 'returns with a status 301 when search specified' do + get :index, + namespace_id: project.namespace, + project_id: project, + search: 'feature', + format: :html + + expect(response).to redirect_to project_branches_filtered_path(project, state: 'all') + end + + it 'returns with a status 301 when page specified' do + get :index, + namespace_id: project.namespace, + project_id: project, + page: 2, + format: :html + + expect(response).to redirect_to project_branches_filtered_path(project, state: 'all') + end + end end end diff --git a/spec/features/projects/branches/download_buttons_spec.rb b/spec/features/projects/branches/download_buttons_spec.rb index 39bcea013e7..605298ba8ab 100644 --- a/spec/features/projects/branches/download_buttons_spec.rb +++ b/spec/features/projects/branches/download_buttons_spec.rb @@ -29,7 +29,7 @@ feature 'Download buttons in branches page' do describe 'when checking branches' do context 'with artifacts' do before do - visit project_branches_path(project, search: 'binary-encoding') + visit project_branches_filtered_path(project, state: 'all', search: 'binary-encoding') end scenario 'shows download artifacts button' do diff --git a/spec/features/projects/branches_spec.rb b/spec/features/projects/branches_spec.rb index 2fddd274078..2a9d9e6416c 100644 --- a/spec/features/projects/branches_spec.rb +++ b/spec/features/projects/branches_spec.rb @@ -11,15 +11,109 @@ describe 'Branches' do project.add_developer(user) end - describe 'Initial branches page' do - it 'shows all the branches sorted by last updated by default' do + context 'on the projects with 6 active branches and 4 stale branches' do + let(:project) { create(:project, :public, :empty_repo) } + let(:repository) { project.repository } + let(:threshold) { Gitlab::Git::Branch::STALE_BRANCH_THRESHOLD } + + before do + # Add 4 stale branches + (1..4).reverse_each do |i| + Timecop.freeze((threshold + i).ago) { create_file(message: "a commit in stale-#{i}", branch_name: "stale-#{i}") } + end + # Add 6 active branches + (1..6).each do |i| + Timecop.freeze((threshold - i).ago) { create_file(message: "a commit in active-#{i}", branch_name: "active-#{i}") } + end + end + + describe 'Overview page of the branches' do + it 'shows the first 5 active branches and the first 4 stale branches sorted by last updated' do + visit project_branches_path(project) + + expect(page).to have_content(sorted_branches(repository, count: 5, sort_by: :updated_desc, state: 'active')) + expect(page).to have_content(sorted_branches(repository, count: 4, sort_by: :updated_desc, state: 'stale')) + + expect(page).to have_link('Show more active branches', href: project_branches_filtered_path(project, state: 'active')) + expect(page).not_to have_content('Show more stale branches') + end + end + + describe 'Active branches page' do + it 'shows 6 active branches sorted by last updated' do + visit project_branches_filtered_path(project, state: 'active') + + expect(page).to have_content(sorted_branches(repository, count: 6, sort_by: :updated_desc, state: 'active')) + end + end + + describe 'Stale branches page' do + it 'shows 4 active branches sorted by last updated' do + visit project_branches_filtered_path(project, state: 'stale') + + expect(page).to have_content(sorted_branches(repository, count: 4, sort_by: :updated_desc, state: 'stale')) + end + end + + describe 'All branches page' do + it 'shows 10 branches sorted by last updated' do + visit project_branches_filtered_path(project, state: 'all') + + expect(page).to have_content(sorted_branches(repository, count: 10, sort_by: :updated_desc)) + end + end + + context 'with branches over more than one page' do + before do + allow(Kaminari.config).to receive(:default_per_page).and_return(5) + end + + it 'shows only default_per_page active branches sorted by last updated' do + visit project_branches_filtered_path(project, state: 'active') + + expect(page).to have_content(sorted_branches(repository, count: Kaminari.config.default_per_page, sort_by: :updated_desc, state: 'active')) + end + + it 'shows only default_per_page branches sorted by last updated on All branches' do + visit project_branches_filtered_path(project, state: 'all') + + expect(page).to have_content(sorted_branches(repository, count: Kaminari.config.default_per_page, sort_by: :updated_desc)) + end + end + end + + describe 'Find branches' do + it 'shows filtered branches', :js do 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 on Overview' do + it 'removes branch after confirmation', :js do + visit project_branches_filtered_path(project, state: 'all') + + expect(all('.all-branches').last).to have_selector('li', count: 20) + accept_confirm { find('.js-branch-add-pdf-text-binary .btn-remove').click } + + expect(all('.all-branches').last).to have_selector('li', count: 19) + end + end + + describe 'All branches page' do + it 'shows all the branches sorted by last updated by default' do + visit project_branches_filtered_path(project, state: 'all') + expect(page).to have_content(sorted_branches(repository, count: 20, sort_by: :updated_desc)) end it 'sorts the branches by name' do - visit project_branches_path(project) + visit project_branches_filtered_path(project, state: 'all') click_button "Last updated" # Open sorting dropdown click_link "Name" @@ -28,7 +122,7 @@ describe 'Branches' do end it 'sorts the branches by oldest updated' do - visit project_branches_path(project) + visit project_branches_filtered_path(project, state: 'all') click_button "Last updated" # Open sorting dropdown click_link "Oldest updated" @@ -41,13 +135,13 @@ describe 'Branches' do %w(one two three four five).each { |ref| repository.add_branch(user, ref, 'master') } - expect { visit project_branches_path(project) }.not_to exceed_query_limit(control_count) + expect { visit project_branches_filtered_path(project, state: 'all') }.not_to exceed_query_limit(control_count) end end - describe 'Find branches' do + describe 'Find branches on All branches' do it 'shows filtered branches', :js do - visit project_branches_path(project) + visit project_branches_filtered_path(project, state: 'all') fill_in 'branch-search', with: 'fix' find('#branch-search').native.send_keys(:enter) @@ -57,9 +151,9 @@ describe 'Branches' do end end - describe 'Delete unprotected branch' do + describe 'Delete unprotected branch on All branches' do it 'removes branch after confirmation', :js do - visit project_branches_path(project) + visit project_branches_filtered_path(project, state: 'all') fill_in 'branch-search', with: 'fix' @@ -73,6 +167,19 @@ describe 'Branches' do expect(find('.all-branches')).to have_selector('li', count: 0) end end + + context 'on project with 0 branch' do + let(:project) { create(:project, :public, :empty_repo) } + let(:repository) { project.repository } + + describe '0 branches on Overview' do + it 'shows warning' do + visit project_branches_path(project) + + expect(page).not_to have_selector('.all-branches') + end + end + end end context 'logged in as master' do @@ -83,7 +190,7 @@ describe 'Branches' do describe 'Initial branches page' do it 'shows description for admin' do - visit project_branches_path(project) + visit project_branches_filtered_path(project, state: 'all') expect(page).to have_content("Protected branches can be managed in project settings") end @@ -102,12 +209,18 @@ describe 'Branches' do end end - def sorted_branches(repository, count:, sort_by:) + def sorted_branches(repository, count:, sort_by:, state: nil) + branches = repository.branches_sorted_by(sort_by) + branches = branches.select { |b| state == 'active' ? b.active? : b.stale? } if state sorted_branches = - repository.branches_sorted_by(sort_by).first(count).map do |branch| + branches.first(count).map do |branch| Regexp.escape(branch.name) end Regexp.new(sorted_branches.join('.*')) end + + def create_file(message: 'message', branch_name:) + repository.create_file(user, generate(:branch), 'content', message: message, branch_name: branch_name) + end end diff --git a/spec/features/projects/environments/environment_spec.rb b/spec/features/projects/environments/environment_spec.rb index 64e600144e0..b233af83eec 100644 --- a/spec/features/projects/environments/environment_spec.rb +++ b/spec/features/projects/environments/environment_spec.rb @@ -234,7 +234,7 @@ feature 'Environment' do end scenario 'user deletes the branch with running environment' do - visit project_branches_path(project, search: 'feature') + visit project_branches_filtered_path(project, state: 'all', search: 'feature') remove_branch_with_hooks(project, user, 'feature') do page.within('.js-branch-feature') { find('a.btn-remove').click } diff --git a/spec/features/projects/merge_request_button_spec.rb b/spec/features/projects/merge_request_button_spec.rb index 85d518c0cc3..40689964b91 100644 --- a/spec/features/projects/merge_request_button_spec.rb +++ b/spec/features/projects/merge_request_button_spec.rb @@ -81,8 +81,8 @@ feature 'Merge Request button' do context 'on branches page' do it_behaves_like 'Merge request button only shown when allowed' do let(:label) { 'Merge request' } - let(:url) { project_branches_path(project, search: 'feature') } - let(:fork_url) { project_branches_path(forked_project, search: 'feature') } + let(:url) { project_branches_filtered_path(project, state: 'all', search: 'feature') } + let(:fork_url) { project_branches_filtered_path(forked_project, state: 'all', search: 'feature') } end end diff --git a/spec/lib/gitlab/git/branch_spec.rb b/spec/lib/gitlab/git/branch_spec.rb index 708870060e7..a19155ed5b0 100644 --- a/spec/lib/gitlab/git/branch_spec.rb +++ b/spec/lib/gitlab/git/branch_spec.rb @@ -59,5 +59,69 @@ describe Gitlab::Git::Branch, seed_helper: true do it { expect(branch.dereferenced_target.sha).to eq(SeedRepo::LastCommit::ID) } end + context 'with active, stale and future branches' do + let(:repository) do + Gitlab::Git::Repository.new('default', TEST_MUTABLE_REPO_PATH, '') + end + + let(:user) { create(:user) } + let(:committer) do + Gitlab::Git.committer_hash(email: user.email, name: user.name) + end + let(:params) do + parents = [repository.rugged.head.target] + tree = parents.first.tree + + { + message: 'commit message', + author: committer, + committer: committer, + tree: tree, + parents: parents + } + end + let(:stale_sha) { Timecop.freeze(Gitlab::Git::Branch::STALE_BRANCH_THRESHOLD.ago - 5.days) { create_commit } } + let(:active_sha) { Timecop.freeze(Gitlab::Git::Branch::STALE_BRANCH_THRESHOLD.ago + 5.days) { create_commit } } + let(:future_sha) { Timecop.freeze(100.days.since) { create_commit } } + + before do + repository.create_branch('stale-1', stale_sha) + repository.create_branch('active-1', active_sha) + repository.create_branch('future-1', future_sha) + end + + after do + ensure_seeds + end + + describe 'examine if the branch is active or stale' do + let(:stale_branch) { repository.find_branch('stale-1') } + let(:active_branch) { repository.find_branch('active-1') } + let(:future_branch) { repository.find_branch('future-1') } + + describe '#active?' do + it { expect(stale_branch.active?).to be_falsey } + it { expect(active_branch.active?).to be_truthy } + it { expect(future_branch.active?).to be_truthy } + end + + describe '#stale?' do + it { expect(stale_branch.stale?).to be_truthy } + it { expect(active_branch.stale?).to be_falsey } + it { expect(future_branch.stale?).to be_falsey } + end + + describe '#state' do + it { expect(stale_branch.state).to eq(:stale) } + it { expect(active_branch.state).to eq(:active) } + it { expect(future_branch.state).to eq(:active) } + end + end + end + it { expect(repository.branches.size).to eq(SeedRepo::Repo::BRANCHES.size) } + + def create_commit + repository.create_commit(params.merge(committer: committer.merge(time: Time.now))) + end end |