モデル:
class Attachment < ActiveRecord::Base
belongs_to :narrative
attr_accessible :description, :user_id, :narrative_id
has_attached_file :file
validates_presence_of :user_id
validates_presence_of :narrative_id
validates_attachment :file, :presence => true,
:size => {:less_than => 20.megabytes}
end
動作しないテスト:
describe Attachment do
it { should validate_presence_of :file }
it { should validate_size_of :file } # validate_size_of does not exist
end
これをテストするためだけに、20 MB のファイルをリポジトリにダンプすることは避けたいと思います。上記で試したのと同様の方法で実際に機能する方法はありますか?