Sha256: f7f0e9f67f5d38c6f179b2ff0beb01c40af216af0d42ca0f8f3c788b219392a0
Contents?: true
Size: 1.7 KB
Versions: 3
Compression:
Stored size: 1.7 KB
Contents
module FactoryGirl module Strategy class Stub @@next_id = 1000 def association(runner) runner.run(:build_stubbed) end def result(evaluation) evaluation.object.tap do |instance| stub_database_interaction_on_result(instance) evaluation.notify(:after_stub, instance) end end private def next_id @@next_id += 1 end def stub_database_interaction_on_result(result_instance) result_instance.id = next_id result_instance.instance_eval do def persisted? !new_record? end 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 def update_attribute(*args) raise 'stubbed models are not allowed to access the database' end end created_at_missing_default = result_instance.respond_to?(:created_at) && !result_instance.created_at result_instance_missing_created_at = !result_instance.respond_to?(:created_at) if created_at_missing_default || result_instance_missing_created_at result_instance.instance_eval do def created_at @created_at ||= Time.now end end end end end end end
Version data entries
3 entries across 3 versions & 2 rubygems