“undefined方法'name'表示false:FalseClass”

时间:2012-08-20 20:59:39

标签: ruby-on-rails factory-bot

我的对象“Line”的所有功能测试都失败了。我甚至不知道从哪里开始调试:

  

21)错误:test_should_update_line(LinesControllerTest):   NoMethodError:未定义的方法name' for false:FalseClass c:/Ruby193/lib/ruby/gems/1.9.1/gems/factory_girl-4.0.0/lib/factory_girl/decl aration/static.rb:11:in =='       C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/att   ribute_methods / write.rb:57:in convert_number_column_value' c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/att ribute_methods/write.rb:50:in type_cast_attribute_for_write'       C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/att   ribute_methods / serialization.rb:88:在type_cast_attribute_for_write' c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/att ribute_methods/write.rb:38:in write_attribute'中       C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/att   ribute_methods / dirty.rb:67:在write_attribute' c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/att ribute_methods/write.rb:14:in port ='       C:/Ruby193/lib/ruby/gems/1.9.1/gems/factory_girl-4.0.0/lib/factory_girl/attr   ibute_assigner.rb:16:block (2 levels) in object' c:/Ruby193/lib/ruby/gems/1.9.1/gems/factory_girl-4.0.0/lib/factory_girl/attr ibute_assigner.rb:15:in每个'       C:/Ruby193/lib/ruby/gems/1.9.1/gems/factory_girl-4.0.0/lib/factory_girl/attr   ibute_assigner.rb:15:block in object' c:/Ruby193/lib/ruby/gems/1.9.1/gems/factory_girl-4.0.0/lib/factory_girl/attr ibute_assigner.rb:14:in点按'       C:/Ruby193/lib/ruby/gems/1.9.1/gems/factory_girl-4.0.0/lib/factory_girl/attr   ibute_assigner.rb:14:在object' c:in对象中       C:/Ruby193/lib/ruby/gems/1.9.1/gems/factory_girl-4.0.0/lib/factory_girl/stra   tegy / create.rb:9:in result' c:/Ruby193/lib/ruby/gems/1.9.1/gems/factory_girl-4.0.0/lib/factory_girl/fact ory.rb:42:in run'       C:/Ruby193/lib/ruby/gems/1.9.1/gems/factory_girl-4.0.0/lib/factory_girl/fact   ory_runner.rb:23:in block in run' c:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/n otifications.rb:125:in instrument'       C:/Ruby193/lib/ruby/gems/1.9.1/gems/factory_girl-4.0.0/lib/factory_girl/fact   ory_runner.rb:22:在run' c:/Ruby193/lib/ruby/gems/1.9.1/gems/factory_girl-4.0.0/lib/factory_girl/stra tegy_syntax_method_registrar.rb:19:in块中   define_singular_strategy_method'

c:/code/vsdb/test/functional/lines_controller_test.rb:5:in `block in <class: LinesControllerTest>'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/c
     

allbacks.rb:462:在_run__987382823__setup__855471168__callbacks' c:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/c allbacks.rb:405:in __ run_callback'中       C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/c   allbacks.rb:385:在_run_setup_callbacks' c:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/c allbacks.rb:81:in run_callbacks'中       C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/t   esting / setup_and_teardown.rb:34:在'run'

lines_controller_test.rb:

  

class LinesControllerTest&lt; ActionController的TestCase的::
      设置做         @line = FactoryGirl.create(:line)
      端

test "should update line" do
  put :update, id: @line, line: { description: @line.description }
  assert_redirected_to line_path(assigns(:line))   
end
     

test_helper.rb中:

  

ENV [“RAILS_ENV”] =“测试”要求   File.expand_path('../../ config / environment', FILE )需要   'rails / test_help'需要'capybara / rails'

     

类ActiveSupport :: TestCase#设置所有灯具   test / fixtures / *。(yml | csv)按字母顺序进行所有测试。 ##   注意:您目前仍需要明确声明灯具   集成测试# - 他们尚未继承此设置

     

def设置       #all的所有者       @admin = FactoryGirl.create(:owner,iso:true,admin:true)       @iso = FactoryGirl.create(:owner,iso:true)       @isa = FactoryGirl.create(:所有者)         #be admin默认情况下         @ controller.stubs(:current_owner).returns(@admin)

#fixtures for compliance rates verification
@art = FactoryGirl.create(:unit, name: "art", unit_code: "1110000", parent_unit_id: 1100000)   end
     

#添加更多辅助方法,供所有测试使用...结束

     

类ActionDispatch :: IntegrationTest包括Capybara :: DSL

     

def teardown Capybara.reset_sessions! Capybara.use_default_driver     结束

1 个答案:

答案 0 :(得分:0)

您似乎正在通过@line更新您应该传递@line.id的位置。尝试将其更改为:

put :update, id: @line.id, line: { description: @line.description }