On Nov 18, 6:16 pm, Joshua Partogi <[email protected]> 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

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?

--

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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=.


Reply via email to