Skip to content
Snippets Groups Projects
Commit f46c25cd authored by Phil Hughes's avatar Phil Hughes
Browse files

Added tests

parent 6259deb8
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -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|
Loading
Loading
Loading
Loading
@@ -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?
Loading
Loading
Loading
Loading
@@ -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
Loading
Loading
@@ -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
Loading
Loading
@@ -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) } }
Loading
Loading
Loading
Loading
@@ -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
 
Loading
Loading
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment