As I wrote about previously, I needed to have a logged on user when doing my tests of the StoryController. With a little help from google and "Programming Ruby," I found a way to send the login action to a different controller. This mostly was because I couldn't figure out how to set a session value (session[:user_id]).
Just a couple pages later in the book, there are two methods
def get_with_user(action, parameters=nil, session=nil, flash=nil)
get action, parameters, :user_id => users(:patrick).id
end
def post_with_user(action, parameters=nil, session=nil, flash=nil)
post action, parameters, :user_id=>users(:patrick).id
end
Well, those are slightly easier. It looks like I know how to set session values on post and get, so I now have learned two things today: how to pass a code block and execute it; and, posting/getting with session variables set.
Sweet!
Going a few pages later, it has the following paragraph:
"If you've been particularly eager, and tried executing your functional test suite prematurely, you'll have noticed that a few tests that worked previously now fail. These failures occur because we modified our story submission form - it requires that a user_id is present in the session before a page request can be successful. Our old tests didn't account for this change, so they now fail."
HAHA! It has been ingrained in me that all my tests should pass always before I move on to something new has failed me here; I didn't follow the directions of the book word-for-word. If I had just been satisfied with typing the stuff from the book and following directions, I wouldn't have had spent time figuring out how to get the tests to pass. :) In the end, though, I learned a couple things about Ruby and Rails, so I'm happy.