Skip to content

Commit

Permalink
test that adapters can set the User-Agent string
Browse files Browse the repository at this point in the history
  • Loading branch information
mislav committed Apr 14, 2012
1 parent 9c49b0b commit 96490b3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
6 changes: 6 additions & 0 deletions test/adapters/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ def test_GET_with_body
assert_equal %(get {"bodyrock"=>"true"}), response.body
end

def test_GET_sends_user_agent
response = create_connection(adapter).get('echo_header', {:name => 'user-agent'},
:user_agent => 'Agent Faraday')
assert_equal 'Agent Faraday', response.body
end

def test_POST_send_url_encoded_params
resp = create_connection(adapter).post do |req|
req.url 'echo_name'
Expand Down
13 changes: 0 additions & 13 deletions test/adapters/typhoeus_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,5 @@ def adapter() :typhoeus end
undef :test_GET_with_body
end

def setup
@connection = Faraday.new('http://disney.com') do |b|
b.adapter :typhoeus
end
end

def test_handles_user_agent
# default typhoeus agent
stub_request(:get, 'disney.com/world').with(:headers => {'User-Agent'=>'Faraday Agent'}){ |request|
request.headers["User-Agent"] == 'Faraday Agent'
}
@connection.get('/world', nil, :user_agent => 'Faraday Agent')
end
end
end
5 changes: 5 additions & 0 deletions test/live_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
end
end

get '/echo_header' do
header = "HTTP_#{params[:name].tr('-', '_').upcase}"
request.env.fetch(header) { 'NONE' }
end

get '/hello_world' do
'hello world'
end
Expand Down

0 comments on commit 96490b3

Please sign in to comment.