Advertisement
Guest User

Untitled

a guest
Jul 30th, 2017
466
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.39 KB | None | 0 0
  1. require "#{File.dirname(__FILE__)}/../test_helper"
  2.  
  3. class NewUserFirstPostTest < ActionController::IntegrationTest
  4. all_fixtures
  5.  
  6. ## PLEASE
  7. ## don't refactor this code - it's me learning integration testing, and I plan
  8. ## on improving it myself over the next few days / weeks
  9.  
  10. def test_signup_and_post_edit_and_topic
  11. go_home
  12.  
  13. get login_url
  14. assert_response :success
  15. assert_template "sessions/new"
  16.  
  17. get signup_url
  18. assert_response :success
  19. assert_template "users/new"
  20.  
  21. # create an account
  22. post users_path, :user => { :display_name => "Josh Goebel", :login => "jgoebel", :password => "beast", :password_confirmation => "beast", :email => "josh@dwgsolutions.com" }
  23. assert_response :redirect
  24. follow_redirect!
  25. assert_response :success
  26. assert_template "sessions/new"
  27.  
  28. # sign in
  29. login("jgoebel","beast")
  30.  
  31. review_topic(topics(:pdi))
  32. first_post=add_reply(topics(:pdi), "I'm on it.")
  33. click_edit_post(first_post)
  34.  
  35. # update that post
  36. 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"
  37. assert_response :redirect
  38. follow_redirect!
  39. assert_template "topics/show"
  40. assert_equal("I change my mind, I'm scared.", first_post.reload.body)
  41.  
  42. # ponies
  43. review_topic(topics(:ponies))
  44. add_reply(topics(:ponies), "Ponies are cool.")
  45.  
  46. # post new topic
  47. post topics_path(:forum_id => forums(:rails).id), :topic => { :title => "Beast rocks!", :body => "I love beast!"}
  48. assert_response :redirect
  49. follow_redirect!
  50. assert_template "topics/show"
  51.  
  52. # back to home
  53. go_home
  54.  
  55. # logoff
  56. get logout_url
  57. assert_response :redirect
  58. follow_redirect!
  59. assert_template "forums/index"
  60.  
  61. josh=User.find_by_login "jgoebel"
  62. assert_equal 3, josh.posts.count
  63. end
  64.  
  65. private
  66.  
  67. # return to /
  68. def go_home
  69. get forums_path
  70. assert_response :success
  71. assert_template "forums/index"
  72. end
  73.  
  74. # adds a reply to a particular post
  75. def add_reply(topic,body)
  76. post posts_path(topic.forum, topic), :post => { :body => body }
  77. assert_response :redirect
  78. post = assigns(:post)
  79. follow_redirect!
  80. assert_response :success
  81. assert_template "topics/show"
  82. post
  83. end
  84.  
  85. # pulls up the edit form for a post
  86. def click_edit_post(post)
  87. get edit_post_path(post.topic.forum, post.topic, post)
  88. assert_response :success
  89. assert_template "posts/edit"
  90. end
  91.  
  92. def login(user, password)
  93. post sessions_path, :login => user, :password => password
  94. assert_response :redirect
  95. follow_redirect!
  96. assert_response :success
  97. assert_template "forums/index"
  98. end
  99.  
  100. # walks down the tree, index, forum, topic
  101. def review_topic(topic)
  102. get forums_path
  103. assert_response :success
  104. assert assigns(:forums)
  105. assert_template "forums/index"
  106.  
  107. get forum_path(topic.forum)
  108. assert_response :success
  109. assert assigns(:forum)
  110. assert assigns(:topics)
  111. assert_template "forums/show"
  112.  
  113. get topic_path(topic.forum, topic)
  114. assert_response :success
  115. assert assigns(:topic)
  116. assert assigns(:posts)
  117. assert_template "topics/show"
  118. end
  119.  
  120. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement