Guest User

Untitled

a guest
Apr 8th, 2018
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.47 KB | None | 0 0
  1. require 'spec_helper'
  2.  
  3. describe User do
  4.  
  5. describe "creating a user" do
  6. it "changes the number of users by one" do
  7. lambda {Factory(:user)}.should change{User.count}.by(1)
  8. end
  9. end
  10.  
  11. describe "creating a member" do
  12. it "changes the number of active user from 0 to 1" do
  13. lambda {Factory(:member)}.should change{User.count}.from(0).to(1)
  14. end
  15. end
  16.  
  17.  
  18. describe "authentication" do
  19. before do
  20. @login = 'dickdivers'
  21. @email = 'dick@divers.com'
  22. @password = 'nightingale'
  23. end
  24.  
  25. context "of not active user" do
  26. before(:each) do
  27. @user = Factory(:user, :login => @login, :email => @email,
  28. :password => @password, :password_confirmation => @password)
  29. end
  30.  
  31. it "return nil for correct login attempts using login column" do
  32. Tog::Config["plugins.tog_user.email_as_login"] = false
  33. User.authenticate(@login, @password).should be_nil
  34. end
  35.  
  36. it "return nil for correct login attempts using email column" do
  37. Tog::Config["plugins.tog_user.email_as_login"] = true
  38. User.authenticate(@email, @password).should be_nil
  39. end
  40. end
  41.  
  42. context "of a member" do
  43. before(:each) do
  44. @user = Factory(:member, :login => @login, :email => @email,
  45. :password => @password, :password_confirmation => @password)
  46. end
  47.  
  48. it "return nil for incorrect login attempts" do
  49. Tog::Config["plugins.tog_user.email_as_login"] = false
  50. User.authenticate(@login, "bad_password").should be_nil
  51. User.authenticate("bad_login_email", "badpass").should be_nil
  52. User.authenticate("", "").should be_nil
  53. User.authenticate(nil, nil).should be_nil
  54.  
  55. Tog::Config["plugins.tog_user.email_as_login"] = true
  56. User.authenticate(@email, "bad_password").should be_nil
  57. User.authenticate("bad_login_email", "badpass").should be_nil
  58. User.authenticate("", "").should be_nil
  59. User.authenticate(nil, nil).should be_nil
  60. end
  61.  
  62. context "using email" do
  63. before(:each) do
  64. Tog::Config["plugins.tog_user.email_as_login"] = true
  65. end
  66.  
  67. it "return the user object for a valid login using his email" do
  68. User.authenticate(@email, @password).should == @user
  69. User.authenticate(@email.upcase, @password).should == @user
  70. end
  71. end
  72.  
  73. context "using login" do
  74. before(:each) do
  75. Tog::Config["plugins.tog_user.email_as_login"] = false
  76. end
  77.  
  78. it "return the user object for a valid login using his login" do
  79. User.authenticate(@login, @password).should == @user
  80. User.authenticate(@login.upcase, @password).should == @user
  81. end
  82. end
  83.  
  84. context "using login or email without check out email_as_login property" do
  85. before(:each) do
  86. Tog::Config.should_receive(:[]).never
  87. end
  88.  
  89. it "return the user object for a valid login using his login" do
  90. User.authenticate(@login, @password).should == @user
  91. end
  92.  
  93. it "return the user object for a valid login using his email" do
  94. User.authenticate(@email, @password).should == @user
  95. end
  96. end
  97. end
  98. end
  99.  
  100. describe "register" do
  101. before(:each) do
  102. @user = Factory.build(:user)
  103. end
  104.  
  105. it "should be in state pending" do
  106. @user.register!
  107. @user.state.should == "pending"
  108. end
  109.  
  110. it "generate an activation code" do
  111. @user.register!
  112. @user.activation_code.should_not be_nil
  113. end
  114.  
  115. it "receive an signup notification" do
  116. UserMailer.stub!(:deliver_signup_notification)
  117. UserMailer.should_receive(:deliver_signup_notification).with(@user)
  118.  
  119. @user.register!
  120. end
  121. end
  122.  
  123. describe "a registered user activates his account" do
  124. before(:each) do
  125. @user = Factory(:registered)
  126. end
  127.  
  128. it "should be in state active" do
  129. @user.activate!
  130. @user.state.should == "active"
  131. end
  132.  
  133. it "receive a welcome message (activation)" do
  134. UserMailer.stub!(:deliver_activation)
  135. UserMailer.should_receive(:deliver_activation).with(@user)
  136.  
  137. @user.activate!
  138. end
  139. end
  140.  
  141. describe "a member has forgotten his password" do
  142. before(:each) do
  143. @user = Factory(:member)
  144. end
  145.  
  146. it "generate a password reset code" do
  147. @user.forgot_password
  148.  
  149. @user.password_reset_code.should_not be_nil
  150. end
  151.  
  152. it "receive an email to reset the password (reset notification)" do
  153. UserMailer.stub!(:deliver_reset_notification)
  154. UserMailer.should_receive(:deliver_reset_notification).with(@user)
  155.  
  156. @user.forgot_password
  157. end
  158. end
  159.  
  160. desrcibe "trying activate without register" do
  161. it "raise an invalid transition exception (AASM::InvalidTransition)" do
  162. lambda {
  163. Factory(:user).activate!
  164. }.should raise_exception(AASM::InvalidTransition)
  165. end
  166. end
  167.  
  168. describe "validations" do
  169. context "authentication patches" do
  170. it "not be valid include @.- in the login"
  171.  
  172. # it "not be valid include @.- in the login" do
  173. # pending "require authentication patches to use login in the profile url"
  174. # end
  175. #
  176. # it "not be valid include @.- in the login" do
  177. # pending "require authentication patches to use login in the profile url" do
  178. # %w(Holden@com Holde.com Holde-com).each do |login|
  179. # user = Factory.build(:user, :login => login)
  180. # user.should_not be_valid
  181. # user.errors.on(:login).should_not be_empty
  182. # end
  183. # end
  184. # end
  185. end
  186. end
  187.  
  188. end
Add Comment
Please, Sign In to add comment