Created
January 16, 2010 20:19
-
-
Save jtrupiano/278983 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
From ff49afda3beb5bb20dd43f05e301bee7b3c57a06 Mon Sep 17 00:00:00 2001 | |
From: John Trupiano <[email protected]> | |
Date: Sat, 16 Jan 2010 15:17:10 -0500 | |
Subject: [PATCH 3/3] Don't allow database access in rails3 | |
* Override Stub#class to return a dup'd class instance that mocks #active_relation | |
--- | |
lib/factory_girl/proxy/stub.rb | 14 ++++++++++++-- | |
1 files changed, 12 insertions(+), 2 deletions(-) | |
diff --git a/lib/factory_girl/proxy/stub.rb b/lib/factory_girl/proxy/stub.rb | |
index 95610fb..0f6a1b6 100644 | |
--- a/lib/factory_girl/proxy/stub.rb | |
+++ b/lib/factory_girl/proxy/stub.rb | |
@@ -2,7 +2,7 @@ class Factory | |
class Proxy | |
class Stub < Proxy #:nodoc: | |
@@next_id = 1000 | |
- | |
+ | |
def initialize(klass) | |
@instance = klass.new | |
@instance.id = next_id | |
@@ -14,7 +14,17 @@ class Factory | |
def connection | |
raise "stubbed models are not allowed to access the database" | |
end | |
- | |
+ | |
+ def class | |
+ klass = super.dup | |
+ klass.instance_eval do | |
+ def active_relation | |
+ raise "stubbed models are not allowed to access the database" | |
+ end | |
+ end | |
+ klass | |
+ end | |
+ | |
def reload | |
raise "stubbed models are not allowed to access the database" | |
end | |
-- | |
1.6.1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment