Hi everyone

I am new to Rails. My platform is Ubuntu 9.04 with Ruby 1.9.1p243 and
Rails 2.3.4. I am reading SitePoint's Simply Rails 2 book. On page
240, the author shows how to test the associations between Story and
Vote model.

The code is below

app/models/story.rb:
----------------------------
class Story < ActiveRecord::Base
  validates_presence_of :name, :link
  has_many :votes
end

app/models/vote.rb:
-----------------------------
class Vote < ActiveRecord::Base
  belongs_to :story
end



test/fixtures/stories.yml:
------------------------------------

one:
  name: My Shiny Weblog
  link: http://www.google.com/

two:
  name: Another stupid site
  link: http://www.apple.com/


test/fixtures/votes.yml:
----------------------------------

one:
  story: one

two:
  story: one



test/unit/story_test.rb:
--------------------------------

def test_should_have_a_votes_association
  assert_equal [ votes(:one), votes(:two) ], stories(:one).votes
end



$ rake test:units

The output of assert return failure. So I do trial-and-error fix and
manage to fix it by swap the position of votes(:one) and votes(:two)
order so the test method become:
  assert_equal [ votes(:two), votes(:one) ], stories(:one).votes
Can some Rails experts explain to me why the order of vote inside the
array could affect the assert_equal measure?
Thank you so much

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to