diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/models/service_spec.rb | 28 | ||||
-rw-r--r-- | spec/requests/api/group_members_spec.rb | 63 | ||||
-rw-r--r-- | spec/requests/api/projects_spec.rb | 103 |
3 files changed, 121 insertions, 73 deletions
diff --git a/spec/models/service_spec.rb b/spec/models/service_spec.rb index c96f2b20529..1df34f56cf1 100644 --- a/spec/models/service_spec.rb +++ b/spec/models/service_spec.rb @@ -5,11 +5,12 @@ # id :integer not null, primary key # type :string(255) # title :string(255) -# project_id :integer not null +# project_id :integer # created_at :datetime # updated_at :datetime # active :boolean default(FALSE), not null # properties :text +# template :boolean default(FALSE) # require 'spec_helper' @@ -59,4 +60,29 @@ describe Service do end end end + + describe "Template" do + describe "for pushover service" do + let(:service_template) { + PushoverService.create(template: true, properties: {device: 'MyDevice', sound: 'mic', priority: 4, api_key: '123456789'}) + } + let(:project) { create(:project) } + + describe 'should be prefilled for projects pushover service' do + before do + service_template + project.build_missing_services + end + + it "should have all fields prefilled" do + service = project.pushover_service + expect(service.template).to eq(false) + expect(service.device).to eq('MyDevice') + expect(service.sound).to eq('mic') + expect(service.priority).to eq(4) + expect(service.api_key).to eq('123456789') + end + end + end + end end diff --git a/spec/requests/api/group_members_spec.rb b/spec/requests/api/group_members_spec.rb index 4957186f605..43d26d67efe 100644 --- a/spec/requests/api/group_members_spec.rb +++ b/spec/requests/api/group_members_spec.rb @@ -104,6 +104,69 @@ describe API::API, api: true do end end + describe 'PUT /groups/:id/members/:user_id' do + context 'when not a member of the group' do + it 'should return a 409 error if the user is not a group member' do + put( + api("/groups/#{group_no_members.id}/members/#{developer.id}", + owner), access_level: GroupMember::MASTER + ) + expect(response.status).to eq(404) + end + end + + context 'when a member of the group' do + it 'should return ok and update member access level' do + put( + api("/groups/#{group_with_members.id}/members/#{reporter.id}", + owner), + access_level: GroupMember::MASTER + ) + + expect(response.status).to eq(200) + + get api("/groups/#{group_with_members.id}/members", owner) + json_reporter = json_response.find do |e| + e['id'] == reporter.id + end + + expect(json_reporter['access_level']).to eq(GroupMember::MASTER) + end + + it 'should not allow guest to modify group members' do + put( + api("/groups/#{group_with_members.id}/members/#{developer.id}", + guest), + access_level: GroupMember::MASTER + ) + + expect(response.status).to eq(403) + + get api("/groups/#{group_with_members.id}/members", owner) + json_developer = json_response.find do |e| + e['id'] == developer.id + end + + expect(json_developer['access_level']).to eq(GroupMember::DEVELOPER) + end + + it 'should return a 400 error when access level is not given' do + put( + api("/groups/#{group_with_members.id}/members/#{master.id}", owner) + ) + expect(response.status).to eq(400) + end + + it 'should return a 422 error when access level is not known' do + put( + api("/groups/#{group_with_members.id}/members/#{master.id}", owner), + access_level: 1234 + ) + expect(response.status).to eq(422) + end + end + end + describe "DELETE /groups/:id/members/:user_id" do context "when not a member of the group" do it "should not delete guest's membership of group_with_members" do diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index dc410107410..65c894ac0c2 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -119,57 +119,33 @@ describe API::API, api: true do describe 'POST /projects' do context 'maximum number of projects reached' do - before do - (1..user2.projects_limit).each do |project| - post api('/projects', user2), name: "foo#{project}" - end - end - - it 'should not create new project' do + it 'should not create new project and respond with 403' do + User.any_instance.stub(:projects_limit_left).and_return(0) expect { post api('/projects', user2), name: 'foo' }.to change {Project.count}.by(0) + response.status.should == 403 end end - it 'should create new project without path' do - expect { post api('/projects', user), name: 'foo' }.to change {Project.count}.by(1) - end - - it 'should not create new project without name' do - expect { post api('/projects', user) }.to_not change {Project.count} - end - - it 'should return a 400 error if name not given' do - post api('/projects', user) - response.status.should == 400 + it 'should create new project without path and return 201' do + expect { post api('/projects', user), name: 'foo' }. + to change { Project.count }.by(1) + response.status.should == 201 end it 'should create last project before reaching project limit' do - (1..user2.projects_limit-1).each { |p| post api('/projects', user2), name: "foo#{p}" } + User.any_instance.stub(:projects_limit_left).and_return(1) post api('/projects', user2), name: 'foo' response.status.should == 201 end - it 'should respond with 201 on success' do - post api('/projects', user), name: 'foo' - response.status.should == 201 - end - - it 'should respond with 400 if name is not given' do - post api('/projects', user) + it 'should not create new project without name and return 400' do + expect { post api('/projects', user) }.to_not change { Project.count } response.status.should == 400 end - it 'should return a 403 error if project limit reached' do - (1..user.projects_limit).each do |p| - post api('/projects', user), name: "foo#{p}" - end - post api('/projects', user), name: 'bar' - response.status.should == 403 - end - - it 'should assign attributes to project' do + it "should assign attributes to project" do project = attributes_for(:project, { path: 'camelCasePath', description: Faker::Lorem.sentence, @@ -232,21 +208,15 @@ describe API::API, api: true do before { project } before { admin } - it 'should create new project without path' do + it 'should create new project without path and return 201' do expect { post api("/projects/user/#{user.id}", admin), name: 'foo' }.to change {Project.count}.by(1) - end - - it 'should not create new project without name' do - expect { post api("/projects/user/#{user.id}", admin) }.to_not change {Project.count} - end - - it 'should respond with 201 on success' do - post api("/projects/user/#{user.id}", admin), name: 'foo' response.status.should == 201 end - it 'should respond with 400 on failure' do - post api("/projects/user/#{user.id}", admin) + it 'should respond with 400 on failure and not project' do + expect { post api("/projects/user/#{user.id}", admin) }. + to_not change { Project.count } + response.status.should == 400 json_response['message']['name'].should == [ 'can\'t be blank', @@ -350,26 +320,28 @@ describe API::API, api: true do describe 'permissions' do context 'personal project' do - before do + it 'Sets project access and returns 200' do project.team << [user, :master] get api("/projects/#{project.id}", user) - end - it { response.status.should == 200 } - it { json_response['permissions']['project_access']['access_level'].should == Gitlab::Access::MASTER } - it { json_response['permissions']['group_access'].should be_nil } + expect(response.status).to eq(200) + expect(json_response['permissions']['project_access']['access_level']). + to eq(Gitlab::Access::MASTER) + expect(json_response['permissions']['group_access']).to be_nil + end end context 'group project' do - before do + it 'should set the owner and return 200' do project2 = create(:project, group: create(:group)) project2.group.add_owner(user) get api("/projects/#{project2.id}", user) - end - it { response.status.should == 200 } - it { json_response['permissions']['project_access'].should be_nil } - it { json_response['permissions']['group_access']['access_level'].should == Gitlab::Access::OWNER } + expect(response.status).to eq(200) + expect(json_response['permissions']['project_access']).to be_nil + expect(json_response['permissions']['group_access']['access_level']). + to eq(Gitlab::Access::OWNER) + end end end end @@ -432,22 +404,9 @@ describe API::API, api: true do json_response['title'].should == 'api test' end - it 'should return a 400 error if title is not given' do - post api("/projects/#{project.id}/snippets", user), - file_name: 'sample.rb', code: 'test' - response.status.should == 400 - end - - it 'should return a 400 error if file_name not given' do - post api("/projects/#{project.id}/snippets", user), - title: 'api test', code: 'test' - response.status.should == 400 - end - - it 'should return a 400 error if code not given' do - post api("/projects/#{project.id}/snippets", user), - title: 'api test', file_name: 'sample.rb' - response.status.should == 400 + it 'should return a 400 error if invalid snippet is given' do + post api("/projects/#{project.id}/snippets", user) + expect(status).to eq(400) end end |