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
宣言を修正