Permalink
Browse files

Move database interaction stubbing on the result to the result call

  • Loading branch information...
1 parent 5fc57da commit 8ce897f592c9ed3c71bae41a973ed2a2b7b3a731 @joshuaclayton joshuaclayton committed Dec 3, 2011
Showing with 18 additions and 18 deletions.
  1. +18 −18 lib/factory_girl/proxy/stub.rb
@@ -3,8 +3,24 @@ class Proxy
class Stub < Proxy #:nodoc:
@@next_id = 1000
- def initialize(klass, callbacks = [])
- super
+ def association(factory_name, overrides = {})
+ factory = FactoryGirl.factory_by_name(factory_name)
+ factory.run(Proxy::Stub, overrides.except(:method))
+ end
+
+ def result(to_create)
+ stub_database_interaction_on_result
+ run_callbacks(:after_stub)
+ result_instance
+ end
+
+ private
+
+ def next_id
+ @@next_id += 1
+ end
+
+ def stub_database_interaction_on_result
result_instance.id = next_id
result_instance.instance_eval do
def persisted?
@@ -40,22 +56,6 @@ def update_attribute(*args)
end
end
end
-
- def association(factory_name, overrides = {})
- factory = FactoryGirl.factory_by_name(factory_name)
- factory.run(Proxy::Stub, overrides.except(:method))
- end
-
- def result(to_create)
- run_callbacks(:after_stub)
- result_instance
- end
-
- private
-
- def next_id
- @@next_id += 1
- end
end
end
end

0 comments on commit 8ce897f

Please sign in to comment.