Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 41 lines (38 sloc) 1.082 kb
bbcebcd @dchelimsky Use Rails config to determine whether or not we're using AR
dchelimsky authored
1 module RSpec
2 module Rails
a5949a5 @dchelimsky just ask if AR is defined instead
dchelimsky authored
3 if defined?(ActiveRecord)
afea2f5 @dchelimsky Add error_on and errors_on (pulled from rspec-1 and tweaked for rails-3)
dchelimsky authored
4 module Extensions
5 module ActiveRecord
73991af @dchelimsky Move error[s]_on to ActiveModel::Validations so it can be used by other
dchelimsky authored
6 # :call-seq:
7 # ModelClass.should have(:no).records
8 # ModelClass.should have(1).record
9 # ModelClass.should have(n).records
10 #
11 # Extension to enhance <tt>should have</tt> on AR Model classes
12 def records
13 find(:all)
afea2f5 @dchelimsky Add error_on and errors_on (pulled from rspec-1 and tweaked for rails-3)
dchelimsky authored
14 end
73991af @dchelimsky Move error[s]_on to ActiveModel::Validations so it can be used by other
dchelimsky authored
15 alias :record :records
afea2f5 @dchelimsky Add error_on and errors_on (pulled from rspec-1 and tweaked for rails-3)
dchelimsky authored
16 end
96a29c4 @dchelimsky cleanup whitespace
dchelimsky authored
17
73991af @dchelimsky Move error[s]_on to ActiveModel::Validations so it can be used by other
dchelimsky authored
18 class ::ActiveRecord::Base #:nodoc:
19 extend RSpec::Rails::Extensions::ActiveRecord
20 end
bbcebcd @dchelimsky Use Rails config to determine whether or not we're using AR
dchelimsky authored
21 end
22 end
afea2f5 @dchelimsky Add error_on and errors_on (pulled from rspec-1 and tweaked for rails-3)
dchelimsky authored
23 end
24 end
25
73991af @dchelimsky Move error[s]_on to ActiveModel::Validations so it can be used by other
dchelimsky authored
26 module ::ActiveModel::Validations
27 # :call-seq:
28 # model.should have(:no).errors_on(:attribute)
29 # model.should have(1).error_on(:attribute)
30 # model.should have(n).errors_on(:attribute)
31 #
32 # Extension to enhance <tt>should have</tt> on AR Model instances.
33 # Calls model.valid? in order to prepare the object's errors
34 # object.
35 def errors_on(attribute)
36 self.valid?
37 [self.errors[attribute]].flatten.compact
38 end
39 alias :error_on :errors_on
40 end
Something went wrong with that request. Please try again.