module RSpec::Rails::Mocks::ActiveRecordStubExtensions

def as_new_record

Stubs +id+ (or other primary key method) to return nil
def as_new_record
  self.__send__("#{self.class.primary_key}=", nil)
  super
end

def connection

@raises IllegalDataAccessException
Raises an IllegalDataAccessException (stubbed models are not allowed to access the database)
def connection
  raise RSpec::Rails::IllegalDataAccessException.new("stubbed models are not allowed to access the database")
end

def new_record?

Returns the opposite of +persisted?+.
def new_record?
  !persisted?
end