Hi all, I''ve just started doing functional testing in Rails. I want to test my controller whether it displays the page correctly or not. This is the test code that I have written: =============================== fixtures :all def test_index get(:index, {''code'' => ''PR'', ''project_id'' => ''9999''}) end But when I ran this test I encounter this error: 1) Error: test_index(ReleasesControllerTest): NoMethodError: undefined method `releases'' for nil:NilClass vendor/rails/activesupport/lib/active_support/whiny_nil.rb:52:in `method_missing'' app/controllers/releases_controller.rb:46:in `index'' And this is how my controller looks like: @project = Project.find_by_code(params[:code]) @releases = @project.releases ============================== Why do I get this error? * Shouldn''t the releases be a instance variable instead of method? * Shouldn''t the instace be created because I have passed the parameter? Did I miss anything here? Because I got this from reading the rails guide. Thanks for the assistance. Kind regards, -- Certified Scrum Master http://blog.scrum8.com | http://jobs.scrum8.com | http://twitter.com/scrum8 -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=.
On Nov 18, 6:16 pm, Joshua Partogi <joshua.part...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi all, > > I''ve just started doing functional testing in Rails. I want to test my > controller whether it displays the page correctly or not. This is the > test code that I have written: > ===============================> fixtures :all > > def test_index > get(:index, {''code'' => ''PR'', ''project_id'' => ''9999''}) > end > > But when I ran this test I encounter this error: > 1) Error: > test_index(ReleasesControllerTest): > NoMethodError: undefined method `releases'' for nil:NilClass > vendor/rails/activesupport/lib/active_support/whiny_nil.rb:52:in > `method_missing'' > app/controllers/releases_controller.rb:46:in `index'' > > And this is how my controller looks like: > @project = Project.find_by_code(params[:code]) > @releases = @project.releases > > ==============================> > Why do I get this error? > * Shouldn''t the releases be a instance variable instead of method? > * Shouldn''t the instace be created because I have passed the parameter? > > Did I miss anything here? Because I got this from reading the rails > guide. Thanks for the assistance. > > Kind regards, > > -- > Certified Scrum Masterhttp://blog.scrum8.com|http://jobs.scrum8.com|http://twitter.com/scrum8Well, if there are no rows in the projects table whose code column is "PR", Project.find_by_code is doing to return nil. Have you properly set up your fixtures or otherwise seeded your test database? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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=.
Do you have your model relationships setup properly? (project has_many releases and releases belongs_to project?) On Nov 18, 3:16 pm, Joshua Partogi <joshua.part...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi all, > > I''ve just started doing functional testing in Rails. I want to test my > controller whether it displays the page correctly or not. This is the > test code that I have written: > ===============================> fixtures :all > > def test_index > get(:index, {''code'' => ''PR'', ''project_id'' => ''9999''}) > end > > But when I ran this test I encounter this error: > 1) Error: > test_index(ReleasesControllerTest): > NoMethodError: undefined method `releases'' for nil:NilClass > vendor/rails/activesupport/lib/active_support/whiny_nil.rb:52:in > `method_missing'' > app/controllers/releases_controller.rb:46:in `index'' > > And this is how my controller looks like: > @project = Project.find_by_code(params[:code]) > @releases = @project.releases > > ==============================> > Why do I get this error? > * Shouldn''t the releases be a instance variable instead of method? > * Shouldn''t the instace be created because I have passed the parameter? > > Did I miss anything here? Because I got this from reading the rails > guide. Thanks for the assistance. > > Kind regards, > > -- > Certified Scrum Masterhttp://blog.scrum8.com|http://jobs.scrum8.com|http://twitter.com/scrum8-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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=.
Hi all, Thanks for the help and assistance. I''m not sure why. But when I configured whiny_nils to false, the tests runs. Best regards, On Nov 19, 10:23 am, pharrington <xenogene...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Well, if there are no rows in the projects table whose code column is > "PR", Project.find_by_code is doing to return nil. Have you properly > set up your fixtures or otherwise seeded your test database?-- Certified Scrum Master http://blog.scrum8.com | http://jobs.scrum8.com | http://twitter.com/scrum8 -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=.