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?? Does
that user get retrieved from the development database somehow?

Later, the tutorial says this:

===
The code in Listing 7.17 relies on the User.find method in the
controller action to retrieve the right user from the test database.

so an empty test db somehow returns a user.

Well, I guess I overlooked this statement at the beginning of the
section:

===
We’ll accomplish this goal with a user factory, which is a convenient
way to define a user object and insert it into our test database.

So calling the factory like this:

@user = Factory(:user)

does two things:

  1. assigns a user to @user

  2. inserts the user in the test db

(You never see anything in the test db because the tests roll back
changes to the db after each test.)