Created
April 1, 2010 22:28
-
-
Save drewB/352449 to your computer and use it in GitHub Desktop.
This file contains 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 stub_find_for_specific_values(model, stubs) | |
model.stub!(:find).at_least(1).and_return do |id| | |
if stubs.has_key? id | |
stubs[id] | |
else | |
model.find_by_id(id) | |
end | |
end | |
end | |
#example below will return the mock_user if its id is search for otherwise find will search as normal | |
mock_user = mock_model(User) | |
stub_find_for_specific_values(User, mock_user.id => mock_user) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment