forked from jnunemaker/httparty
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correctly merge default headers with request provided headers - fixes j…
- Loading branch information
Showing
3 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper')) | ||
|
||
describe HTTParty do | ||
|
||
class SimpleClient | ||
include HTTParty | ||
end | ||
|
||
class HeadersClient | ||
include HTTParty | ||
headers "Accept" => "application/json" | ||
end | ||
|
||
def request | ||
FakeWeb.last_request | ||
end | ||
|
||
context 'request headers' do | ||
|
||
before do | ||
@headers = { "User-Agent" => 'my-ruby', 'Content-Type' => 'text/plain' } | ||
@uri = "http://localhost/request_headers" | ||
FakeWeb.register_uri(:get, @uri, :body => "OK") | ||
end | ||
|
||
it 'should correctly set the request headers' do | ||
SimpleClient.get(@uri, :headers => @headers) | ||
@headers.each do |name, value| | ||
request[name].should == value | ||
end | ||
end | ||
|
||
it 'should correctly mix the current request and default headers' do | ||
HeadersClient.get(@uri, :headers => @headers) | ||
@headers.each do |name, value| | ||
request[name].should == value | ||
end | ||
request['Accept'].should == 'application/json' | ||
end | ||
|
||
it 'should correctly override default headers with request headers' do | ||
HeadersClient.get(@uri, :headers => @headers.merge('Accept' => 'text/html')) | ||
@headers.each do |name, value| | ||
request[name].should == value | ||
end | ||
request['Accept'].should == 'text/html' | ||
end | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
$:.push File.expand_path("../lib", __FILE__) | ||
|
||
require "httparty" | ||
|
||
require 'spec/autorun' | ||
|