diff options
author | jessib <jessib@leap.se> | 2013-01-14 11:50:54 -0800 |
---|---|---|
committer | jessib <jessib@leap.se> | 2013-01-14 11:50:54 -0800 |
commit | c2f232d994b3ee01ff9d50da1e4f3798df2136f3 (patch) | |
tree | 5b7a11e9aed58357d2a38b248b965cd936de6888 /users/test/functional | |
parent | d81bf00ecd8bdfcddf50e4881428c917253326fe (diff) | |
parent | ee2ea4ac8f4c6b0c3b09be6ed49e7a1faec7a9c1 (diff) |
Merge branch 'master' into feature/show_user. Added new tests.
Conflicts:
users/test/functional/users_controller_test.rb
Diffstat (limited to 'users/test/functional')
-rw-r--r-- | users/test/functional/users_controller_test.rb | 79 |
1 files changed, 55 insertions, 24 deletions
diff --git a/users/test/functional/users_controller_test.rb b/users/test/functional/users_controller_test.rb index 1f6c868..46db4d1 100644 --- a/users/test/functional/users_controller_test.rb +++ b/users/test/functional/users_controller_test.rb @@ -10,14 +10,14 @@ class UsersControllerTest < ActionController::TestCase end test "failed show without login" do - user = find_record User + user = find_record :user get :show, :id => user.id assert_response :redirect assert_redirected_to login_path end test "user can see user" do - user = find_record User, + user = find_record :user, :email => nil, :email_forward => nil, :email_aliases => [], @@ -29,34 +29,64 @@ class UsersControllerTest < ActionController::TestCase assert_response :success end + test "admin can see other user" do + user = find_record :user, + :email => nil, + :email_forward => nil, + :email_aliases => [], + :created_at => Time.now, + :updated_at => Time.now, + :most_recent_tickets => [] + login :is_admin? => true + get :show, :id => user.id + assert_response :success + + end + + test "user cannot see other user" do + user = find_record :user, + :email => nil, + :email_forward => nil, + :email_aliases => [], + :created_at => Time.now, + :updated_at => Time.now, + :most_recent_tickets => [] + login + get :show, :id => user.id + assert_response :redirect + assert_access_denied + end + + test "should create new user" do - user = stub_record User - User.expects(:create).with(user.params).returns(user) + user_attribs = record_attributes_for :user + user = User.new(user_attribs) + User.expects(:create).with(user_attribs).returns(user) + + + post :create, :user => user_attribs, :format => :json + - post :create, :user => user.params, :format => :json assert_nil session[:user_id] assert_json_response user assert_response :success end test "should redirect to signup form on failed attempt" do - params = User.valid_attributes_hash.slice(:login) - user = User.new(params) - params.stringify_keys! + user_attribs = record_attributes_for :user + user_attribs.slice!('login') + user = User.new(user_attribs) assert !user.valid? - User.expects(:create).with(params).returns(user) + User.expects(:create).with(user_attribs).returns(user) - post :create, :user => params, :format => :json + post :create, :user => user_attribs, :format => :json assert_json_error user.errors.messages assert_response 422 end test "should get edit view" do - user = find_record User, - :email => nil, - :email_forward => nil, - :email_aliases => [] + user = find_record :user login user get :edit, :id => user.id @@ -65,14 +95,14 @@ class UsersControllerTest < ActionController::TestCase end test "user can change settings" do - user = find_record User - user.expects(:attributes=).with(user.params) + user = find_record :user + changed_attribs = record_attributes_for :user_with_settings + user.expects(:attributes=).with(changed_attribs) user.expects(:changed?).returns(true) user.expects(:save).returns(true) - user.stubs(:email_aliases).returns([]) login user - put :update, :user => user.params, :id => user.id, :format => :json + put :update, :user => changed_attribs, :id => user.id, :format => :json assert_equal user, assigns[:user] assert_response 204 @@ -80,14 +110,15 @@ class UsersControllerTest < ActionController::TestCase end test "admin can update user" do - user = find_record User - user.expects(:attributes=).with(user.params) + user = find_record :user + changed_attribs = record_attributes_for :user_with_settings + user.expects(:attributes=).with(changed_attribs.stringify_keys) user.expects(:changed?).returns(true) user.expects(:save).returns(true) user.stubs(:email_aliases).returns([]) login :is_admin? => true - put :update, :user => user.params, :id => user.id, :format => :json + put :update, :user => changed_attribs, :id => user.id, :format => :json assert_equal user, assigns[:user] assert_response 204 @@ -95,7 +126,7 @@ class UsersControllerTest < ActionController::TestCase end test "admin can destroy user" do - user = find_record User + user = find_record :user user.expects(:destroy) login :is_admin? => true @@ -106,7 +137,7 @@ class UsersControllerTest < ActionController::TestCase end test "user can cancel account" do - user = find_record User + user = find_record :user user.expects(:destroy) login user @@ -117,7 +148,7 @@ class UsersControllerTest < ActionController::TestCase end test "non-admin can't destroy user" do - user = stub_record User + user = find_record :user login delete :destroy, :id => user.id |