Aashish Kiran
2012-Jan-19 09:03 UTC
Problem in testing with separate validation of :attachment_file_name
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.
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
