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/api/project_snippets_spec.rb | |
parent | 736d36d8597d0d1ec1b47644e6d091c3f4a78f45 (diff) | |
download | gitlab-ce-1c8fa70f9d0818e2a82089c8643a6e455bca47fd.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/requests/api/project_snippets_spec.rb')
-rw-r--r-- | spec/requests/api/project_snippets_spec.rb | 38 |
1 files changed, 38 insertions, 0 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) |