Created
August 13, 2015 00:56
-
-
Save danielfone/71756cd18306bc14b694 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env ruby | |
require 'active_record' # 4.2.3 | |
require 'paperclip' # 4.3.0 | |
ActiveRecord::Migration.verbose = false | |
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:") | |
ActiveRecord::Base.raise_in_transactional_callbacks = true | |
ActiveRecord::Schema.define(:version => 1) do | |
create_table :widgets, force: true do |t| | |
t.string "image_file_name" | |
t.string "image_content_type" | |
t.integer "image_file_size" | |
t.datetime "image_updated_at" | |
end | |
end | |
class Widget < ActiveRecord::Base | |
include Paperclip::Glue | |
has_attached_file :image | |
validates_attachment_content_type :image, :content_type => %r{image/.*} | |
after_image_post_process :save_image_dimensions | |
def save_image_dimensions | |
puts "We should not get here if the image is invalid!" | |
end | |
end | |
Widget.create! image: File.open('dummy_file.txt') | |
=begin | |
I, [2015-08-13T12:51:38.158976 #85028] INFO -- : Command :: file -b --mime 'dummy_file.txt' | |
I, [2015-08-13T12:51:38.171773 #85028] INFO -- : Command :: file -b --mime '/var/folders/9j/wmdwzgzs40n32kvsrtv183_m0000gn/T/73592beb6ee90d5f310a72375b18924120150813-85028-rvjtzo.txt' | |
We should not get here if the image is invalid! | |
I, [2015-08-13T12:51:38.201334 #85028] INFO -- : Command :: file -b --mime '/var/folders/9j/wmdwzgzs40n32kvsrtv183_m0000gn/T/73592beb6ee90d5f310a72375b18924120150813-85028-1vbfe7v.txt' | |
`raise_record_invalid': Validation failed: Image content type is invalid, Image is invalid (ActiveRecord::RecordInvalid) | |
... | |
from ./post_processing.rb:32:in `<main>' | |
=end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment