Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/yammer/http_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def send_request(method, path, opts={})
result = Yammer::ApiResponse.new(resp.headers, resp.body, resp.code)
rescue => e
if e.is_a?(RestClient::ExceptionWithResponse)
e.response
Yammer::Error.from_status(e.http_code)
else
raise e
end
Expand Down
36 changes: 34 additions & 2 deletions spec/http_adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,39 @@
end
end

context "initialization" do
describe "#send_request" do
context 'when resource is found' do
subject { @conn = Yammer::HttpAdapter.new('https://www.yammer.com') }
let(:uri) { 'https://www.yammer.com/foo' }
before { stub_request(:get, uri).to_return(status: 200, body: nil) }
it "returns a Yammer APIResponse" do
response = subject.send_request(:get, "/foo")
expect(response).to be_a(Yammer::ApiResponse)
end
end

context 'when resource is not found' do
subject { @conn = Yammer::HttpAdapter.new('https://www.yammer.com') }
let(:uri) { 'https://www.yammer.com/foo' }
before { stub_request(:get, uri).to_return(status: 404, body: nil) }
it "returns a Yammer APIResponse" do
response = subject.send_request(:get, "/foo")
expect(response).to eq(Yammer::Error::NotFound)
end
end

context 'when resource is unauthorized' do
subject { @conn = Yammer::HttpAdapter.new('https://www.yammer.com') }
let(:uri) { 'https://www.yammer.com/foo' }
before { stub_request(:get, uri).to_return(status: 401, body: nil) }
it "returns a Yammer APIResponse" do
response = subject.send_request(:get, "/foo")
expect(response).to eq(Yammer::Error::Unauthorized )
end
end
end

context "initialization" do
context "with user options" do

before do
Expand Down Expand Up @@ -106,4 +138,4 @@
end
end
end
end
end