Friday, July 22, 2011

[Rails] rails3 tutorial: testing with factories

I'm having trouble understanding what the assigns() method does, as
described at the following link:

http://ruby.railstutorial.org/chapters/modeling-and-viewing-users-two#sec:better_user_views

The User model has been 'rake db:test:prepare'ed, but I checked and no
records were
copied to the test db after doing that. Yet the description of
assigns() says that the
code:

describe "GET 'show'" do

before(:each) do
@user = Factory(:user)
end

.
.
.


it "should find the right user" do
get :show, :id => @user
assigns(:user).should == @user
end
end
.
.
.
end

'then verifies that the variable retrieved from the database in the
action [where the action looks like this:


class UsersController < ApplicationController

def show
@user = User.find(params[:id])
end


corresponds to the @user instance created by Factory Girl. I don't
know where the 'variable retrieved from the database' comes from??

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

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate