Skip to content

Commit ae06e95

Browse files
author
Sam Davies
committed
Update a project
1 parent 2d2f3fb commit ae06e95

2 files changed

Lines changed: 77 additions & 0 deletions

File tree

lib/github_api/client/projects.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,33 @@ def get(*args)
2727
get_request("/projects/#{arguments.id}", params)
2828
end
2929
alias_method :find, :get
30+
31+
# Edit a project
32+
#
33+
# @param [Hash] params
34+
# @option params [String] :name
35+
# Optional string
36+
# @option params [String] :body
37+
# Optional string
38+
# @option params [String] :state
39+
# Optional string
40+
#
41+
# @example
42+
# github = Github.new
43+
# github.projects.edit 1002604,
44+
# name: "Outcomes Tracker",
45+
# body: "The board to track work for the Outcomes application."
46+
#
47+
# @api public
48+
def edit(*args)
49+
arguments(args, required: [:id]) do
50+
permit %w[ name body state ]
51+
end
52+
53+
params = arguments.params
54+
params['options'] = OPTIONS
55+
56+
patch_request("/projects/#{arguments.id}",params)
57+
end
3058
end # Projects
3159
end # Github
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
RSpec.describe Github::Client::Projects, '#edit' do
6+
let(:project_id) { 1002604 }
7+
let(:request_path) { "/projects/#{project_id}" }
8+
let(:body) { fixture("projects/project.json") }
9+
let(:status) { 200 }
10+
let(:inputs) {
11+
{
12+
"name" => 'Outcomes Tracker',
13+
"body" => "The board to track work for the Outcomes application."
14+
}
15+
}
16+
17+
before do
18+
stub_patch(request_path).with(inputs).
19+
to_return(body: body, status: status,
20+
headers: {content_type: 'application/json; charset=utf-8'})
21+
end
22+
23+
after { reset_authentication_for(subject) }
24+
25+
context "resource edited successfully" do
26+
it "fails to edit without id parameter" do
27+
expect { subject.edit }.to raise_error(ArgumentError)
28+
end
29+
30+
it "edits the resource" do
31+
subject.edit(project_id, inputs)
32+
expect(a_patch(request_path).with(inputs)).to have_been_made
33+
end
34+
35+
it "returns resource" do
36+
project = subject.edit project_id, inputs
37+
expect(project).to be_a Github::ResponseWrapper
38+
end
39+
40+
it "retrieves information" do
41+
project = subject.edit project_id
42+
expect(project.name).to eq('Projects Documentation')
43+
end
44+
end
45+
46+
it_should_behave_like 'request failure' do
47+
let(:requestable) { subject.edit project_id }
48+
end
49+
end # edit

0 commit comments

Comments
 (0)