summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjessib <jessib@leap.se>2013-01-17 12:35:48 -0800
committerjessib <jessib@leap.se>2013-01-17 12:35:48 -0800
commitcce882a42cc0c139b75d932ea8ee42525e4fdb32 (patch)
tree03e8643035aa61bb0f650175309e7dedf0d2b44a
parenta4105f068e6f8ce89fbba475048f2a1e02e0fcbc (diff)
Should be able to create a user when not logged in.
This isn't ready to merge, as there is an issue with logging in as an admin in the test.
-rw-r--r--users/app/controllers/users_controller.rb2
-rw-r--r--users/test/functional/users_controller_test.rb26
2 files changed, 25 insertions, 3 deletions
diff --git a/users/app/controllers/users_controller.rb b/users/app/controllers/users_controller.rb
index a8ba1ab..c0fe243 100644
--- a/users/app/controllers/users_controller.rb
+++ b/users/app/controllers/users_controller.rb
@@ -3,7 +3,7 @@ class UsersController < ApplicationController
skip_before_filter :verify_authenticity_token, :only => [:create]
- before_filter :authorize
+ before_filter :authorize, :only => [:show, :edit, :update, :destroy]
before_filter :fetch_user, :only => [:show, :edit, :update, :destroy]
before_filter :set_anchor, :only => [:edit, :update]
before_filter :authorize_admin, :only => [:index]
diff --git a/users/test/functional/users_controller_test.rb b/users/test/functional/users_controller_test.rb
index 46db4d1..8c584ef 100644
--- a/users/test/functional/users_controller_test.rb
+++ b/users/test/functional/users_controller_test.rb
@@ -10,10 +10,12 @@ class UsersControllerTest < ActionController::TestCase
end
test "failed show without login" do
- user = find_record :user
+ user = FactoryGirl.build(:user)
+ user.save
get :show, :id => user.id
assert_response :redirect
assert_redirected_to login_path
+ user.destroy
end
test "user can see user" do
@@ -42,7 +44,7 @@ class UsersControllerTest < ActionController::TestCase
assert_response :success
end
-
+
test "user cannot see other user" do
user = find_record :user,
:email => nil,
@@ -57,6 +59,26 @@ class UsersControllerTest < ActionController::TestCase
assert_access_denied
end
+ test "show for non-existing user" do
+ nonid = 'thisisnotanexistinguserid'
+
+ # when unauthenticated:
+ get :show, :id => nonid
+ assert_access_denied(true, false)
+
+ # when authenticated but not admin:
+ login
+ get :show, :id => nonid
+ assert_access_denied
+
+ # when authenticated as admin:
+ # TODO: THIS IS failing to login and have admin? return true in users_controller. Will look into it later.
+ login :is_admin => true
+ get :show, :id => nonid
+ assert_response :redirect
+ assert_equal({:alert => "No such user."}, flash.to_hash)
+ assert_redirected_to users_path
+ end
test "should create new user" do
user_attribs = record_attributes_for :user