Skip to content

Commit 7788b61

Browse files
authored
Merge pull request piotrmurach#312 from samphilipd/master
Fix some project-related unit specs, flatten namespace for listing cards
2 parents 00b7225 + 5ef5c87 commit 7788b61

File tree

15 files changed

+359
-33
lines changed

15 files changed

+359
-33
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Feature: Projects Cards API
22

33
Background:
4-
Given I have "Github::Client::Projects::Columns::Cards" instance
4+
Given I have "Github::Client::Projects::Cards" instance
55

66
Scenario: List
77

lib/github_api/client/projects.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@ class Client::Projects < API
77
PREVIEW_MEDIA = "application/vnd.github.inertia-preview+json" # :nodoc:
88

99
require_all 'github_api/client/projects',
10-
'columns'
10+
'columns',
11+
'cards'
1112

1213
# Access to Projects::Columns API
1314
namespace :columns
1415

16+
# Access to Projects::Cards API
17+
namespace :cards
18+
1519
# Get properties for a single project
1620
#
1721
# @see https://developer.github.com/v3/projects/#get-a-project

lib/github_api/client/projects/columns/cards.rb renamed to lib/github_api/client/projects/cards.rb

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
# encoding: utf-8
33

44
module Github
5-
class Client::Projects::Columns::Cards < API
5+
class Client::Projects::Cards < API
66
REQUIRED_MOVE_CARD_PARAMS = %w(position).freeze
77

88
# List project cards for a column
99
#
1010
# @example
1111
# github = Github.new
12-
# github.projects.columns.cards.list :column_id
12+
# github.projects.cards.list :column_id
1313
#
1414
# @see https://developer.github.com/v3/projects/cards/#list-project-cards
1515
#
@@ -20,15 +20,18 @@ def list(*args)
2020

2121
params["accept"] ||= ::Github::Client::Projects::PREVIEW_MEDIA
2222

23-
get_request("/projects/columns/#{arguments.column_id}/cards", params)
23+
response = get_request("/projects/columns/#{arguments.column_id}/cards", params)
24+
25+
return response unless block_given?
26+
response.each { |el| yield el }
2427
end
2528
alias all list
2629

2730
# Get a project card
2831
#
2932
# @example
3033
# github = Github.new
31-
# github.projects.columns.cards.get :card_id
34+
# github.projects.cards.get :card_id
3235
#
3336
# @see https://developer.github.com/v3/projects/cards/#get-a-project-card
3437
#
@@ -58,11 +61,11 @@ def get(*args)
5861
#
5962
# @example
6063
# github = Github.new
61-
# github.projects.columns.cards.create :column_id, note: 'Card Note'
64+
# github.projects.cards.create :column_id, note: 'Card Note'
6265
#
6366
# @example
6467
# github = Github.new
65-
# github.projects.columns.cards.create :column_id, id: <content-id>, content_type: 'content-type'
68+
# github.projects.cards.create :column_id, id: <content-id>, content_type: 'content-type'
6669
#
6770
# @see https://developer.github.com/v3/projects/cards/#create-a-project-card
6871
#
@@ -86,7 +89,7 @@ def create(*args)
8689
#
8790
# @example
8891
# github = Github.new
89-
# github.projects.columns.cards.update :card_id, note: 'New card note'
92+
# github.projects.cards.update :card_id, note: 'New card note'
9093
#
9194
# @see https://developer.github.com/v3/projects/cards/#update-a-project-card
9295
#
@@ -104,7 +107,7 @@ def update(*args)
104107
#
105108
# @example
106109
# github = Github.new
107-
# github.projects.columns.cards.delete :card_id
110+
# github.projects.cards.delete :card_id
108111
#
109112
# @see https://developer.github.com/v3/projects/cards/#delete-a-project-card
110113
#
@@ -117,6 +120,7 @@ def delete(*args)
117120

118121
delete_request("/projects/columns/cards/#{arguments.card_id}", params)
119122
end
123+
alias remove delete
120124

121125
# Move a project card
122126
#
@@ -128,11 +132,11 @@ def delete(*args)
128132
#
129133
# @example
130134
# github = Github.new
131-
# github.projects.columns.cards.move :card_id, position: 'bottom'
135+
# github.projects.cards.move :card_id, position: 'bottom'
132136
#
133137
# @example
134138
# github = Github.new
135-
# github.projects.columns.cards.move :card_id, position: 'after:<card-id>', column_id: <column-id>
139+
# github.projects.cards.move :card_id, position: 'after:<card-id>', column_id: <column-id>
136140
#
137141
# @see https://developer.github.com/v3/projects/cards/#move-a-project-card
138142
#

