lib/stella/data/http.rb in stella-0.8.2.003 vs lib/stella/data/http.rb in stella-0.8.3.001
- old
+ new
@@ -3,12 +3,21 @@
module Stella::Data::HTTP
class Request < Storable
include Gibbler::Complex
include Stella::Data::Helpers
- field :id, &gibbler_id_processor
+ field :id => String, &gibbler_id_processor
+ # A hash containing blocks to be executed depending on the HTTP response status.
+ # The hash keys are numeric HTTP Status Codes.
+ #
+ # 200 => { ... }
+ # 304 => { ... }
+ # 500 => { ... }
+ #
+ field :response_handler => Hash, &hash_proc_processor
+
# Store the description in the attic so
# it's not used in the gibbler digest.
attic :description
field :description
@@ -22,25 +31,21 @@
field :content_type
field :http_auth
field :timeout
field :autofollow # boolean. Was this an auto generated follow request.
+
- # A hash containing blocks to be executed depending on the HTTP response status.
- # The hash keys are numeric HTTP Status Codes.
- #
- # 200 => { ... }
- # 304 => { ... }
- # 500 => { ... }
- #
- field :response_handler, &hash_proc_processor
-
def has_body?
!@body.nil?
end
- def initialize (method, uri_str, version="1.1", &definition)
+ def id
+ Gibbler::Digest.new @id || self.digest
+ end
+
+ def initialize (method=nil, uri_str=nil, version="1.1", &definition)
@uri = uri_str.to_s
@http_method, @http_version = method, version
@headers, @params, @response_handler = {}, {}, {}
@resources = {}
@autofollow = false
@@ -51,10 +56,20 @@
def autofollow!
@autofollow = true
end
+ def self.from_hash(hash={})
+ me = super(hash)
+ me.response_handler.keys.each do |status|
+ proc_str = me.response_handler[status]
+ me.response_handler[status] = eval "Proc.new #{proc_str}"
+ me.response_handler[status].source = proc_str
+ end
+ me
+ end
+
def auth(user=nil, pass=nil, domain=nil)
@http_auth ||= Stella::Testplan::Usecase::Auth.new
@http_auth.user, @http_auth.pass, @http_auth.domain = user, pass, domain
end
@@ -141,9 +156,10 @@
return [] if !header.is_a?(Hash) || header[:Cookie].empty?
header[:Cookie]
end
def freeze
+ return if frozen?
@params = convert_values_to_templates @params
@headers = convert_values_to_templates @headers
super
self
end
\ No newline at end of file