rack_phantom 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7b24aff91966a742772634e4476f18f033a7d90e
4
- data.tar.gz: 3eeb030ab9e14d4905975328c09c911fbc23fcb1
3
+ metadata.gz: 228af5ff03c29c2e333491e784ddbd0508ca3b6d
4
+ data.tar.gz: 31238f79e1a1b2e61c38e6df1d34670ac45e660a
5
5
  SHA512:
6
- metadata.gz: 0e8ed289c296b7eb6ff2cf190f1029192de33efcb42b9e39578b2f1ca1ed312844d1abdb3eafc55c8cec83dcbb4a2fb75a9f780a9d611c5b5a46662c476e1988
7
- data.tar.gz: 6ae87b22d1b4c2ace8bef14f9fd9020a2167dc264fc60c30abfa48e4ec046d42937cd08a335106ae4100cdef9486dcf691ce68f15b8db1caab5631e3b338992d
6
+ metadata.gz: ec40ae7c9940e0f2682193df063406e2f5688b60b59801f3f012d4166ffe8d60bdf77137ce4885bd98ab37081dbec4d4e375bdef57bd6e383917112488763cf8
7
+ data.tar.gz: 770ed195fdaade233a87457fd6844f2d11fc63a23081f863417135bfca18a3419a009e3f2efd0d93650bb6e4696a9c8bc59bb77346f292954b26dcce996c9898
@@ -21,11 +21,18 @@ module RackPhantom
21
21
 
22
22
  return [status, headers, response] unless render?(headers, env)
23
23
 
24
- html = Phantomjs.run('js/render.js', %['#{response}'])
25
- [status, headers, html]
24
+ html = Phantomjs.run(render_js, %['#{response.join("\n")}']).strip
25
+ headers['Content-Length'] = html.length.to_s
26
+
27
+ [status, headers, [html]]
26
28
  end
27
29
 
28
30
  private
31
+
32
+ def render_js
33
+ File.expand_path(File.join(File.dirname(__FILE__), '..', 'js', 'render.js'))
34
+ end
35
+
29
36
  def render?(headers, env)
30
37
  html_response?(headers) && bot?(env) && get?(env)
31
38
  end
@@ -1,3 +1,3 @@
1
1
  module RackPhantom
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe RackPhantom do
4
4
 
5
5
  let(:html) { %q{<html><head><script>document.write("Hello World");</script></head><body></body></html>} }
6
- let(:real_app) { ->(env) { [200, {'Content-Type' => 'text/html'}, html] } }
6
+ let(:real_app) { ->(env) { [200, {'Content-Type' => 'text/html'}, [html]] } }
7
7
  let(:app) { RackPhantom::Middleware.new(real_app) }
8
8
 
9
9
 
@@ -11,7 +11,12 @@ describe RackPhantom do
11
11
  it 'should execute javascript' do
12
12
  get '/', {}, as_bot
13
13
  last_response.should be_ok
14
- last_response.body.strip.should == evaluated_html
14
+ last_response.body.should == evaluated_html
15
+ end
16
+
17
+ it 'should update the content length header' do
18
+ get '/', {}, as_bot
19
+ last_response.headers['Content-Length'].should == evaluated_html.length.to_s
15
20
  end
16
21
 
17
22
  it 'escapes the single quotes'
@@ -25,24 +30,24 @@ describe RackPhantom do
25
30
  context 'for non bots' do
26
31
  it 'should not render' do
27
32
  get '/'
28
- last_response.body.strip.should == html
33
+ last_response.body.should == html
29
34
  end
30
35
  end
31
36
 
32
37
  context 'for POST requests' do
33
38
  it 'should not render' do
34
39
  post '/', {}, as_bot
35
- last_response.body.strip.should == html
40
+ last_response.body.should == html
36
41
  end
37
42
  end
38
43
 
39
44
  context 'for non html responses' do
40
45
  let(:json) { '{}' }
41
- let(:real_app) { ->(env) { [200, {'Content-Type' => 'application/json'}, json] } }
46
+ let(:real_app) { ->(env) { [200, {'Content-Type' => 'application/json'}, [json]] } }
42
47
 
43
48
  it 'should not render' do
44
49
  get '/'
45
- last_response.body.strip.should == json
50
+ last_response.body.should == json
46
51
  end
47
52
  end
48
53
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack_phantom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Selva