mirror of
https://gitlink.org.cn/Gitlink/forgeplus.git
synced 2026-05-03 11:50:49 +08:00
init project
This commit is contained in:
103
lib/gitlab-cli/spec/gitlab/client/branches_spec.rb
Normal file
103
lib/gitlab-cli/spec/gitlab/client/branches_spec.rb
Normal file
@@ -0,0 +1,103 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Gitlab::Client do
|
||||
it { should respond_to :repo_branches }
|
||||
it { should respond_to :repo_branch }
|
||||
it { should respond_to :repo_protect_branch }
|
||||
it { should respond_to :repo_unprotect_branch }
|
||||
|
||||
describe ".branches" do
|
||||
before do
|
||||
stub_get("/projects/3/repository/branches", "branches")
|
||||
@branches = Gitlab.branches(3)
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_get("/projects/3/repository/branches")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return an array of repository branches" do
|
||||
expect(@branches).to be_an Array
|
||||
expect(@branches.first.name).to eq("api")
|
||||
end
|
||||
end
|
||||
|
||||
describe ".branch" do
|
||||
before do
|
||||
stub_get("/projects/3/repository/branches/api", "branch")
|
||||
@branch = Gitlab.branch(3, "api")
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_get("/projects/3/repository/branches/api")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about a repository branch" do
|
||||
expect(@branch.name).to eq("api")
|
||||
end
|
||||
end
|
||||
|
||||
describe ".protect_branch" do
|
||||
before do
|
||||
stub_put("/projects/3/repository/branches/api/protect", "protect_branch")
|
||||
@branch = Gitlab.protect_branch(3, "api")
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_put("/projects/3/repository/branches/api/protect")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about a protected repository branch" do
|
||||
expect(@branch.name).to eq("api")
|
||||
expect(@branch.protected).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
describe ".unprotect_branch" do
|
||||
before do
|
||||
stub_put("/projects/3/repository/branches/api/unprotect", "unprotect_branch")
|
||||
@branch = Gitlab.unprotect_branch(3, "api")
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_put("/projects/3/repository/branches/api/unprotect")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about an unprotected repository branch" do
|
||||
expect(@branch.name).to eq("api")
|
||||
expect(@branch.protected).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
describe ".create_branch" do
|
||||
context "with branch name" do
|
||||
before do
|
||||
stub_post("/projects/3/repository/branches", "create_branch")
|
||||
@branch = Gitlab.create_branch(3, "api","master")
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_post("/projects/3/repository/branches")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about a new repository branch" do
|
||||
expect(@branch.name).to eq("api")
|
||||
end
|
||||
end
|
||||
context "with commit hash" do
|
||||
before do
|
||||
stub_post("/projects/3/repository/branches", "create_branch")
|
||||
@branch = Gitlab.create_branch(3, "api","949b1df930bedace1dbd755aaa4a82e8c451a616")
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_post("/projects/3/repository/branches")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about a new repository branch" do
|
||||
expect(@branch.name).to eq("api")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
111
lib/gitlab-cli/spec/gitlab/client/groups_spec.rb
Normal file
111
lib/gitlab-cli/spec/gitlab/client/groups_spec.rb
Normal file
@@ -0,0 +1,111 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Gitlab::Client do
|
||||
describe ".groups" do
|
||||
before do
|
||||
stub_get("/groups", "groups")
|
||||
stub_get("/groups/3", "group")
|
||||
@group = Gitlab.group(3)
|
||||
@groups = Gitlab.groups
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_get("/groups")).to have_been_made
|
||||
expect(a_get("/groups/3")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return an array of Groups" do
|
||||
expect(@groups).to be_an Array
|
||||
expect(@groups.first.path).to eq("threegroup")
|
||||
end
|
||||
end
|
||||
|
||||
describe ".create_group" do
|
||||
before do
|
||||
stub_post("/groups", "group_create")
|
||||
@group = Gitlab.create_group('GitLab-Group', 'gitlab-path')
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_post("/groups").
|
||||
with(:body => {:path => 'gitlab-path', :name => 'GitLab-Group'})).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about a created group" do
|
||||
expect(@group.name).to eq("Gitlab-Group")
|
||||
expect(@group.path).to eq("gitlab-group")
|
||||
end
|
||||
end
|
||||
|
||||
describe ".transfer_project_to_group" do
|
||||
before do
|
||||
stub_post("/projects", "project")
|
||||
@project = Gitlab.create_project('Gitlab')
|
||||
stub_post("/groups", "group_create")
|
||||
@group = Gitlab.create_group('GitLab-Group', 'gitlab-path')
|
||||
|
||||
stub_post("/groups/#{@group.id}/projects/#{@project.id}", "group_create")
|
||||
@group_transfer = Gitlab.transfer_project_to_group(@group.id,@project.id)
|
||||
end
|
||||
|
||||
it "should post to the correct resource" do
|
||||
expect(a_post("/groups/#{@group.id}/projects/#{@project.id}").with(:body => {:id => @group.id.to_s, :project_id => @project.id.to_s})).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about the group" do
|
||||
expect(@group_transfer.name).to eq(@group.name)
|
||||
expect(@group_transfer.path).to eq(@group.path)
|
||||
expect(@group_transfer.id).to eq(@group.id)
|
||||
end
|
||||
end
|
||||
|
||||
describe ".group_members" do
|
||||
before do
|
||||
stub_get("/groups/3/members", "group_members")
|
||||
@members = Gitlab.group_members(3)
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_get("/groups/3/members")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about a group members" do
|
||||
expect(@members).to be_an Array
|
||||
expect(@members.size).to eq(2)
|
||||
expect(@members[1].name).to eq("John Smith")
|
||||
end
|
||||
end
|
||||
|
||||
describe ".add_group_member" do
|
||||
before do
|
||||
stub_post("/groups/3/members", "group_member")
|
||||
@member = Gitlab.add_group_member(3, 1, 40)
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_post("/groups/3/members").
|
||||
with(:body => {:user_id => '1', :access_level => '40'})).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about an added member" do
|
||||
expect(@member.name).to eq("John Smith")
|
||||
end
|
||||
end
|
||||
|
||||
describe ".remove_group_member" do
|
||||
before do
|
||||
stub_delete("/groups/3/members/1", "group_member_delete")
|
||||
@group = Gitlab.remove_group_member(3, 1)
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_delete("/groups/3/members/1")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about the group the member was removed from" do
|
||||
expect(@group.group_id).to eq(3)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
122
lib/gitlab-cli/spec/gitlab/client/issues_spec.rb
Normal file
122
lib/gitlab-cli/spec/gitlab/client/issues_spec.rb
Normal file
@@ -0,0 +1,122 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Gitlab::Client do
|
||||
describe ".issues" do
|
||||
context "with project ID passed" do
|
||||
before do
|
||||
stub_get("/projects/3/issues", "project_issues")
|
||||
@issues = Gitlab.issues(3)
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_get("/projects/3/issues")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return an array of project's issues" do
|
||||
expect(@issues).to be_an Array
|
||||
expect(@issues.first.project_id).to eq(3)
|
||||
end
|
||||
end
|
||||
|
||||
context "without project ID passed" do
|
||||
before do
|
||||
stub_get("/issues", "issues")
|
||||
@issues = Gitlab.issues
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_get("/issues")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return an array of user's issues" do
|
||||
expect(@issues).to be_an Array
|
||||
expect(@issues.first.closed).to be_falsey
|
||||
expect(@issues.first.author.name).to eq("John Smith")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe ".issue" do
|
||||
before do
|
||||
stub_get("/projects/3/issues/33", "issue")
|
||||
@issue = Gitlab.issue(3, 33)
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_get("/projects/3/issues/33")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about an issue" do
|
||||
expect(@issue.project_id).to eq(3)
|
||||
expect(@issue.assignee.name).to eq("Jack Smith")
|
||||
end
|
||||
end
|
||||
|
||||
describe ".create_issue" do
|
||||
before do
|
||||
stub_post("/projects/3/issues", "issue")
|
||||
@issue = Gitlab.create_issue(3, 'title')
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_post("/projects/3/issues").
|
||||
with(:body => {:title => 'title'})).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about a created issue" do
|
||||
expect(@issue.project_id).to eq(3)
|
||||
expect(@issue.assignee.name).to eq("Jack Smith")
|
||||
end
|
||||
end
|
||||
|
||||
describe ".edit_issue" do
|
||||
before do
|
||||
stub_put("/projects/3/issues/33", "issue")
|
||||
@issue = Gitlab.edit_issue(3, 33, :title => 'title')
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_put("/projects/3/issues/33").
|
||||
with(:body => {:title => 'title'})).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about an edited issue" do
|
||||
expect(@issue.project_id).to eq(3)
|
||||
expect(@issue.assignee.name).to eq("Jack Smith")
|
||||
end
|
||||
end
|
||||
|
||||
describe ".close_issue" do
|
||||
before do
|
||||
stub_put("/projects/3/issues/33", "issue")
|
||||
@issue = Gitlab.close_issue(3, 33)
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_put("/projects/3/issues/33").
|
||||
with(:body => {:state_event => 'close'})).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about an closed issue" do
|
||||
expect(@issue.project_id).to eq(3)
|
||||
expect(@issue.assignee.name).to eq("Jack Smith")
|
||||
end
|
||||
end
|
||||
|
||||
describe ".reopen_issue" do
|
||||
before do
|
||||
stub_put("/projects/3/issues/33", "issue")
|
||||
@issue = Gitlab.reopen_issue(3, 33)
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_put("/projects/3/issues/33").
|
||||
with(:body => {:state_event => 'reopen'})).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about an reopened issue" do
|
||||
expect(@issue.project_id).to eq(3)
|
||||
expect(@issue.assignee.name).to eq("Jack Smith")
|
||||
end
|
||||
end
|
||||
end
|
||||
124
lib/gitlab-cli/spec/gitlab/client/merge_requests_spec.rb
Normal file
124
lib/gitlab-cli/spec/gitlab/client/merge_requests_spec.rb
Normal file
@@ -0,0 +1,124 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Gitlab::Client do
|
||||
describe ".merge_requests" do
|
||||
before do
|
||||
stub_get("/projects/3/merge_requests", "merge_requests")
|
||||
@merge_requests = Gitlab.merge_requests(3)
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_get("/projects/3/merge_requests")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return an array of project's merge requests" do
|
||||
expect(@merge_requests).to be_an Array
|
||||
expect(@merge_requests.first.project_id).to eq(3)
|
||||
end
|
||||
end
|
||||
|
||||
describe ".merge_request" do
|
||||
before do
|
||||
stub_get("/projects/3/merge_request/1", "merge_request")
|
||||
@merge_request = Gitlab.merge_request(3, 1)
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_get("/projects/3/merge_request/1")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about a merge request" do
|
||||
expect(@merge_request.project_id).to eq(3)
|
||||
expect(@merge_request.assignee.name).to eq("Jack Smith")
|
||||
end
|
||||
end
|
||||
|
||||
describe ".create_merge_request" do
|
||||
before do
|
||||
stub_post("/projects/3/merge_requests", "create_merge_request")
|
||||
end
|
||||
|
||||
it "should fail if it doesn't have a source_branch" do
|
||||
expect {
|
||||
Gitlab.create_merge_request(3, 'New merge request', :target_branch => 'master')
|
||||
}.to raise_error Gitlab::Error::MissingAttributes
|
||||
end
|
||||
|
||||
it "should fail if it doesn't have a target_branch" do
|
||||
expect {
|
||||
Gitlab.create_merge_request(3, 'New merge request', :source_branch => 'dev')
|
||||
}.to raise_error Gitlab::Error::MissingAttributes
|
||||
end
|
||||
|
||||
it "should return information about a merge request" do
|
||||
@merge_request = Gitlab.create_merge_request(3, 'New feature',
|
||||
:source_branch => 'api',
|
||||
:target_branch => 'master'
|
||||
)
|
||||
expect(@merge_request.project_id).to eq(3)
|
||||
expect(@merge_request.assignee.name).to eq("Jack Smith")
|
||||
expect(@merge_request.title).to eq('New feature')
|
||||
end
|
||||
end
|
||||
|
||||
describe ".update_merge_request" do
|
||||
before do
|
||||
stub_put("/projects/3/merge_request/2", "update_merge_request")
|
||||
@merge_request = Gitlab.update_merge_request(3, 2,
|
||||
:assignee_id => '1',
|
||||
:target_branch => 'master',
|
||||
:title => 'A different new feature'
|
||||
)
|
||||
end
|
||||
|
||||
it "should return information about a merge request" do
|
||||
expect(@merge_request.project_id).to eq(3)
|
||||
expect(@merge_request.assignee.name).to eq("Jack Smith")
|
||||
expect(@merge_request.title).to eq('A different new feature')
|
||||
end
|
||||
end
|
||||
|
||||
describe ".merge_request_comments" do
|
||||
before do
|
||||
stub_get("/projects/3/merge_request/2/comments", "merge_request_comments")
|
||||
@merge_request = Gitlab.merge_request_comments(3, 2)
|
||||
end
|
||||
|
||||
it "should return merge request's comments" do
|
||||
expect(@merge_request).to be_an Array
|
||||
expect(@merge_request.length).to eq(2)
|
||||
expect(@merge_request[0].note).to eq("this is the 1st comment on the 2merge merge request")
|
||||
expect(@merge_request[0].author.id).to eq(11)
|
||||
expect(@merge_request[1].note).to eq("another discussion point on the 2merge request")
|
||||
expect(@merge_request[1].author.id).to eq(12)
|
||||
end
|
||||
end
|
||||
|
||||
describe ".merge_request_comments" do
|
||||
before do
|
||||
stub_get("/projects/3/merge_request/2/comments", "merge_request_comments")
|
||||
@merge_request = Gitlab.merge_request_comments(3, 2)
|
||||
end
|
||||
|
||||
it "should return merge request's comments" do
|
||||
expect(@merge_request).to be_an Array
|
||||
expect(@merge_request.length).to eq(2)
|
||||
expect(@merge_request[0].note).to eq("this is the 1st comment on the 2merge merge request")
|
||||
expect(@merge_request[0].author.id).to eq(11)
|
||||
expect(@merge_request[1].note).to eq("another discussion point on the 2merge request")
|
||||
expect(@merge_request[1].author.id).to eq(12)
|
||||
end
|
||||
end
|
||||
|
||||
describe ".create_merge_request_comment" do
|
||||
before do
|
||||
stub_post("/projects/3/merge_request/2/comments", "comment_merge_request")
|
||||
end
|
||||
|
||||
it "should return information about a merge request" do
|
||||
@merge_request = Gitlab.create_merge_request_comment(3, 2, 'Cool Merge Request!')
|
||||
expect(@merge_request.note).to eq('Cool Merge Request!')
|
||||
@merge_request.author.id == 1
|
||||
end
|
||||
end
|
||||
end
|
||||
66
lib/gitlab-cli/spec/gitlab/client/milestones_spec.rb
Normal file
66
lib/gitlab-cli/spec/gitlab/client/milestones_spec.rb
Normal file
@@ -0,0 +1,66 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Gitlab::Client do
|
||||
describe ".milestones" do
|
||||
before do
|
||||
stub_get("/projects/3/milestones", "milestones")
|
||||
@milestones = Gitlab.milestones(3)
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_get("/projects/3/milestones")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return an array of project's milestones" do
|
||||
expect(@milestones).to be_an Array
|
||||
expect(@milestones.first.project_id).to eq(3)
|
||||
end
|
||||
end
|
||||
|
||||
describe ".milestone" do
|
||||
before do
|
||||
stub_get("/projects/3/milestones/1", "milestone")
|
||||
@milestone = Gitlab.milestone(3, 1)
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_get("/projects/3/milestones/1")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about a milestone" do
|
||||
expect(@milestone.project_id).to eq(3)
|
||||
end
|
||||
end
|
||||
|
||||
describe ".create_milestone" do
|
||||
before do
|
||||
stub_post("/projects/3/milestones", "milestone")
|
||||
@milestone = Gitlab.create_milestone(3, 'title')
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_post("/projects/3/milestones").
|
||||
with(:body => {:title => 'title'})).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about a created milestone" do
|
||||
expect(@milestone.project_id).to eq(3)
|
||||
end
|
||||
end
|
||||
|
||||
describe ".edit_milestone" do
|
||||
before do
|
||||
stub_put("/projects/3/milestones/33", "milestone")
|
||||
@milestone = Gitlab.edit_milestone(3, 33, :title => 'title')
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_put("/projects/3/milestones/33").
|
||||
with(:body => {:title => 'title'})).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about an edited milestone" do
|
||||
expect(@milestone.project_id).to eq(3)
|
||||
end
|
||||
end
|
||||
end
|
||||
156
lib/gitlab-cli/spec/gitlab/client/notes_spec.rb
Normal file
156
lib/gitlab-cli/spec/gitlab/client/notes_spec.rb
Normal file
@@ -0,0 +1,156 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Gitlab::Client do
|
||||
describe "notes" do
|
||||
context "when wall notes" do
|
||||
before do
|
||||
stub_get("/projects/3/notes", "notes")
|
||||
@notes = Gitlab.notes(3)
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_get("/projects/3/notes")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return an array of notes" do
|
||||
expect(@notes).to be_an Array
|
||||
expect(@notes.first.author.name).to eq("John Smith")
|
||||
end
|
||||
end
|
||||
|
||||
context "when issue notes" do
|
||||
before do
|
||||
stub_get("/projects/3/issues/7/notes", "notes")
|
||||
@notes = Gitlab.issue_notes(3, 7)
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_get("/projects/3/issues/7/notes")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return an array of notes" do
|
||||
expect(@notes).to be_an Array
|
||||
expect(@notes.first.author.name).to eq("John Smith")
|
||||
end
|
||||
end
|
||||
|
||||
context "when snippet notes" do
|
||||
before do
|
||||
stub_get("/projects/3/snippets/7/notes", "notes")
|
||||
@notes = Gitlab.snippet_notes(3, 7)
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_get("/projects/3/snippets/7/notes")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return an array of notes" do
|
||||
expect(@notes).to be_an Array
|
||||
expect(@notes.first.author.name).to eq("John Smith")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "note" do
|
||||
context "when wall note" do
|
||||
before do
|
||||
stub_get("/projects/3/notes/1201", "note")
|
||||
@note = Gitlab.note(3, 1201)
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_get("/projects/3/notes/1201")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about a note" do
|
||||
expect(@note.body).to eq("The solution is rather tricky")
|
||||
expect(@note.author.name).to eq("John Smith")
|
||||
end
|
||||
end
|
||||
|
||||
context "when issue note" do
|
||||
before do
|
||||
stub_get("/projects/3/issues/7/notes/1201", "note")
|
||||
@note = Gitlab.issue_note(3, 7, 1201)
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_get("/projects/3/issues/7/notes/1201")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about a note" do
|
||||
expect(@note.body).to eq("The solution is rather tricky")
|
||||
expect(@note.author.name).to eq("John Smith")
|
||||
end
|
||||
end
|
||||
|
||||
context "when snippet note" do
|
||||
before do
|
||||
stub_get("/projects/3/snippets/7/notes/1201", "note")
|
||||
@note = Gitlab.snippet_note(3, 7, 1201)
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_get("/projects/3/snippets/7/notes/1201")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about a note" do
|
||||
expect(@note.body).to eq("The solution is rather tricky")
|
||||
expect(@note.author.name).to eq("John Smith")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "create note" do
|
||||
context "when wall note" do
|
||||
before do
|
||||
stub_post("/projects/3/notes", "note")
|
||||
@note = Gitlab.create_note(3, "The solution is rather tricky")
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_post("/projects/3/notes").
|
||||
with(:body => {:body => 'The solution is rather tricky'})).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about a created note" do
|
||||
expect(@note.body).to eq("The solution is rather tricky")
|
||||
expect(@note.author.name).to eq("John Smith")
|
||||
end
|
||||
end
|
||||
|
||||
context "when issue note" do
|
||||
before do
|
||||
stub_post("/projects/3/issues/7/notes", "note")
|
||||
@note = Gitlab.create_issue_note(3, 7, "The solution is rather tricky")
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_post("/projects/3/issues/7/notes").
|
||||
with(:body => {:body => 'The solution is rather tricky'})).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about a created note" do
|
||||
expect(@note.body).to eq("The solution is rather tricky")
|
||||
expect(@note.author.name).to eq("John Smith")
|
||||
end
|
||||
end
|
||||
|
||||
context "when snippet note" do
|
||||
before do
|
||||
stub_post("/projects/3/snippets/7/notes", "note")
|
||||
@note = Gitlab.create_snippet_note(3, 7, "The solution is rather tricky")
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_post("/projects/3/snippets/7/notes").
|
||||
with(:body => {:body => 'The solution is rather tricky'})).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about a created note" do
|
||||
expect(@note.body).to eq("The solution is rather tricky")
|
||||
expect(@note.author.name).to eq("John Smith")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
357
lib/gitlab-cli/spec/gitlab/client/projects_spec.rb
Normal file
357
lib/gitlab-cli/spec/gitlab/client/projects_spec.rb
Normal file
@@ -0,0 +1,357 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Gitlab::Client do
|
||||
describe ".projects" do
|
||||
before do
|
||||
stub_get("/projects", "projects")
|
||||
@projects = Gitlab.projects
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_get("/projects")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return an array of projects" do
|
||||
expect(@projects).to be_an Array
|
||||
expect(@projects.first.name).to eq("Brute")
|
||||
expect(@projects.first.owner.name).to eq("John Smith")
|
||||
end
|
||||
end
|
||||
|
||||
describe ".project" do
|
||||
before do
|
||||
stub_get("/projects/3", "project")
|
||||
@project = Gitlab.project(3)
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_get("/projects/3")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about a project" do
|
||||
expect(@project.name).to eq("Gitlab")
|
||||
expect(@project.owner.name).to eq("John Smith")
|
||||
end
|
||||
end
|
||||
|
||||
describe ".project_events" do
|
||||
before do
|
||||
stub_get("/projects/2/events", "project_events")
|
||||
@events = Gitlab.project_events(2)
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_get("/projects/2/events")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return an array of events" do
|
||||
expect(@events).to be_an Array
|
||||
expect(@events.size).to eq(2)
|
||||
end
|
||||
|
||||
it "should return the action name of the event" do
|
||||
expect(@events.first.action_name).to eq("opened")
|
||||
end
|
||||
end
|
||||
|
||||
describe ".create_project" do
|
||||
before do
|
||||
stub_post("/projects", "project")
|
||||
@project = Gitlab.create_project('Gitlab')
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_post("/projects")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about a created project" do
|
||||
expect(@project.name).to eq("Gitlab")
|
||||
expect(@project.owner.name).to eq("John Smith")
|
||||
end
|
||||
end
|
||||
|
||||
describe ".create_project for user" do
|
||||
before do
|
||||
stub_post("/users", "user")
|
||||
@owner = Gitlab.create_user("john@example.com", "pass", {name: 'John Owner'})
|
||||
stub_post("/projects/user/#{@owner.id}", "project_for_user")
|
||||
@project = Gitlab.create_project('Brute', {:user_id => @owner.id})
|
||||
end
|
||||
|
||||
it "should return information about a created project" do
|
||||
expect(@project.name).to eq("Brute")
|
||||
expect(@project.owner.name).to eq("John Owner")
|
||||
end
|
||||
end
|
||||
|
||||
describe ".delete_project" do
|
||||
before do
|
||||
stub_delete("/projects/Gitlab", "project")
|
||||
@project = Gitlab.delete_project('Gitlab')
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_delete("/projects/Gitlab")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about a deleted project" do
|
||||
expect(@project.name).to eq("Gitlab")
|
||||
expect(@project.owner.name).to eq("John Smith")
|
||||
end
|
||||
end
|
||||
|
||||
describe ".team_members" do
|
||||
before do
|
||||
stub_get("/projects/3/members", "team_members")
|
||||
@team_members = Gitlab.team_members(3)
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_get("/projects/3/members")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return an array of team members" do
|
||||
expect(@team_members).to be_an Array
|
||||
expect(@team_members.first.name).to eq("John Smith")
|
||||
end
|
||||
end
|
||||
|
||||
describe ".team_member" do
|
||||
before do
|
||||
stub_get("/projects/3/members/1", "team_member")
|
||||
@team_member = Gitlab.team_member(3, 1)
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_get("/projects/3/members/1")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about a team member" do
|
||||
expect(@team_member.name).to eq("John Smith")
|
||||
end
|
||||
end
|
||||
|
||||
describe ".add_team_member" do
|
||||
before do
|
||||
stub_post("/projects/3/members", "team_member")
|
||||
@team_member = Gitlab.add_team_member(3, 1, 40)
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_post("/projects/3/members").
|
||||
with(:body => {:user_id => '1', :access_level => '40'})).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about an added team member" do
|
||||
expect(@team_member.name).to eq("John Smith")
|
||||
end
|
||||
end
|
||||
|
||||
describe ".edit_team_member" do
|
||||
before do
|
||||
stub_put("/projects/3/members/1", "team_member")
|
||||
@team_member = Gitlab.edit_team_member(3, 1, 40)
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_put("/projects/3/members/1").
|
||||
with(:body => {:access_level => '40'})).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about an edited team member" do
|
||||
expect(@team_member.name).to eq("John Smith")
|
||||
end
|
||||
end
|
||||
|
||||
describe ".remove_team_member" do
|
||||
before do
|
||||
stub_delete("/projects/3/members/1", "team_member")
|
||||
@team_member = Gitlab.remove_team_member(3, 1)
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_delete("/projects/3/members/1")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about a removed team member" do
|
||||
expect(@team_member.name).to eq("John Smith")
|
||||
end
|
||||
end
|
||||
|
||||
describe ".project_hooks" do
|
||||
before do
|
||||
stub_get("/projects/1/hooks", "project_hooks")
|
||||
@hooks = Gitlab.project_hooks(1)
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_get("/projects/1/hooks")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return an array of hooks" do
|
||||
expect(@hooks).to be_an Array
|
||||
expect(@hooks.first.url).to eq("https://api.example.net/v1/webhooks/ci")
|
||||
end
|
||||
end
|
||||
|
||||
describe ".project_hook" do
|
||||
before do
|
||||
stub_get("/projects/1/hooks/1", "project_hook")
|
||||
@hook = Gitlab.project_hook(1, 1)
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_get("/projects/1/hooks/1")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about a hook" do
|
||||
expect(@hook.url).to eq("https://api.example.net/v1/webhooks/ci")
|
||||
end
|
||||
end
|
||||
|
||||
describe ".add_project_hook" do
|
||||
context "without specified events" do
|
||||
before do
|
||||
stub_post("/projects/1/hooks", "project_hook")
|
||||
@hook = Gitlab.add_project_hook(1, "https://api.example.net/v1/webhooks/ci")
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
body = {:url => "https://api.example.net/v1/webhooks/ci"}
|
||||
expect(a_post("/projects/1/hooks").with(:body => body)).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about an added hook" do
|
||||
expect(@hook.url).to eq("https://api.example.net/v1/webhooks/ci")
|
||||
end
|
||||
end
|
||||
|
||||
context "with specified events" do
|
||||
before do
|
||||
stub_post("/projects/1/hooks", "project_hook")
|
||||
@hook = Gitlab.add_project_hook(1, "https://api.example.net/v1/webhooks/ci", push_events: true, merge_requests_events: true)
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
body = {:url => "https://api.example.net/v1/webhooks/ci", push_events: "true", merge_requests_events: "true"}
|
||||
expect(a_post("/projects/1/hooks").with(:body => body)).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about an added hook" do
|
||||
expect(@hook.url).to eq("https://api.example.net/v1/webhooks/ci")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe ".edit_project_hook" do
|
||||
before do
|
||||
stub_put("/projects/1/hooks/1", "project_hook")
|
||||
@hook = Gitlab.edit_project_hook(1, 1, "https://api.example.net/v1/webhooks/ci")
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
body = {:url => "https://api.example.net/v1/webhooks/ci"}
|
||||
expect(a_put("/projects/1/hooks/1").with(:body => body)).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about an edited hook" do
|
||||
expect(@hook.url).to eq("https://api.example.net/v1/webhooks/ci")
|
||||
end
|
||||
end
|
||||
|
||||
describe ".delete_project_hook" do
|
||||
before do
|
||||
stub_delete("/projects/1/hooks/1", "project_hook")
|
||||
@hook = Gitlab.delete_project_hook(1, 1)
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_delete("/projects/1/hooks/1")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about a deleted hook" do
|
||||
expect(@hook.url).to eq("https://api.example.net/v1/webhooks/ci")
|
||||
end
|
||||
end
|
||||
|
||||
describe ".make_forked_from" do
|
||||
before do
|
||||
stub_post("/projects/42/fork/24", "project_fork_link")
|
||||
@forked_project_link = Gitlab.make_forked_from(42, 24)
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_post("/projects/42/fork/24")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about a forked project" do
|
||||
expect(@forked_project_link.forked_from_project_id).to eq(24)
|
||||
expect(@forked_project_link.forked_to_project_id).to eq(42)
|
||||
end
|
||||
end
|
||||
|
||||
describe ".remove_forked" do
|
||||
before do
|
||||
stub_delete("/projects/42/fork", "project_fork_link")
|
||||
@forked_project_link = Gitlab.remove_forked(42)
|
||||
end
|
||||
|
||||
it "should be sent to correct resource" do
|
||||
expect(a_delete("/projects/42/fork")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about an unforked project" do
|
||||
expect(@forked_project_link.forked_to_project_id).to eq(42)
|
||||
end
|
||||
end
|
||||
|
||||
describe ".deploy_keys" do
|
||||
before do
|
||||
stub_get("/projects/42/keys", "project_keys")
|
||||
@deploy_keys = Gitlab.deploy_keys(42)
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_get("/projects/42/keys")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return project deploy keys" do
|
||||
expect(@deploy_keys).to be_an Array
|
||||
expect(@deploy_keys.first.id).to eq 2
|
||||
expect(@deploy_keys.first.title).to eq "Key Title"
|
||||
expect(@deploy_keys.first.key).to match(/ssh-rsa/)
|
||||
end
|
||||
end
|
||||
|
||||
describe ".deploy_key" do
|
||||
before do
|
||||
stub_get("/projects/42/keys/2", "project_key")
|
||||
@deploy_key = Gitlab.deploy_key(42, 2)
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_get("/projects/42/keys/2")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return project deploy key" do
|
||||
expect(@deploy_key.id).to eq 2
|
||||
expect(@deploy_key.title).to eq "Key Title"
|
||||
expect(@deploy_key.key).to match(/ssh-rsa/)
|
||||
end
|
||||
end
|
||||
|
||||
describe ".delete_deploy_key" do
|
||||
before do
|
||||
stub_delete("/projects/42/keys/2", "project_delete_key")
|
||||
@deploy_key = Gitlab.delete_deploy_key(42, 2)
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_delete("/projects/42/keys/2")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about a deleted key" do
|
||||
expect(@deploy_key.id).to eq(2)
|
||||
end
|
||||
end
|
||||
end
|
||||
92
lib/gitlab-cli/spec/gitlab/client/repositories_spec.rb
Normal file
92
lib/gitlab-cli/spec/gitlab/client/repositories_spec.rb
Normal file
@@ -0,0 +1,92 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Gitlab::Client do
|
||||
it { should respond_to :repo_tags }
|
||||
it { should respond_to :repo_create_tag }
|
||||
it { should respond_to :repo_branches }
|
||||
it { should respond_to :repo_branch }
|
||||
it { should respond_to :repo_commits }
|
||||
it { should respond_to :repo_commit }
|
||||
it { should respond_to :repo_commit_diff }
|
||||
|
||||
describe ".tags" do
|
||||
before do
|
||||
stub_get("/projects/3/repository/tags", "project_tags")
|
||||
@tags = Gitlab.tags(3)
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_get("/projects/3/repository/tags")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return an array of repository tags" do
|
||||
expect(@tags).to be_an Array
|
||||
expect(@tags.first.name).to eq("v2.8.2")
|
||||
end
|
||||
end
|
||||
|
||||
describe ".create_tag" do
|
||||
before do
|
||||
stub_post("/projects/3/repository/tags", "tag")
|
||||
@tag = Gitlab.create_tag(3, 'v1.0.0', '2695effb5807a22ff3d138d593fd856244e155e7')
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_post("/projects/3/repository/tags")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about a new repository tag" do
|
||||
expect(@tag.name).to eq("v1.0.0")
|
||||
end
|
||||
end
|
||||
|
||||
describe ".commits" do
|
||||
before do
|
||||
stub_get("/projects/3/repository/commits", "project_commits").
|
||||
with(:query => {:ref_name => "api"})
|
||||
@commits = Gitlab.commits(3, :ref_name => "api")
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_get("/projects/3/repository/commits").
|
||||
with(:query => {:ref_name => "api"})).to have_been_made
|
||||
end
|
||||
|
||||
it "should return an array of repository commits" do
|
||||
expect(@commits).to be_an Array
|
||||
expect(@commits.first.id).to eq("f7dd067490fe57505f7226c3b54d3127d2f7fd46")
|
||||
end
|
||||
end
|
||||
|
||||
describe ".commit" do
|
||||
before do
|
||||
stub_get("/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6", "project_commit")
|
||||
@commit = Gitlab.commit(3, '6104942438c14ec7bd21c6cd5bd995272b3faff6')
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_get("/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6"))
|
||||
.to have_been_made
|
||||
end
|
||||
|
||||
it "should return a repository commit" do
|
||||
expect(@commit.id).to eq("6104942438c14ec7bd21c6cd5bd995272b3faff6")
|
||||
end
|
||||
end
|
||||
|
||||
describe ".commit_diff" do
|
||||
before do
|
||||
stub_get("/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/diff", "project_commit_diff")
|
||||
@diff = Gitlab.commit_diff(3, '6104942438c14ec7bd21c6cd5bd995272b3faff6')
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_get("/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/diff"))
|
||||
.to have_been_made
|
||||
end
|
||||
|
||||
it "should return a diff of a commit" do
|
||||
expect(@diff.new_path).to eq("doc/update/5.4-to-6.0.md")
|
||||
end
|
||||
end
|
||||
end
|
||||
85
lib/gitlab-cli/spec/gitlab/client/snippets_spec.rb
Normal file
85
lib/gitlab-cli/spec/gitlab/client/snippets_spec.rb
Normal file
@@ -0,0 +1,85 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Gitlab::Client do
|
||||
describe ".snippets" do
|
||||
before do
|
||||
stub_get("/projects/3/snippets", "snippets")
|
||||
@snippets = Gitlab.snippets(3)
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_get("/projects/3/snippets")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return an array of project's snippets" do
|
||||
expect(@snippets).to be_an Array
|
||||
expect(@snippets.first.file_name).to eq("mailer_test.rb")
|
||||
end
|
||||
end
|
||||
|
||||
describe ".snippet" do
|
||||
before do
|
||||
stub_get("/projects/3/snippets/1", "snippet")
|
||||
@snippet = Gitlab.snippet(3, 1)
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_get("/projects/3/snippets/1")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about a snippet" do
|
||||
expect(@snippet.file_name).to eq("mailer_test.rb")
|
||||
expect(@snippet.author.name).to eq("John Smith")
|
||||
end
|
||||
end
|
||||
|
||||
describe ".create_snippet" do
|
||||
before do
|
||||
stub_post("/projects/3/snippets", "snippet")
|
||||
@snippet = Gitlab.create_snippet(3, {:title => 'API', :file_name => 'api.rb', :code => 'code'})
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
body = {:title => 'API', :file_name => 'api.rb', :code => 'code'}
|
||||
expect(a_post("/projects/3/snippets").with(:body => body)).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about a new snippet" do
|
||||
expect(@snippet.file_name).to eq("mailer_test.rb")
|
||||
expect(@snippet.author.name).to eq("John Smith")
|
||||
end
|
||||
end
|
||||
|
||||
describe ".edit_snippet" do
|
||||
before do
|
||||
stub_put("/projects/3/snippets/1", "snippet")
|
||||
@snippet = Gitlab.edit_snippet(3, 1, :file_name => 'mailer_test.rb')
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_put("/projects/3/snippets/1").
|
||||
with(:body => {:file_name => 'mailer_test.rb'})).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about an edited snippet" do
|
||||
expect(@snippet.file_name).to eq("mailer_test.rb")
|
||||
expect(@snippet.author.name).to eq("John Smith")
|
||||
end
|
||||
end
|
||||
|
||||
describe ".delete_snippet" do
|
||||
before do
|
||||
stub_delete("/projects/3/snippets/1", "snippet")
|
||||
@snippet = Gitlab.delete_snippet(3, 1)
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_delete("/projects/3/snippets/1")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about a deleted snippet" do
|
||||
expect(@snippet.file_name).to eq("mailer_test.rb")
|
||||
expect(@snippet.author.name).to eq("John Smith")
|
||||
end
|
||||
end
|
||||
end
|
||||
69
lib/gitlab-cli/spec/gitlab/client/system_hooks_spec.rb
Normal file
69
lib/gitlab-cli/spec/gitlab/client/system_hooks_spec.rb
Normal file
@@ -0,0 +1,69 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Gitlab::Client do
|
||||
it { should respond_to :system_hooks }
|
||||
it { should respond_to :add_system_hook }
|
||||
it { should respond_to :system_hook }
|
||||
it { should respond_to :delete_system_hook }
|
||||
|
||||
describe ".hooks" do
|
||||
before do
|
||||
stub_get("/hooks", "system_hooks")
|
||||
@hooks = Gitlab.hooks
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_get("/hooks")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return an array of system hooks" do
|
||||
expect(@hooks).to be_an Array
|
||||
expect(@hooks.first.url).to eq("http://example.com/hook")
|
||||
end
|
||||
end
|
||||
|
||||
describe ".add_hook" do
|
||||
before do
|
||||
stub_post("/hooks", "system_hook")
|
||||
@hook = Gitlab.add_hook("http://example.com/hook")
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_post("/hooks")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about a added system hook" do
|
||||
expect(@hook.url).to eq("http://example.com/hook")
|
||||
end
|
||||
end
|
||||
|
||||
describe ".hook" do
|
||||
before do
|
||||
stub_get("/hooks/3", "system_hook_test")
|
||||
@hook = Gitlab.hook(3)
|
||||
end
|
||||
it "should get the correct resource" do
|
||||
expect(a_get("/hooks/3")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about a added system hook" do
|
||||
expect(@hook.event_name).to eq("project_create")
|
||||
expect(@hook.project_id).to eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
describe ".delete_hook" do
|
||||
before do
|
||||
stub_delete("/hooks/3", "system_hook")
|
||||
@hook = Gitlab.delete_hook(3)
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_delete("/hooks/3")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about a deleted system hook" do
|
||||
expect(@hook.url).to eq("http://example.com/hook")
|
||||
end
|
||||
end
|
||||
end
|
||||
192
lib/gitlab-cli/spec/gitlab/client/users_spec.rb
Normal file
192
lib/gitlab-cli/spec/gitlab/client/users_spec.rb
Normal file
@@ -0,0 +1,192 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Gitlab::Client do
|
||||
describe ".users" do
|
||||
before do
|
||||
stub_get("/users", "users")
|
||||
@users = Gitlab.users
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_get("/users")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return an array of users" do
|
||||
expect(@users).to be_an Array
|
||||
expect(@users.first.email).to eq("john@example.com")
|
||||
end
|
||||
end
|
||||
|
||||
describe ".user" do
|
||||
context "with user ID passed" do
|
||||
before do
|
||||
stub_get("/users/1", "user")
|
||||
@user = Gitlab.user(1)
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_get("/users/1")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about a user" do
|
||||
expect(@user.email).to eq("john@example.com")
|
||||
end
|
||||
end
|
||||
|
||||
context "without user ID passed" do
|
||||
before do
|
||||
stub_get("/user", "user")
|
||||
@user = Gitlab.user
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_get("/user")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about an authorized user" do
|
||||
expect(@user.email).to eq("john@example.com")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe ".create_user" do
|
||||
context "when successful request" do
|
||||
before do
|
||||
stub_post("/users", "user")
|
||||
@user = Gitlab.create_user("email", "pass")
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
body = {:email => "email", :password => "pass", :name => "email"}
|
||||
expect(a_post("/users").with(:body => body)).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about a created user" do
|
||||
expect(@user.email).to eq("john@example.com")
|
||||
end
|
||||
end
|
||||
|
||||
context "when bad request" do
|
||||
it "should throw an exception" do
|
||||
stub_post("/users", "error_already_exists", 409)
|
||||
expect {
|
||||
Gitlab.create_user("email", "pass")
|
||||
}.to raise_error(Gitlab::Error::Conflict, "Server responded with code 409, message: 409 Already exists. Request URI: #{Gitlab.endpoint}/users")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe ".edit_user" do
|
||||
before do
|
||||
@options = { :name => "Roberto" }
|
||||
stub_put("/users/1", "user").with(:body => @options)
|
||||
@user = Gitlab.edit_user(1, @options)
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_put("/users/1").with(:body => @options)).to have_been_made
|
||||
end
|
||||
end
|
||||
|
||||
describe ".session" do
|
||||
after do
|
||||
Gitlab.endpoint = 'https://api.example.com'
|
||||
Gitlab.private_token = 'secret'
|
||||
end
|
||||
|
||||
before do
|
||||
stub_request(:post, "#{Gitlab.endpoint}/session").
|
||||
to_return(:body => load_fixture('session'), :status => 200)
|
||||
@session = Gitlab.session("email", "pass")
|
||||
end
|
||||
|
||||
context "when endpoint is not set" do
|
||||
it "should raise Error::MissingCredentials" do
|
||||
Gitlab.endpoint = nil
|
||||
expect {
|
||||
Gitlab.session("email", "pass")
|
||||
}.to raise_error(Gitlab::Error::MissingCredentials, 'Please set an endpoint to API')
|
||||
end
|
||||
end
|
||||
|
||||
context "when private_token is not set" do
|
||||
it "should not raise Error::MissingCredentials" do
|
||||
Gitlab.private_token = nil
|
||||
expect { Gitlab.session("email", "pass") }.to_not raise_error
|
||||
end
|
||||
end
|
||||
|
||||
context "when endpoint is set" do
|
||||
it "should get the correct resource" do
|
||||
expect(a_request(:post, "#{Gitlab.endpoint}/session")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about a created session" do
|
||||
expect(@session.email).to eq("john@example.com")
|
||||
expect(@session.private_token).to eq("qEsq1pt6HJPaNciie3MG")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe ".ssh_keys" do
|
||||
before do
|
||||
stub_get("/user/keys", "keys")
|
||||
@keys = Gitlab.ssh_keys
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_get("/user/keys")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return an array of SSH keys" do
|
||||
expect(@keys).to be_an Array
|
||||
expect(@keys.first.title).to eq("narkoz@helium")
|
||||
end
|
||||
end
|
||||
|
||||
describe ".ssh_key" do
|
||||
before do
|
||||
stub_get("/user/keys/1", "key")
|
||||
@key = Gitlab.ssh_key(1)
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_get("/user/keys/1")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about an SSH key" do
|
||||
expect(@key.title).to eq("narkoz@helium")
|
||||
end
|
||||
end
|
||||
|
||||
describe ".create_ssh_key" do
|
||||
before do
|
||||
stub_post("/user/keys", "key")
|
||||
@key = Gitlab.create_ssh_key("title", "body")
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
body = {:title => "title", :key => "body"}
|
||||
expect(a_post("/user/keys").with(:body => body)).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about a created SSH key" do
|
||||
expect(@key.title).to eq("narkoz@helium")
|
||||
end
|
||||
end
|
||||
|
||||
describe ".delete_ssh_key" do
|
||||
before do
|
||||
stub_delete("/user/keys/1", "key")
|
||||
@key = Gitlab.delete_ssh_key(1)
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
expect(a_delete("/user/keys/1")).to have_been_made
|
||||
end
|
||||
|
||||
it "should return information about a deleted SSH key" do
|
||||
expect(@key.title).to eq("narkoz@helium")
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user