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.