connection()
click to toggle source
def connection
raise 'stubbed models are not allowed to access the database'
end
created_at()
click to toggle source
def created_at
@created_at ||= Time.now
end
destroy(*args)
click to toggle source
def destroy(*args)
raise 'stubbed models are not allowed to access the database'
end
new_record?()
click to toggle source
def new_record?
id.nil?
end
next_id()
click to toggle source
def next_id
@@next_id += 1
end
persisted?()
click to toggle source
def persisted?
!new_record?
end
reload()
click to toggle source
def reload
raise 'stubbed models are not allowed to access the database'
end
save(*args)
click to toggle source
def save(*args)
raise 'stubbed models are not allowed to access the database'
end
stub_database_interaction_on_result(result_instance)
click to toggle source
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
def update_column(*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
update_attribute(*args)
click to toggle source
def update_attribute(*args)
raise 'stubbed models are not allowed to access the database'
end
update_column(*args)
click to toggle source
def update_column(*args)
raise 'stubbed models are not allowed to access the database'
end