Simply Rails 2 by Patrick Lenz

Simply Rails 2 by Patrick Lenz

Author:Patrick Lenz
Language: eng
Format: mobi, epub, pdf
Publisher: SitePoint Pty. Ltd.
Published: 2008-08-16T04:00:00+00:00


Testing Vote Storage

To test the basics of the vote-casting functionality, add the following test to test/functional/votes_controller_test.rb. It simply confirms that new votes are stored correctly:

28-votes_controller_test.rb (excerpt)

class VotesControllerTest < ActionController::TestCase

def test_should_accept_vote

assert stories(:two).votes.empty?

post :create, :story_id => stories(:two)

assert ! assigns(:story).votes.empty?

end

end

The test uses a before-and-after check to confirm that this action, which is supposed to modify data, is indeed doing its job. Let’s look at each line in turn.

The first line confirms that the story initially has no votes:

assert stories(:two).votes.empty?



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.