Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

61 lines (49 sloc) 1.408 kb
module FactoryGirl
class Proxy
class Stub < Proxy #:nodoc:
@@next_id = 1000
def initialize(klass)
@instance = klass.new
@instance.id = next_id
@instance.instance_eval do
def new_record?
id.nil?
end
def save(*args)
raise "stubbed models are not allowed to access the database"
end
def destroy(*args)
raise "stubbed models are not allowed to access the database"
end
def connection
raise "stubbed models are not allowed to access the database"
end
def reload
raise "stubbed models are not allowed to access the database"
end
end
end
def next_id
@@next_id += 1
end
def get(attribute)
@instance.send(attribute)
end
def set(attribute, value)
@instance.send(:"#{attribute}=", value)
end
def associate(name, factory_name, overrides)
factory = FactoryGirl.factory_by_name(factory_name)
set(name, factory.run(Proxy::Stub, overrides))
end
def association(factory_name, overrides = {})
factory = FactoryGirl.factory_by_name(factory_name)
factory.run(Proxy::Stub, overrides)
end
def result
run_callbacks(:after_stub)
@instance
end
end
end
end
Jump to Line
Something went wrong with that request. Please try again.