Skip to content

Commit

Permalink
Properly generating status_report even with multiple date nodes under…
Browse files Browse the repository at this point in the history
… the format node.
  • Loading branch information
kdonovan authored and esp committed Mar 2, 2010
1 parent e64d610 commit bfe8758
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
10 changes: 6 additions & 4 deletions lib/encoding_dot_com/media_status_report.rb
Expand Up @@ -20,15 +20,17 @@ def initialize(node)
@file_size = (node / "filesize").text.to_i
@notify_url = (node / "notifyurl").text

@created = parse_time_node(node / "created")
@started = parse_time_node(node / "started")
@finished = parse_time_node(node / "finished")
@downloaded = parse_time_node(node / "downloaded")
# Different xpath to handle multiple created nodes in document (e.g. in format sections)
@created = parse_time_node(node.xpath('response/created'))
@started = parse_time_node(node.xpath('response/started'))
@finished = parse_time_node(node.xpath('response/finished'))
@downloaded = parse_time_node(node.xpath('response/downloaded'))
end

private

def parse_time_node(node)
node = node.is_a?(Array) ? node.first : node
time_elements = ParseDate.parsedate(node.text)
Time.local *time_elements unless time_elements.all? {|e| e.nil? || e == 0 }
end
Expand Down
5 changes: 4 additions & 1 deletion spec/queue_spec.rb
Expand Up @@ -126,9 +126,12 @@ def expect_response_xml(response_xml)
# <processor>RACKSPACE</processor>
# <time_left>0</time_left>
# <progress>100.0</progress>
# <format>
# <created>otherTime</created>
# </format>
# </response>
it "should parse everything properly" do
expect_response_xml("<response><id>101</id><userid>100</userid><sourcefile>sourceURL</sourcefile><status>Finished</status><notifyurl>notifyURL</notifyurl><created>2010-02-26 15:29:55</created><started>2010-02-26 15:30:31</started><finished>2010-02-26 15:30:48</finished><downloaded>2010-02-26 15:30:07</downloaded><filesize>4399104</filesize><processor>RACKSPACE</processor><time_left>0</time_left><progress>100.0</progress></response>")
expect_response_xml("<response><id>101</id><userid>100</userid><sourcefile>sourceURL</sourcefile><status>Finished</status><notifyurl>notifyURL</notifyurl><created>2010-02-26 15:29:55</created><started>2010-02-26 15:30:31</started><finished>2010-02-26 15:30:48</finished><downloaded>2010-02-26 15:30:07</downloaded><filesize>4399104</filesize><processor>RACKSPACE</processor><time_left>0</time_left><progress>100.0</progress><format><created>otherTime</created></format></response>")
r = @facade.status_report("mediaid")
r.progress.should == 100
r.time_left.should == 0
Expand Down

0 comments on commit bfe8758

Please sign in to comment.