Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
juliocesar committed Apr 14, 2009
0 parents commit 0ac9bb6
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 0 deletions.
35 changes: 35 additions & 0 deletions README.markdown
@@ -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.
8 changes: 8 additions & 0 deletions Rakefile
@@ -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
21 changes: 21 additions & 0 deletions lib/noie.rb
@@ -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
29 changes: 29 additions & 0 deletions test/noie_test.rb
@@ -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

0 comments on commit 0ac9bb6

Please sign in to comment.