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