test/paperclip_test.rb in paperclip-2.4.5 vs test/paperclip_test.rb in paperclip-2.5.0
- old
+ new
@@ -84,10 +84,20 @@
end
Dummy2.class_eval do
has_attached_file :blah
end
end
+
+ should "not generate warning if attachment is redifined with the same url string but has :class in it" do
+ Paperclip.expects(:log).never
+ Dummy.class_eval do
+ has_attached_file :blah, :url => "/system/:class/:attachment/:id/:style/:filename"
+ end
+ Dummy2.class_eval do
+ has_attached_file :blah, :url => "/system/:class/:attachment/:id/:style/:filename"
+ end
+ end
end
context "An ActiveRecord model with an 'avatar' attachment" do
setup do
rebuild_model :path => "tmp/:class/omg/:style.:extension"
@@ -168,41 +178,81 @@
assert @dummy.valid?
end
end
context "a validation with an if guard clause" do
- setup do
- Dummy.send(:"validates_attachment_presence", :avatar, :if => lambda{|i| i.foo })
- @dummy = Dummy.new
- @dummy.stubs(:avatar_file_name).returns(nil)
- end
+ context "as a lambda" do
+ setup do
+ Dummy.send(:"validates_attachment_presence", :avatar, :if => lambda{|i| i.foo })
+ @dummy = Dummy.new
+ @dummy.stubs(:avatar_file_name).returns(nil)
+ end
- should "attempt validation if the guard returns true" do
- @dummy.expects(:foo).returns(true)
- assert ! @dummy.valid?
+ should "attempt validation if the guard returns true" do
+ @dummy.expects(:foo).returns(true)
+ assert ! @dummy.valid?
+ end
+
+ should "not attempt validation if the guard returns false" do
+ @dummy.expects(:foo).returns(false)
+ assert @dummy.valid?
+ end
end
- should "not attempt validation if the guard returns false" do
- @dummy.expects(:foo).returns(false)
- assert @dummy.valid?
+ context "as a method name" do
+ setup do
+ Dummy.send(:"validates_attachment_presence", :avatar, :if => :foo)
+ @dummy = Dummy.new
+ @dummy.stubs(:avatar_file_name).returns(nil)
+ end
+
+ should "attempt validation if the guard returns true" do
+ @dummy.expects(:foo).returns(true)
+ assert ! @dummy.valid?
+ end
+
+ should "not attempt validation if the guard returns false" do
+ @dummy.expects(:foo).returns(false)
+ assert @dummy.valid?
+ end
end
end
context "a validation with an unless guard clause" do
- setup do
- Dummy.send(:"validates_attachment_presence", :avatar, :unless => lambda{|i| i.foo })
- @dummy = Dummy.new
- @dummy.stubs(:avatar_file_name).returns(nil)
- end
+ context "as a lambda" do
+ setup do
+ Dummy.send(:"validates_attachment_presence", :avatar, :unless => lambda{|i| i.foo })
+ @dummy = Dummy.new
+ @dummy.stubs(:avatar_file_name).returns(nil)
+ end
- should "attempt validation if the guard returns true" do
- @dummy.expects(:foo).returns(false)
- assert ! @dummy.valid?
+ should "attempt validation if the guard returns true" do
+ @dummy.expects(:foo).returns(false)
+ assert ! @dummy.valid?
+ end
+
+ should "not attempt validation if the guard returns false" do
+ @dummy.expects(:foo).returns(true)
+ assert @dummy.valid?
+ end
end
- should "not attempt validation if the guard returns false" do
- @dummy.expects(:foo).returns(true)
- assert @dummy.valid?
+ context "as a method name" do
+ setup do
+ Dummy.send(:"validates_attachment_presence", :avatar, :unless => :foo)
+ @dummy = Dummy.new
+ @dummy.stubs(:avatar_file_name).returns(nil)
+ end
+
+ should "attempt validation if the guard returns true" do
+ @dummy.expects(:foo).returns(false)
+ assert ! @dummy.valid?
+ end
+
+ should "not attempt validation if the guard returns false" do
+ @dummy.expects(:foo).returns(true)
+ assert @dummy.valid?
+ end
end
end
should "not have Attachment in the ActiveRecord::Base namespace" do
assert_raises(NameError) do