|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
Simple functional test failsHi 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)?. Thanks in advance, txapelgorri. --~--~---------~--~----~------------~-------~--~----~ 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@... To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@... For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: Simple functional test failsOn Wed, 2008-07-23 at 10:03 -0700, txapelgorri wrote: > 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)?. > > Thanks in advance, txapelgorri. does test database have data? Are you using fixtures to populate test database? if you run... script/console test @story = Story.find_by_name('txapelgorri') does it also generate an error? Craig --~--~---------~--~----~------------~-------~--~----~ 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@... To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@... For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: Simple functional test failsQuoting txapelgorri <ibon.castilla@...>: > > 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@... To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@... For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: Simple functional test failsThanks both for answering. I was playing around with the code and I probably miss to change the instance variable at any of the three files :S It finally get solved by it self. Thanks again. Cheers, txapelgorri. 2008/7/23 txapelgorri <ibon.castilla@...>: > > 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)?. > > Thanks in advance, txapelgorri. > > > > -- -- Visitame en http://sinanimodelucro.net Usa GNU/Linux, tus úlceras te lo agradecerán. Realizado con Software Libre. -- GPG public key at http://sinanimodelucro.net/txapelgorri.asc Finderprint: 9402 CEBF 0274 F213 8B88 1209 7B2D 70B3 843E F99C -- --~--~---------~--~----~------------~-------~--~----~ 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@... To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@... For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~--- |
| Free Forum Powered by Nabble | Forum Help |