summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorMayra Cabrera <mcabrera@gitlab.com>2018-03-29 20:11:36 -0600
committerMayra Cabrera <mcabrera@gitlab.com>2018-04-06 21:20:16 -0500
commit345ac03b7afb1dc9b941c53bc45cc3dfcf22e61c (patch)
tree42da609254928d746a961465d9ecfbff3ab71ad4 /spec
parent370fc05da7f95bf6621867a71d51493cf3899e25 (diff)
downloadgitlab-ce-345ac03b7afb1dc9b941c53bc45cc3dfcf22e61c.tar.gz
Address UX review
- Keep 'Deploy Section' open upon save, otherwise the token might get lost - When an error appears, display the error inside the form and also keep the Deploy Section open - Changue copy of revoke modal
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/projects/deploy_tokens_controller_spec.rb9
-rw-r--r--spec/controllers/projects/settings/repository_controller_spec.rb26
-rw-r--r--spec/features/projects/settings/repository_settings_spec.rb6
-rw-r--r--spec/services/deploy_tokens/create_service_spec.rb30
4 files changed, 49 insertions, 22 deletions
diff --git a/spec/controllers/projects/deploy_tokens_controller_spec.rb b/spec/controllers/projects/deploy_tokens_controller_spec.rb
index 0ade61f4380..f037aacfe8e 100644
--- a/spec/controllers/projects/deploy_tokens_controller_spec.rb
+++ b/spec/controllers/projects/deploy_tokens_controller_spec.rb
@@ -27,6 +27,11 @@ describe Projects::DeployTokensController do
subject
expect(flash[:notice]).to eq('Your new project deploy token has been created.')
end
+
+ it 'should redirect to project settings repository' do
+ subject
+ expect(response).to redirect_to project_settings_repository_path(project)
+ end
end
context 'with invalid params' do
@@ -36,9 +41,9 @@ describe Projects::DeployTokensController do
expect { subject }.not_to change(DeployToken, :count)
end
- it 'should include a flash alert with the error message' do
+ it 'should redirect to project settings repository' do
subject
- expect(flash[:alert]).to eq("Scopes can't be blank")
+ expect(response).to redirect_to project_settings_repository_path(project)
end
end
diff --git a/spec/controllers/projects/settings/repository_controller_spec.rb b/spec/controllers/projects/settings/repository_controller_spec.rb
index 03867661483..da4d3e5732d 100644
--- a/spec/controllers/projects/settings/repository_controller_spec.rb
+++ b/spec/controllers/projects/settings/repository_controller_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe Projects::Settings::RepositoryController do
+describe Projects::Settings::RepositoryController, :clean_gitlab_redis_shared_state do
let(:project) { create(:project_empty_repo, :public) }
let(:user) { create(:user) }
@@ -17,7 +17,7 @@ describe Projects::Settings::RepositoryController do
expect(response).to render_template(:show)
end
- context 'with no deploy token params' do
+ context 'with no deploy token attributes present' do
it 'should build an empty instance of DeployToken' do
get :show, namespace_id: project.namespace, project_id: project
@@ -29,17 +29,29 @@ describe Projects::Settings::RepositoryController do
end
end
- context 'when rendering an invalid deploy token' do
- let(:deploy_token_attributes) { attributes_for(:deploy_token, project_id: project.id) }
+ context 'with deploy token attributes present' do
+ let(:deploy_token_key) { "gitlab:deploy_token:#{project.id}:#{user.id}:attributes" }
- it 'should build an instance of DeployToken' do
- get :show, namespace_id: project.namespace, project_id: project, deploy_token: deploy_token_attributes
+ let(:deploy_token_attributes) do
+ {
+ name: 'test-token',
+ expires_at: Date.today + 1.month
+ }
+ end
+ before do
+ Gitlab::Redis::SharedState.with do |redis|
+ redis.set(deploy_token_key, deploy_token_attributes.to_json)
+ end
+
+ get :show, namespace_id: project.namespace, project_id: project
+ end
+
+ it 'should build an instance of DeployToken' do
deploy_token = assigns(:deploy_token)
expect(deploy_token).to be_an_instance_of(DeployToken)
expect(deploy_token.name).to eq(deploy_token_attributes[:name])
expect(deploy_token.expires_at.to_date).to eq(deploy_token_attributes[:expires_at].to_date)
- expect(deploy_token.scopes).to match_array(deploy_token_attributes[:scopes])
end
end
end
diff --git a/spec/features/projects/settings/repository_settings_spec.rb b/spec/features/projects/settings/repository_settings_spec.rb
index 1106a31d444..f0997b6809d 100644
--- a/spec/features/projects/settings/repository_settings_spec.rb
+++ b/spec/features/projects/settings/repository_settings_spec.rb
@@ -90,17 +90,16 @@ feature 'Repository settings' do
end
context 'Deploy tokens' do
- let(:deploy_token) { create(:deploy_token, project: project, expires_at: Date.today + 2.days) }
+ let(:deploy_token) { create(:deploy_token, project: project) }
before do
project.deploy_tokens << deploy_token
visit project_settings_repository_path(project)
- end
+ end
scenario 'view deploy tokens' do
within('.deploy-tokens') do
expect(page).to have_content(deploy_token.name)
- expect(page).to have_content('In 1 day')
expect(page).to have_content(deploy_token.scopes.join(", "))
end
end
@@ -121,7 +120,6 @@ feature 'Repository settings' do
click_link "Revoke #{deploy_token.name}"
expect(page).not_to have_content(deploy_token.name)
- expect(page).not_to have_content('In 1 day')
expect(page).not_to have_content(deploy_token.scopes.join(", "))
end
end
diff --git a/spec/services/deploy_tokens/create_service_spec.rb b/spec/services/deploy_tokens/create_service_spec.rb
index 84aa17971d6..df18213cf84 100644
--- a/spec/services/deploy_tokens/create_service_spec.rb
+++ b/spec/services/deploy_tokens/create_service_spec.rb
@@ -6,40 +6,52 @@ describe DeployTokens::CreateService, :clean_gitlab_redis_shared_state do
let(:deploy_token_params) { attributes_for(:deploy_token) }
describe '#execute' do
- subject { described_class.new(project, user, deploy_token_params) }
+ subject { described_class.new(project, user, deploy_token_params).execute }
context 'when the deploy token is valid' do
it 'should create a new DeployToken' do
- expect { subject.execute }.to change { DeployToken.count }.by(1)
+ expect { subject }.to change { DeployToken.count }.by(1)
end
- it 'should assign the DeployToken to the project' do
- subject.execute
+ it 'returns a DeployToken' do
+ expect(subject).to be_an_instance_of DeployToken
+ end
+ it 'should assign the DeployToken to the project' do
expect(subject.project).to eq(project)
end
it 'should store the token on redis' do
- subject.execute
- redis_key = DeployToken.redis_shared_state_key(user.id)
+ redis_key = subject.redis_shared_state_key(user.id)
expect(Gitlab::Redis::SharedState.with { |redis| redis.get(redis_key) }).not_to be_nil
end
+
+ it 'should not store deploy token attributes on redis' do
+ redis_key = subject.redis_shared_state_key(user.id) + ":attributes"
+
+ expect(Gitlab::Redis::SharedState.with { |redis| redis.get(redis_key) }).to be_nil
+ end
end
context 'when the deploy token is invalid' do
let(:deploy_token_params) { attributes_for(:deploy_token, scopes: []) }
it 'it should not create a new DeployToken' do
- expect { subject.execute }.not_to change { DeployToken.count }
+ expect { subject }.not_to change { DeployToken.count }
end
it 'should not store the token on redis' do
- subject.execute
- redis_key = DeployToken.redis_shared_state_key(user.id)
+ redis_key = subject.redis_shared_state_key(user.id)
expect(Gitlab::Redis::SharedState.with { |redis| redis.get(redis_key) }).to be_nil
end
+
+ it 'should store deploy token attributes on redis' do
+ redis_key = subject.redis_shared_state_key(user.id) + ":attributes"
+
+ expect(Gitlab::Redis::SharedState.with { |redis| redis.get(redis_key) }).not_to be_nil
+ end
end
end
end