SitePoint Sponsor

User Tag List

Results 1 to 13 of 13

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Jun 2007
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Chapter 7 Full Test - Depreciation error &

    I'm attempting to run the test for the Full Test Suite in Chapter 7 of the Build Your Own Ruby On Rails book and I'm getting the following two errors:

    1) Error:
    test_should_show_story(StoryControllerTest):
    ActionView::TemplateError: You have a nil object when you didn't expect it!
    You might have expected an instance of Array.
    The error occurred while evaluating nil.to_formatted_s
    On line #1 of app/views/story/_vote.rhtml

    2) Error:
    test_should_show_story_vote_elements(StoryControllerTest):
    ActionView::TemplateError: You have a nil object when you didn't expect it!
    You might have expected an instance of Array.
    The error occurred while evaluating nil.to_formatted_s
    On line #1 of app/views/story/_vote.rhtml

    I've checked the code and run the code from the code archive for both the story_controller_test.rb and _vote.rthml files, but I'm still getting these errors.

    Any ideas as to what could be wrong? Here's the code I have for the test_should_show_story and test_should_show_vote_elements:

    def test_should_show_story
    get :show, ermalink => 'my-shiny-weblog'
    assert_response :success
    assert_template 'show'
    assert_equal storiesanother), assignsstory)
    end

    def test_should_show_story_vote_elements
    get :show, ermalink => 'my-shiny-weblog'
    assert_select 'h2 span#vote_score'
    assert_select 'ul#vote_history li', :count => 2
    assert_select 'div#vote_link'
    end

    Also, I'm seeing the following deprecation warning:

    ....DEPRECATION WARNING: votes_count See http://www.rubyonrails.org/deprecation for details. (called from votes_count at /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/deprecated_associations.rb:7)

    Any help, ideas? Thanks!

  2. #2
    SitePoint Member
    Join Date
    Feb 2007
    Location
    Wiesbaden, Germany
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kln View Post
    [...]
    1) Error:
    test_should_show_story(StoryControllerTest):
    ActionView::TemplateError: You have a nil object when you didn't expect it!
    You might have expected an instance of Array.
    The error occurred while evaluating nil.to_formatted_s
    On line #1 of app/views/story/_vote.rhtml

    2) Error:
    test_should_show_story_vote_elements(StoryControllerTest):
    ActionView::TemplateError: You have a nil object when you didn't expect it!
    You might have expected an instance of Array.
    The error occurred while evaluating nil.to_formatted_s
    On line #1 of app/views/story/_vote.rhtml

    [...]

    ....DEPRECATION WARNING: votes_count See http://www.rubyonrails.org/deprecation for details. (called from votes_count at /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/deprecated_associations.rb:7)
    Hi!

    First of all, both test failures seem to originate from the same source. Do you have a created_at value for each of the votes in your test/fixtures/votes.yml fixture file?

    The deprecation warning can be taken care of by replacing any instance of the votes_count method with votes.size (eg. @story.votes.size).

    Best,
    Patrick

  3. #3
    SitePoint Zealot lord's Avatar
    Join Date
    Nov 2003
    Location
    sLOVEnia
    Posts
    117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hey

    I also get the same problems ... i manage to solve the problem whene I change the "storiesfirst)" with "Story.find(1)" in my tests.
    I don't know why "storiesfirst)" (from the book) don't work ... maybe someone else will tell.

    tell me if you solve the problem

    have a nice day

  4. #4
    SitePoint Member
    Join Date
    Jun 2007
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Still receiving errors....

    Patrick,

    My votes.yml code is as follows:

    # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
    first:
    id: 1
    story_id: 1
    created_at: <% Time.now.to_sdb) %>
    second:
    id: 2
    story_id: 1
    created_at: <% Time.now.to_sdb) %>

    Any ideas?

    Also, I changed the votes_count to votes.size in both the vote.rjs and show.rhtml files, but I'm still getting the Depreciation error (only 2 times now instead of 3). I'll keep looking for other files with the vote_count method and update them.

    Thanks,
    Kevin

  5. #5
    SitePoint Member
    Join Date
    Jun 2007
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Lord, I tried your suggestion, but it did not work for me, and I received the same errors.

    Thanks for the help

    KLN

  6. #6
    SitePoint Zealot lord's Avatar
    Join Date
    Nov 2003
    Location
    sLOVEnia
    Posts
    117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    kln, I didn't bother with deprication errors, but only with errors from the code .. and these errors I manage to solve with the changes in test's files

    here is the example of one part of code:
    story_controller_test.rb
    Code:
      def test_should_show_story
        get :show, :permalink => 'my-shiny-weblog'
        assert_response :success
        assert_template 'show'
        assert_equal Story.find(1), assigns(:story)
      end
    If you won't solve problems maybe I can email you my test files ...

  7. #7
    SitePoint Member
    Join Date
    Jun 2007
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is what scoop was referring to above:

    Path: /test/fixtures/votes.yml

    This is what I originally came up with:
    1:
    id: 1
    story_id: 1
    created_at: <&#37; Time.now.to_sdb) %>
    2:
    id: 2
    story_id: 1
    created_at: <% Time.now.to_sdb) %>

    This is what it looks like now that I've fixed my errors(see red chars):
    first:
    id: 1
    story_id: 1
    created_at: <%= Time.now.to_sdb) %>
    second:
    id: 2
    story_id: 1
    created_at: <%= Time.now.to_sdb) %>
    Last edited by dorklogic; Jun 9, 2007 at 13:41. Reason: Added some clarification

  8. #8
    SitePoint Member
    Join Date
    Jun 2007
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    That was it!

    Dorklogic,

    You got it, I had left the '=' out of the following statments:

    <%= Time.now.to_sdb) %>

    Thanks for your help,
    KLN

  9. #9
    SitePoint Member
    Join Date
    Jun 2007
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks to all for solving this problem. I was beating myself up until I found this thread.

    My tests have passed and I've removed all but one deprecation warning. I have rails 1.2.3 and see the following warning.


    DEPRECATION WARNING: has_votes? is deprecated and will be removed from Rails 2.0 (use !votes.empty? instead)

    This function is in three places so I've find/replaced all three (with !votes.empty?) and rake test. But it failed pretty solidly.

    It makes me recall that I've not seen a not statement joined with another function, so a find/replace itself is not appropriate.

    Does anyone have a better approach to removing that last deprecation warning? thanx, sam

  10. #10
    SitePoint Guru silver trophy Luke Redpath's Avatar
    Join Date
    Mar 2003
    Location
    London
    Posts
    794
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It seems a bit strange for Rails to recommend !votes.empty? as a replacement for has_votes?. votes.any? would make far more semantic sense to me, and reads better.

  11. #11
    SitePoint Member
    Join Date
    Mar 2009
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    1) Failure:
    test_should_show_story(StoryControllerTest)
    [./test/functional/story_controller_test.rb:58:in `test_should_show_story'
    D:/instantrails2/ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/testing/setup_and_teardown.rb:60:in `__
    send__'
    D:/instantrails2/ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/testing/setup_and_teardown.rb:60:in `ru
    n']:
    Expected response to be a <:sccess>, but was <200>

    10 tests, 22 assertions, 1 failures, 0 errors

    I've got the following error with test for story_controller_test.rb

    I've googled the response code 200 and found out that code 200 is actually a successful response. So the question is there any reserved word in Rails that is equivalent to respone code 200?

  12. #12
    SitePoint Member
    Join Date
    Mar 2009
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oops, just realised my own error, I've got a typo. Sorry people.

  13. #13
    SitePoint Member
    Join Date
    Feb 2007
    Location
    Wiesbaden, Germany
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was about to say that

    Glad you've got it worked out!


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
  •