Created
October 26, 2012 13:31
-
-
Save shepmaster/3958842 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def self.get_random_quiz | |
quiz_ids = Quiz.all.map(&:id) # simplified to use a symbol proc | |
random_ids = quiz_ids.shuffle | |
Quiz.find(random_ids.first) | |
end | |
# Misspelled, should be "Challenge" | |
it "retrieves a random quiz" do | |
quiz_a = FactoryGirl.create(:quiz_A) | |
quiz_b = FactoryGirl.create(:quiz_B) | |
quiz_ids = [quiz_a.id, quiz_b.id] # ensure using the right ids | |
Quiz.stub_chain(:all, :collect).and_return(quiz_ids) # do you really need to stub this? Why not use the database? | |
quiz_ids.should_receive(:shuffle).and_return(quiz_ids.reverse) | |
QuizChalengeBuilder.get_random_quiz.should eq(quiz_b) # changed due to difference in rand | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment