Module: RSpec::Rails::Mocks::ActiveRecordStubExtensions

Defined in:
lib/rspec/rails/mocks.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) as_new_record

Stubs id (or other primary key method) to return nil



193
194
195
196
# File 'lib/rspec/rails/mocks.rb', line 193

def as_new_record
  self.__send__("#{self.class.primary_key}=", nil)
  super
end

- (Object) connection

Raises an IllegalDataAccessException (stubbed models are not allowed to access the database)



205
206
207
# File 'lib/rspec/rails/mocks.rb', line 205

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

- (Boolean) new_record?

Returns the opposite of persisted?.

Returns:

  • (Boolean)


199
200
201
# File 'lib/rspec/rails/mocks.rb', line 199

def new_record?
  !persisted?
end