lib/github_api/client/projects/columns.rb

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@ class Client::Projects::Columns < API
66
REQUIRED_COLUMN_PARAMS = %w(name).freeze
77
REQUIRED_MOVE_COLUMN_PARAMS = %w(position).freeze
88

9-
require_all 'github_api/client/projects/columns',
10-
'cards'
11-
12-
# Access to Projects::Cards API
13-
namespace :cards
14-
159
# List a project's columns
1610
#
1711
# @example
@@ -27,7 +21,10 @@ def list(*args)
2721

2822
params["accept"] ||= ::Github::Client::Projects::PREVIEW_MEDIA
2923

30-
get_request("/projects/#{arguments.project_id}/columns", params)
24+
response = get_request("/projects/#{arguments.project_id}/columns", params)
25+
26+
return response unless block_given?
27+
response.each { |el| yield el }
3128
end
3229
alias all list
3330

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"url": "https://api.github.com/projects/columns/cards/1478",
3+
"column_url": "https://api.github.com/projects/columns/367",
4+
"content_url": "https://api.github.com/repos/api-playground/projects-test/issues/3",
5+
"id": 1478,
6+
"note": "Add payload for delete Project column",
7+
"creator": {
8+
"login": "octocat",
9+
"id": 1,
10+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
11+
"gravatar_id": "",
12+
"url": "https://api.github.com/users/octocat",
13+
"html_url": "https://github.com/octocat",
14+
"followers_url": "https://api.github.com/users/octocat/followers",
15+
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
16+
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
17+
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
18+
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
19+
"organizations_url": "https://api.github.com/users/octocat/orgs",
20+
"repos_url": "https://api.github.com/users/octocat/repos",
21+
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
22+
"received_events_url": "https://api.github.com/users/octocat/received_events",
23+
"type": "User",
24+
"site_admin": false
25+
},
26+
"created_at": "2016-09-05T14:21:06Z",
27+
"updated_at": "2016-09-05T14:20:22Z"
28+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[
2+
{
3+
"url": "https://api.github.com/projects/columns/cards/1478",
4+
"column_url": "https://api.github.com/projects/columns/367",
5+
"content_url": "https://api.github.com/repos/api-playground/projects-test/issues/3",
6+
"id": 1478,
7+
"note": "Add payload for delete Project column",
8+
"creator": {
9+
"login": "octocat",
10+
"id": 1,
11+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
12+
"gravatar_id": "",
13+
"url": "https://api.github.com/users/octocat",
14+
"html_url": "https://github.com/octocat",
15+
"followers_url": "https://api.github.com/users/octocat/followers",
16+
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
17+
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
18+
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
19+
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
20+
"organizations_url": "https://api.github.com/users/octocat/orgs",
21+
"repos_url": "https://api.github.com/users/octocat/repos",
22+
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
23+
"received_events_url": "https://api.github.com/users/octocat/received_events",
24+
"type": "User",
25+
"site_admin": false
26+
},
27+
"created_at": "2016-09-05T14:21:06Z",
28+
"updated_at": "2016-09-05T14:20:22Z"
29+
}
30+
]
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# encoding: utf-8
2+
3+
require 'spec_helper'
4+
5+
describe Github::Client::Projects::Cards, '#create' do
6+
let(:column_id) { 367 }
7+
let(:inputs) do
8+
{
9+
note: 'Add payload for delete Project column',
10+
content_id: 3,
11+
content_type: 'Issue'
12+
}
13+
end
14+
15+
before do
16+
subject.oauth_token = OAUTH_TOKEN
17+
stub_post(request_path).with(body: inputs)
18+
.to_return(body: body, status: status,
19+
headers: { content_type: "application/json; charset=utf-8" })
20+
end
21+
22+
after { reset_authentication_for subject }
23+
24+
context "resource created successfully" do
25+
let(:body) { fixture('projects/cards/card.json') }
26+
let(:status) { 201 }
27+
28+
context "for the authenticated user" do
29+
let(:request_path) { "/projects/columns/#{column_id}/cards?access_token=#{OAUTH_TOKEN}" }
30+
31+
it "should create resource" do
32+
subject.create column_id, inputs
33+
a_post(request_path).with(body: inputs).should have_been_made
34+
end
35+
36+
it "should return the resource" do
37+
card = subject.create column_id, inputs
38+
expect(card.note).to eq 'Add payload for delete Project column'
39+
end
40+
41+
it "should return mash type" do
42+
card = subject.create column_id, inputs
43+
expect(card).to be_a Github::ResponseWrapper
44+
end
45+
end
46+
end
47+
end # create
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
describe Github::Client::Projects::Cards, '#delete' do
6+
let(:card_id) { 1478 }
7+
let(:request_path) { "/projects/columns/cards/#{card_id}" }
8+
let(:body) { '' }
9+
let(:status) { 204 }
10+
11+
before do
12+
stub_delete(request_path).to_return(body: body, status: status,
13+
headers: { content_type: "application/json; charset=utf-8" })
14+
end
15+
16+
after { reset_authentication_for subject }
17+
18+
it { expect(subject).to respond_to :remove }
19+
20+
it "should delete the resource successfully" do
21+
subject.delete card_id
22+
expect(a_delete(request_path)).to have_been_made
23+
end
24+
25+
it "should fail to delete resource without 'id' parameter" do
26+
expect { subject.delete }.to raise_error(ArgumentError)
27+
end
28+
29+
it_should_behave_like 'request failure' do
30+
let(:requestable) { subject.delete card_id }
31+
end
32+
end # delete
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
RSpec.describe Github::Client::Projects::Cards, '#get' do
6+
let(:card_id) { 1478 }
7+
let(:request_path) { "/projects/columns/cards/#{card_id}" }
8+
let(:body) { fixture('projects/cards/card.json') }
9+
let(:status) { 200 }
10+
11+
before do
12+
stub_get(request_path).to_return(body: body, status: status,
13+
headers: { content_type: "application/json; charset=utf-8" })
14+
end
15+
16+
after { reset_authentication_for(subject) }
17+
18+
context "resource found" do
19+
it "fails to get resource without project id" do
20+
expect { subject.get }.to raise_error(ArgumentError)
21+
end
22+
23+
it "gets the resource" do
24+
subject.get(card_id)
25+
expect(a_get(request_path)).to have_been_made
26+
end
27+
28+
it "gets project information" do
29+
card = subject.get card_id
30+
expect(card.id).to eq card_id
31+
expect(card.note).to eq('Add payload for delete Project column')
32+
end
33+
34+
it "returns response wrapper" do
35+
card = subject.get card_id
36+
expect(card).to be_a Github::ResponseWrapper
37+
end
38+
end
39+
40+
it_should_behave_like 'request failure' do
41+
let(:requestable) { subject.get card_id }
42+
end
43+
end # get
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
describe Github::Client::Projects::Cards, '#list' do
6+
let(:column_id) { 367 }
7+
let(:request_path) { "/projects/columns/#{column_id}/cards" }
8+
9+
before do
10+
stub_get(request_path)
11+
.with(headers: { 'Accept' => 'application/vnd.github.inertia-preview+json' })
12+
.to_return(
13+
body: body,
14+
status: status,
15+
headers: {
16+
content_type: "application/json; charset=utf-8"
17+
}
18+
)
19+
end
20+
21+
after { reset_authentication_for(subject) }
22+
23+
context "resource found" do
24+
let(:body) { fixture('projects/cards/cards.json') }
25+
let(:status) { 200 }
26+
27+
it { expect(subject).to respond_to :all }
28+
29+
it "should fail to get resource without column_id" do
30+
expect { subject.list }.to raise_error(ArgumentError)
31+
end
32+
33+
it "should get the resources" do
34+
subject.list column_id
35+
expect(a_get(request_path)).to have_been_made
36+
end
37+
38+
it_should_behave_like 'an array of resources' do
39+
let(:requestable) { subject.list column_id }
40+
end
41+
42+
it "should get project information" do
43+
cards = subject.list column_id
44+
expect(cards.first.note).to eq 'Add payload for delete Project column'
45+
end
46+
47+
it "should yield to a block" do
48+
yielded = []
49+
result = subject.list(column_id) { |obj| yielded << obj }
50+
expect(yielded).to eq result
51+
end
52+
end
53+
54+
it_should_behave_like 'request failure' do
55+
let(:requestable) { subject.list column_id }
56+
end
57+
end # list

0 commit comments

Comments
 (0)