【问题标题】:"undefined method 'name' for false:FalseClass"“未定义的方法‘名称’为 false:FalseClass”
【发布时间】:2012-08-16 05:18:05
【问题描述】:

我的对象“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:intype_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: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/write.rb:38:inwrite_attribute' c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/att ribute_methods/dirty.rb:67:in write_attribute' c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/att ribute_methods/write.rb:14:inport=' c:/Ruby193/lib/ruby/gems/1.9.1/gems/factory_girl-4.0.0/lib/factory_girl/attr ibute_assigner.rb:16:in 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:ineach' c:/Ruby193/lib/ruby/gems/1.9.1/gems/factory_girl-4.0.0/lib/factory_girl/attr ibute_assigner.rb:15:in 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:intap' c:/Ruby193/lib/ruby/gems/1.9.1/gems/factory_girl-4.0.0/lib/factory_girl/attr ibute_assigner.rb:14:in object' c:inobject' 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:inrun' 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:ininstrument' c:/Ruby193/lib/ruby/gems/1.9.1/gems/factory_girl-4.0.0/lib/factory_girl/fact ory_runner.rb:22:in 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:inblock 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:in _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:in _run_setup_callbacks' c:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/c allbacks.rb:81:inrun_callbacks' c:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/t esting/setup_and_teardown.rb:34:in `run'

lines_controller_test.rb:

类 LinesControllerTest 设置做 @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”

class ActiveSupport::TestCase # 设置所有灯具 test/fixtures/*.(yml|csv) 用于按字母顺序排列的所有测试。 ## 注意:您目前仍然需要在 集成测试 # -- 他们还没有继承这个设置

默认设置 #各种业主 @admin = FactoryGirl.create(:owner, iso:true, admin:true) @iso = FactoryGirl.create(:owner, iso:true) @isa = FactoryGirl.create(:owner) #默认是管理员 @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

# 在此处添加更多供所有测试使用的辅助方法... end

类 ActionDispatch::IntegrationTest 包括 Capybara::DSL

def 拆解 Capybara.reset_sessions! Capybara.use_default_driver 结束结束

【问题讨论】:

  • 您的生产线工厂可能有问题
  • 你能把line的工厂代码贴出来吗?

标签: ruby-on-rails factory-bot


【解决方案1】:

看起来您正在传递 @line 以更新您应该传递 @line.id 的位置。尝试将其更改为:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-18
    • 1970-01-01
    • 2016-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多