Passing user id to spec | error

-----Controller --------------
def update
@user = User.find_by_id( user.id )
if request.post?

  unless params[ :user ].nil?

    if @user.update_attributes( params[ :user ] )
      redirect_to :action => :show

    end
  else
    render :status => 400,
           :text => 'No user parameters

end

------- spec -------------
describe UserProfilesController do

before(:each) do
@user = mock_model(User)
controller.stub!(:requires_user).and_return @user
controller.stub!(:user).and_return @user
User.stub!(:find_by_id).and_return(@user)
@user.stub!(:update_attributes).and_return(true)
end

it “should find User and return object” do
User.should_receive(:find_by_id).with(“1”).and_return(@user)
@user.should_receive(:update_attributes).and_return(true)
post :update, :id =>“1”, :user => {}
end
end

------- Error --------------------------------
<User(id: integer, created_on: datetime, updated_on: datetime,
destroyed_on:
dat
etime, accessed_on: datetime, email_address: string, name_first: string,
name_la
st: string, mailing_address_id: integer, billing_address_id: integer,
name_displ
ay: string, picture_id: integer, url: string, country: string,
freelance:
boolea
n, statement: string, hostname_active: boolean, hostname: string,
promotional_ma
ilings: boolean, sales_commission_rate: float, referral_commission_rate:
float,
employee_lock: boolean) (class)> expected :find_by_id with (“1”) but
received it
with ([1001])

How shall I pass the id to the spec. Please help overcome this issue


View this message in context:
http://www.nabble.com/Passing-user-id-to-spec-|-error-tp23553916p23553916.html
Sent from the rspec-users mailing list archive at Nabble.com.

On Fri, May 15, 2009 at 1:02 AM, manoah [email protected] wrote:

-----Controller --------------
def update
@user = User.find_by_id( user.id )

This uses user.id, not params[:id]

          :text => 'No user parameters

end

------- spec -------------
describe UserProfilesController do

before(:each) do
@user = mock_model(User)

The @user gets defined with an ID of 1001 (in this case). Try:

@user = mock_model(User, :id => 1)

HTH,
David

manoah wrote:

@user = mock_model(User)    

end
boolea


Now I am getting the below error

expected :find_by_id with (“1”) but received it with ([1])

How shall I pass

manoah wrote:

@user = mock_model(User)    

end
boolea

Thank you David.
The example passes when we pass the id as string
@user = mock_model(User, :id=> “1”)


View this message in context:
http://www.nabble.com/Passing-user-id-to-spec-|-error-tp23553916p23570544.html
Sent from the rspec-users mailing list archive at Nabble.com.