I would like to hear ideas about a problem I’m having with testing a
controller from a model that uses polimorphism. It seems that the
fixture do not recognize the relationship. Did you see errors in these
files? The error I get is:
/***** ERROR *****/
-
Error:
test_should_show_ingreso(IngresosControllerTest):
ActionView::TemplateError: You have a nil object when you didn’t expect
it!
The error occurred while evaluating nil.nombre
On line #18 of app/views/ingresos/show.html.erb15:
16:
17: Origen
18: <%=h @ingreso.origen_type %>: <%= @ingreso.origen.nombre
%>
19:
20:
21:app/views/ingresos/show.html.erb:18
app/controllers/ingresos_controller.rb:86:inshow' /test/functional/ingresos_controller_test.rb:32:in
test_should_show_ingreso’
c:/ruby/lib/ruby/1.8/test/unit/testsuite.rb:34:inrun' c:/ruby/lib/ruby/1.8/test/unit/testsuite.rb:33:in
each’
c:/ruby/lib/ruby/1.8/test/unit/testsuite.rb:33:inrun' c:/ruby/lib/ruby/1.8/test/unit/testsuite.rb:34:in
run’
c:/ruby/lib/ruby/1.8/test/unit/testsuite.rb:33:ineach' c:/ruby/lib/ruby/1.8/test/unit/testsuite.rb:33:in
run’
c:/ruby/lib/ruby/1.8/test/unit/ui/testrunnermediator.rb:46:in
run_suite' c:/ruby/lib/ruby/1.8/test/unit/ui/console/testrunner.rb:67:in
start_mediator’
c:/ruby/lib/ruby/1.8/test/unit/ui/console/testrunner.rb:41:in
start' c:/ruby/lib/ruby/1.8/test/unit/ui/testrunnerutilities.rb:29:in
run’
c:/ruby/lib/ruby/1.8/test/unit/autorunner.rb:216:inrun' c:/ruby/lib/ruby/1.8/test/unit/autorunner.rb:12:in
run’
c:/ruby/lib/ruby/1.8/test/unit.rb:278
rake (0.8.7) lib/rake/rake_test_loader.rb:5
/***** clientes.yml *****/
jack:
NIF: B98654321
nombre: Jack
/***** ingresos.yml *****/
primero:
origen: jack (Cliente)
/***** cliente.rb *****/
class Cliente < ActiveRecord::Base
has_many :ingresos, :as => :origen
end
/***** ingreso.rb *****/
class Ingreso < ActiveRecord::Base
belongs_to :origen, :polymorphic => true
end
/***** test_ingresos_controller.rb *****/
test “should show ingreso” do
get :show, { :id => ingresos(:primero).to_param }, { :usuario_id =>
usuarios(:fulanito).id }
assert_response :success
end
/***** views/ingresos/show.html.erb
Origen <%=h @ingreso.origen_type %>: <%= @ingreso.origen.nombre %>
Any help will be appreciated. Thanks in advance.