Skip to content

Commit

Permalink
Move database interaction stubbing on the result to the result call
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaclayton committed Dec 3, 2011
1 parent 5fc57da commit 8ce897f
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions lib/factory_girl/proxy/stub.rb
Expand Up @@ -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?
Expand Down Expand Up @@ -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.