https://github.com/sixarm/sixarm_ruby_active_record_mock
SixArm.com » Ruby » ActiveRecord mock object for testing Rails
https://github.com/sixarm/sixarm_ruby_active_record_mock
activerecord gem mock rails ruby
Last synced: over 1 year ago
JSON representation
SixArm.com » Ruby » ActiveRecord mock object for testing Rails
- Host: GitHub
- URL: https://github.com/sixarm/sixarm_ruby_active_record_mock
- Owner: SixArm
- License: other
- Created: 2010-05-23T23:22:23.000Z (about 16 years ago)
- Default Branch: main
- Last Pushed: 2023-09-15T19:27:37.000Z (almost 3 years ago)
- Last Synced: 2025-02-06T00:26:12.802Z (over 1 year ago)
- Topics: activerecord, gem, mock, rails, ruby
- Language: Ruby
- Homepage: http://sixarm.com
- Size: 320 KB
- Stars: 0
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
# SixArm.com → Ruby →
ActiveRecord mock object for testing Rails
* Doc:
* Gem:
* Repo:
## Introduction
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)
For docs go to
Want to help? We're happy to get pull requests.
## Install
### Gem
To install this gem in your shell or terminal:
gem install sixarm_ruby_active_record_mock
### Gemfile
To add this gem to your Gemfile:
gem 'sixarm_ruby_active_record_mock'
### Require
To require the gem in your code:
require 'sixarm_ruby_active_record_mock'
## Examples
Basic:
require "sixarm_ruby_active_record_mock"
mock = ActiveRecordMock.new
mock.write_attribute('foo','bar')
mock.read_attribute('foo') => 'bar'
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'
Creating mock users:
anne = ActiveRecordMock.new(:id => 123, :name => 'Anne')
beth = ActiveRecordMock.new(:id => 456, :name => 'Beth')
cate = ActiveRecordMock.new(:id => 789, :name => 'Cate')
Mock finder creation:
ActiveRecordMock.find=[anne,beth,cate]
Mock finder retrieval of records by id:
ActiveRecordMock.find(123) => anne
ActiveRecordMock.find(456) => beth
ActiveRecordMock.find(789) => cate
Mock finder retrieval of all records:
ActiveRecordMock.find(:all) => [anne,beth,cate]