diff options
author | Phil Hughes <me@iamphill.com> | 2016-05-18 11:06:33 +0100 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2016-06-14 10:09:06 +0100 |
commit | f46c25cd0a189807386e491eae4afc2d3819e24d (patch) | |
tree | 706f3829aa852c9e15b03ad614ab814c55a91288 | |
parent | 6259deb84f6a69338f789de93117f339c8ee43ba (diff) | |
download | gitlab-ce-branches-ui.tar.gz |
Added testsbranches-ui
-rw-r--r-- | app/controllers/projects/branches_controller.rb | 3 | ||||
-rw-r--r-- | app/controllers/projects/protected_branches_controller.rb | 1 | ||||
-rw-r--r-- | app/views/projects/branches/_branch.html.haml | 10 | ||||
-rw-r--r-- | features/steps/project/commits/branches.rb | 4 | ||||
-rw-r--r-- | spec/features/projects/branches_spec.rb | 75 |
5 files changed, 85 insertions, 8 deletions
diff --git a/app/controllers/projects/branches_controller.rb b/app/controllers/projects/branches_controller.rb index dd9508da049..1f7a114fc3d 100644 --- a/app/controllers/projects/branches_controller.rb +++ b/app/controllers/projects/branches_controller.rb @@ -8,6 +8,9 @@ class Projects::BranchesController < Projects::ApplicationController def index @sort = params[:sort] || 'name' @branches = @repository.branches_sorted_by(@sort) + branch_names = @branches.map(&:name) + @protected_branches = @project.protected_branches.where(name: branch_names) + @branches = Kaminari.paginate_array(@branches).page(params[:page]) @max_commits = @branches.reduce(0) do |memo, branch| diff --git a/app/controllers/projects/protected_branches_controller.rb b/app/controllers/projects/protected_branches_controller.rb index ed170bb5595..3f541fe18dc 100644 --- a/app/controllers/projects/protected_branches_controller.rb +++ b/app/controllers/projects/protected_branches_controller.rb @@ -11,7 +11,6 @@ class Projects::ProtectedBranchesController < Projects::ApplicationController end def create - branch_params = protected_branch_params @project.protected_branches.create(protected_branch_params) if params[:protected_branch][:branch_index].nil? diff --git a/app/views/projects/branches/_branch.html.haml b/app/views/projects/branches/_branch.html.haml index 3e122a3f1b1..11b61f3020f 100644 --- a/app/views/projects/branches/_branch.html.haml +++ b/app/views/projects/branches/_branch.html.haml @@ -3,7 +3,7 @@ - diverging_commit_counts = @repository.diverging_commit_counts(branch) - number_commits_behind = diverging_commit_counts[:behind] - number_commits_ahead = diverging_commit_counts[:ahead] -- protected_branch = @project.protected_branches.find_by_name(branch.name) +- protected_branch = @protected_branches.find_by_name(branch.name) %li(class="js-branch-#{branch.name}") %div = link_to namespace_project_tree_path(@project.namespace, @project, branch.name) do @@ -32,7 +32,7 @@ - if can? current_user, :admin_project, @project .dropdown.inline - %button.btn.btn-default.btn-xs{ type: "button", data: { toggle: "dropdown" } } + %button.btn.btn-default.btn-xs.js-branch-settings-toggle{ type: "button", data: { toggle: "dropdown" } } %span.sr-only Settings = icon("gear") %span.caret @@ -46,13 +46,13 @@ = button_tag type: "submit", class: "dropdown-link #{"is-active" if @project.protected_branch? branch.name}", disabled: @project.protected_branch?(branch.name) do Protected %li - = link_to "Unprotect", [@project.namespace.becomes(Namespace), @project, protected_branch, branch_index: true], data: { confirm: 'Branch will be writable for developers. Are you sure?' }, method: :delete, class: ("is-active" if !@project.protected_branch? branch.name) + = link_to "Unprotected", [@project.namespace.becomes(Namespace), @project, protected_branch, branch_index: true], data: { confirm: 'Branch will be writable for developers. Are you sure?' }, method: :delete, class: ("is-active" if !@project.protected_branch? branch.name) - if can_remove_branch?(@project, branch.name) %li.divider %li - = link_to namespace_project_branch_path(@project.namespace, @project, branch.name), class: "btn btn-warning branch-delete-button block", title: "Delete branch", method: :delete, data: { confirm: "Deleting the '#{branch.name}' branch cannot be undone. Are you sure?" }, remote: true do + = link_to namespace_project_branch_path(@project.namespace, @project, branch.name), class: "btn btn-warning branch-delete-button block", title: "Delete branch", method: :delete, data: { confirm: "Deleting the '#{branch.name}' branch cannot be undone. Are you sure?" } do Delete branch - - else + - elsif !protected_branch.nil? %li.divider %li %a.js-branch-dev-push{ href: "#", class: ("is-active" if @project.developers_can_push_to_protected_branch?(branch.name)), data: { value: protected_branch.id, url: namespace_project_protected_branch_path(@project.namespace, @project, protected_branch) } } diff --git a/features/steps/project/commits/branches.rb b/features/steps/project/commits/branches.rb index 94ad4ceabca..ce0c9cde116 100644 --- a/features/steps/project/commits/branches.rb +++ b/features/steps/project/commits/branches.rb @@ -75,8 +75,8 @@ class Spinach::Features::ProjectCommitsBranches < Spinach::FeatureSteps step "I click branch 'improve/awesome' delete link" do page.within '.js-branch-improve\/awesome' do - find('.branch-delete-button', visible: false).click - sleep 0.05 + first('.js-branch-settings-toggle').click + find('.branch-delete-button').click end end diff --git a/spec/features/projects/branches_spec.rb b/spec/features/projects/branches_spec.rb new file mode 100644 index 00000000000..7ac58b4dd02 --- /dev/null +++ b/spec/features/projects/branches_spec.rb @@ -0,0 +1,75 @@ +require 'rails_helper' + +feature 'Branches', feature: true, js: true do + let(:project) { create(:project) } + let(:user) { create(:user) } + + before do + project.team << [user, :master] + login_as user + + visit namespace_project_branches_path(project.namespace, project) + end + + it 'should show list of branches' do + page.within '.all-branches' do + expect(page).to have_content project.repository.branches.first.name + end + end + + it 'should protect a branch' do + branch_el = first('.all-branches li') + first('.js-branch-settings-toggle').click + + page.within branch_el do + click_button 'Protected' + end + + expect(page).to have_content 'protected' + end + + it 'should unprotect branch' do + branch_el = first('.all-branches li') + first('.js-branch-settings-toggle').click + + page.within branch_el do + click_button 'Protected' + end + + expect(page).to have_content 'protected' + + first('.js-branch-settings-toggle').click + click_link 'Unprotected' + + expect(page).to have_no_content 'protected' + end + + it 'should allow developers to push' do + branch_el = first('.all-branches li') + first('.js-branch-settings-toggle').click + page.within branch_el do + click_button 'Protected' + end + expect(page).to have_content 'protected' + + first('.js-branch-settings-toggle').click + + branch_el = first('.all-branches li') + page.within branch_el do + click_link 'Developers can push' + end + + expect(page).to have_selector('.js-branch-dev-push.is-active', visible: false) + end + + it 'should allow branch to be deleted' do + branch_el = first('.all-branches li') + branch_name = project.repository.branches.first.name + first('.js-branch-settings-toggle').click + + page.within branch_el do + click_link 'Delete branch' + end + expect(page).to have_no_content branch_name + end +end |