Module: RSpec::Rails::Mocks::ActiveModelStubExtensions

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

Instance Method Summary collapse

Instance Method Details

#as_new_recordObject

Stubs ‘persisted` to return false and `id` to return nil



152
153
154
155
156
# File 'lib/rspec/rails/mocks.rb', line 152

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

#persisted?Boolean

Returns ‘true` by default. Override with a stub.

Returns:

  • (Boolean)


159
160
161
# File 'lib/rspec/rails/mocks.rb', line 159

def persisted?
  true
end