Permalink
Browse files

Merge pull request #642 from jfirebaugh/am

Don't assume ActiveModel is available
  • Loading branch information...
2 parents fe4e8f3 + d41bd9b commit 6e7712b3f425f3c98dc9532c77505fcec190e4a8 @alindeman alindeman committed Nov 28, 2012
Showing with 22 additions and 19 deletions.
  1. +22 −19 lib/rspec/rails/extensions/active_record/base.rb
@@ -24,24 +24,27 @@ class ::ActiveRecord::Base
end
end
-module ::ActiveModel::Validations
- # Extension to enhance `should have` on AR Model instances. Calls
- # model.valid? in order to prepare the object's errors object. Accepts
- # a :context option to specify the validation context.
- #
- # You can also use this to specify the content of the error messages.
- #
- # @example
- #
- # model.should have(:no).errors_on(:attribute)
- # model.should have(1).error_on(:attribute)
- # model.should have(n).errors_on(:attribute)
- # model.should have(n).errors_on(:attribute, :context => :create)
- #
- # model.errors_on(:attribute).should include("can't be blank")
- def errors_on(attribute, options = {})
- self.valid?(options[:context])
- [self.errors[attribute]].flatten.compact
+if defined?(::ActiveModel)
+ module ::ActiveModel::Validations
+ # Extension to enhance `should have` on AR Model instances. Calls
+ # model.valid? in order to prepare the object's errors object. Accepts
+ # a :context option to specify the validation context.
+ #
+ # You can also use this to specify the content of the error messages.
+ #
+ # @example
+ #
+ # model.should have(:no).errors_on(:attribute)
+ # model.should have(1).error_on(:attribute)
+ # model.should have(n).errors_on(:attribute)
+ # model.should have(n).errors_on(:attribute, :context => :create)
+ #
+ # model.errors_on(:attribute).should include("can't be blank")
+ def errors_on(attribute, options = {})
+ self.valid?(options[:context])
+ [self.errors[attribute]].flatten.compact
+ end
+
+ alias :error_on :errors_on
end
- alias :error_on :errors_on
end

0 comments on commit 6e7712b

Please sign in to comment.