summaryrefslogtreecommitdiff
path: root/users/test
diff options
context:
space:
mode:
Diffstat (limited to 'users/test')
-rw-r--r--users/test/functional/application_controller_test.rb29
-rw-r--r--users/test/functional/helper_methods_test.rb42
-rw-r--r--users/test/integration/api/account_flow_test.rb2
-rw-r--r--users/test/support/auth_test_helper.rb29
-rw-r--r--users/test/test_helper.rb1
-rw-r--r--users/test/unit/user_test.rb2
6 files changed, 102 insertions, 3 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..69bcb2f
--- /dev/null
+++ b/users/test/functional/application_controller_test.rb
@@ -0,0 +1,29 @@
+require 'test_helper'
+
+class ApplicationControllerTest < ActionController::TestCase
+
+ def setup
+ # so we can test the effect on the response
+ @controller.response = @response
+ end
+
+ def test_authorize_redirect
+ stub_logged_out
+ @controller.send(:authorize)
+ assert_access_denied
+ end
+
+ def test_authorized
+ @user = stub_logged_in
+ @controller.send(:authorize)
+ assert_access_denied(false)
+ end
+
+ def test_authorize_admin
+ @user = stub_logged_in
+ @user.expects(:is_admin?).returns(false)
+ @controller.send(:authorize_admin)
+ assert_access_denied
+ end
+
+end
diff --git a/users/test/functional/helper_methods_test.rb b/users/test/functional/helper_methods_test.rb
new file mode 100644
index 0000000..c0eaf61
--- /dev/null
+++ b/users/test/functional/helper_methods_test.rb
@@ -0,0 +1,42 @@
+#
+# Testing and documenting the helper methods available from
+# ApplicationController
+#
+
+require 'test_helper'
+
+class HelperMethodsTest < ActionController::TestCase
+ tests ApplicationController
+
+ # we test them right in here...
+ include ApplicationController._helpers
+
+ # they all reference the controller.
+ def controller
+ @controller
+ end
+
+ def test_current_user_with_caching
+ @user = stub_logged_in
+ assert_equal @user, current_user
+ assert_equal @user, current_user # tests caching
+ end
+
+ def test_logged_in
+ @user = stub_logged_in
+ assert logged_in?
+ end
+
+ def test_logged_out
+ stub_logged_out
+ assert !logged_in?
+ end
+
+ def test_admin
+ bool = stub
+ @user = stub_logged_in
+ @user.expects(:is_admin?).returns(bool)
+ assert_equal bool, admin?
+ end
+
+end
diff --git a/users/test/integration/api/account_flow_test.rb b/users/test/integration/api/account_flow_test.rb
index 66de1e5..5800d46 100644
--- a/users/test/integration/api/account_flow_test.rb
+++ b/users/test/integration/api/account_flow_test.rb
@@ -39,7 +39,7 @@ class AccountFlowTest < ActionDispatch::IntegrationTest
end
test "signup response" do
- assert_json_response @user_params.slice(:login, :password_salt)
+ assert_json_response :login => @login, :ok => true
assert_response :success
end
diff --git a/users/test/support/auth_test_helper.rb b/users/test/support/auth_test_helper.rb
new file mode 100644
index 0000000..9412058
--- /dev/null
+++ b/users/test/support/auth_test_helper.rb
@@ -0,0 +1,29 @@
+module AuthTestHelper
+
+ def stub_logged_in
+ @user_id = stub
+ @user = stub
+ session[:user_id] = @user_id
+ User.expects(:find).once.with(@user_id).returns(@user)
+ return @user
+ end
+
+ def stub_logged_out
+ @user_id = stub
+ session[:user_id] = @user_id
+ User.expects(:find).once.with(@user_id).returns(nil)
+ end
+
+ def assert_access_denied(denied = true)
+ if denied
+ assert_equal({:alert => "Not authorized"}, flash.to_hash)
+ assert_redirected_to login_path
+ else
+ assert flash[:alert].blank?
+ end
+ end
+end
+
+class ActionController::TestCase
+ include AuthTestHelper
+end
diff --git a/users/test/test_helper.rb b/users/test/test_helper.rb
index 08d4d41..e8f0125 100644
--- a/users/test/test_helper.rb
+++ b/users/test/test_helper.rb
@@ -7,4 +7,3 @@ Rails.backtrace_cleaner.remove_silencers!
# Load support files
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
-
diff --git a/users/test/unit/user_test.rb b/users/test/unit/user_test.rb
index 822ef33..f057ca7 100644
--- a/users/test/unit/user_test.rb
+++ b/users/test/unit/user_test.rb
@@ -19,7 +19,7 @@ class UserTest < ActiveSupport::TestCase
end
test "test require alphanumerical for login" do
- @user.login = "qwär"
+ @user.login = "qw#r"
assert !@user.valid?
end