Commit 928b7f3bff82c614b8b6e68be8ed51707927a8c6
1 parent
0ea0e542
Exists in
spb-stable
and in
3 other branches
Add tests for API project permissions info
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Showing
2 changed files
with
26 additions
and
1 deletions
Show diff stats
lib/api/entities.rb
| ... | ... | @@ -181,7 +181,9 @@ module API |
| 181 | 181 | end |
| 182 | 182 | |
| 183 | 183 | expose :group_access, using: Entities::GroupAccess do |project, options| |
| 184 | - project.group.users_groups.find_by(user_id: options[:user].id) | |
| 184 | + if project.group | |
| 185 | + project.group.users_groups.find_by(user_id: options[:user].id) | |
| 186 | + end | |
| 185 | 187 | end |
| 186 | 188 | end |
| 187 | 189 | end | ... | ... |
spec/requests/api/projects_spec.rb
| ... | ... | @@ -259,6 +259,7 @@ describe API::API do |
| 259 | 259 | |
| 260 | 260 | describe "GET /projects/:id" do |
| 261 | 261 | before { project } |
| 262 | + before { users_project } | |
| 262 | 263 | |
| 263 | 264 | it "should return a project by id" do |
| 264 | 265 | get api("/projects/#{project.id}", user) |
| ... | ... | @@ -284,6 +285,28 @@ describe API::API do |
| 284 | 285 | get api("/projects/#{project.id}", other_user) |
| 285 | 286 | response.status.should == 404 |
| 286 | 287 | end |
| 288 | + | |
| 289 | + describe 'permissions' do | |
| 290 | + context 'personal project' do | |
| 291 | + before { get api("/projects/#{project.id}", user) } | |
| 292 | + | |
| 293 | + it { response.status.should == 200 } | |
| 294 | + it { json_response['permissions']["project_access"]["access_level"].should == Gitlab::Access::MASTER } | |
| 295 | + it { json_response['permissions']["group_access"].should be_nil } | |
| 296 | + end | |
| 297 | + | |
| 298 | + context 'group project' do | |
| 299 | + before do | |
| 300 | + project2 = create(:project, group: create(:group)) | |
| 301 | + project2.group.add_owner(user) | |
| 302 | + get api("/projects/#{project2.id}", user) | |
| 303 | + end | |
| 304 | + | |
| 305 | + it { response.status.should == 200 } | |
| 306 | + it { json_response['permissions']["project_access"].should be_nil } | |
| 307 | + it { json_response['permissions']["group_access"]["access_level"].should == Gitlab::Access::OWNER } | |
| 308 | + end | |
| 309 | + end | |
| 287 | 310 | end |
| 288 | 311 | |
| 289 | 312 | describe "GET /projects/:id/events" do | ... | ... |