Advertisement
Guest User

Untitled

a guest
Jul 30th, 2017
471
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. require "#{File.dirname(__FILE__)}/../test_helper"
  2.  
  3. class NewUserFirstPostTest < ActionController::IntegrationTest
  4. all_fixtures
  5.  
  6. def test_signup_and_first_post
  7. get login_url
  8. assert_response :success
  9. assert_template "sessions/new"
  10.  
  11. get signup_url
  12. assert_response :success
  13. assert_template "users/new"
  14.  
  15. # create an account
  16. post users_path, :user => { :display_name => "Josh Goebel", :login => "jgoebel", :password => "squirrels", :password_confirmation => "squirrels", :email => "josh@dwgsolutions.com" }
  17. assert_response :redirect
  18. follow_redirect!
  19. assert_response :success
  20. assert_template "sessions/new"
  21.  
  22. # sign in
  23.  
  24. login("jgoebel","squirrels")
  25.  
  26.  
  27. review_topic(topics(:pdi))
  28. first_post=add_reply(topics(:pdi), "I'm on it.")
  29. edit_post(first_post)
  30.  
  31. # update that post
  32.  
  33. post post_path (:forum_id => forums(:rails), :topic_id => topics(:pdi), :id => first_post), :post => { :body => "I change my mind, I'm scared."}, :_method => "put"
  34. assert_response :redirect
  35. follow_redirect!
  36. assert_template "topics/show"
  37. assert_equal("I change my mind, I'm scared.", first_post.reload.body)
  38.  
  39. # ponies
  40. review_topic(topics(:ponies))
  41. add_reply(topics(:ponies), "Ponies are cool.")
  42.  
  43. # back to home
  44. go_home
  45.  
  46. # logoff
  47. get logout_url
  48. assert_response :redirect
  49. follow_redirect!
  50. assert_template "forums/index"
  51.  
  52. end
  53.  
  54. private
  55.  
  56. # return to /
  57. def go_home
  58. get forums_path
  59. assert_response :success
  60. assert_template "forums/index"
  61. end
  62.  
  63. # adds a reply to a particular post
  64. def add_reply(topic,body)
  65. post posts_path(topic.forum, topic), :post => { :body => body }
  66. assert_response :redirect
  67. post = assigns(:post)
  68. follow_redirect!
  69. assert_response :success
  70. assert_template "topics/show"
  71. post
  72. end
  73.  
  74. # pulls up the edit form for a post
  75. def edit_post(post)
  76. get edit_post_path (post.topic.forum, post.topic, post)
  77. assert_response :success
  78. assert_template "posts/edit"
  79. end
  80.  
  81. def login(user, password)
  82. post sessions_path, :login => user, :password => password
  83. assert_response :redirect
  84. follow_redirect!
  85. assert_response :success
  86. assert_template "forums/index"
  87. end
  88.  
  89. # walks down the tree, index, forum, topic
  90. def review_topic(topic)
  91. get forums_path
  92. assert_response :success
  93. assert_template "forums/index"
  94.  
  95. get forum_path(topic.forum)
  96. assert_response :success
  97. assert_template "forums/show"
  98.  
  99. get topic_path(topic.forum, topic)
  100. assert_response :success
  101. assert_template "topics/show"
  102. end
  103.  
  104. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement