[rspec-users] Rspec approach to test model

Kaleem Ullah lists at ruby-forum.com
Thu Feb 12 02:21:04 EST 2009

Hi all,
Below is my model action.

def activate!
    self.update_attribute(:active, true)

here is spec/models/user_spec.rb

describe User do
  before(:each) do
    @user=User.new(:email=>'kkk at gmail.com',:password='1234'....,)

This is my spec.

it "should activate the user" do
  @user.active.should be_true

 but it gives error like "#23000Duplicate entry
 'kkkkk at gmail.com Insert INTO (...) Values(...)".
 It should do update not Insert.
 But when i try call it with a new instance of user (with no values
 assigned to any user attribute) then it works.
 it "should activate the user" do
  @user_1.active.should be_true

 I think i have to erase all the User attributes from "before (:each)"
 and only assigned it in Examples which required it.

 am i right ?


Posted via http://www.ruby-forum.com/.

More information about the rspec-users mailing list