Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0ac9bb6
Showing
4 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# rack-noie | ||
|
||
rack-noie is the coolest rack middleware ever created. And it is so because it does _everyone_ | ||
a favor: it shows the way out of your website to poor souls out there using Internet Explorer 6. | ||
|
||
I don't wanna hear excuses. IE6 stinks. If we keep developing software that plays well with it, | ||
they'll come up with yet more crap (read: IE7, although a little bit less bad than IE6), until | ||
Microsoft single-handedly manages to hold us back for a few more years. | ||
|
||
# usage | ||
|
||
just | ||
|
||
require 'noie' # or 'juliocesar-noie' when i gemify it | ||
|
||
and | ||
|
||
use NoIE, :redirect => '/noieplease.html' | ||
|
||
the above will redirect to a page noieplease.html in your website. You can redirect to | ||
a URL as well, like so | ||
|
||
use NoIE, :redirect => 'http://slashdot.org' | ||
|
||
or let the default kick in | ||
|
||
use NoIE | ||
|
||
# disclaimer | ||
|
||
I'm a nice guy. I'm so nice that the default URL points to Microsoft's IE7 upgrade page. | ||
|
||
# license | ||
|
||
MIT, as usual. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require 'rake/testtask' | ||
|
||
task :default => [:test] | ||
|
||
Rake::TestTask.new do |task| | ||
task.pattern = 'test/noie_test.rb' | ||
task.warning, task.verbose = true, true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class NoIE | ||
def initialize(app, options = {}) | ||
@app = app | ||
@options = options | ||
# Defaults to a slighly less of an excuse that passes for a browser | ||
@options[:redirect] ||= 'http://www.microsoft.com/windows/downloads/ie/getitnow.mspx' | ||
end | ||
|
||
def call(env) | ||
ie6_found_in?(env) ? kick_it : @app.call(env) | ||
end | ||
|
||
private | ||
def ie6_found_in?(env) | ||
env['HTTP_USER_AGENT'][/MSIE 6.0/] and @options[:redirect] != env['PATH_INFO'] | ||
end | ||
|
||
def kick_it | ||
[301, {'Location' => @options[:redirect]}, 'Fail browser is fail'] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require 'test/unit' | ||
|
||
require 'rubygems' | ||
require 'rack/mock' | ||
|
||
require File.join(File.dirname(__FILE__), '..', 'lib', 'noie') | ||
|
||
class TestApp | ||
def call(env) | ||
[200, {}, 'Hi Internets!'] | ||
end | ||
end | ||
|
||
class NoieTest < Test::Unit::TestCase | ||
|
||
def test_redirects_to_where_it_should_if_ie6 | ||
request = Rack::MockRequest.new(NoIE.new(TestApp.new, {:redirect => 'http://slashdot.org'})) | ||
response = request.get('/', {'HTTP_USER_AGENT' => 'MSIE 6.0' }) | ||
assert_equal 301, response.status | ||
assert_equal response.location, 'http://slashdot.org' | ||
end | ||
|
||
def test_allows_local_local_urls | ||
request = Rack::MockRequest.new(NoIE.new(TestApp.new, {:redirect => '/foo'})) | ||
response = request.get('/foo', {'HTTP_USER_AGENT' => 'MSIE 6.0' }) | ||
assert_equal "Hi Internets!", response.body | ||
end | ||
|
||
end |