diff options
author | jessib <jessib@leap.se> | 2013-07-08 11:30:35 -0700 |
---|---|---|
committer | jessib <jessib@leap.se> | 2013-07-08 11:30:35 -0700 |
commit | fc3c5994df61de04b8b17b495a638efc0d760126 (patch) | |
tree | 644aa93dfd0a6da2ed9b20ba688712fb9082f425 /users/test/functional/v1 | |
parent | cfb9e1d4c2e954222b77c4dd11e06ae3a0092be5 (diff) | |
parent | 3113f8b814417a896ad5340fda88927733f8ab22 (diff) |
Merge branch 'master' into feature/disable_account
Conflicts:
users/app/controllers/users_controller.rb
users/app/helpers/users_helper.rb
users/app/views/users/edit.html.haml
users/app/views/users/show.html.haml
users/config/locales/en.yml
Diffstat (limited to 'users/test/functional/v1')
-rw-r--r-- | users/test/functional/v1/users_controller_test.rb | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/users/test/functional/v1/users_controller_test.rb b/users/test/functional/v1/users_controller_test.rb new file mode 100644 index 0000000..0d44e50 --- /dev/null +++ b/users/test/functional/v1/users_controller_test.rb @@ -0,0 +1,70 @@ +require 'test_helper' + +class V1::UsersControllerTest < ActionController::TestCase + + test "user can change settings" do + user = find_record :user + changed_attribs = record_attributes_for :user_with_settings + user.expects(:update_attributes).with(changed_attribs) + + login user + put :update, :user => changed_attribs, :id => user.id, :format => :json + + assert_equal user, assigns[:user] + assert_response 204 + assert_equal " ", @response.body + end + + test "admin can update user" do + user = find_record :user + changed_attribs = record_attributes_for :user_with_settings + user.expects(:update_attributes).with(changed_attribs) + + login :is_admin? => true + put :update, :user => changed_attribs, :id => user.id, :format => :json + + assert_equal user, assigns[:user] + assert_response 204 + end + + test "user cannot update other user" do + user = find_record :user + login + put :update, :user => record_attributes_for(:user_with_settings), :id => user.id, :format => :json + assert_access_denied + end + + test "should create new user" do + 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 + + assert_nil session[:user_id] + assert_json_response user + assert_response :success + end + + test "should redirect to signup form on failed attempt" do + user_attribs = record_attributes_for :user + user_attribs.slice!('login') + user = User.new(user_attribs) + assert !user.valid? + User.expects(:create).with(user_attribs).returns(user) + + post :create, :user => user_attribs, :format => :json + + assert_json_error user.errors.messages + assert_response 422 + end + + test "admin can autocomplete users" do + login :is_admin? => true + get :index, :query => 'a', :format => :json + + assert_response :success + assert assigns(:users) + end + +end |