Permalink
Browse files

Step 1: We're going to extract the authorization into a middleware; l…

…et's test it first.
  • Loading branch information...
1 parent 8763add commit 6e476294165a5c846f5ac06976a27148e7116b04 Yehuda Katz + Carl Lerche committed with Carl Lerche Aug 25, 2009
Showing with 38 additions and 0 deletions.
  1. +35 −0 test/integration/middleware_test.rb
  2. +3 −0 test/test_helper.rb
@@ -0,0 +1,35 @@
+require File.join(File.dirname(__FILE__), '..', 'test_helper')
+
+require 'webrat'
+
+Webrat.configure do |config|
+ config.mode = :rails
+end
+
+class MiddlewareTest < ActionController::IntegrationTest
+ def setup
+ User.delete_all
+ User.create(:name => "dave", :password => "secret", :password_confirmation => "secret")
+ end
+
+ # Replace this with your real tests.
+ test "login does return a 401" do
+ visit "/admin/login"
+ assert_response :success
+ end
+
+ test "other URLs return a 401" do
+ visit "/admin"
+ assert_response :unauthorized
+ assert_have_selector "p:contains('Access denied')"
+ end
+
+ test "if the user is :logged_out, redirect to /admin/login" do
+ basic_auth "dave", "secret"
+ visit "/admin"
+ visit "/admin/logout"
+
+ visit "/admin"
+ assert_equal current_url, "/admin/login"
+ end
+end
View
@@ -0,0 +1,3 @@
+ENV["RAILS_ENV"] = "test"
+require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
+require 'test_help'

0 comments on commit 6e47629

Please sign in to comment.