Results 1 to 3 of 3
Apr 28, 2010, 23:41 #1
- Join Date
- Apr 2010
- 0 Post(s)
- 0 Thread(s)
SR2 - testing stories association - getting failures
I'm on page 286 of Simply Rails 2, and having another issue with testing (does anybody seem to have more problems with the writing the tests than they do the actual code?).
Specifically the method is
def test_should_have_a_stories_association assert_equal 2, users(:patrick).stories.size assert_equal stories(:one), users(:patrick).stories.first end
There are 2 stories that are in the yml file, and the "first" record that is being returned is the 2nd one in the order in which they are in.
Now, I came across a similar (I think) issue in the previous chapter, where the errata said that there are issues with the ordering of yml test data due to the way that they were inserted, and recommended forcing the order by giving them a forced id. This worked for that, but not for this.
Attempting to do that just gave nil returns everywhere.
The other option given in the errata was to use the created_at to find the most recent entry.
Will that work in this situation? And how is that actually coded? I can't seem to find anything that will return me the entry. The only way I could get it to work just returned me the created_at time.
Thanks in advance!