diff options
author | Robert Schilling <rschilling@student.tugraz.at> | 2018-08-21 11:14:31 +0200 |
---|---|---|
committer | Robert Schilling <rschilling@student.tugraz.at> | 2018-08-21 12:30:22 +0200 |
commit | 6dc4d1b52c3401c98b8796b38d3da5080ac9b3a7 (patch) | |
tree | 62fdf6c01c7aa71d6acfcdaf09f3fd4e991d0325 /spec/requests | |
parent | ceaee58c491a4c027f0e81fae0ad345028e6795a (diff) | |
download | gitlab-ce-6dc4d1b52c3401c98b8796b38d3da5080ac9b3a7.tar.gz |
Extend to PUT request
Diffstat (limited to 'spec/requests')
-rw-r--r-- | spec/requests/api/files_spec.rb | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/spec/requests/api/files_spec.rb b/spec/requests/api/files_spec.rb index 20992362b8c..d797a20d8a1 100644 --- a/spec/requests/api/files_spec.rb +++ b/spec/requests/api/files_spec.rb @@ -313,7 +313,7 @@ describe API::Files do describe "POST /projects/:id/repository/files/:file_path" do let!(:file_path) { "new_subfolder%2Fnewfile%2Erb" } - let(:valid_params) do + let(:params) do { branch: "master", content: "puts 8", @@ -322,7 +322,7 @@ describe API::Files do end it "creates a new file in project repo" do - post api(route(file_path), user), valid_params + post api(route(file_path), user), params expect(response).to have_gitlab_http_status(201) expect(json_response["file_path"]).to eq(CGI.unescape(file_path)) @@ -338,13 +338,9 @@ describe API::Files do end it 'returns a 400 bad request if the commit message is empty' do - invalid_params = { - branch: 'master', - content: 'puts 8', - commit_message: '' - } + params[:commit_message] = '' - post api(route(file_path), user), invalid_params + post api(route(file_path), user), params expect(response).to have_gitlab_http_status(400) end @@ -353,16 +349,16 @@ describe API::Files do allow_any_instance_of(Repository).to receive(:create_file) .and_raise(Gitlab::Git::CommitError, 'Cannot create file') - post api(route("any%2Etxt"), user), valid_params + post api(route("any%2Etxt"), user), params expect(response).to have_gitlab_http_status(400) end context "when specifying an author" do it "creates a new file with the specified author" do - valid_params.merge!(author_email: author_email, author_name: author_name) + params.merge!(author_email: author_email, author_name: author_name) - post api(route("new_file_with_author%2Etxt"), user), valid_params + post api(route("new_file_with_author%2Etxt"), user), params expect(response).to have_gitlab_http_status(201) expect(response.content_type).to eq('application/json') @@ -376,7 +372,7 @@ describe API::Files do let!(:project) { create(:project_empty_repo, namespace: user.namespace ) } it "creates a new file in project repo" do - post api(route("newfile%2Erb"), user), valid_params + post api(route("newfile%2Erb"), user), params expect(response).to have_gitlab_http_status(201) expect(json_response['file_path']).to eq('newfile.rb') @@ -388,7 +384,7 @@ describe API::Files do end describe "PUT /projects/:id/repository/files" do - let(:valid_params) do + let(:params) do { branch: 'master', content: 'puts 8', @@ -397,7 +393,7 @@ describe API::Files do end it "updates existing file in project repo" do - put api(route(file_path), user), valid_params + put api(route(file_path), user), params expect(response).to have_gitlab_http_status(200) expect(json_response['file_path']).to eq(CGI.unescape(file_path)) @@ -406,8 +402,16 @@ describe API::Files do expect(last_commit.author_name).to eq(user.name) end + it 'returns a 400 bad request if the commit message is empty' do + params[:commit_message] = '' + + put api(route(file_path), user), params + + expect(response).to have_gitlab_http_status(400) + end + it "returns a 400 bad request if update existing file with stale last commit id" do - params_with_stale_id = valid_params.merge(last_commit_id: 'stale') + params_with_stale_id = params.merge(last_commit_id: 'stale') put api(route(file_path), user), params_with_stale_id @@ -418,7 +422,7 @@ describe API::Files do it "updates existing file in project repo with accepts correct last commit id" do last_commit = Gitlab::Git::Commit .last_for_path(project.repository, 'master', URI.unescape(file_path)) - params_with_correct_id = valid_params.merge(last_commit_id: last_commit.id) + params_with_correct_id = params.merge(last_commit_id: last_commit.id) put api(route(file_path), user), params_with_correct_id @@ -433,9 +437,9 @@ describe API::Files do context "when specifying an author" do it "updates a file with the specified author" do - valid_params.merge!(author_email: author_email, author_name: author_name, content: "New content") + params.merge!(author_email: author_email, author_name: author_name, content: "New content") - put api(route(file_path), user), valid_params + put api(route(file_path), user), params expect(response).to have_gitlab_http_status(200) last_commit = project.repository.commit.raw |