-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
"should validate_attachment_content_type" not working (rspec) #1158
Comments
Upon further tests and reading code from another repo https://github.com/ffbit/simple-forum/blob/master/spec/models/user_spec.rb I tested what they had: it { should validate_attachment_content_type(:image).
allowing('image/png').
allowing('image/gif').
allowing('image/jpeg').
rejecting('text/plain', 'text/xml')
} And now it seems to work, but this is different from the doc http://rubydoc.info/gems/paperclip/Paperclip/Shoulda/Matchers |
@sikachu pointed out that the chained allowing() method calls aren't going to work properly because we don't merge them together. Beyond that, can you fork the paperclip_demo repo and replicate your problem there? It'd be helpful to see this failure in a working application. |
Sure, will do. Let's see what happens |
Ok so I did what @djcp told me and I could not replicate the error. I was confused on why... so I went back to my code and it was working fine even when I rolled back to my earlier version. Tried whipping the gems to discard the new gems in the paperclip demo making my code work. Nope that wasn't it. Long story short, I realize my error and what could help someone avoid this. My model validation was missing the 'image/gif' I was asking for in my spec validates_attachment :image,
:content_type => { :content_type => ["image/jpeg", "image/png"] },
:size => { :in => 0..2.megabytes } in my spec it { should validate_attachment_content_type(:image).
allowing('image/png', 'image/gif', 'image/jpeg').
rejecting('text/plain', 'text/xml') } The thing is, the error the rspec throws is so not helpful, maybe to a more experienced ruby programmer it was. Is there anything you guys could do about it?
Thanks anyway, I feel a bit blind now, but I'm glad I now understand what happened |
Glad you sorted it out, and thanks for reporting back. |
thanks man @ResidentBio helped to deduce my error. |
yeah, I ran into this same error. I fixed it, but it appears this happens whenever anything in the "allowing" method is spelled wrong. In my case, I accidentally spelled it "jpg" rather than "jpeg", and all I got was the "any?" error, which is really not helpful. If you misspell it in the model, you get a "content type is illegal", which is helpful. Anyway, thanks @ResidentBio for showing this, it led me down the right path. |
I ran into the same issue today and cannot figure out how to fix it.
In my spec file:
throws: undefined method `validate_attachment_content_type' for #RSpec::ExampleGroups::EventInformation:0x007fd75b1eeee0 |
I'm doing the basic unit tests for the attachment I have for my model, but I keep getting this error
"Failure/Error: rejecting('text/plain', 'text/xml') }
NoMethodError:
undefined method `any?' for nil:NilClass "
"
Here is my model
Here is the spec
I'm not missing "subject", actually this is the only test failing.
The text was updated successfully, but these errors were encountered: