SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Member jennifert's Avatar
    Join Date
    Oct 2007
    Location
    Canada
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Trouble with fixtures and unit tests

    Hello,

    While creating an app similar to the "shove it" in the book, I came across an error in chapter 7 unit test (page. 226).

    The console displays 5 errors..all with the same message "FixtureClassNotFound: The class "Tran" was not found". So I removed all code from error testing from one unit tests and left only votes_test.rb in place.

    test_votes.rb
    Code Ruby:
    class VoteTest < ActiveSupport::TestCase
     
     fixtures :votes, :trans
     
      def test_story_association
        assert_equal trans(:first), votes(:first).trans
      end
     
    end

    fixture data for votes.yml
    Code Ruby:
    first:
      id: 1
      trans_id: 1
      created_at: <% Time.now.to_s(:db) %>
    second:
      id: 2
      trans_id: 1
      created_at: <% Time.now.to_s(:db) %>

    fixture data for trans.yml
    Code Ruby:
    first:
      id: 1
      eng: Apply online
      fre: Faites votre demande en ligne
      permalink: apply-online
    another:
      id: 2
      eng: Available in French
      fre: Disponible en fran&#231;ais
      permalink: available-in_french

    The code achieve says:
    Code Ruby:
    assert_equal stories(:first), votes(:first).story

    I believe this is my problem line. is it because their "stories" fixture I name "trans" and the "story" item was also named trans?
    Last edited by jennifert; Jan 25, 2008 at 09:44. Reason: missed typos in explaination

  2. #2
    SitePoint Member
    Join Date
    Oct 2006
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I think you're right. Your test should be rewritten as:

    Code Ruby:
    assert_equal trans(:first), votes(:first).tran

    i.e. without the "s" on the end.

    I presume you have used the class Tran throughout your application in place of Story?

    Rgds

    Robin

  3. #3
    SitePoint Member jennifert's Avatar
    Join Date
    Oct 2007
    Location
    Canada
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    Quote Originally Posted by robinjfisher View Post
    I presume you have used the class Tran throughout your application in place of Story?
    Hello,

    Thanks for the reply.

    Thats the strange thing. I double checked my code, and no classes actually have "Tran", the say "Trans". i tried editing the value to tran, and the error message was "undefined method". I looked at the class names and db names and saw "trans".

    Here is my votes.rb:
    Code Ruby:
    class Vote < ActiveRecord::Base
    	belongs_to :trans
    end

    Here is trans.rb
    Code Ruby:
    class Trans < ActiveRecord::Base
    	validates_presence_of :eng, :fre
    	has_many :votes
     
    	def latest_votes
    		votes.find(:all, :order => 'id DESC', :limit => 3)
    	end
    end
    Last edited by jennifert; Jan 28, 2008 at 10:10. Reason: did further testing

  4. #4
    SitePoint Member
    Join Date
    Oct 2006
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I think this is a problem with the inflector that Rails uses. Classes should be a singular name. So where you are referring to "Trans", Rails is looking for a class name of "Tran".

    Kind Regards

    Robin


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
  •