Quoting txapelgorri
<ibon.castilla-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:>
> Hi there:
>
> I''m starting with rails and I founded and issue that I
can''t figure
> out how to solve:
>
> - This is the controller:
> class StoriesController < ApplicationController
> def index
> @current_time = Time.now
> @story = Story.find_by_name(''txapelgorri'')
> @rand_story = Story.find(:first, :order =>
''RANDOM()'')
> end
> end
> - This is the view:
> <p>Time <%= @current_time %></p>
> <p>A story <a href="<%= @story.link
%>"><%= @story.name %></a></p>
> <p>A story (more polite): <%= link_to @story.name, @story.link
%></
> p>
> <p>Random history: <%= link_to @rand_story.name,
@rand_story.link
> %></p>
> - And finally this is the test:
> class StoriesControllerTest < ActionController::TestCase
> def test_should_show_index
> get :index
> assert_response :success
> assert_template ''index''
> assert_not_nil assigns(:story)
> end
> end
>
> When running "rake test:functionals" it shows an error: "The
error
> occurred while evaluating nil.link on line #2 of stories/
> index.html.erb". This error belongs to "assert_not_nil
> assigns(:story)" at the test file (so it says the console).
Isn''t
> supposed to be already a "not nil" instance variable when I
declared
> it at controller (Story.find_by_name, blah, blah)?.
You are not loading any fixtures, so the test database may very well be
empty. It the database is empty find(:first) will return nil. You may be
confusing nil with undefined.
HTH,
Jeffrey
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---