Sha256: 67da6b743059301584ea93e24b67cd3ef2b5f7cdfe59f8e228489f37714af4f5
Contents?: true
Size: 1.01 KB
Versions: 9
Compression:
Stored size: 1.01 KB
Contents
class Factory 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 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, attributes) set(name, Factory.stub(factory, attributes)) end def association(factory, overrides = {}) Factory.stub(factory, overrides) end def result run_callbacks(:after_stub) @instance end end end end
Version data entries
9 entries across 9 versions & 6 rubygems