Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require "#{File.dirname(__FILE__)}/../test_helper"
- class NewUserFirstPostTest < ActionController::IntegrationTest
- all_fixtures
- def test_signup_and_first_post
- get login_url
- assert_response :success
- assert_template "sessions/new"
- get signup_url
- assert_response :success
- assert_template "users/new"
- # create an account
- post users_path, :user => { :display_name => "Josh Goebel", :login => "jgoebel", :password => "squirrels", :password_confirmation => "squirrels", :email => "josh@dwgsolutions.com" }
- assert_response :redirect
- follow_redirect!
- assert_response :success
- assert_template "sessions/new"
- # sign in
- login("jgoebel","squirrels")
- review_topic(topics(:pdi))
- first_post=add_reply(topics(:pdi), "I'm on it.")
- edit_post(first_post)
- # update that post
- 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"
- assert_response :redirect
- follow_redirect!
- assert_template "topics/show"
- assert_equal("I change my mind, I'm scared.", first_post.reload.body)
- # ponies
- review_topic(topics(:ponies))
- add_reply(topics(:ponies), "Ponies are cool.")
- # back to home
- go_home
- # logoff
- get logout_url
- assert_response :redirect
- follow_redirect!
- assert_template "forums/index"
- end
- private
- # return to /
- def go_home
- get forums_path
- assert_response :success
- assert_template "forums/index"
- end
- # adds a reply to a particular post
- def add_reply(topic,body)
- post posts_path(topic.forum, topic), :post => { :body => body }
- assert_response :redirect
- post = assigns(:post)
- follow_redirect!
- assert_response :success
- assert_template "topics/show"
- post
- end
- # pulls up the edit form for a post
- def edit_post(post)
- get edit_post_path (post.topic.forum, post.topic, post)
- assert_response :success
- assert_template "posts/edit"
- end
- def login(user, password)
- post sessions_path, :login => user, :password => password
- assert_response :redirect
- follow_redirect!
- assert_response :success
- assert_template "forums/index"
- end
- # walks down the tree, index, forum, topic
- def review_topic(topic)
- get forums_path
- assert_response :success
- assert_template "forums/index"
- get forum_path(topic.forum)
- assert_response :success
- assert_template "forums/show"
- get topic_path(topic.forum, topic)
- assert_response :success
- assert_template "topics/show"
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement