prerender_rails 0.1.5 → 0.1.6

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: 9f6ccf511a4930229738289e20a58cd4563699b9
4
- data.tar.gz: bd43962bf1bb2388b622903626cae2d7f0f6c86a
3
+ metadata.gz: b445e95eba89c9f2c17ef1bfba560d12d47ec6cb
4
+ data.tar.gz: 119ded420f8926a35ffc37bc61bac6872f226f5d
5
5
  SHA512:
6
- metadata.gz: 78c2a53a69a90f6b39b3cf72b456d74880376af05e73503c82603c8988ee5a79116d0264a555e302c05c1b0c91177ffd9876dc0ebbd594e93b8f42a52a3f06d0
7
- data.tar.gz: e23f7ab089d525a29f7d6c902722147722c6fabad1cf4d8caf90bc81aac6985012aa0b085402a5b433919b9fba5aeaf976db9b9484ae1eb8a5735297670cd0ad
6
+ metadata.gz: 7416c6e2b014f91ef21acd2fbe5713052725262b5855c4d14ebeff86012c62702378ea6e3ad8545f8f2b3b3ffa7ccefefb1bd821af77ef54b019edaac4009e08
7
+ data.tar.gz: a4bdc217487a6814bf6d096d852733ada4a11a30f8a090925be4b618f343945f5b3a227272778af01d0ca3af7d4cb5377b0fd887f6984d398ebb35a8d68674f1
@@ -66,7 +66,7 @@ module Rack
66
66
  prerendered_response = get_prerendered_page_response(env)
67
67
 
68
68
  if prerendered_response
69
- response = Rack::Response.new(prerendered_response.body, prerendered_response.code, [])
69
+ response = Rack::Response.new(prerendered_response.body, prerendered_response.code, prerendered_response.header)
70
70
  return response.finish
71
71
  end
72
72
  end
@@ -77,6 +77,7 @@ module Rack
77
77
  def should_show_prerendered_page(env)
78
78
  user_agent = env['HTTP_USER_AGENT']
79
79
  return false if !user_agent
80
+ return false if env['REQUEST_METHOD'] != 'GET'
80
81
 
81
82
  request = Rack::Request.new(env)
82
83
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "prerender_rails"
5
- spec.version = "0.1.5"
5
+ spec.version = "0.1.6"
6
6
  spec.authors = ["Todd Hooper"]
7
7
  spec.email = ["todd@collectiveip.com"]
8
8
  spec.description = %q{Rails middleware to prerender your javascript heavy pages on the fly by a phantomjs service}
@@ -13,13 +13,14 @@ describe Rack::Prerender do
13
13
  @prerender = Rack::Prerender.new(@app)
14
14
  end
15
15
 
16
- it "should return a prerendered response for a crawler with the returned status code" do
16
+ it "should return a prerendered response for a crawler with the returned status code and headers" do
17
17
  request = Rack::MockRequest.env_for "/", "HTTP_USER_AGENT" => bot
18
- stub_request(:get, @prerender.build_api_url(request)).with(:headers => { 'User-Agent' => bot }).to_return(:body => "<html></html>", :status => 201)
18
+ stub_request(:get, @prerender.build_api_url(request)).with(:headers => { 'User-Agent' => bot }).to_return(:body => "<html></html>", :status => 301, :headers => { 'Location' => 'http://google.com'})
19
19
  response = Rack::Prerender.new(@app).call(request)
20
20
 
21
21
  assert_equal response[2].body, ["<html></html>"]
22
- assert_equal response[2].status, 201
22
+ assert_equal response[2].status, 301
23
+ assert_equal response[2].headers, { 'location' => 'http://google.com', 'Content-Length' => '13'}
23
24
  end
24
25
 
25
26
  it "should return a prerendered reponse if user is a bot by checking for _escaped_fragment_" do
@@ -37,6 +38,13 @@ describe Rack::Prerender do
37
38
  assert_equal response[2], ""
38
39
  end
39
40
 
41
+ it "should continue to app routes if the request is not a GET" do
42
+ request = Rack::MockRequest.env_for "/path?_escaped_fragment_=", { "HTTP_USER_AGENT" => user, "REQUEST_METHOD" => "POST" }
43
+ response = Rack::Prerender.new(@app).call(request)
44
+
45
+ assert_equal response[2], ""
46
+ end
47
+
40
48
  it "should continue to app routes if user is not a bot by checking agent string" do
41
49
  request = Rack::MockRequest.env_for "/", "HTTP_USER_AGENT" => user
42
50
  response = Rack::Prerender.new(@app).call(request)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prerender_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Todd Hooper
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-31 00:00:00.000000000 Z
11
+ date: 2013-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack