-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Strange Behaviour on validate_attachment_content_type #1334
Comments
Ah, by the way, I'm using Rails 3.2.14 and Paperclip 3.5.1. If no one knows what is the origin of that bug, I'll fork and then create a pull request. |
@bamorim - definitely odd. I'm going to attempt to replicate. |
Ok. I could not replicate EXCEPT when I put the same MIME type into both the whitelist (:content_type) and blacklist (:not) options. The test: require 'spec_helper'
describe Friend do
include Paperclip::Shoulda::Matchers
it { should validate_presence_of :name }
it { should validate_attachment_content_type(:avatar).allowing(
"image/png", "image/jpg", "image/jpeg"
).rejecting(
"text/plain", "text/html", "text/xml", "application/octet-stream", "application/exe"
)
}
end The model: class Friend < ActiveRecord::Base
attr_accessible :name, :avatar
validates_presence_of :name
has_attached_file :avatar, styles: {
thumb: '100x100>',
square: '200x200#',
medium: '300x300>'
}
validates_attachment_content_type :avatar,
content_type: ["image/png", "image/jpg", "image/jpeg"],
not: ["text/html", "text/xml", "application/octet-stream", "application/exe"]
end If I just set the allowed The only way I could get your error was to do something like: validates_attachment_content_type :avatar,
content_type: ["image/png", "image/jpg", "image/jpeg"],
not: ["image/png", "text/html", "text/xml", "application/octet-stream", "application/exe"] Note the existence of "image/png" in both. Is it possible you had this going on in your code? |
No, actually i didn't have a "not" key in my code at all. I'll do it in my next free time and then I'll link the repository here. By the way, you've got the test fixed and running the way I did it? Because my "bugfix" was odd too HAHAHA |
I was attempting to replicate the error, I didn't use your monkeypatch. Let us know if you are able to narrow this down at all. |
@bamorim can you show us what the model looks like (at least the validates_attachment_content_type or validates declaration)? I might be able to help, just had the same issue, make sure that you are either passing an array of strings with appropriate mime types or a regular expression like: validates_attachment_content_type :image,
:content_type => /\Aimage\/.*\Z/ or validates_attachment_content_type :image,
:content_type => ['image/jpg', 'image/png', 'image/gif'] my specs pass like so: it { should validate_attachment_content_type(:image)
.allowing('image/jpg', 'image/png', 'image/gif')
.rejecting('text/plain', 'text/xml') } I think that the spec is trying to call |
Hi @bamorim ! Is this still an issue for you in Paperclip; I know this issue is from approximately 2 years ago. If it is still an issue, can you please provide the code that's causing you the error? Thanks! |
ping @bamorim. Is this still an issue with Paperclip? |
Closing due to lack of activity. |
I'd make a PR, but have no time, sorry. I think, it needs a test on how params are passed. By the way, my ruby version is ruby 2.1.3p242 (2014-09-19 revision 47630) [x86_64-darwin14.0], rails is 4.1.5 |
So, I was writing a test to validate the content_type of some attachments.
And the output from the test was:
Then trying to fix that I discovered that if rejected_types_rejected? must be, for some reason I don't know, called first
So when I placed that code:
The return from RSpec went as I expected:
I didn't created a Pull Request becouse that sounded really weird to me, so I decided just to open an issue.
Any clues on what might be going wrong? Anyone else can replicate the error there?
Thank you folks.
The text was updated successfully, but these errors were encountered: