summaryrefslogtreecommitdiff
path: root/spec/requests/api/groups_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/requests/api/groups_spec.rb')
-rw-r--r--spec/requests/api/groups_spec.rb76
1 files changed, 38 insertions, 38 deletions
diff --git a/spec/requests/api/groups_spec.rb b/spec/requests/api/groups_spec.rb
index 7ecefce80d6..04141a45031 100644
--- a/spec/requests/api/groups_spec.rb
+++ b/spec/requests/api/groups_spec.rb
@@ -23,14 +23,14 @@ describe API::API, api: true do
context "when unauthenticated" do
it "should return authentication error" do
get api("/groups")
- expect(response.status).to eq(401)
+ expect(response).to have_http_status(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)
- expect(response.status).to eq(200)
+ expect(response).to have_http_status(200)
expect(json_response).to be_an Array
expect(json_response.length).to eq(1)
expect(json_response.first['name']).to eq(group1.name)
@@ -40,7 +40,7 @@ describe API::API, api: true do
context "when authenticated as admin" do
it "admin: should return an array of all groups" do
get api("/groups", admin)
- expect(response.status).to eq(200)
+ expect(response).to have_http_status(200)
expect(json_response).to be_an Array
expect(json_response.length).to eq(2)
end
@@ -51,51 +51,51 @@ describe API::API, api: true do
context "when authenticated as user" do
it "should return one of user1's groups" do
get api("/groups/#{group1.id}", user1)
- expect(response.status).to eq(200)
+ expect(response).to have_http_status(200)
json_response['name'] == group1.name
end
it "should not return a non existing group" do
get api("/groups/1328", user1)
- expect(response.status).to eq(404)
+ expect(response).to have_http_status(404)
end
it "should not return a group not attached to user1" do
get api("/groups/#{group2.id}", user1)
- expect(response.status).to eq(404)
+ expect(response).to have_http_status(404)
end
end
context "when authenticated as admin" do
it "should return any existing group" do
get api("/groups/#{group2.id}", admin)
- expect(response.status).to eq(200)
+ expect(response).to have_http_status(200)
expect(json_response['name']).to eq(group2.name)
end
it "should not return a non existing group" do
get api("/groups/1328", admin)
- expect(response.status).to eq(404)
+ expect(response).to have_http_status(404)
end
end
context 'when using group path in URL' do
it 'should return any existing group' do
get api("/groups/#{group1.path}", admin)
- expect(response.status).to eq(200)
+ expect(response).to have_http_status(200)
expect(json_response['name']).to eq(group1.name)
end
it 'should not return a non existing group' do
get api('/groups/unknown', admin)
- expect(response.status).to eq(404)
+ expect(response).to have_http_status(404)
end
it 'should not return a group not attached to user1' do
get api("/groups/#{group2.path}", user1)
- expect(response.status).to eq(404)
+ expect(response).to have_http_status(404)
end
end
end
@@ -107,14 +107,14 @@ describe API::API, api: true do
it 'updates the group' do
put api("/groups/#{group1.id}", user1), name: new_group_name
- expect(response.status).to eq(200)
+ expect(response).to have_http_status(200)
expect(json_response['name']).to eq(new_group_name)
end
it 'returns 404 for a non existing group' do
put api('/groups/1328', user1)
- expect(response.status).to eq(404)
+ expect(response).to have_http_status(404)
end
end
@@ -122,7 +122,7 @@ describe API::API, api: true do
it 'updates the group' do
put api("/groups/#{group1.id}", admin), name: new_group_name
- expect(response.status).to eq(200)
+ expect(response).to have_http_status(200)
expect(json_response['name']).to eq(new_group_name)
end
end
@@ -131,7 +131,7 @@ describe API::API, api: true do
it 'does not updates the group' do
put api("/groups/#{group1.id}", user2), name: new_group_name
- expect(response.status).to eq(403)
+ expect(response).to have_http_status(403)
end
end
@@ -139,7 +139,7 @@ describe API::API, api: true do
it 'returns 404 when trying to update the group' do
put api("/groups/#{group2.id}", user1), name: new_group_name
- expect(response.status).to eq(404)
+ expect(response).to have_http_status(404)
end
end
end
@@ -149,7 +149,7 @@ describe API::API, api: true do
it "should return the group's projects" do
get api("/groups/#{group1.id}/projects", user1)
- expect(response.status).to eq(200)
+ expect(response).to have_http_status(200)
expect(json_response.length).to eq(2)
project_names = json_response.map { |proj| proj['name' ] }
expect(project_names).to match_array([project1.name, project3.name])
@@ -157,13 +157,13 @@ describe API::API, api: true do
it "should not return a non existing group" do
get api("/groups/1328/projects", user1)
- expect(response.status).to eq(404)
+ expect(response).to have_http_status(404)
end
it "should not return a group not attached to user1" do
get api("/groups/#{group2.id}/projects", user1)
- expect(response.status).to eq(404)
+ expect(response).to have_http_status(404)
end
it "should only return projects to which user has access" do
@@ -171,7 +171,7 @@ describe API::API, api: true do
get api("/groups/#{group1.id}/projects", user3)
- expect(response.status).to eq(200)
+ expect(response).to have_http_status(200)
expect(json_response.length).to eq(1)
expect(json_response.first['name']).to eq(project3.name)
end
@@ -180,14 +180,14 @@ describe API::API, api: true do
context "when authenticated as admin" do
it "should return any existing group" do
get api("/groups/#{group2.id}/projects", admin)
- expect(response.status).to eq(200)
+ expect(response).to have_http_status(200)
expect(json_response.length).to eq(1)
expect(json_response.first['name']).to eq(project2.name)
end
it "should not return a non existing group" do
get api("/groups/1328/projects", admin)
- expect(response.status).to eq(404)
+ expect(response).to have_http_status(404)
end
end
@@ -195,20 +195,20 @@ describe API::API, api: true do
it 'should return any existing group' do
get api("/groups/#{group1.path}/projects", admin)
- expect(response.status).to eq(200)
+ expect(response).to have_http_status(200)
project_names = json_response.map { |proj| proj['name' ] }
expect(project_names).to match_array([project1.name, project3.name])
end
it 'should not return a non existing group' do
get api('/groups/unknown/projects', admin)
- expect(response.status).to eq(404)
+ expect(response).to have_http_status(404)
end
it 'should not return a group not attached to user1' do
get api("/groups/#{group2.path}/projects", user1)
- expect(response.status).to eq(404)
+ expect(response).to have_http_status(404)
end
end
end
@@ -217,30 +217,30 @@ describe API::API, api: true do
context "when authenticated as user without group permissions" do
it "should not create group" do
post api("/groups", user1), attributes_for(:group)
- expect(response.status).to eq(403)
+ expect(response).to have_http_status(403)
end
end
context "when authenticated as user with group permissions" do
it "should create group" do
post api("/groups", user3), attributes_for(:group)
- expect(response.status).to eq(201)
+ expect(response).to have_http_status(201)
end
it "should not create group, duplicate" do
post api("/groups", user3), { name: 'Duplicate Test', path: group2.path }
- expect(response.status).to eq(400)
+ expect(response).to have_http_status(400)
expect(response.message).to eq("Bad Request")
end
it "should return 400 bad request error if name not given" do
post api("/groups", user3), { path: group2.path }
- expect(response.status).to eq(400)
+ expect(response).to have_http_status(400)
end
it "should return 400 bad request error if path not given" do
post api("/groups", user3), { name: 'test' }
- expect(response.status).to eq(400)
+ expect(response).to have_http_status(400)
end
end
end
@@ -249,37 +249,37 @@ describe API::API, api: true do
context "when authenticated as user" do
it "should remove group" do
delete api("/groups/#{group1.id}", user1)
- expect(response.status).to eq(200)
+ expect(response).to have_http_status(200)
end
it "should not remove a group if not an owner" do
user4 = create(:user)
group1.add_master(user4)
delete api("/groups/#{group1.id}", user3)
- expect(response.status).to eq(403)
+ expect(response).to have_http_status(403)
end
it "should not remove a non existing group" do
delete api("/groups/1328", user1)
- expect(response.status).to eq(404)
+ expect(response).to have_http_status(404)
end
it "should not remove a group not attached to user1" do
delete api("/groups/#{group2.id}", user1)
- expect(response.status).to eq(404)
+ expect(response).to have_http_status(404)
end
end
context "when authenticated as admin" do
it "should remove any existing group" do
delete api("/groups/#{group2.id}", admin)
- expect(response.status).to eq(200)
+ expect(response).to have_http_status(200)
end
it "should not remove a non existing group" do
delete api("/groups/1328", admin)
- expect(response.status).to eq(404)
+ expect(response).to have_http_status(404)
end
end
end
@@ -295,14 +295,14 @@ describe API::API, api: true do
context "when authenticated as user" do
it "should not transfer project to group" do
post api("/groups/#{group1.id}/projects/#{project.id}", user2)
- expect(response.status).to eq(403)
+ expect(response).to have_http_status(403)
end
end
context "when authenticated as admin" do
it "should transfer project to group" do
post api("/groups/#{group1.id}/projects/#{project.id}", admin)
- expect(response.status).to eq(201)
+ expect(response).to have_http_status(201)
end
end
end