0

我在 Rails 3 应用程序中有以下类:

class AssetAttribute < ActiveRecord::Base
  ...
  def self.ANNOTATION
    self.find_by_table_name('annotations')
  end
  ...
end

在另一个类中,我在调用中引用了这个方法validates

validates :attribute_type_id, :attr_correct => {attr: AssetAttribute.ANNOTATION}

当我使用 Ruby 命令行运行测试时,一切正常:

ruby -Itest test/unit/annotation_test.rb

但是当我用 Rake 尝试时:

rake test:units

我突然明白NoMethodError: undefined method 'xxx' for nil:NilClass“xxx”是什么方法AssetAttribute

为什么这些测试的运行方式不同?我正在运行 Rails 3.2.13 和 Ruby 1.9.3

编辑:固定AssetAttribute声明

4

0 回答 0