Guest User

Untitled

a guest
Sep 17th, 2018
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. how to use padrino helper methods in rspec
  2. describe "POST /sessions" do
  3. it "should populate current_user after posting correct user/pass" do
  4.  
  5. u = User.create({:email=>"john@gmail.com", :password=>"helloworld", :password_confirmation=>"helloworld"})
  6.  
  7. user = {
  8. email:"john@gmail.com",
  9. password:"hellowolrd"
  10. }
  11. post '/sessions/new', user
  12. current_user.should_not == "null"
  13. end
  14. end
  15.  
  16. post "/new" do
  17. user = User.authenticate(params[:email], params[:password])
  18. if user
  19. session[:user_id] = user.id
  20. redirect '/'
  21. else
  22. render "sessions/new"
  23. end
  24. end
  25.  
  26. Testing.helpers do
  27. def current_user
  28. @current_user ||= User.find(:id=>session[:user_id]) if session[:user_id]
  29. end
  30. end
  31.  
  32. Failures:
  33.  
  34. 1) SessionsController POST /users should populate current_user after posting correct user/pass
  35. Failure/Error: current_user.should_not == "null"
  36. NameError:
  37. undefined local variable or method `current_user' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_2:0x0000000313c0d8>
  38. # ./spec/app/controllers/sessions_controller_spec.rb:20:in `block (3 levels) in <top (required)>'
Add Comment
Please, Sign In to add comment