Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

do not add the Provider layout if the heroku-nav-data cookie is not p…

…resent
  • Loading branch information...
commit 7ffd6d55b54e3b2ee70c5409be62e9d5de4b9e4d 1 parent 3368a38
@pedro pedro authored
Showing with 39 additions and 18 deletions.
  1. +4 −0 lib/heroku/nav.rb
  2. +35 −18 spec/nav_spec.rb
View
4 lib/heroku/nav.rb
@@ -118,6 +118,10 @@ def html
end
end
+ def can_insert?(env)
+ super && env['HTTP_COOKIE'] && env['HTTP_COOKIE'].include?('heroku-nav-data')
+ end
+
def insert!
if @nav
match = @body.match(/(\<body[^\>]*\>)/i)
View
53 spec/nav_spec.rb
@@ -112,35 +112,52 @@ def app
Heroku::Nav::Provider.stubs(:fetch).returns('<!-- heroku header -->')
end
- def app
- make_app { use Heroku::Nav::Provider }
- end
-
- it "adds the body" do
- get '/', :body => '<html><body>hi</body>'
- last_response.body.should.equal '<html><body><!-- heroku header -->hi</body>'
- end
+ describe "when there's no heroku-nav-data cookie" do
+ def app
+ make_app { use Heroku::Nav::Provider }
+ end
- it "doesn't add if there is no body tag" do
- get '/', :body => 'no body!'
- last_response.body.should.equal 'no body!'
+ it "doesn't add the body" do
+ get '/', :body => '<html><body>hi</body>'
+ last_response.body.should.equal '<html><body>hi</body>'
+ end
end
- describe "special chars" do
+ describe "when there's a heroku-nav-data cookie" do
before do
- Heroku::Nav::Provider.stubs(:fetch).returns('<!-- \+ nav -->')
+ set_cookie("heroku-nav-data=data")
end
def app
make_app { use Heroku::Nav::Provider }
end
- # tricky situation, the first implementation of Heroku::Nav would inject the
- # html by using gsub. That worked out alright until the html got a sequence of
- # chars like "\+". those got interpreted by gsub and resulted in a bad output
- it "doesn't freakout if the header contains special chars relevant to Ruby's gsub" do
+ it "adds the body" do
get '/', :body => '<html><body>hi</body>'
- last_response.body.should.equal '<html><body><!-- \+ nav -->hi</body>'
+ last_response.body.should.equal '<html><body><!-- heroku header -->hi</body>'
+ end
+
+ it "doesn't add if there is no body tag" do
+ get '/', :body => 'no body!'
+ last_response.body.should.equal 'no body!'
+ end
+
+ describe "special chars" do
+ before do
+ Heroku::Nav::Provider.stubs(:fetch).returns('<!-- \+ nav -->')
+ end
+
+ def app
+ make_app { use Heroku::Nav::Provider }
+ end
+
+ # tricky situation, the first implementation of Heroku::Nav would inject the
+ # html by using gsub. That worked out alright until the html got a sequence of
+ # chars like "\+". those got interpreted by gsub and resulted in a bad output
+ it "doesn't freakout if the header contains special chars relevant to Ruby's gsub" do
+ get '/', :body => '<html><body>hi</body>'
+ last_response.body.should.equal '<html><body><!-- \+ nav -->hi</body>'
+ end
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.