Sha256: c09f24c81ad7823ae329597edb7e9bf75dac4ca8389bec91f6811de4e3133324

Contents?: true

Size: 1.41 KB

Versions: 3

Compression:

Stored size: 1.41 KB

Contents

= SixArm.com » Ruby » ActiveRecord mock object for testing Rails

Author:: Joel Parker Henderson, joel@joelparkerhenderson.com
Copyright:: Copyright (c) 2006-2011 Joel Parker Henderson
License:: See LICENSE.txt file

A simple mock object that provides the ActiveRecord method
signatures read_attribute(key) and write_attribute(key,val),
and simple record finder signatures find(id) and find(:all).


This provides some of the ActiveRecord method signatures we use:
  - read_attribute(key)
  - write_attribute(key,val)
  - find(id)
  - find(:all)

Example:
  mock = ActiveRecordMock.new
  mock.write_attribute('foo','bar')
  mock.read_attribute('foo') => 'bar'

Example of initialize with attributes:
  mock = ActiveRecordMock.new(:foo => 'bar', :goo => 'car', :hoo => 'dar')
  mock.read_attribute(:foo') => 'bar'
  mock.read_attribute(:goo') => 'car'
  mock.read_attribute(:hoo') => 'dar'

Example of creating mock users:
  anne = ActiveRecordMock.new(:id => 123, :name => 'Anne')
  beth = ActiveRecordMock.new(:id => 456, :name => 'Beth')
  cate = ActiveRecordMock.new(:id => 789, :name => 'Cate')

Example of mock finder creation:
  ActiveRecordMock.find=[anne,beth,cate]

Example of mock finder retrieval of records by id:
  ActiveRecordMock.find(123) => anne
  ActiveRecordMock.find(456) => beth
  ActiveRecordMock.find(789) => cate

Example of mock finder retrieval of all records:
  ActiveRecordMock.find(:all) => [anne,beth,cate]

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sixarm_ruby_active_record_mock-1.4.6 README.rdoc
sixarm_ruby_active_record_mock-1.4.4 README.rdoc
sixarm_ruby_active_record_mock-1.4.2 README.rdoc