Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
add default translation for spoofed media type error
Browse files Browse the repository at this point in the history
  • Loading branch information
morgoth committed Feb 11, 2014
1 parent 81669c1 commit 00787da
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/paperclip/locales/en.yml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 20 additions & 0 deletions test/validators/media_type_spoof_detection_validator_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,7 +6,27 @@ def setup
@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

0 comments on commit 00787da

Please sign in to comment.