[rspec-users] How to write a test for validates_uniqueness_of

Ben Mabey ben at benmabey.com
Tue May 20 20:40:03 EDT 2008


Try this:
http://github.com/joshknowles/rspec-on-rails-matchers/tree/master

Maurício Linhares wrote:
> This plugin does it -> http://code.google.com/p/rspec-on-rails-matchers/
>
> But it's throwing a "forbidden" error right now.
>
> On Tue, May 20, 2008 at 8:59 PM, T K <tek.katu at gmail.com> wrote:
>   
>> Hi,
>>
>> I have a spec
>>
>>  it "should have a unique username "
>>
>> I have a code:
>>
>>  validates_uniqueness_of :user_name
>>
>>
>> Now, I don't know how to test this code. In order to test this, do I
>> need to run `save`?
>>
>> For example,
>>
>> @user = User.create(:username => "mike")
>> @another = User.create(:username => "mike")
>> @another.save.should be_false
>>
>> This messes up test database. Is there any better way?
>>
>> -T
>> _______________________________________________
>> rspec-users mailing list
>> rspec-users at rubyforge.org
>> http://rubyforge.org/mailman/listinfo/rspec-users
>>
>>     
>
>
>
>   



More information about the rspec-users mailing list