Skip to content

Commit

Permalink
Add specs
Browse files Browse the repository at this point in the history
  • Loading branch information
mdeloupy committed Oct 6, 2016
1 parent 7b6388e commit a85d166
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 14 deletions.
4 changes: 4 additions & 0 deletions lib/checklister/github/issue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ def create(project_id, attributes = {})
issue = Checklister::Issue.new(attributes.merge(project_id: project_id))
@client.create_issue(issue.project_id, issue.title, issue.description)
end

def url(issue)
JSON.parse(issue)["url"]
end
end
end
end
4 changes: 4 additions & 0 deletions lib/checklister/gitlab/issue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ def create(project_id, attributes = {})
issue = Checklister::Issue.new(attributes.merge(project_id: project_id))
@client.create_issue(issue.project_id, issue.title, description: issue.description)
end

def url(issue)
issue.to_hash["web_url"]
end
end
end
end
16 changes: 10 additions & 6 deletions spec/checklister/github/issue_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,26 @@
{ endpoint: "https://api.github.com", private_token: "supersecret", kind: "github" }
end
let(:client) { Checklister::Client.new(github_config).api_client }
let(:issue) { Checklister::Github::Issue.new(client).create(3, title: "Beatae possimus nostrum", body: "nihil reiciendis laboriosam nihil delectus alias accusantium dolor unde.") }

before(:each) do
stub_request(:post, /api.github.com/).
to_return(status: 200, body: load_fixture("github_issue"), headers: {})
end

describe "#create" do
before(:each) do
stub_request(:post, /api.github.com/).
to_return(status: 200, body: load_fixture("github_issue"), headers: {})
end

context "with valid attributes" do
it "creates an issue by calling the remote service" do
issue = Checklister::Github::Issue.new(client).create(3, title: "Beatae possimus nostrum", body: "nihil reiciendis laboriosam nihil delectus alias accusantium dolor unde.")
expect(JSON.parse(issue)["title"]).to eq("Found a bug")
expect(JSON.parse(issue)["body"]).to eq("I'm having a problem with this.")
end
end
end

context "with invalid attributes" do
describe "#url" do
it "returns the issue URL" do
expect(Checklister::Github::Issue.new(client).url(issue)).to eq "https://api.github.com/repos/octocat/Hello-World/issues/1347"
end
end
end
17 changes: 10 additions & 7 deletions spec/checklister/gitlab/issue_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,26 @@
{ endpoint: "https://www.gitlab.com/api", private_token: "supersecret", kind: "gitlab" }
end
let(:client) { Checklister::Client.new(gitlab_config).api_client }
let(:issue) { Checklister::Gitlab::Issue.new(client).create(3, title: "Beatae possimus nostrum", body: "nihil reiciendis laboriosam nihil delectus alias accusantium dolor unde.") }

describe "#create" do
before(:each) do
stub_request(:post, /www.gitlab.com/).
to_return(status: 200, body: load_fixture("issue"), headers: {})
end
before(:each) do
stub_request(:post, /www.gitlab.com/).
to_return(status: 200, body: load_fixture("issue"), headers: {})
end

describe "#create" do
context "with valid attributes" do
it "creates an issue by calling the remote service" do
issue = Checklister::Gitlab::Issue.new(client).create(3, title: "Beatae possimus nostrum", body: "nihil reiciendis laboriosam nihil delectus alias accusantium dolor unde.")
expect(issue.to_hash["project_id"]).to eq(3)
expect(issue.to_hash["title"]).to eq("Beatae possimus nostrum")
expect(issue.to_hash["description"]).to eq("nihil reiciendis laboriosam nihil delectus alias accusantium dolor unde.")
end
end
end

context "with invalid attributes" do
describe "#url" do
it "returns the issue URL" do
expect(Checklister::Gitlab::Issue.new(client).url(issue)).to eq "http://example.com/example/example/issues/14"
end
end
end
3 changes: 2 additions & 1 deletion spec/fixtures/issue.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@
},
"closed":false,
"updated_at":"2012-09-17T09:42:20Z",
"created_at":"2012-09-17T09:42:20Z"
"created_at":"2012-09-17T09:42:20Z",
"web_url": "http://example.com/example/example/issues/14"
}

0 comments on commit a85d166

Please sign in to comment.