I'm writing an app that let's users take a test online. The test has 2 sets of 18 questions which are randomized on the view. I'm trying to write tests to make sure that I get the correct 18 questions on each part. I'd like to create a factory that will hit the db and load in a random sequence of questions. Any idea how to do this? I can hard code the text but I actually want to test the seed data and DRY out my code by not repeating the questions in my seeds.rb and factory.rb.
Here's what I've done that is hard coded
Factory.define :test do |test|
test.association :user
end
Factory.define :question do |question|
question.phrase "2+2"
question.answer "4"
question.association :test
end
Then, in my tests, I can write something like:
@test = Factory(:test, :user => @user)
@question = Factory(:question, :test => @test)
Any ideas how to do this?
Thanks!