changelog shortlog tags changeset manifest revisions annotate raw

vendor/plugins/rspec_on_rails/lib/spec/rails/extensions/active_record/base.rb

changeset 16: 01fd3f10ae84
author: moriq@moriq.com
date: Mon Mar 10 10:13:18 2008 +0900 (16 years ago)
permissions: -rw-r--r--
description: add plugins rspec_on_rails
1if defined?(ActiveRecord::Base)
2 module ActiveRecord #:nodoc:
3 class Base
4
5 (class << self; self; end).class_eval do
6 # Extension for <tt>should have</tt> on AR Model classes
7 #
8 # ModelClass.should have(:no).records
9 # ModelClass.should have(1).record
10 # ModelClass.should have(n).records
11 def records
12 find(:all)
13 end
14 alias :record :records
15 end
16
17 # Extension for <tt>should have</tt> on AR Model instances
18 #
19 # model.should have(:no).errors_on(:attribute)
20 # model.should have(1).error_on(:attribute)
21 # model.should have(n).errors_on(:attribute)
22 def errors_on(attribute)
23 self.valid?
24 [self.errors.on(attribute)].flatten.compact
25 end
26 alias :error_on :errors_on
27
28 end
29 end
30end