FactoryGirlでfixture_file_uploadが使えない
fixtures/images.rb
include ActionDispatch::TestProcess
FactoryGirl.define do
factory :image do
content {
fixture_file_upload("/test/sample.jpg","image/jpeg", true)
}
end
end
こんな感じで、fixtures/test/sample.jpgを置いてspecを走らせてみたところ、エラーとなった。
RuntimeError:
/test/sample.jpg file does not exist
FactoryGirlの中でfixture_file_uploadを使う場合は以下のようにパスの部分を変更しないといけない。
include ActionDispatch::TestProcess
FactoryGirl.define do
factory :image do
content {
fixture_file_upload("#{ActionController::TestCase.fixture_path}test/sample.jpg","image/jpeg", true)
}
end
end
参考 https://groups.google.com/forum/#!topic/rubyonrails-talk/pstCrf5vmW0