Skip to content

Commit

Permalink
Merge branch 'integration' of git@github.com:jnunemaker/httparty into…
Browse files Browse the repository at this point in the history
… integration
  • Loading branch information
jnunemaker committed Jul 19, 2009
2 parents baa0ab5 + cf420a0 commit ae3cd0f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/httparty.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
gem 'crack'
require 'crack'

require 'httparty/cookie_hash'

module HTTParty

AllowedFormats = {
Expand All @@ -26,7 +28,9 @@ def self.included(base)
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
Expand Down Expand Up @@ -90,8 +94,7 @@ def headers(h={})

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.
Expand Down Expand Up @@ -157,11 +160,10 @@ def perform_request(http_method, path, options) #:nodoc:
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
Expand Down Expand Up @@ -198,7 +200,6 @@ def self.delete(*args)
end
end

require 'httparty/cookie_hash'
require 'httparty/core_extensions'
require 'httparty/exceptions'
require 'httparty/request'
Expand Down
7 changes: 7 additions & 0 deletions spec/httparty_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ def expect_cookie_header(s)
@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"

Expand Down

0 comments on commit ae3cd0f

Please sign in to comment.