多くの画像を持つモデル Person があり、画像には data と呼ばれる Paperclip 添付ファイル フィールドがあり、その省略形を以下に示します。
class Person
has_many :images
...
end
class Image
has_attached_file :data
belongs_to :person
...
end
Person には少なくとも 1 つの画像が添付されている必要があります。
FactoryGirl を使用する場合、次のようなコードがあります。
Factory.define :image do |a|
a.data { File.new(File.join(Rails.root, 'features', 'support', 'file.png')) }
a.association :person
end
Factory.define :person do |p|
p.first_name 'Keyzer'
p.last_name 'Soze'
p.after_create do |person|
person.assets = [Factory.build(:image, :person => person)]
end
# p.images {|images| [images.association(:image)]}
end
(注: 上記でコメントアウトされたコードも試しました) ほとんどの場合、cucumber 機能を実行すると、次のようなエラーが発生します。
そのようなファイルまたはディレクトリはありません - /tmp/stream,9887,0.png (Errno::ENOENT)
...
場合によっては、テストが正常に実行されることがあります。
私がここで抱えている問題や、FactoryGirl と Paperclip を一緒に使用して、私が達成しようとしているようなことを達成する方法を誰か教えてもらえますか?
Rails3を使用しています。