Skip to content
This repository has been archived by the owner on Oct 19, 2023. It is now read-only.

Commit

Permalink
Instead of 'signing' the page with 'J.G.', force a custom name when n…
Browse files Browse the repository at this point in the history
…o block is given.
  • Loading branch information
cypher committed Apr 11, 2009
1 parent 0303afe commit 873efbd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
7 changes: 5 additions & 2 deletions lib/rack/contrib/dick_bar_blocker.rb
@@ -1,8 +1,11 @@
module Rack
module Contrib
class DickBarBlocker
def initialize(app, &block)
def initialize(app, name = nil, &block)
raise ArgumentError, "You need to supply a name or a block" if name.nil? and block.nil?

@app = app
@name = name
@block = block
end

Expand Down Expand Up @@ -41,7 +44,7 @@ def call(env)
Framing sites is bullshit.<br>
<br>
Your pal,<br>
J.G.
#{@name}
</p>
<p>
p.s. Firefox users may enjoy the<br>
Expand Down
19 changes: 17 additions & 2 deletions test/spec_rack_dick_bar_blocker.rb
Expand Up @@ -7,7 +7,7 @@

context "non-digg-toolbar referrer" do
specify "returns unmodified response" do
status, headers, body = Rack::Contrib::DickBarBlocker.new(app).call({'HTTP_REFERER' => 'http://daringfireball.net'})
status, headers, body = Rack::Contrib::DickBarBlocker.new(app, 'J.G.').call({'HTTP_REFERER' => 'http://daringfireball.net'})

status.should.equal 200
headers['Content-Type'].should.equal 'text/plain'
Expand All @@ -17,14 +17,29 @@

context "via digg bar" do
specify "return anti-digg-toolbar site" do
status, headers, body = Rack::Contrib::DickBarBlocker.new(app).call({'HTTP_REFERER' => 'http://digg.com/d1oNOZ'})
status, headers, body = Rack::Contrib::DickBarBlocker.new(app, 'J.G.').call({'HTTP_REFERER' => 'http://digg.com/d1oNOZ'})

status.should.equal 200
headers['Content-Type'].should.equal 'text/html'
body.should =~ %r{<title>Don't be a dick, say no to the DiggBar</title>}i
body.should =~ %r{Dear Digg,<br>\s+Framing sites is bullshit\.<br>\s+<br>\s+Your pal,<br>\s+—J.G.}mi
end

specify "uses the given name" do
name = "test name"
status, headers, body = Rack::Contrib::DickBarBlocker.new(app, name).call({'HTTP_REFERER' => 'http://digg.com/d1oNOZ'})

status.should.equal 200
headers['Content-Type'].should.equal 'text/html'
body.should =~ %r{Your pal,<br>\s+—#{name}}i
end

specify "raises an error when no name or block is supplied" do
lambda {
Rack::Contrib::DickBarBlocker.new(app).call({'HTTP_REFERER' => 'http://digg.com/d1oNOZ'})
}.should.raise ArgumentError
end

specify "returns custom content when supplied with a block" do
block = lambda { "Here be kittens." }
status, headers, body = Rack::Contrib::DickBarBlocker.new(app, &block).call({'HTTP_REFERER' => 'http://digg.com/d1oNOZ'})
Expand Down

0 comments on commit 873efbd

Please sign in to comment.