SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot basicwebus's Avatar
    Join Date
    Jul 2003
    Location
    Missouri
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cool Simply Rails 2 Ch 7 Vote Test 2 Failures

    I hope someone can tell me how to fix this. When I run the rake test:units test, I get two failures. It looks like the problem is in the id associations between the votes and stories tables. However, I'm not sure how to fix the problem.
    I think this is the file that has the problem (test/unit/story_test.rb):
    Code Ruby:
    require 'test_helper'
    class StoryTest < ActiveSupport::TestCase
      # Replace this with your real tests.
      def test_should_not_be_valid_without_name
      s = Story.create(:name => nil, :link => 'http://www.testsubmission.com/')
      assert s.errors.on(:name)
      end
      def test_should_not_be_valid_without_link
      s = Story.create(:name => 'My test submission', :link => nil)
      assert s.errors.on(:link)
      end
      def test_should_create_story
        s = Story.create(
          :name => 'My test submission',
          :link => 'http://www.testsubmission.com/')
        assert s.valid?
      end
      [COLOR=darkred]def test_should_have_a_votes_association
        assert_equal [ votes(:one), votes(:two) ],
       stories(:one).votes
      end
      def test_should_return_highest_vote_id_first
        assert_equal votes(:two), stories(:one).votes.latest.first
      end
      def test_should_return_3_latest
        10.times { stories(:one).votes.create }
     assert_equal 3, stories(:one).votes.latest.size
      end
    [/COLOR]end
    After the third time of reading the instructions,
    it finally soaks in to my thick skull.



  2. #2
    SitePoint Zealot basicwebus's Avatar
    Join Date
    Jul 2003
    Location
    Missouri
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What I can't figure out on this problem is that it works great when I view this in the browser. I click the shove it, it adds another vote to that particular story, and then it displays the lastest three vote dates.

    So, why is it failing on the test? Must be in the test code somewhere. Thinking in print here hoping someone can add to my thoughts on this.
    After the third time of reading the instructions,
    it finally soaks in to my thick skull.



  3. #3
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)
    Has the problem corrected itself after fixing the votes controller file?

    If not, you are probably experiencing the same problem as others have had:
    http://www.sitepoint.com/forums/showthread.php?t=558993

  4. #4
    SitePoint Zealot basicwebus's Avatar
    Join Date
    Jul 2003
    Location
    Missouri
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is the code from the shovell/test/unit/vote_test.rb file:
    Code Ruby:
    require 'test_helper'
    class VoteTest < ActiveSupport::TestCase
      def test_story_association
        assert_equal stories(:one), votes(:one).story
      end
    end

    code from shovell/test/fixtures/votes.yml
    Code Ruby:
    one:
      story: one
    two:
      story: two

    Test is run from a Ruby command window by changing to the shovell directory, then typing in:
    ruby test:units

    I am stuck at this on page 242 (I am using the pdf version of the second edition of this book - still haven't received my printed version yet because of Christmas holiday).
    After the third time of reading the instructions,
    it finally soaks in to my thick skull.



  5. #5
    SitePoint Zealot basicwebus's Avatar
    Join Date
    Jul 2003
    Location
    Missouri
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, after visiting the link posted, I used that fix and it worked. Here is the code I ended up with in my shovell/test/fixtures/votes.yml file:
    Code Ruby:
    one:
      story: one
      id: 1
    two:
      story: one
      id: 2

    I tried using story: two on two, but still got the failures, so I changed it to story: one also and the test goes through without failing.

    Thanks for posting the link so I could find that fix.
    After the third time of reading the instructions,
    it finally soaks in to my thick skull.




Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •