Skip to content
Newer
Older
100644 46 lines (43 sloc) 1.2 KB
bbcebcd @dchelimsky Use Rails config to determine whether or not we're using AR
dchelimsky authored Sep 5, 2010
1 module RSpec
2 module Rails
a5949a5 @dchelimsky just ask if AR is defined instead
dchelimsky authored Nov 6, 2010
3 if defined?(ActiveRecord)
afea2f5 @dchelimsky Add error_on and errors_on (pulled from rspec-1 and tweaked for rails-3)
dchelimsky authored Apr 28, 2010
4 module Extensions
5 module ActiveRecord
6ab0bb6 @dchelimsky cleanup and add some rdoc
dchelimsky authored Oct 16, 2011
6 # Extension to enhance +should have+ on AR Model classes
7 #
e26fb34 @dchelimsky small rdoc tweak
dchelimsky authored Nov 22, 2011
8 # ## Examples:
9 #
73991af @dchelimsky Move error[s]_on to ActiveModel::Validations so it can be used by other
dchelimsky authored Oct 27, 2010
10 # ModelClass.should have(:no).records
11 # ModelClass.should have(1).record
12 # ModelClass.should have(n).records
13 def records
14 find(:all)
afea2f5 @dchelimsky Add error_on and errors_on (pulled from rspec-1 and tweaked for rails-3)
dchelimsky authored Apr 28, 2010
15 end
73991af @dchelimsky Move error[s]_on to ActiveModel::Validations so it can be used by other
dchelimsky authored Oct 27, 2010
16 alias :record :records
afea2f5 @dchelimsky Add error_on and errors_on (pulled from rspec-1 and tweaked for rails-3)
dchelimsky authored Apr 28, 2010
17 end
96a29c4 @dchelimsky cleanup whitespace
dchelimsky authored Jul 18, 2010
18
6ab0bb6 @dchelimsky cleanup and add some rdoc
dchelimsky authored Oct 16, 2011
19 class ::ActiveRecord::Base
73991af @dchelimsky Move error[s]_on to ActiveModel::Validations so it can be used by other
dchelimsky authored Oct 27, 2010
20 extend RSpec::Rails::Extensions::ActiveRecord
21 end
bbcebcd @dchelimsky Use Rails config to determine whether or not we're using AR
dchelimsky authored Sep 5, 2010
22 end
23 end
afea2f5 @dchelimsky Add error_on and errors_on (pulled from rspec-1 and tweaked for rails-3)
dchelimsky authored Apr 28, 2010
24 end
25 end
26
73991af @dchelimsky Move error[s]_on to ActiveModel::Validations so it can be used by other
dchelimsky authored Oct 27, 2010
27 module ::ActiveModel::Validations
e26fb34 @dchelimsky small rdoc tweak
dchelimsky authored Nov 22, 2011
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.
6ab0bb6 @dchelimsky cleanup and add some rdoc
dchelimsky authored Oct 16, 2011
32 #
e26fb34 @dchelimsky small rdoc tweak
dchelimsky authored Nov 22, 2011
33 # ## Examples:
6ab0bb6 @dchelimsky cleanup and add some rdoc
dchelimsky authored Oct 16, 2011
34 #
73991af @dchelimsky Move error[s]_on to ActiveModel::Validations so it can be used by other
dchelimsky authored Oct 27, 2010
35 # model.should have(:no).errors_on(:attribute)
36 # model.should have(1).error_on(:attribute)
37 # model.should have(n).errors_on(:attribute)
38 #
e26fb34 @dchelimsky small rdoc tweak
dchelimsky authored Nov 22, 2011
39 # model.errors_on(:attribute).should include("can't be blank")
73991af @dchelimsky Move error[s]_on to ActiveModel::Validations so it can be used by other
dchelimsky authored Oct 27, 2010
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.