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

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

Instance Method Summary (collapse)

Instance Method Details

- (Object) [](key)

Transforms the key to a method and calls it.



55
56
57
# File 'lib/rspec/rails/mocks.rb', line 55

def [](key)
  send(key)
end

- (Object) association(association_name)

Returns an object representing an association from the mocked model's perspective. For use by Rails internally only.



66
67
68
69
# File 'lib/rspec/rails/mocks.rb', line 66

def association(association_name)
  @associations ||= Hash.new { |h, k| h[k] = Association.new(k) }
  @associations[association_name]
end

- (Object) destroy

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



49
50
51
52
# File 'lib/rspec/rails/mocks.rb', line 49

def destroy
  RSpec::Mocks.allow_message(self, :persisted?).and_return(false)
  RSpec::Mocks.allow_message(self, :id).and_return(nil)
end

- (Boolean) new_record?

Returns the opposite of persisted?

Returns:

  • (Boolean)


60
61
62
# File 'lib/rspec/rails/mocks.rb', line 60

def new_record?
  !persisted?
end