summaryrefslogtreecommitdiff
path: root/users/test/functional
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2013-01-14 12:04:12 +0100
committerAzul <azul@leap.se>2013-01-14 12:04:12 +0100
commit3cd3c261bdf02b2da5217fa1c469d30f9d92c9a3 (patch)
tree3cf64d58e588b12103b3adac7397872427ed6677 /users/test/functional
parent1623f51cc003f7de92f7192bba5ca88dfb2a92f6 (diff)
got users controller test to pass - tickets controller test next.
Diffstat (limited to 'users/test/functional')
-rw-r--r--users/test/functional/users_controller_test.rb43
1 files changed, 21 insertions, 22 deletions
diff --git a/users/test/functional/users_controller_test.rb b/users/test/functional/users_controller_test.rb
index 1fa1462..8f1ee15 100644
--- a/users/test/functional/users_controller_test.rb
+++ b/users/test/functional/users_controller_test.rb
@@ -10,10 +10,11 @@ class UsersControllerTest < ActionController::TestCase
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.params, :format => :json
+ post :create, :user => user_attribs, :format => :json
assert_nil session[:user_id]
assert_json_response user
@@ -21,23 +22,20 @@ class UsersControllerTest < ActionController::TestCase
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
@@ -46,14 +44,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
@@ -61,14 +59,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
@@ -76,7 +75,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
@@ -87,7 +86,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
@@ -98,7 +97,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