/test/functional/users_controller_test.rb

https://github.com/jbillsx/zena · Ruby · 149 lines · 123 code · 26 blank · 0 comment · 3 complexity · c55c4c61692c86e9bd972d913b45e643 MD5 · raw file

  1. require 'test_helper'
  2. class UsersControllerTest < Zena::Controller::TestCase
  3. context "on GET index" do
  4. context " if visitor is admin" do
  5. setup do
  6. login(:su)
  7. get :index
  8. end
  9. should_assign_to :users
  10. should_render_with_layout :_main
  11. should_respond_with :success
  12. end
  13. context " if visitor is not admin" do
  14. setup do
  15. login(:ant)
  16. get :index
  17. end
  18. should_not_assign_to :users
  19. should_render_without_layout
  20. should_respond_with 404
  21. end
  22. context " if layout is invalid" do
  23. setup do
  24. login(:lion)
  25. Version.connection.execute "UPDATE #{Version.table_name} SET properties = '{\"data\":{\"text\":\"empty\"},\"json_class\":\"Property::Properties\"}' WHERE id = #{versions_id(:Node_admin_layout_zafu_en)}"
  26. without_files('test.host/zafu') do
  27. get 'index'
  28. end
  29. end
  30. should_respond_with :success
  31. should_render_with_layout :_main
  32. end
  33. end
  34. context "on GET show" do
  35. setup do
  36. login(:su)
  37. get(:show, {'id'=>visitor.id})
  38. end
  39. should 'succeed' do
  40. assert_response :success
  41. end
  42. should_render_without_layout
  43. end
  44. context 'With an admin user' do
  45. setup do
  46. login(:lion)
  47. end
  48. context 'setting dev_skin' do
  49. subject do
  50. get(:dev_skin, {'skin_id' => nodes_zip(:wikiSkin)})
  51. end
  52. should 'store value in visitor properties' do
  53. subject
  54. assert_equal nodes_zip(:wikiSkin), visitor.dev_skin_id
  55. end
  56. end # setting dev_skin
  57. context 'calling rescue' do
  58. subject do
  59. get(:rescue)
  60. end
  61. should 'set dev_skin in visitor properties' do
  62. subject
  63. assert_equal -1, visitor.dev_skin_id
  64. end
  65. end # setting dev_skin
  66. context 'creating a new user' do
  67. subject do
  68. {
  69. :user => {
  70. 'name' => 'Dupont',
  71. 'lang' => 'fr',
  72. 'time_zone' => 'Europe/Zurich',
  73. 'status' => '50',
  74. 'password' => 'secret',
  75. 'login' => 'bolomey',
  76. 'first_name' => 'Paul',
  77. 'group_ids' => [groups_id(:admin), ''],
  78. 'email' => 'paul.bolomey@brainfuck.com',
  79. '_' => '' # This is in the original post
  80. },
  81. :action => 'create'
  82. }
  83. end
  84. should 'succeed' do
  85. post_subject
  86. assert_response :success
  87. user = assigns(:user)
  88. assert !user.new_record?
  89. end
  90. should 'create a new user' do
  91. assert_difference('User.count', 1) do
  92. post_subject
  93. end
  94. end
  95. should 'create a new node' do
  96. assert_difference('Node.count', 1) do
  97. post_subject
  98. end
  99. end
  100. end # creating a new user
  101. end # With an admin user
  102. context 'on GET preferences' do
  103. setup do
  104. login(:su)
  105. get(:preferences, {'id'=>visitor.id})
  106. end
  107. should_respond_with :success
  108. should_render_with_layout :_main
  109. end
  110. context "on PUT" do
  111. context "in order to update parameters" do
  112. setup do
  113. login(:lion)
  114. put 'update', 'id' => users_id(:lion), 'user'=>{'name'=>'Leo Verneyi', 'lang'=>'en', 'time_zone'=>'Africa/Algiers', 'first_name'=>'Panthera', 'login'=>'lion', 'email'=>'lion@zenadmin.info'}
  115. end
  116. should_assign_to :user
  117. should_respond_with :success
  118. should "be able to set timezone" do
  119. assert_equal 'Africa/Algiers', assigns(:user)[:time_zone]
  120. end
  121. end
  122. end
  123. end