Skip to content
This repository
Newer
Older
100644 41 lines (38 sloc) 1.082 kb
bbcebcd4 »
2010-09-05 Use Rails config to determine whether or not we're using AR
1 module RSpec
2 module Rails
a5949a56 »
2010-11-06 just ask if AR is defined instead
3 if defined?(ActiveRecord)
afea2f56 »
2010-04-28 Add error_on and errors_on (pulled from rspec-1 and tweaked for rails-3)
4 module Extensions
5 module ActiveRecord
73991af4 »
2010-10-27 Move error[s]_on to ActiveModel::Validations so it can be used by other
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)
afea2f56 »
2010-04-28 Add error_on and errors_on (pulled from rspec-1 and tweaked for rails-3)
14 end
73991af4 »
2010-10-27 Move error[s]_on to ActiveModel::Validations so it can be used by other
15 alias :record :records
afea2f56 »
2010-04-28 Add error_on and errors_on (pulled from rspec-1 and tweaked for rails-3)
16 end
96a29c48 »
2010-07-18 cleanup whitespace
17
73991af4 »
2010-10-27 Move error[s]_on to ActiveModel::Validations so it can be used by other
18 class ::ActiveRecord::Base #:nodoc:
19 extend RSpec::Rails::Extensions::ActiveRecord
20 end
bbcebcd4 »
2010-09-05 Use Rails config to determine whether or not we're using AR
21 end
22 end
afea2f56 »
2010-04-28 Add error_on and errors_on (pulled from rspec-1 and tweaked for rails-3)
23 end
24 end
25
73991af4 »
2010-10-27 Move error[s]_on to ActiveModel::Validations so it can be used by other
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.