Using: RSpec, Shoulda, Paperclip (including matchers)
Example Model
class Example < ActiveRecord::Base
has_attached_file :attachment
validates_attachment_presence :attachment
validates_format_of :attachment_file_name, :with => /.(png|jpe?g)$/
end
Example Test
require ‘spec/helper’
describe Example do
it { should validate_attachment_presence(:attachment) }
it { should validate_format_of(:attachment_file_name).
with(‘example.png’) }
it { should validate_format_of(:attachment_file_name).
not_with(‘example.zip’).
with_message(/is invalid/) }
end
This causes my validates_attachment_presence(:attachment) test to fail.
If I remove the validates_format_of :attachment_file_name line from my
model, the presence test now passes, but, obviously, the format test
fails.
I noticed that basically all validates_attachment_presence does is
require attachment_file_name, but I can’t seem to find any reason why it
affects my format tests.
I am not sure if this is necessarily Paperclip issue (as apposed to
perhaps a Shoulda one), but hopefully this is a good enough report to
explain the issue.