summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorAdam Niedzielski <adamsunday@gmail.com>2016-10-28 11:31:45 +0200
committerAdam Niedzielski <adamsunday@gmail.com>2016-10-28 11:31:45 +0200
commite2c603696a9647c15cd154156f13d0e203a930f1 (patch)
tree22f64b82526f74fabb9009db8f6932c4e8d74d12 /spec
parent20a7db4483904c7280093a0309a63dfd1b7ef72e (diff)
downloadgitlab-ce-e2c603696a9647c15cd154156f13d0e203a930f1.tar.gz
Pass user instance to Labels::FindOrCreateService or skip_authorization: trueadam-fix-labels-find-or-create
Do not pass project.owner because it may return a group and Labels::FindOrCreateService throws an error in this case. Fixes #23694.
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/projects/labels_controller_spec.rb21
-rw-r--r--spec/services/labels/find_or_create_service_spec.rb51
2 files changed, 47 insertions, 25 deletions
diff --git a/spec/controllers/projects/labels_controller_spec.rb b/spec/controllers/projects/labels_controller_spec.rb
index 41df63d445a..8faecec0063 100644
--- a/spec/controllers/projects/labels_controller_spec.rb
+++ b/spec/controllers/projects/labels_controller_spec.rb
@@ -2,7 +2,7 @@ require 'spec_helper'
describe Projects::LabelsController do
let(:group) { create(:group) }
- let(:project) { create(:project, namespace: group) }
+ let(:project) { create(:empty_project, namespace: group) }
let(:user) { create(:user) }
before do
@@ -73,16 +73,27 @@ describe Projects::LabelsController do
describe 'POST #generate' do
let(:admin) { create(:admin) }
- let(:project) { create(:empty_project) }
before do
sign_in(admin)
end
- it 'creates labels' do
- post :generate, namespace_id: project.namespace.to_param, project_id: project.to_param
+ context 'personal project' do
+ let(:personal_project) { create(:empty_project) }
- expect(response).to have_http_status(302)
+ it 'creates labels' do
+ post :generate, namespace_id: personal_project.namespace.to_param, project_id: personal_project.to_param
+
+ expect(response).to have_http_status(302)
+ end
+ end
+
+ context 'project belonging to a group' do
+ it 'creates labels' do
+ post :generate, namespace_id: project.namespace.to_param, project_id: project.to_param
+
+ expect(response).to have_http_status(302)
+ end
end
end
end
diff --git a/spec/services/labels/find_or_create_service_spec.rb b/spec/services/labels/find_or_create_service_spec.rb
index cbfc63de811..7a9b34f9f96 100644
--- a/spec/services/labels/find_or_create_service_spec.rb
+++ b/spec/services/labels/find_or_create_service_spec.rb
@@ -2,7 +2,6 @@ require 'spec_helper'
describe Labels::FindOrCreateService, services: true do
describe '#execute' do
- let(:user) { create(:user) }
let(:group) { create(:group) }
let(:project) { create(:project, namespace: group) }
@@ -14,37 +13,49 @@ describe Labels::FindOrCreateService, services: true do
}
end
- subject(:service) { described_class.new(user, project, params) }
-
- before do
- project.team << [user, :developer]
- end
+ context 'when acting on behalf of a specific user' do
+ let(:user) { create(:user) }
+ subject(:service) { described_class.new(user, project, params) }
+ before do
+ project.team << [user, :developer]
+ end
- context 'when label does not exist at group level' do
- it 'creates a new label at project level' do
- expect { service.execute }.to change(project.labels, :count).by(1)
+ context 'when label does not exist at group level' do
+ it 'creates a new label at project level' do
+ expect { service.execute }.to change(project.labels, :count).by(1)
+ end
end
- end
- context 'when label exists at group level' do
- it 'returns the group label' do
- group_label = create(:group_label, group: group, title: 'Security')
+ context 'when label exists at group level' do
+ it 'returns the group label' do
+ group_label = create(:group_label, group: group, title: 'Security')
- expect(service.execute).to eq group_label
+ expect(service.execute).to eq group_label
+ end
end
- end
- context 'when label does not exist at group level' do
- it 'creates a new label at project leve' do
- expect { service.execute }.to change(project.labels, :count).by(1)
+ context 'when label does not exist at group level' do
+ it 'creates a new label at project leve' do
+ expect { service.execute }.to change(project.labels, :count).by(1)
+ end
+ end
+
+ context 'when label exists at project level' do
+ it 'returns the project label' do
+ project_label = create(:label, project: project, title: 'Security')
+
+ expect(service.execute).to eq project_label
+ end
end
end
- context 'when label exists at project level' do
+ context 'when authorization is not required' do
+ subject(:service) { described_class.new(nil, project, params) }
+
it 'returns the project label' do
project_label = create(:label, project: project, title: 'Security')
- expect(service.execute).to eq project_label
+ expect(service.execute(skip_authorization: true)).to eq project_label
end
end
end