Module: RSpec::ActiveModel::Mocks::Mocks::ActiveRecordStubExtensions

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

Instance Method Summary collapse

Instance Method Details

#as_new_recordObject

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



190
191
192
193
# File 'lib/rspec/active_model/mocks/mocks.rb', line 190

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

#connectionObject

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



202
203
204
# File 'lib/rspec/active_model/mocks/mocks.rb', line 202

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

#new_record?Boolean

Returns the opposite of persisted?.

Returns:

  • (Boolean)


196
197
198
# File 'lib/rspec/active_model/mocks/mocks.rb', line 196

def new_record?
  !persisted?
end