summaryrefslogtreecommitdiff
path: root/spec/requests
diff options
context:
space:
mode:
authorSebastian Ziebell <sebastian.ziebell@asquera.de>2013-02-08 10:32:42 +0100
committerSebastian Ziebell <sebastian.ziebell@asquera.de>2013-02-08 10:32:42 +0100
commit8045a81bcf5822f1992442750e1484a93c368229 (patch)
tree94ce2b257f3ba002ac1a0fde70b69b622304810d /spec/requests
parent5d8a99f10429168e6471fdd1843f5045a10a84b3 (diff)
parent2f0a75ab77af430f682d67aa9bb865007d832795 (diff)
downloadgitlab-ce-8045a81bcf5822f1992442750e1484a93c368229.tar.gz
Merge branch 'master' into fixes/api
Diffstat (limited to 'spec/requests')
-rw-r--r--spec/requests/api/groups_spec.rb93
-rw-r--r--spec/requests/api/notes_spec.rb11
-rw-r--r--spec/requests/api/projects_spec.rb23
-rw-r--r--spec/requests/api/users_spec.rb48
-rw-r--r--spec/requests/notes_on_merge_requests_spec.rb8
-rw-r--r--spec/requests/notes_on_wall_spec.rb6
6 files changed, 182 insertions, 7 deletions
diff --git a/spec/requests/api/groups_spec.rb b/spec/requests/api/groups_spec.rb
new file mode 100644
index 00000000000..c39a4228408
--- /dev/null
+++ b/spec/requests/api/groups_spec.rb
@@ -0,0 +1,93 @@
+require 'spec_helper'
+
+describe Gitlab::API do
+ include ApiHelpers
+
+ let(:user1) { create(:user) }
+ let(:user2) { create(:user) }
+ let(:admin) { create(:admin) }
+ let!(:group1) { create(:group, owner: user1) }
+ let!(:group2) { create(:group, owner: user2) }
+
+ describe "GET /groups" do
+ context "when unauthenticated" do
+ it "should return authentication error" do
+ get api("/groups")
+ response.status.should == 401
+ end
+ end
+
+ context "when authenticated as user" do
+ it "normal user: should return an array of groups of user1" do
+ get api("/groups", user1)
+ response.status.should == 200
+ json_response.should be_an Array
+ json_response.length.should == 1
+ json_response.first['name'].should == group1.name
+ end
+ end
+
+ context "when authenticated as admin" do
+ it "admin: should return an array of all groups" do
+ get api("/groups", admin)
+ response.status.should == 200
+ json_response.should be_an Array
+ json_response.length.should == 2
+ end
+ end
+ end
+
+ describe "GET /groups/:id" do
+ context "when authenticated as user" do
+ it "should return one of user1's groups" do
+ get api("/groups/#{group1.id}", user1)
+ response.status.should == 200
+ json_response['name'] == group1.name
+ end
+
+ it "should not return a non existing group" do
+ get api("/groups/1328", user1)
+ response.status.should == 404
+ end
+
+ it "should not return a group not attached to user1" do
+ get api("/groups/#{group2.id}", user1)
+ response.status.should == 404
+ end
+ end
+
+ context "when authenticated as admin" do
+ it "should return any existing group" do
+ get api("/groups/#{group2.id}", admin)
+ response.status.should == 200
+ json_response['name'] == group2.name
+ end
+
+ it "should not return a non existing group" do
+ get api("/groups/1328", admin)
+ response.status.should == 404
+ end
+ end
+ end
+
+ describe "POST /groups" do
+ context "when authenticated as user" do
+ it "should not create group" do
+ post api("/groups", user1), attributes_for(:group)
+ response.status.should == 403
+ end
+ end
+
+ context "when authenticated as admin" do
+ it "should create group" do
+ post api("/groups", admin), attributes_for(:group)
+ response.status.should == 201
+ end
+
+ it "should not create group, duplicate" do
+ post api("/groups", admin), {:name => "Duplicate Test", :path => group2.path}
+ response.status.should == 404
+ end
+ end
+ end
+end
diff --git a/spec/requests/api/notes_spec.rb b/spec/requests/api/notes_spec.rb
index a4abbd93349..d382d7d9294 100644
--- a/spec/requests/api/notes_spec.rb
+++ b/spec/requests/api/notes_spec.rb
@@ -6,8 +6,10 @@ describe Gitlab::API do
let(:user) { create(:user) }
let!(:project) { create(:project, namespace: user.namespace ) }
let!(:issue) { create(:issue, project: project, author: user) }
+ let!(:merge_request) { create(:merge_request, project: project, author: user) }
let!(:snippet) { create(:snippet, project: project, author: user) }
let!(:issue_note) { create(:note, noteable: issue, project: project, author: user) }
+ let!(:merge_request_note) { create(:note, noteable: merge_request, project: project, author: user) }
let!(:snippet_note) { create(:note, noteable: snippet, project: project, author: user) }
let!(:wall_note) { create(:note, project: project, author: user) }
before { project.team << [user, :reporter] }
@@ -84,6 +86,15 @@ describe Gitlab::API do
response.status.should == 404
end
end
+
+ context "when noteable is a Merge Request" do
+ it "should return an array of merge_requests notes" do
+ get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/notes", user)
+ response.status.should == 200
+ json_response.should be_an Array
+ json_response.first['body'].should == merge_request_note.note
+ end
+ end
end
describe "GET /projects/:id/noteable/:noteable_id/notes/:note_id" do
diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb
index b9f42acce04..2682629e7db 100644
--- a/spec/requests/api/projects_spec.rb
+++ b/spec/requests/api/projects_spec.rb
@@ -113,6 +113,29 @@ describe Gitlab::API do
json_response['name'].should == 'new_design'
json_response['commit']['id'].should == '621491c677087aa243f165eab467bfdfbee00be1'
+ json_response['protected'].should == false
+ end
+ end
+
+ describe "PUT /projects/:id/repository/branches/:branch/protect" do
+ it "should protect a single branch" do
+ put api("/projects/#{project.id}/repository/branches/new_design/protect", user)
+ response.status.should == 200
+
+ json_response['name'].should == 'new_design'
+ json_response['commit']['id'].should == '621491c677087aa243f165eab467bfdfbee00be1'
+ json_response['protected'].should == true
+ end
+ end
+
+ describe "PUT /projects/:id/repository/branches/:branch/unprotect" do
+ it "should unprotect a single branch" do
+ put api("/projects/#{project.id}/repository/branches/new_design/unprotect", user)
+ response.status.should == 200
+
+ json_response['name'].should == 'new_design'
+ json_response['commit']['id'].should == '621491c677087aa243f165eab467bfdfbee00be1'
+ json_response['protected'].should == false
end
end
diff --git a/spec/requests/api/users_spec.rb b/spec/requests/api/users_spec.rb
index ee5f510aac5..1645117e231 100644
--- a/spec/requests/api/users_spec.rb
+++ b/spec/requests/api/users_spec.rb
@@ -83,6 +83,54 @@ describe Gitlab::API do
end
end
+ describe "PUT /users/:id" do
+ before { admin }
+
+ it "should update user" do
+ put api("/users/#{user.id}", admin), {bio: 'new test bio'}
+ response.status.should == 200
+ json_response['bio'].should == 'new test bio'
+ user.reload.bio.should == 'new test bio'
+ end
+
+ it "should not allow invalid update" do
+ put api("/users/#{user.id}", admin), {email: 'invalid email'}
+ response.status.should == 404
+ user.reload.email.should_not == 'invalid email'
+ end
+
+ it "shouldn't available for non admin users" do
+ put api("/users/#{user.id}", user), attributes_for(:user)
+ response.status.should == 403
+ end
+
+ it "should return 404 for non-existing user" do
+ put api("/users/999999", admin), {bio: 'update should fail'}
+ response.status.should == 404
+ end
+ end
+
+ describe "DELETE /users/:id" do
+ before { admin }
+
+ it "should delete user" do
+ delete api("/users/#{user.id}", admin)
+ response.status.should == 200
+ expect { User.find(user.id) }.to raise_error ActiveRecord::RecordNotFound
+ json_response['email'].should == user.email
+ end
+
+ it "shouldn't available for non admin users" do
+ delete api("/users/#{user.id}", user)
+ response.status.should == 403
+ end
+
+ it "should return 404 for non-existing user" do
+ delete api("/users/999999", admin)
+ response.status.should == 404
+ end
+ end
+
describe "GET /user" do
it "should return current user" do
get api("/user", user)
diff --git a/spec/requests/notes_on_merge_requests_spec.rb b/spec/requests/notes_on_merge_requests_spec.rb
index 2b670359a49..0111cf42ac7 100644
--- a/spec/requests/notes_on_merge_requests_spec.rb
+++ b/spec/requests/notes_on_merge_requests_spec.rb
@@ -22,9 +22,9 @@ describe "On a merge request", js: true do
it { within(".js-main-target-form") { should_not have_link("Cancel") } }
# notifiactions
- it { within(".js-main-target-form") { should have_checked_field("Project team") } }
- it { within(".js-main-target-form") { should_not have_checked_field("Commit author") } }
- it { within(".js-main-target-form") { should_not have_unchecked_field("Commit author") } }
+ it { within(".js-main-target-form") { should have_checked_field("Notify team via email") } }
+ it { within(".js-main-target-form") { should_not have_checked_field("Notify commit author") } }
+ it { within(".js-main-target-form") { should_not have_unchecked_field("Notify commit author") } }
describe "without text" do
it { within(".js-main-target-form") { should have_css(".js-note-preview-button", visible: false) } }
@@ -125,7 +125,7 @@ describe "On a merge request diff", js: true, focus: true do
it { should have_css(".js-close-discussion-note-form", text: "Cancel") }
# notification options
- it { should have_checked_field("Project team") }
+ it { should have_checked_field("Notify team via email") }
it "shouldn't add a second form for same row" do
find("#4735dfc552ad7bf15ca468adc3cad9d05b624490_185_185.line_holder .js-add-diff-note-button").trigger("click")
diff --git a/spec/requests/notes_on_wall_spec.rb b/spec/requests/notes_on_wall_spec.rb
index 01673f997e9..4adcf74e0b6 100644
--- a/spec/requests/notes_on_wall_spec.rb
+++ b/spec/requests/notes_on_wall_spec.rb
@@ -21,9 +21,9 @@ describe "On the project wall", js: true do
it { within(".js-main-target-form") { should_not have_link("Cancel") } }
# notifiactions
- it { within(".js-main-target-form") { should have_checked_field("Project team") } }
- it { within(".js-main-target-form") { should_not have_checked_field("Commit author") } }
- it { within(".js-main-target-form") { should_not have_unchecked_field("Commit author") } }
+ it { within(".js-main-target-form") { should have_checked_field("Notify team via email") } }
+ it { within(".js-main-target-form") { should_not have_checked_field("Notify commit author") } }
+ it { within(".js-main-target-form") { should_not have_unchecked_field("Notify commit author") } }
describe "without text" do
it { within(".js-main-target-form") { should have_css(".js-note-preview-button", visible: false) } }