[rspec-users] spec'ing validates_uniqueness_of :whatever

Matt Berther matt at mattberther.com
Thu Apr 3 02:14:59 EDT 2008


Hi Juanma,

I do this this way:

describe Model do
   def create(options={})
     Model.create(options)
   end

   it "should not allow duplicate names" do
     model = create(:name => "name")
     new_model = create(:name => "name")

     new_model.should have_error_on(:name, :taken)
   end
end

--
Matt Berther
http://www.mattberther.com




On Apr 2, 2008, at 2:13 AM, Juanma Cervera wrote:

> Hello
>
> I am learning rspec and trying to especify the activerecord  
> validations
> of my models.
>
> How would I make a require_uniqueness_of specification for a field.
> Can I make this with mocks, without touching the database?
> Can somebody point me to some information or plugin for this issue.
>
> Thank you very much.
>
> Juan M. Cervera
> -- 
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users



More information about the rspec-users mailing list