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

Commit

Permalink
has_attached_file will raise if the _file_size and _content_type fiel…
Browse files Browse the repository at this point in the history
…ds don't exist.
  • Loading branch information
Jon Yurek committed Jul 25, 2008
1 parent 9b3c51d commit 2ff75d1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/paperclip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ module ClassMethods
def has_attached_file name, options = {}
include InstanceMethods

%w(file_name content_type).each do |field|
unless column_names.include?("#{name}_#{field}")
raise PaperclipError.new("#{self} model does not have required column '#{name}_#{field}'")
end
end

write_inheritable_attribute(:attachment_definitions, {}) if attachment_definitions.nil?
attachment_definitions[name] = {:validations => []}.merge(options)

Expand Down
8 changes: 8 additions & 0 deletions test/paperclip_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ class PaperclipTest < Test::Unit::TestCase
@file = File.new(File.join(FIXTURES_DIR, "5k.png"))
end

should "error when trying to also create a 'blah' attachment" do
assert_raises(Paperclip::PaperclipError) do
Dummy.class_eval do
has_attached_file :blah
end
end
end

context "that is attr_protected" do
setup do
Dummy.class_eval do
Expand Down

0 comments on commit 2ff75d1

Please sign in to comment.