Module: RSpec::Rails::Mocks::ActiveRecordInstanceMethods

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

Instance Method Summary collapse

Instance Method Details

#[](key) ⇒ Object

Transforms the key to a method and calls it.



40
41
42
# File 'lib/rspec/rails/mocks.rb', line 40

def [](key)
  send(key)
end

#destroyObject

Stubs persisted? to return false and id to return nil.



34
35
36
37
# File 'lib/rspec/rails/mocks.rb', line 34

def destroy
  self.stub(:persisted?) { false }
  self.stub(:id) { nil }
end

#new_record?Boolean

Returns the opposite of persisted?

Returns:

  • (Boolean)


45
46
47
# File 'lib/rspec/rails/mocks.rb', line 45

def new_record?
  !persisted?
end