1
0
Fork 0
mirror of https://github.com/jnunemaker/httparty synced 2023-03-27 23:23:07 -04:00

Merge branch 'integration' of git@github.com:jnunemaker/httparty into integration

This commit is contained in:
John Nunemaker 2009-07-19 19:52:51 -04:00
commit ae3cd0f0dd
2 changed files with 14 additions and 6 deletions

View file

@ -7,6 +7,8 @@ require 'rubygems'
gem 'crack'
require 'crack'
require 'httparty/cookie_hash'
module HTTParty
AllowedFormats = {
@ -26,7 +28,9 @@ module HTTParty
base.extend ClassMethods
base.send :include, HTTParty::ModuleInheritableAttributes
base.send(:mattr_inheritable, :default_options)
base.send(:mattr_inheritable, :default_cookies)
base.instance_variable_set("@default_options", {})
base.instance_variable_set("@default_cookies", CookieHash.new)
end
module ClassMethods
@ -90,8 +94,7 @@ module HTTParty
def cookies(h={})
raise ArgumentError, 'Cookies must be a hash' unless h.is_a?(Hash)
default_options[:cookies] ||= CookieHash.new
default_options[:cookies].add_cookies(h)
default_cookies.add_cookies(h)
end
# Allows setting the format with which to parse.
@ -157,11 +160,10 @@ module HTTParty
end
def process_cookies(options) #:nodoc:
return unless options[:cookies] || default_options[:cookies]
return unless options[:cookies] || default_cookies
options[:headers] ||= {}
options[:headers]["cookie"] = cookies(options[:cookies] || {}).to_cookie_string
options[:headers]["cookie"] = cookies.merge(options[:cookies] || {}).to_cookie_string
default_options.delete(:cookies)
options.delete(:cookies)
end
end
@ -198,7 +200,6 @@ module HTTParty
end
end
require 'httparty/cookie_hash'
require 'httparty/core_extensions'
require 'httparty/exceptions'
require 'httparty/request'

View file

@ -96,6 +96,13 @@ describe HTTParty do
@klass.get("")
end
it "should pass the proper cookies when requested multiple times" do
2.times do
expect_cookie_header "type=snickerdoodle"
@klass.get("")
end
end
it "should allow the class defaults to be overridden" do
expect_cookie_header "type=chocolate_chip"