cypher-rack-dickbarblocker 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +4 -5
- data/VERSION.yml +1 -1
- data/lib/rack/contrib/dick_bar_blocker.rb +1 -1
- data/test/spec_rack_dick_bar_blocker.rb +9 -0
- metadata +1 -1
data/README.markdown
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# rack-dickbarblocker
|
2
2
|
|
3
|
-
A Rack middleware that displays a special page
|
3
|
+
A Rack middleware that displays a special page to anyone using the DiggBar.
|
4
4
|
|
5
5
|
Hat-tip to [rue](http://github.com/rue) for suggesting the name.
|
6
6
|
|
@@ -31,7 +31,7 @@ Hat-tip to [rue](http://github.com/rue) for suggesting the name.
|
|
31
31
|
# rest of your config
|
32
32
|
end
|
33
33
|
|
34
|
-
By default, it shows the following text (sans markup):
|
34
|
+
By default, it shows the following text, taken from John Grubers page (sans markup):
|
35
35
|
|
36
36
|
> Dear Digg,
|
37
37
|
> Framing sites is bullshit.
|
@@ -59,9 +59,8 @@ You can override this by supplying the middleware with a block that returns what
|
|
59
59
|
|
60
60
|
This would return an HTML page with "Kittens are fun!" on it instead.
|
61
61
|
|
62
|
-
DickBarBlocker expects the return value of the
|
63
|
-
It also currently hardcodes the content type to `text/html`, so your
|
64
|
-
be HTML.
|
62
|
+
DickBarBlocker expects the return value of the block to respond to `to_s`.
|
63
|
+
It also currently hardcodes the content type to `text/html`, so your return value should also be (or generate) HTML.
|
65
64
|
|
66
65
|
## Copyright
|
67
66
|
|
data/VERSION.yml
CHANGED
@@ -12,7 +12,7 @@ module Rack
|
|
12
12
|
def call(env)
|
13
13
|
referrer = env['HTTP_REFERER']
|
14
14
|
# Regex courtesy of John Gruber: http://daringfireball.net/2009/04/how_to_block_the_diggbar
|
15
|
-
if referrer && referrer =~ %r{http://digg.com/\w{1,8}/*(\?.*)?$}
|
15
|
+
if referrer && referrer =~ %r{http://(?:www\.)?digg.com/\w{1,8}/*(\?.*)?$}
|
16
16
|
if @block
|
17
17
|
body = @block.call.to_s
|
18
18
|
else
|
@@ -25,6 +25,15 @@ context "Rack::Contrib::DickBarBlocker" do
|
|
25
25
|
body.should =~ %r{Dear Digg,<br>\s+Framing sites is bullshit\.<br>\s+<br>\s+Your pal,<br>\s+—J.G.}mi
|
26
26
|
end
|
27
27
|
|
28
|
+
specify "works also with a www.digg.com referrer" do
|
29
|
+
status, headers, body = Rack::Contrib::DickBarBlocker.new(app, 'J.G.').call({'HTTP_REFERER' => 'http://www.digg.com/d1oNOZ'})
|
30
|
+
|
31
|
+
status.should.equal 200
|
32
|
+
headers['Content-Type'].should.equal 'text/html'
|
33
|
+
body.should =~ %r{<title>Don't be a dick, say no to the DiggBar</title>}i
|
34
|
+
body.should =~ %r{Dear Digg,<br>\s+Framing sites is bullshit\.<br>\s+<br>\s+Your pal,<br>\s+—J.G.}mi
|
35
|
+
end
|
36
|
+
|
28
37
|
specify "uses the given name" do
|
29
38
|
name = "test name"
|
30
39
|
status, headers, body = Rack::Contrib::DickBarBlocker.new(app, name).call({'HTTP_REFERER' => 'http://digg.com/d1oNOZ'})
|