Skip to content

Commit

Permalink
Merge pull request #25 from planningcenter/204-no-content
Browse files Browse the repository at this point in the history
Fix bug handling 204 No Content responses
  • Loading branch information
seven1m authored Jan 10, 2023
2 parents e82c4bb + ab953e1 commit 963a645
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 26 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# 2.0.2 (January 10, 2023)

- Fix: fix bug handling 204 No Content responses

# 2.0.1 (August 8, 2022)

- Chore: Update Faraday dependency and update Faraday auth setup
- Chore: update Faraday dependency and update Faraday auth setup

# 2.0.0 (March 1, 2021)

Expand Down
6 changes: 5 additions & 1 deletion lib/pco/api/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ def delete

def _build_response(result)
case result.status
when 204
res = Response.new
res.headers = result.headers
res
when 200..299
res = Response[result.body]
res.headers = result.headers
Expand Down Expand Up @@ -158,4 +162,4 @@ def _retry_after_timeout?(e)
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/pco/api/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module PCO
module API
VERSION = '2.0.1'
VERSION = '2.0.2'
end
end
63 changes: 40 additions & 23 deletions spec/pco/api/endpoint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,34 +169,51 @@
end

describe '#post' do
subject { base.people.v2.people }
context do
subject { base.people.v2.people }

let(:resource) do
{
'type' => 'Person',
'first_name' => 'Tim',
'last_name' => 'Morgan'
}
end
let(:resource) do
{
'type' => 'Person',
'first_name' => 'Tim',
'last_name' => 'Morgan'
}
end

let(:result) do
{
'type' => 'Person',
'id' => '1',
'first_name' => 'Tim',
'last_name' => 'Morgan'
}
end
let(:result) do
{
'type' => 'Person',
'id' => '1',
'first_name' => 'Tim',
'last_name' => 'Morgan'
}
end

before do
stub_request(:post, 'https://api.planningcenteronline.com/people/v2/people')
.to_return(status: 201, body: { data: result }.to_json, headers: { 'Content-Type' => 'application/vnd.api+json' })
@result = subject.post(data: resource)
before do
stub_request(:post, 'https://api.planningcenteronline.com/people/v2/people')
.to_return(status: 201, body: { data: result }.to_json, headers: { 'Content-Type' => 'application/vnd.api+json' })
@result = subject.post(data: resource)
end

it 'returns the result of making a POST request to the endpoint' do
expect(@result).to be_a(Hash)
expect(@result['data']).to eq(result)
end
end

it 'returns the result of making a POST request to the endpoint' do
expect(@result).to be_a(Hash)
expect(@result['data']).to eq(result)
context 'given a 204 No Content response' do
subject { base.people.v2.some_action }

before do
stub_request(:post, 'https://api.planningcenteronline.com/people/v2/some_action')
.to_return(status: 204, body: '')
@result = subject.post
end

it 'returns an empty hash' do
expect(@result).to be_a(Hash)
expect(@result).to eq({})
end
end
end

Expand Down

0 comments on commit 963a645

Please sign in to comment.