PageRenderTime 41ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/test/functional/users_controller_test.rb

https://github.com/newrooky/lftwb
Ruby | 195 lines | 157 code | 38 blank | 0 comment | 0 complexity | af81a8b103d2e83ce16ffd0d4f21bfa1 MD5 | raw file
Possible License(s): MIT
  1. require File.dirname(__FILE__) + '/../test_helper'
  2. class UsersControllerTest < Test::Unit::TestCase
  3. def setup
  4. @controller = UsersController.new
  5. @request = ActionController::TestRequest.new
  6. @response = ActionController::TestResponse.new
  7. end
  8. context "automatically activate account and log user in. " do
  9. setup do
  10. GlobalConfig.automatically_activate = true
  11. GlobalConfig.automatically_login_after_account_create = true
  12. end
  13. context "on POST to :create" do
  14. setup { post_create_user }
  15. should_redirect_to "edit_user_path(@user, :fv => true)"
  16. should "reset global settings" do
  17. GlobalConfig.automatically_activate = false
  18. GlobalConfig.automatically_login_after_account_create = false
  19. end
  20. end
  21. end
  22. context "automatically activate account do not log user in" do
  23. setup do
  24. GlobalConfig.automatically_activate = true
  25. GlobalConfig.automatically_login_after_account_create = false
  26. end
  27. context "on POST to :create" do
  28. setup { post_create_user }
  29. should_redirect_to "login_path"
  30. should_set_the_flash_to(/you may login/i)
  31. should "reset global settings" do
  32. GlobalConfig.automatically_activate = false
  33. end
  34. end
  35. context "on POST to :create with bad login (space in login name)" do
  36. setup { post_create_user(:login => 'test guy') }
  37. should_respond_with :success
  38. should_render_template :new
  39. should "assign an error to the login field" do
  40. assert assigns(:user).errors.on(:login)
  41. end
  42. end
  43. end
  44. context "do not auto activate. do not login after create" do
  45. setup do
  46. GlobalConfig.automatically_activate = false
  47. GlobalConfig.automatically_login_after_account_create = false
  48. end
  49. context "on POST to :create -- Allow signup. " do
  50. setup do
  51. post_create_user
  52. end
  53. should_redirect_to "welcome_user_path(@user)"
  54. should_set_the_flash_to(/check your email to activate your account/i)
  55. end
  56. context "on POST to :create -- require login on signup. " do
  57. setup do
  58. post_create_user :login => ''
  59. end
  60. should_respond_with :success
  61. should_render_template :new
  62. should "assign an error to the login field" do
  63. assert assigns(:user).errors.on(:login)
  64. end
  65. end
  66. context "on POST to :create with bad login (space in login name)" do
  67. setup { post_create_user(:login => 'test guy') }
  68. should_respond_with :success
  69. should_render_template :new
  70. should "assign an error to the login field" do
  71. assert assigns(:user).errors.on(:login)
  72. end
  73. end
  74. context "on POST to :create -- require password on signup. " do
  75. setup { post_create_user :password => nil }
  76. should_respond_with :success
  77. should_render_template :new
  78. should "assign an error to the password field" do
  79. assert assigns(:user).errors.on(:password)
  80. end
  81. end
  82. context "on POST to :create -- require password confirmation on signup. " do
  83. setup { post_create_user :password_confirmation => nil }
  84. should_respond_with :success
  85. should_render_template :new
  86. should "assign an error to the password confirmation field" do
  87. assert assigns(:user).errors.on(:password_confirmation)
  88. end
  89. end
  90. context "on POST to :create -- require email on signup. " do
  91. setup { post_create_user :email => nil }
  92. should_respond_with :success
  93. should_render_template :new
  94. should "assign an error to the email field" do
  95. assert assigns(:user).errors.on(:email)
  96. end
  97. end
  98. end
  99. context "on GET to :index" do
  100. setup { get :index }
  101. should_redirect_to "profiles_url"
  102. end
  103. context "on GET to :help" do
  104. setup { get :help, :id => users(:quentin).login }
  105. should_respond_with :success
  106. should_render_template :help
  107. end
  108. context "on GET to :welcome" do
  109. setup { get :welcome, :id => users(:quentin).login }
  110. should_respond_with :success
  111. should_render_template :welcome
  112. end
  113. context "on GET to new (signup)" do
  114. setup do
  115. @quentin = users(:quentin)
  116. login_as :quentin
  117. get :new
  118. end
  119. should_redirect_to "user_url(@quentin)"
  120. end
  121. context "on GET to edit (preferences) not logged in" do
  122. setup do
  123. get :edit, :id => users(:quentin)
  124. end
  125. should_redirect_to "login_url"
  126. end
  127. context "on GET to edit (preferences) logged in" do
  128. setup do
  129. login_as :quentin
  130. get :edit, :id => users(:quentin).login
  131. end
  132. should_respond_with :success
  133. should_render_template :edit
  134. end
  135. context "on GET to edit (preferences) logged in but wrong user" do
  136. setup do
  137. @follower_guy = users(:follower_guy)
  138. login_as :follower_guy
  139. get :edit, :id => users(:aaron).login
  140. end
  141. should_redirect_to "user_url(@follower_guy)"
  142. end
  143. def post_create_user(options = {})
  144. post :create,
  145. :user => { :login => 'testguy',
  146. :email => rand(1000).to_s + 'testguy@example.com',
  147. :password => 'testpasswrod',
  148. :password_confirmation => 'testpasswrod',
  149. :language_id => languages(:english).id,
  150. :language_ids => [languages(:english).id, languages(:japanese).id, languages(:tonga).id],
  151. :country_id => countries(:usa),
  152. :first_name => 'Ed',
  153. :last_name => 'Decker',
  154. :grade_level_experience_ids => [grade_level_experiences(:college), grade_level_experiences(:first), grade_level_experiences(:high_school)],
  155. :terms_of_service => true }.merge(options)
  156. end
  157. end