Testing Paperclip file uploading with RSpec
I don't really care about testing file uploads, but since I have 开发者_开发百科validates_attachment_presence
, etc.. in my model, rspec is complaining.
So now I'm creating my model with these attributes in the spec to try and shut it up:
@attr = {
:name => "value for name",
:title => "value for title",
:content => "value for content",
:pic_file_name => "example.jpg",
:pic_content_type => "image/jpg",
:pic_file_size => "8192",
:pic_updated_at => nil
}
This doesn't work, though.
I found this: http://fr.ivolo.us/posts/mocking-paperclip-with-rspec So I tried something like this:
Post.should_receive(:save_attached_files).and_return(true)
Which doesn't work either. How do I appease RSpec?
If the model has_attached_file :pic
, you should be able to just point the pic
attribute at some file and all should be dandy.
Meaning something like @attr = { :pic => File.open(File.join(Rails.root, 'spec', 'fixtures', 'file.png')) }
精彩评论