Commit b900f3f0 authored by Jose Ivan Vargas's avatar Jose Ivan Vargas

Added test case for the available project keys

parent dd0589f8
......@@ -58,27 +58,7 @@ class Projects::ProtectedBranchesController < Projects::ApplicationController
push_access_levels_attributes: [:access_level, :id, :user_id, :_destroy, :group_id])
end
def load_protected_branches
@protected_branches = @project.protected_branches.order(:name).page(params[:page])
end
def access_levels_options
{
push_access_levels: {
roles: ProtectedBranch::PushAccessLevel.human_access_levels.map { |id, text| { id: id, text: text, before_divider: true } },
},
merge_access_levels: {
roles: ProtectedBranch::MergeAccessLevel.human_access_levels.map { |id, text| { id: id, text: text, before_divider: true } },
},
selected_merge_access_levels: @protected_branch.merge_access_levels.map { |access_level| access_level.user_id || access_level.access_level },
selected_push_access_levels: @protected_branch.push_access_levels.map { |access_level| access_level.user_id || access_level.access_level }
}
end
def load_gon_index
params = { open_branches: @project.open_branches.map { |br| { text: br.name, id: br.name, title: br.name } } }
params.merge!(current_project_id: @project.id) if @project
gon.push(params.merge(access_levels_options))
end
end
......@@ -34,8 +34,12 @@ module Projects
def access_levels_options
{
push_access_levels: ProtectedBranch::PushAccessLevel.human_access_levels.map { |id, text| { id: id, text: text } },
merge_access_levels: ProtectedBranch::MergeAccessLevel.human_access_levels.map { |id, text| { id: id, text: text } },
push_access_levels: {
roles: ProtectedBranch::PushAccessLevel.human_access_levels.map { |id, text| { id: id, text: text, before_divider: true } },
},
merge_access_levels: {
roles: ProtectedBranch::MergeAccessLevel.human_access_levels.map { |id, text| { id: id, text: text, before_divider: true } },
},
selected_merge_access_levels: @protected_branch.merge_access_levels.map { |access_level| access_level.user_id || access_level.access_level },
selected_push_access_levels: @protected_branch.push_access_levels.map { |access_level| access_level.user_id || access_level.access_level }
}
......
......@@ -36,20 +36,27 @@ describe Projects::Settings::DeployKeysPresenter do
end
describe '#available_keys/#available_project_keys' do
let(:other_deploy_key) { create(:another_deploy_key) }
before do
project_key = create(:deploy_keys_project, deploy_key: other_deploy_key)
project_key.project.add_developer(user)
end
it 'returns the current available_keys' do
expect(presenter.available_keys).to be_empty
expect(presenter.available_keys).not_to be_empty
end
it 'returns the current available_project_keys' do
expect(presenter.available_project_keys).to be_empty
expect(presenter.available_project_keys).not_to be_empty
end
it 'returns false if any available_project_keys are enabled' do
expect(presenter.any_available_project_keys_enabled?).to eq(false)
expect(presenter.any_available_project_keys_enabled?).to eq(true)
end
it 'returns the available_project_keys size' do
expect(presenter.available_project_keys_size).to eq(0)
expect(presenter.available_project_keys_size).to eq(1)
end
it 'shows if there is an available key' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment