Skip to content
This repository
Newer
Older
100644 46 lines (43 sloc) 1.23 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
c1f0eab3 »
2011-12-08 more rdoc cleanup
6 # Extension to enhance `should have` on AR Model classes
6ab0bb66 »
2011-10-16 cleanup and add some rdoc
7 #
c1f0eab3 »
2011-12-08 more rdoc cleanup
8 # @example
e26fb348 »
2011-11-22 small rdoc tweak
9 #
78c75488 »
2011-11-22 rdoc: correct indentation helps (markdown)
10 # ModelClass.should have(:no).records
11 # ModelClass.should have(1).record
12 # ModelClass.should have(n).records
73991af4 »
2010-10-27 Move error[s]_on to ActiveModel::Validations so it can be used by other
13 def records
14 find(:all)
afea2f56 »
2010-04-28 Add error_on and errors_on (pulled from rspec-1 and tweaked for rails-3)
15 end
73991af4 »
2010-10-27 Move error[s]_on to ActiveModel::Validations so it can be used by other
16 alias :record :records
afea2f56 »
2010-04-28 Add error_on and errors_on (pulled from rspec-1 and tweaked for rails-3)
17 end
96a29c48 »
2010-07-18 cleanup whitespace
18
6ab0bb66 »
2011-10-16 cleanup and add some rdoc
19 class ::ActiveRecord::Base
73991af4 »
2010-10-27 Move error[s]_on to ActiveModel::Validations so it can be used by other
20 extend RSpec::Rails::Extensions::ActiveRecord
21 end
bbcebcd4 »
2010-09-05 Use Rails config to determine whether or not we're using AR
22 end
23 end
afea2f56 »
2010-04-28 Add error_on and errors_on (pulled from rspec-1 and tweaked for rails-3)
24 end
25 end
26
73991af4 »
2010-10-27 Move error[s]_on to ActiveModel::Validations so it can be used by other
27 module ::ActiveModel::Validations
e26fb348 »
2011-11-22 small rdoc tweak
28 # Extension to enhance `should have` on AR Model instances. Calls
29 # model.valid? in order to prepare the object's errors object.
30 #
31 # You can also use this to specify the content of the error messages.
6ab0bb66 »
2011-10-16 cleanup and add some rdoc
32 #
c1f0eab3 »
2011-12-08 more rdoc cleanup
33 # @example
6ab0bb66 »
2011-10-16 cleanup and add some rdoc
34 #
78c75488 »
2011-11-22 rdoc: correct indentation helps (markdown)
35 # model.should have(:no).errors_on(:attribute)
36 # model.should have(1).error_on(:attribute)
37 # model.should have(n).errors_on(:attribute)
73991af4 »
2010-10-27 Move error[s]_on to ActiveModel::Validations so it can be used by other
38 #
78c75488 »
2011-11-22 rdoc: correct indentation helps (markdown)
39 # model.errors_on(:attribute).should include("can't be blank")
73991af4 »
2010-10-27 Move error[s]_on to ActiveModel::Validations so it can be used by other
40 def errors_on(attribute)
41 self.valid?
42 [self.errors[attribute]].flatten.compact
43 end
44 alias :error_on :errors_on
45 end
Something went wrong with that request. Please try again.