2017-01-31 09:12:02 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Projects::Settings::DeployKeysPresenter do
|
|
|
|
let(:project) { create(:empty_project) }
|
|
|
|
let(:user) { create(:user) }
|
2017-02-21 16:37:00 -05:00
|
|
|
let(:deploy_key) { create(:deploy_key, public: true) }
|
|
|
|
|
|
|
|
let!(:deploy_keys_project) do
|
|
|
|
create(:deploy_keys_project, project: project, deploy_key: deploy_key)
|
|
|
|
end
|
2017-01-31 09:12:02 -05:00
|
|
|
|
|
|
|
subject(:presenter) do
|
|
|
|
described_class.new(project, current_user: user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'inherits from Gitlab::View::Presenter::Simple' do
|
|
|
|
expect(described_class.superclass).to eq(Gitlab::View::Presenter::Simple)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#enabled_keys' do
|
2017-02-21 16:37:00 -05:00
|
|
|
it 'returns currently enabled keys' do
|
|
|
|
expect(presenter.enabled_keys).to eq [deploy_keys_project.deploy_key]
|
2017-01-31 09:12:02 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not contain enabled_keys inside available_keys' do
|
|
|
|
expect(presenter.available_keys).not_to include deploy_key
|
|
|
|
end
|
2017-02-21 16:37:00 -05:00
|
|
|
|
|
|
|
it 'returns the enabled_keys size' do
|
|
|
|
expect(presenter.enabled_keys_size).to eq(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns true if there is any enabled_keys' do
|
|
|
|
expect(presenter.any_keys_enabled?).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#available_keys/#available_project_keys' do
|
2017-03-06 15:42:04 -05:00
|
|
|
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
|
|
|
|
|
2017-02-21 16:37:00 -05:00
|
|
|
it 'returns the current available_keys' do
|
2017-03-06 15:42:04 -05:00
|
|
|
expect(presenter.available_keys).not_to be_empty
|
2017-02-21 16:37:00 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the current available_project_keys' do
|
2017-03-06 15:42:04 -05:00
|
|
|
expect(presenter.available_project_keys).not_to be_empty
|
2017-02-21 16:37:00 -05:00
|
|
|
end
|
|
|
|
|
2017-03-03 12:41:15 -05:00
|
|
|
it 'returns false if any available_project_keys are enabled' do
|
2017-03-06 15:42:04 -05:00
|
|
|
expect(presenter.any_available_project_keys_enabled?).to eq(true)
|
2017-02-21 16:37:00 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the available_project_keys size' do
|
2017-03-06 15:42:04 -05:00
|
|
|
expect(presenter.available_project_keys_size).to eq(1)
|
2017-02-21 16:37:00 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows if there is an available key' do
|
|
|
|
expect(presenter.key_available?(deploy_key)).to eq(false)
|
|
|
|
end
|
2017-01-31 09:12:02 -05:00
|
|
|
end
|
|
|
|
end
|