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



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

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)



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

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)


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

def new_record?
  !persisted?
end