Commit 00787da6 by Wojciech Wnętrzak

add default translation for spoofed media type error

parent 81669c11
...@@ -2,6 +2,7 @@ en: ...@@ -2,6 +2,7 @@ en:
errors: errors:
messages: messages:
in_between: "must be in between %{min} and %{max}" in_between: "must be in between %{min} and %{max}"
spoofed_media_type: "media type is spoofed"
number: number:
human: human:
......
...@@ -6,7 +6,27 @@ class MediaTypeSpoofDetectionValidatorTest < Test::Unit::TestCase ...@@ -6,7 +6,27 @@ class MediaTypeSpoofDetectionValidatorTest < Test::Unit::TestCase
@dummy = Dummy.new @dummy = Dummy.new
end end
def build_validator(options = {})
@validator = Paperclip::Validators::MediaTypeSpoofDetectionValidator.new(options.merge(
:attributes => :avatar
))
end
should "be on the attachment without being explicitly added" do should "be on the attachment without being explicitly added" do
assert Dummy.validators_on(:avatar).any?{ |validator| validator.kind == :media_type_spoof_detection } assert Dummy.validators_on(:avatar).any?{ |validator| validator.kind == :media_type_spoof_detection }
end end
should "return default error message for spoofed media type" do
build_validator
# Make avatar dirty
file = File.new(fixture_file("5k.png"), "rb")
@dummy.avatar.assign(file)
detector = mock("detector", :spoofed? => true)
Paperclip::MediaTypeSpoofDetector.stubs(:using).returns(detector)
@validator.validate(@dummy)
assert_equal "media type is spoofed", @dummy.errors[:avatar].first
end
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment