diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-28 18:09:07 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-28 18:09:07 +0000 |
commit | 1c8fa70f9d0818e2a82089c8643a6e455bca47fd (patch) | |
tree | f339f97de0425270bdd909e2f4d378927b6e0a18 /spec/requests | |
parent | 736d36d8597d0d1ec1b47644e6d091c3f4a78f45 (diff) | |
download | gitlab-ce-1c8fa70f9d0818e2a82089c8643a6e455bca47fd.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/requests')
-rw-r--r-- | spec/requests/api/project_snippets_spec.rb | 38 | ||||
-rw-r--r-- | spec/requests/api/snippets_spec.rb | 32 |
2 files changed, 69 insertions, 1 deletions
diff --git a/spec/requests/api/project_snippets_spec.rb b/spec/requests/api/project_snippets_spec.rb index 7efc426c81d..16903d9d6d0 100644 --- a/spec/requests/api/project_snippets_spec.rb +++ b/spec/requests/api/project_snippets_spec.rb @@ -98,6 +98,36 @@ describe API::ProjectSnippets do } end + shared_examples 'project snippet repository actions' do + let(:snippet) { ProjectSnippet.find(json_response['id']) } + + it 'creates repository' do + subject + + expect(snippet.repository.exists?).to be_truthy + end + + it 'commit the files to the repository' do + subject + + blob = snippet.repository.blob_at('master', params[:file_name]) + + expect(blob.data).to eq params[:code] + end + + context 'when feature flag :version_snippets is disabled' do + it 'does not create snippet repository' do + stub_feature_flags(version_snippets: false) + + expect do + subject + end.to change { ProjectSnippet.count }.by(1) + + expect(snippet.repository_exists?).to be_falsey + end + end + end + context 'with a regular user' do let(:user) { create(:user) } @@ -118,6 +148,10 @@ describe API::ProjectSnippets do expect(snippet.file_name).to eq(params[:file_name]) expect(snippet.visibility_level).to eq(Snippet::INTERNAL) end + + it_behaves_like 'project snippet repository actions' do + subject { post api("/projects/#{project.id}/snippets/", user), params: params } + end end it 'creates a new snippet' do @@ -132,6 +166,10 @@ describe API::ProjectSnippets do expect(snippet.visibility_level).to eq(Snippet::PUBLIC) end + it_behaves_like 'project snippet repository actions' do + subject { post api("/projects/#{project.id}/snippets/", admin), params: params } + end + it 'creates a new snippet with content parameter' do params[:content] = params.delete(:code) diff --git a/spec/requests/api/snippets_spec.rb b/spec/requests/api/snippets_spec.rb index 21565265b99..cb2a0adc092 100644 --- a/spec/requests/api/snippets_spec.rb +++ b/spec/requests/api/snippets_spec.rb @@ -199,9 +199,13 @@ describe API::Snippets do end shared_examples 'snippet creation' do + let(:snippet) { Snippet.find(json_response["id"]) } + + subject { post api("/snippets/", user), params: params } + it 'creates a new snippet' do expect do - post api("/snippets/", user), params: params + subject end.to change { PersonalSnippet.count }.by(1) expect(response).to have_gitlab_http_status(201) @@ -210,6 +214,32 @@ describe API::Snippets do expect(json_response['file_name']).to eq(params[:file_name]) expect(json_response['visibility']).to eq(params[:visibility]) end + + it 'creates repository' do + subject + + expect(snippet.repository.exists?).to be_truthy + end + + it 'commit the files to the repository' do + subject + + blob = snippet.repository.blob_at('master', params[:file_name]) + + expect(blob.data).to eq params[:content] + end + + context 'when feature flag :version_snippets is disabled' do + it 'does not create snippet repository' do + stub_feature_flags(version_snippets: false) + + expect do + subject + end.to change { PersonalSnippet.count }.by(1) + + expect(snippet.repository_exists?).to be_falsey + end + end end context 'with restricted visibility settings' do |