Commit 43ba052009dc4dd6cf2d20f65f90511692723177
1 parent
403560ba
Exists in
master
and in
22 other branches
users-controller-tests: refactor and improving performance
Showing
1 changed file
with
20 additions
and
32 deletions
Show diff stats
test/functional/users_controller_test.rb
| ... | ... | @@ -11,9 +11,6 @@ class UsersControllerTest < ActionController::TestCase |
| 11 | 11 | @request = ActionController::TestRequest.new |
| 12 | 12 | @response = ActionController::TestResponse.new |
| 13 | 13 | |
| 14 | - | |
| 15 | - Environment.delete_all | |
| 16 | - Environment.create(:name => 'some env', :is_default => true) | |
| 17 | 14 | admin_user = create_user_with_permission('adminuser', 'manage_environment_users', Environment.default) |
| 18 | 15 | login_as('adminuser') |
| 19 | 16 | end |
| ... | ... | @@ -26,9 +23,6 @@ class UsersControllerTest < ActionController::TestCase |
| 26 | 23 | end |
| 27 | 24 | |
| 28 | 25 | should 'grant access with right permission' do |
| 29 | - admin_user = create_user_with_permission('admin_user', 'manage_environment_users', Environment.default) | |
| 30 | - login_as('admin_user') | |
| 31 | - | |
| 32 | 26 | get :index |
| 33 | 27 | assert_response :success |
| 34 | 28 | end |
| ... | ... | @@ -39,10 +33,10 @@ class UsersControllerTest < ActionController::TestCase |
| 39 | 33 | deactivated.person.visible = false |
| 40 | 34 | deactivated.save! |
| 41 | 35 | get :index, :q => '' |
| 42 | - assert_tag :tag => 'div', :attributes => { :id => /users-list/ }, :descendant => {:tag => 'a', :attributes => {:title => /adminuser/}} | |
| 43 | - assert_tag :tag => 'div', :attributes => { :id => /users-list/ }, :descendant => {:tag => 'a', :attributes => {:title => /deactivated/}} | |
| 36 | + assert_tag :tag => 'div', :attributes => { :id => /users-list/ }, :descendant => {:tag => 'a', :attributes => {:title => /adminuser/}} | |
| 37 | + assert_tag :tag => 'div', :attributes => { :id => /users-list/ }, :descendant => {:tag => 'a', :attributes => {:title => /deactivated/}} | |
| 44 | 38 | end |
| 45 | - | |
| 39 | + | |
| 46 | 40 | should 'blank search include all users' do |
| 47 | 41 | (1..5).each {|i| |
| 48 | 42 | u = create_user('user'+i.to_s) |
| ... | ... | @@ -51,10 +45,10 @@ class UsersControllerTest < ActionController::TestCase |
| 51 | 45 | assert_tag :tag => 'div', :attributes => { :id => /users-list/ }, :descendant => {:tag => 'a', :attributes => {:title => /adminuser/}} |
| 52 | 46 | (1..5).each {|i| |
| 53 | 47 | u = 'user'+i.to_s |
| 54 | - assert_tag :tag => 'div', :attributes => { :id => /users-list/ }, :descendant => {:tag => 'a', :attributes => {:title => u}} | |
| 48 | + assert_tag :tag => 'div', :attributes => { :id => /users-list/ }, :descendant => {:tag => 'a', :attributes => {:title => u}} | |
| 55 | 49 | } |
| 56 | 50 | end |
| 57 | - | |
| 51 | + | |
| 58 | 52 | should 'search not include all users' do |
| 59 | 53 | (1..5).each {|i| |
| 60 | 54 | u = create_user('user'+i.to_s) |
| ... | ... | @@ -63,27 +57,27 @@ class UsersControllerTest < ActionController::TestCase |
| 63 | 57 | assert_tag :tag => 'div', :attributes => { :id => /users-list/ }, :descendant => {:tag => 'a', :attributes => {:title => /user5/}} |
| 64 | 58 | (1..4).each {|i| |
| 65 | 59 | u = 'user'+i.to_s |
| 66 | - assert_no_tag :tag => 'div', :attributes => { :id => /users-list/ }, :descendant => {:tag => 'a', :attributes => {:title => u}} | |
| 60 | + assert_no_tag :tag => 'div', :attributes => { :id => /users-list/ }, :descendant => {:tag => 'a', :attributes => {:title => u}} | |
| 67 | 61 | } |
| 68 | 62 | end |
| 69 | - | |
| 63 | + | |
| 70 | 64 | should 'set admin role' do |
| 71 | - u = create_user() | |
| 72 | - assert_equal false, u.person.is_admin? | |
| 73 | - post :set_admin_role, :id => u.person.id, :q => '' | |
| 74 | - u.reload | |
| 75 | - assert u.person.is_admin? | |
| 65 | + person = create_user.person | |
| 66 | + assert_equal false, person.is_admin? | |
| 67 | + post :set_admin_role, :id => person.id, :q => '' | |
| 68 | + person.reload | |
| 69 | + assert person.is_admin? | |
| 76 | 70 | end |
| 77 | 71 | |
| 78 | 72 | should 'reset admin role' do |
| 79 | - u = create_user() | |
| 80 | - e = Environment.default | |
| 81 | - e.add_admin(u.person) | |
| 82 | - u.reload | |
| 83 | - assert u.person.is_admin? | |
| 84 | - post :reset_admin_role, :id => u.person.id, :q => '' | |
| 85 | - u.reload | |
| 86 | - assert_equal false, u.person.is_admin? | |
| 73 | + environment = Environment.default | |
| 74 | + person = create_user.person | |
| 75 | + environment.add_admin(person) | |
| 76 | + assert person.is_admin? | |
| 77 | + | |
| 78 | + post :reset_admin_role, :id => person.id, :q => '' | |
| 79 | + person.reload | |
| 80 | + assert !person.is_admin? | |
| 87 | 81 | end |
| 88 | 82 | |
| 89 | 83 | should 'activate user' do |
| ... | ... | @@ -106,17 +100,11 @@ class UsersControllerTest < ActionController::TestCase |
| 106 | 100 | end |
| 107 | 101 | |
| 108 | 102 | should 'response as XML to export users' do |
| 109 | - admin_user = create_user_with_permission('admin_user', 'manage_environment_users', Environment.default) | |
| 110 | - login_as('admin_user') | |
| 111 | - | |
| 112 | 103 | get :download, :format => 'xml' |
| 113 | 104 | assert_equal 'text/xml', @response.content_type |
| 114 | 105 | end |
| 115 | 106 | |
| 116 | 107 | should 'response as CSV to export users' do |
| 117 | - admin_user = create_user_with_permission('admin_user', 'manage_environment_users', Environment.default) | |
| 118 | - login_as('admin_user') | |
| 119 | - | |
| 120 | 108 | get :download, :format => 'csv' |
| 121 | 109 | assert_equal 'text/csv', @response.content_type |
| 122 | 110 | assert_equal 'name;email', @response.body.split("\n")[0] | ... | ... |