summaryrefslogtreecommitdiff
path: root/users/test/functional/application_controller_test.rb
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2012-10-24 20:35:52 +0200
committerAzul <azul@leap.se>2012-10-24 20:35:52 +0200
commit3e0a1a47c0eafb7f9b79e5f2765ea33ce1ad159b (patch)
tree8c69443d15f23b391cdb282f9194d293307c98e4 /users/test/functional/application_controller_test.rb
parent3ba2e664a26e96a93c8640b57241af6386db361e (diff)
basic admin controller methods and helpers + tests
Diffstat (limited to 'users/test/functional/application_controller_test.rb')
-rw-r--r--users/test/functional/application_controller_test.rb44
1 files changed, 44 insertions, 0 deletions
diff --git a/users/test/functional/application_controller_test.rb b/users/test/functional/application_controller_test.rb
new file mode 100644
index 0000000..d13a354
--- /dev/null
+++ b/users/test/functional/application_controller_test.rb
@@ -0,0 +1,44 @@
+require 'test_helper'
+
+class ApplicationControllerTest < ActionController::TestCase
+
+ def setup
+ @user_id = stub
+ @user = stub
+ session[:user_id] = @user_id
+ # so we can test the effect on the response
+ @controller.response = @response
+ end
+
+ def test_authorize_redirect
+ session[:user_id] = nil
+ @controller.send(:authorize)
+ assert_access_denied
+ end
+
+ def test_current_user_with_caching
+ User.expects(:find).once.with(@user_id).returns(@user)
+ assert_equal @user, @controller.send(:current_user)
+ assert_equal @user, @controller.send(:current_user) # tests caching
+ end
+
+ def test_authorized
+ User.expects(:find).once.with(@user_id).returns(@user)
+ @controller.send(:authorize)
+ end
+
+ def test_admin
+ bool = stub
+ User.expects(:find).once.with(@user_id).returns(@user)
+ @user.expects(:is_admin?).returns(bool)
+ assert_equal bool, @controller.send(:admin?)
+ end
+
+ def test_authorize_admin
+ User.expects(:find).once.with(@user_id).returns(@user)
+ @user.expects(:is_admin?).returns(false)
+ @controller.send(:authorize_admin)
+ assert_access_denied
+ end
+
+end