Permalink
Browse files

Fixed invalid rack response

  • Loading branch information...
jferris committed Dec 18, 2010
1 parent d3ae9ec commit 4703fe0de34a030a1ac26401cef18a88d973a9be
Showing with 7 additions and 4 deletions.
  1. +4 −3 lib/copycopter_client/inject_editor.rb
  2. +3 −1 spec/copycopter_client/inject_editor_spec.rb
@@ -19,7 +19,7 @@ def call(env)
status, headers, body =*response
if status == 200 && headers['Content-Type'].include?('text/html')
- [status, headers, inject_into(body, keys)]
+ inject_into(headers, body, keys)
else
[status, headers, body]
end
@@ -29,10 +29,11 @@ def call(env)
attr_reader :host
- def inject_into(body_parts, keys)
+ def inject_into(headers, body_parts, keys)
body = ""
body_parts.each { |part| body << part }
- [body.sub("</body>", "#{editor_html_for(keys)}</body>")]
+ injected_body = body.sub("</body>", "#{editor_html_for(keys)}</body>")
+ [200, headers.merge('Content-Length' => injected_body.size.to_s), [injected_body]]
end
def editor_html_for(keys)
@@ -41,7 +41,9 @@ def call(env)
response = call('Content-Type' => 'text/html; charset=utf-8',
'Response-Code' => 200,
'Response-Body' => "<body>hello</body>")
- response.last.should == ["<body>hello#{editor_code}</body>"]
+ expected_body = "<body>hello#{editor_code}</body>"
+ response.last.should == [expected_body]
+ response[1]['Content-Length'].should == expected_body.size.to_s
end
it "doesn't inject a translated key into html without a body tag" do

0 comments on commit 4703fe0

Please sign in to comment.