Upgraded Rails and RSpec
[monkeycharger.git] / vendor / plugins / rspec_on_rails / lib / spec / rails / extensions / active_record / base.rb
blobc58e8579fd55f298305f110908346fc6b998a507
1 module ActiveRecord #:nodoc:
2   class Base
4     (class << self; self; end).class_eval do
5       # Extension for <tt>should have</tt> on AR Model classes
6       #
7       #   ModelClass.should have(:no).records
8       #   ModelClass.should have(1).record
9       #   ModelClass.should have(n).records
10       def records
11         find(:all)
12       end
13       alias :record :records
14     end
16     # Extension for <tt>should have</tt> on AR Model instances
17     #
18     #   model.should have(:no).errors_on(:attribute)
19     #   model.should have(1).error_on(:attribute)
20     #   model.should have(n).errors_on(:attribute)
21     def errors_on(attribute)
22       self.valid?
23       [self.errors.on(attribute)].flatten.compact
24     end
25     alias :error_on :errors_on
27   end
28 end