Hi,
I have a one to many relationship ( stories & votes ), that i wish to
test via a unit test. In development everything works great, votes ends
up w/ the correct story_id and the relationship is great ( i can
Vote.find(:last).story or Story.find(:last).votes ) But when I run the
unit test, it fails. The story gets an id of 996332877 ( which is 10000
in dev ) and the votes story_id is 0. Not sure what the heck is going on
here. Any help would be greatly appreciated.
Merrick
stories:
±----------------+
| ID | NAME | URL |
±----------------+
votes:
±--------------+
| ID | STORY_ID |
±--------------+
models:
class Story < ActiveRecord::Base
validates_presence_of :name, :link
has_many :votes do
def latest
find :all, :order => ‘id DESC’, :limit => 3
end
end
def to_param
“#{id}-#{name.gsub(/\W/, ‘-’).downcase}”
end
end
class Vote < ActiveRecord::Base
belongs_to :story
end
vote test:
test “story_association” do
assert_equal stories(:two), votes(:two).story #FAILS!
end