Advertisement
Guest User

Untitled

a guest
Sep 1st, 2015
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. def setup
  2. @user = User.create(email: "user@hlist.com",
  3. encrypted_password: Devise.bcrypt(User, 'password1'))
  4. @post = { title: "This is the title",
  5. content: "Detailed comment."*10,
  6. phone: 9991118888,
  7. email: "email@hlist.com",
  8. user_id: users(:spiderman).id }
  9. @p = @user.posts.build(@post)
  10. end
  11.  
  12. test "creates a new post successfully" do
  13. sign_in_as(@user)
  14. get new_post_path(@user)
  15. assert_template 'posts/new'
  16. assert_difference 'Post.count', 1 do
  17. post posts_path, post: @post
  18. end
  19. assert_template 'posts/show'
  20. end
  21.  
  22. def sign_in_as(user)
  23. post_via_redirect user_session_path, 'user[:email]' => user.email,
  24. 'user[:encrypted_password]' => Devise.bcrypt(User, 'password1')
  25. end
  26.  
  27. 1) Failure:
  28. PostsCrudTest#test_creates_a_new_post_successfully [/Users/harishramachandran/dropbox/documents/harish/coding/workspace/h_list/test/integration/posts_crud_test.rb:19]:
  29. expecting <"posts/new"> but rendering with <[]>
  30.  
  31. require 'test_helper'
  32.  
  33. class UserFlowsTest < ActionDispatch::IntegrationTest
  34. test "user can see home page after login" do
  35. get user_session_path
  36. assert_equal 200, status
  37. @david = User.create(email: "david@mail.com", password: Devise::Encryptor.digest(User, "helloworld"))
  38. post user_session_path, 'user[email]' => @david.email, 'user[password]' => @david.password
  39. follow_redirect!
  40. assert_equal 200, status
  41. assert_equal "/", path
  42. end
  43.  
  44. test "user can not see home page without login" do
  45. get "/"
  46. assert_equal 302, status
  47. follow_redirect!
  48. assert_equal "/users/sign_in", path
  49. assert_equal 200, status
  50. end
  51. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement