Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/graphql/mutations/commits/create_spec.rb')
-rw-r--r--spec/graphql/mutations/commits/create_spec.rb289
1 files changed, 162 insertions, 127 deletions
diff --git a/spec/graphql/mutations/commits/create_spec.rb b/spec/graphql/mutations/commits/create_spec.rb
index 9fc9c731b96..fd0c2c46b2e 100644
--- a/spec/graphql/mutations/commits/create_spec.rb
+++ b/spec/graphql/mutations/commits/create_spec.rb
@@ -9,6 +9,7 @@ RSpec.describe Mutations::Commits::Create do
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project, :public, :repository) }
+ let_it_be(:group) { create(:group, :public) }
let(:context) do
GraphQL::Query::Context.new(
@@ -39,174 +40,208 @@ RSpec.describe Mutations::Commits::Create do
let(:mutated_commit) { subject[:commit] }
- it 'raises an error if the resource is not accessible to the user' do
- expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
- end
-
- context 'when user does not have enough permissions' do
- before do
- project.add_guest(user)
- end
-
+ context 'when user is not a project member' do
it 'raises an error' do
expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
end
end
- context 'when user is a maintainer of a different project' do
- before do
- create(:project_empty_repo).add_maintainer(user)
- end
+ context 'when user is a direct project member' do
+ context 'and user is a guest' do
+ before do
+ project.add_guest(user)
+ end
- it 'raises an error' do
- expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
+ it 'raises an error' do
+ expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
+ end
end
- end
- context 'when the user can create a commit' do
- let(:deltas) { mutated_commit.raw_deltas }
+ context 'and user is a developer' do
+ let(:deltas) { mutated_commit.raw_deltas }
- before_all do
- project.add_developer(user)
- end
-
- context 'when service successfully creates a new commit' do
- it "returns the ETag path for the commit's pipeline" do
- commit_pipeline_path = subject[:commit_pipeline_path]
- expect(commit_pipeline_path).to match(%r(pipelines/sha/\w+))
+ before_all do
+ project.add_developer(user)
end
- it 'returns the content of the commit' do
- expect(subject[:content]).to eq(actions.pluck(:content))
- end
+ context 'when service successfully creates a new commit' do
+ it "returns the ETag path for the commit's pipeline" do
+ commit_pipeline_path = subject[:commit_pipeline_path]
+ expect(commit_pipeline_path).to match(%r(pipelines/sha/\w+))
+ end
- it 'returns a new commit' do
- expect(mutated_commit).to have_attributes(message: message, project: project)
- expect(subject[:errors]).to be_empty
+ it 'returns the content of the commit' do
+ expect(subject[:content]).to eq(actions.pluck(:content))
+ end
- expect_to_contain_deltas([
- a_hash_including(a_mode: '0', b_mode: '100644', new_file: true, new_path: file_path)
- ])
+ it 'returns a new commit' do
+ expect(mutated_commit).to have_attributes(message: message, project: project)
+ expect(subject[:errors]).to be_empty
+
+ expect_to_contain_deltas([
+ a_hash_including(a_mode: '0', b_mode: '100644', new_file: true, new_path: file_path)
+ ])
+ end
end
- end
- context 'when request has multiple actions' do
- let(:actions) do
- [
- {
- action: 'create',
- file_path: 'foo/foobar',
- content: 'some content'
- },
- {
- action: 'delete',
- file_path: 'README.md'
- },
- {
- action: 'move',
- file_path: "LICENSE.md",
- previous_path: "LICENSE",
- content: "some content"
- },
- {
- action: 'update',
- file_path: 'VERSION',
- content: 'new content'
- },
- {
- action: 'chmod',
- file_path: 'CHANGELOG',
- execute_filemode: true
- }
- ]
+ context 'when request has multiple actions' do
+ let(:actions) do
+ [
+ {
+ action: 'create',
+ file_path: 'foo/foobar',
+ content: 'some content'
+ },
+ {
+ action: 'delete',
+ file_path: 'README.md'
+ },
+ {
+ action: 'move',
+ file_path: "LICENSE.md",
+ previous_path: "LICENSE",
+ content: "some content"
+ },
+ {
+ action: 'update',
+ file_path: 'VERSION',
+ content: 'new content'
+ },
+ {
+ action: 'chmod',
+ file_path: 'CHANGELOG',
+ execute_filemode: true
+ }
+ ]
+ end
+
+ it 'returns a new commit' do
+ expect(mutated_commit).to have_attributes(message: message, project: project)
+ expect(subject[:errors]).to be_empty
+
+ expect_to_contain_deltas([
+ a_hash_including(a_mode: '0', b_mode: '100644', new_path: 'foo/foobar'),
+ a_hash_including(deleted_file: true, new_path: 'README.md'),
+ a_hash_including(deleted_file: true, new_path: 'LICENSE'),
+ a_hash_including(new_file: true, new_path: 'LICENSE.md'),
+ a_hash_including(new_file: false, new_path: 'VERSION'),
+ a_hash_including(a_mode: '100644', b_mode: '100755', new_path: 'CHANGELOG')
+ ])
+ end
end
- it 'returns a new commit' do
- expect(mutated_commit).to have_attributes(message: message, project: project)
- expect(subject[:errors]).to be_empty
-
- expect_to_contain_deltas([
- a_hash_including(a_mode: '0', b_mode: '100644', new_path: 'foo/foobar'),
- a_hash_including(deleted_file: true, new_path: 'README.md'),
- a_hash_including(deleted_file: true, new_path: 'LICENSE'),
- a_hash_including(new_file: true, new_path: 'LICENSE.md'),
- a_hash_including(new_file: false, new_path: 'VERSION'),
- a_hash_including(a_mode: '100644', b_mode: '100755', new_path: 'CHANGELOG')
- ])
+ context 'when actions are not defined' do
+ let(:actions) { [] }
+
+ it 'returns a new commit' do
+ expect(mutated_commit).to have_attributes(message: message, project: project)
+ expect(subject[:errors]).to be_empty
+
+ expect_to_contain_deltas([])
+ end
end
- end
- context 'when actions are not defined' do
- let(:actions) { [] }
+ context 'when branch does not exist' do
+ let(:branch) { 'unknown' }
- it 'returns a new commit' do
- expect(mutated_commit).to have_attributes(message: message, project: project)
- expect(subject[:errors]).to be_empty
+ it 'returns errors' do
+ expect(mutated_commit).to be_nil
+ expect(subject[:errors]).to match_array(['You can only create or edit files when you are on a branch'])
+ end
+ end
- expect_to_contain_deltas([])
+ context 'when branch does not exist and a start branch is provided' do
+ let(:branch) { 'my-branch' }
+ let(:start_branch) { 'master' }
+ let(:actions) do
+ [
+ {
+ action: 'create',
+ file_path: 'ANOTHER_FILE.md',
+ content: 'Bye'
+ }
+ ]
+ end
+
+ it 'returns a new commit' do
+ expect(mutated_commit).to have_attributes(message: message, project: project)
+ expect(subject[:errors]).to be_empty
+ expect(subject[:content]).to eq(actions.pluck(:content))
+
+ expect_to_contain_deltas([
+ a_hash_including(a_mode: '0', b_mode: '100644', new_file: true, new_path: 'ANOTHER_FILE.md')
+ ])
+ end
end
- end
- context 'when branch does not exist' do
- let(:branch) { 'unknown' }
+ context 'when message is not set' do
+ let(:message) { nil }
- it 'returns errors' do
- expect(mutated_commit).to be_nil
- expect(subject[:errors]).to eq(['You can only create or edit files when you are on a branch'])
+ it 'returns errors' do
+ expect(mutated_commit).to be_nil
+ expect(subject[:errors].to_s).to match(/3:UserCommitFiles: empty CommitMessage/)
+ end
end
- end
- context 'when branch does not exist and a start branch is provided' do
- let(:branch) { 'my-branch' }
- let(:start_branch) { 'master' }
- let(:actions) do
- [
- {
- action: 'create',
- file_path: 'ANOTHER_FILE.md',
- content: 'Bye'
- }
- ]
+ context 'when actions are incorrect' do
+ let(:actions) { [{ action: 'unknown', file_path: 'test.md', content: '' }] }
+
+ it 'returns errors' do
+ expect(mutated_commit).to be_nil
+ expect(subject[:errors]).to match_array(['Unknown action \'unknown\''])
+ end
end
- it 'returns a new commit' do
- expect(mutated_commit).to have_attributes(message: message, project: project)
- expect(subject[:errors]).to be_empty
- expect(subject[:content]).to eq(actions.pluck(:content))
+ context 'when branch is protected' do
+ before do
+ create(:protected_branch, project: project, name: branch)
+ end
- expect_to_contain_deltas([
- a_hash_including(a_mode: '0', b_mode: '100644', new_file: true, new_path: 'ANOTHER_FILE.md')
- ])
+ it 'returns errors' do
+ expect(mutated_commit).to be_nil
+ expect(subject[:errors]).to match_array(['You are not allowed to push into this branch'])
+ end
end
end
+ end
- context 'when message is not set' do
- let(:message) { nil }
+ context 'when user is an inherited member from the group' do
+ context 'when project is public with private repository' do
+ let(:project) { create(:project, :public, :repository, :repository_private, group: group) }
- it 'returns errors' do
- expect(mutated_commit).to be_nil
- expect(subject[:errors].to_s).to match(/3:UserCommitFiles: empty CommitMessage/)
+ context 'and user is a guest' do
+ before do
+ group.add_guest(user)
+ end
+
+ it 'raises an error' do
+ expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
+ end
end
end
- context 'when actions are incorrect' do
- let(:actions) { [{ action: 'unknown', file_path: 'test.md', content: '' }] }
+ context 'when project is private' do
+ let(:project) { create(:project, :private, :repository, group: group) }
+
+ context 'and user is a guest' do
+ before do
+ group.add_guest(user)
+ end
- it 'returns errors' do
- expect(mutated_commit).to be_nil
- expect(subject[:errors]).to eq(['Unknown action \'unknown\''])
+ it 'raises an error' do
+ expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
+ end
end
end
+ end
- context 'when branch is protected' do
- before do
- create(:protected_branch, project: project, name: branch)
- end
+ context 'when user is a maintainer of a different project' do
+ before do
+ create(:project_empty_repo).add_maintainer(user)
+ end
- it 'returns errors' do
- expect(mutated_commit).to be_nil
- expect(subject[:errors]).to eq(['You are not allowed to push into this branch'])
- end
+ it 'raises an error' do
+ expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
end
end
end