0

I have a model that looks something like this:

class User
   include Mongoid::Document

   field :email

   validate :email, presence: true, uniqueness: true
end

And I have a test that looks like...

it { User.new.should_not be_valid }
it { FactoryGirl.build(:user).should be_valid }
it { should validate_presence_of :email }
it { should validate_uniqueness_of :email }

Both of these want to hit the database when the .valid? method is called. Is there someway I can abstract that out? The uniqueness validator has been tested thoroughly by plenty of other folks, so the last line above is good enough for me.

Not that big a deal if I must run a DB during model specs, but I'd rather avoid it if possible.

Drew
  • 15,158
  • 17
  • 68
  • 77

1 Answers1

0

The .valid? method should still work with ActiveModel, I am not quite sure what Mongoid includes but ActiveModel you must have include ActiveModel:Validations

This may not have been clear but ActiveModel does not try and hit the database.

Jesse Whitham
  • 824
  • 9
  • 32