Guest User

Untitled

a guest
Apr 16th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. describe "On a SessionsController, a visitor" do
  2. tests SessionsController
  3.  
  4. it "should see a login form" do
  5. get :new
  6. status.should.be :success
  7. template.should.be 'sessions/new'
  8. end
  9.  
  10. it "should be able to create a new session" do
  11. post :create, :member => valid_credentials
  12.  
  13. assigns(:unauthenticated).should == members(:kelly)
  14. should.be.authenticated
  15.  
  16. should.redirect_to root_url
  17. end
  18.  
  19. it "should be redirected back to the page she originally requested" do
  20. lambda {
  21. post :create, :member => valid_credentials
  22. should.be.authenticated
  23. }.should.redirect_back_to event_url(events(:supernatural))
  24. end
  25.  
  26. it "should see an explanation if the username or password was wrong" do
  27. post :create, :member => valid_credentials.merge(:password => 'wrong')
  28.  
  29. should.not.be.authenticated
  30. status.should.be :success
  31. assert_select 'p[class=errors]'
  32. end
  33.  
  34. private
  35.  
  36. def valid_credentials
  37. { :username => members(:kelly).username, :password => 'secret' }
  38. end
  39. end
  40.  
  41. describe "On a SessionsController, a member" do
  42. tests SessionsController
  43.  
  44. before do
  45. login members(:adrian)
  46. end
  47.  
  48. it "should be able to clear the logged in session" do
  49. get :clear
  50. should.not.be.authenticated
  51. should.redirect_to root_url
  52. end
  53. end
Add Comment
Please, Sign In to add comment