Commit 9bcb5c81 by Mike Burns

Move the check for path collision out

parent 24dc7b25
...@@ -177,7 +177,6 @@ module Paperclip ...@@ -177,7 +177,6 @@ module Paperclip
HasAttachedFile.define_on(self, name, options) HasAttachedFile.define_on(self, name, options)
options = Paperclip::AttachmentOptions.new(options) options = Paperclip::AttachmentOptions.new(options)
Paperclip.check_for_path_clash(name, options[:path], self.name)
Paperclip::Tasks::Attachments.add(self, name, options) Paperclip::Tasks::Attachments.add(self, name, options)
......
...@@ -15,6 +15,7 @@ module Paperclip ...@@ -15,6 +15,7 @@ module Paperclip
define_getter define_getter
define_setter define_setter
define_query define_query
check_for_path_clash
end end
private private
...@@ -62,5 +63,9 @@ module Paperclip ...@@ -62,5 +63,9 @@ module Paperclip
send(name).file? send(name).file?
end end
end end
def check_for_path_clash
Paperclip.check_for_path_clash(@name, @options[:path], @klass.name)
end
end end
end end
...@@ -18,6 +18,10 @@ class HasAttachedFileTest < Test::Unit::TestCase ...@@ -18,6 +18,10 @@ class HasAttachedFileTest < Test::Unit::TestCase
should 'flush errors as part of validations' do should 'flush errors as part of validations' do
assert_adding_attachment('avatar').defines_validation assert_adding_attachment('avatar').defines_validation
end end
should 'check for a path collision' do
assert_adding_attachment('avatar').checks_for_path_collision
end
end end
private private
...@@ -54,10 +58,24 @@ class HasAttachedFileTest < Test::Unit::TestCase ...@@ -54,10 +58,24 @@ class HasAttachedFileTest < Test::Unit::TestCase
end end
end end
def checks_for_path_collision
a_class = stub_class
Paperclip.stubs(:check_for_path_clash)
Paperclip::HasAttachedFile.define_on(a_class, @attachment_name, {})
assert_received(Paperclip, :check_for_path_clash) do |expect|
expect.with(@attachment_name, nil, a_class.name)
end
end
private private
def stub_class def stub_class
stub('class', validates_each: nil, define_method: nil) stub('class',
validates_each: nil,
define_method: nil,
name: 'Billy')
end end
end 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