Question

I want to test a rails engine by using capybara and factory_girl with Test::Unit (not rspec).

I write the following test:

test 'get review show' do
  review = create(:review)
  visit aecs_review.admin_review_path(review.id)
  assert true
end

rake test now get the following error:

  1) Error:
NavigationTest#test_get_review_show:
ActionView::Template::Error: undefined method `reviewnumber' for nil:NilClass
D:/Webserver/rails-server/ecommerce/aecs_review/app/views/aecs_review/admin/reviews/show.html.erb:1:in `_____ebserve
r_rails_server_ecommerce_aecs_review_app_views_aecs_review_admin_reviews_show_html_erb___218004451_53574504'

reviewnumber is a small model method to give back a formated id. It is executed by @review.reviewnumber in the view.

I get also errors at the other views (index, ect.) at the points, where i try to access a attribute of a variable. Why are the variables in the views always nil? How can I solve this problem?

Here is my controller method:

require_dependency 'aecs_review/application_controller'

module AecsReview
  class Admin::ReviewsController < ApplicationController
    def show
      @review = Review.find(params[:id])
    end
  end
end

And my view:

<h1>Rezension anzeigen: <%= @review.reviewnumber %></h1>
[...]

rake routes of the dummy app of the engine:

root GET   /                                        aecs_review/admin/reviews#index
admin_reviews GET   /admin/index(.:format)                   aecs_review/admin/reviews#index
admin_review GET   /admin/:id/show(.:format)                aecs_review/admin/reviews#show
admin_review_toggle_visibility GET   /admin/:id/toggle_visibility(.:format)   aecs_review/admin/reviews#toggle_visibility
admin_review_destroy GET   /admin/:id/destroy(.:format)             aecs_review/admin/reviews#destroy
review_create POST  /create(.:format)                        aecs_review/reviews#create
reviews GET   /product/:id(.:format)                   aecs_review/reviews#index
reviews_overview GET   /product/:id/overview(.:format)          aecs_review/reviews#overview
reviews_rating GET   /product/:id/rating(.:format)            aecs_review/reviews#rating
review_new GET   /product/:id/new(.:format)               aecs_review/reviews#new
review GET   /:id(.:format)                           aecs_review/reviews#show
review_edit GET   /:id/edit(.:format)                      aecs_review/reviews#edit
review_update PATCH /:id/update(.:format)                    aecs_review/reviews#update
review_destroy GET   /:id/destroy(.:format)                   aecs_review/reviews#destroy
review_create_evaluation_good GET   /:id/create_evaluation/good(.:format)    aecs_review/reviews#create_evaluation_good
review_create_evaluation_bad GET   /:id/create_evaluation/bad(.:format)     aecs_review/reviews#create_evaluation_bad
review_create_evaluation_abusing GET   /:id/create_evaluation/abusing(.:format) aecs_review/reviews#create_evaluation_abusing
Was it helpful?

Solution

I found the problem!

In the controller I have a before_filter, which is a part of the main app. So I wanted to override it. But i accidentally override the complete controller, so there was no more controller method to execute.

Now I skip the before_filter and it works!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top