Commit 84d2d087 by Prem Sichanugrist

Remove unused tests

parent fe706c69
......@@ -191,161 +191,11 @@ class PaperclipTest < Test::Unit::TestCase
end
end
context "a validation with an if guard clause" do
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?
end
should "not attempt validation if the guard returns false" do
@dummy.expects(:foo).returns(false)
assert @dummy.valid?
end
end
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
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?
end
should "not attempt validation if the guard returns false" do
@dummy.expects(:foo).returns(true)
assert @dummy.valid?
end
end
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
ActiveRecord::Base::Attachment
end
end
def self.should_validate validation, options, valid_file, invalid_file
context "with #{validation} validation and #{options.inspect} options" do
setup do
rebuild_class
Dummy.send(:"validates_attachment_#{validation}", :avatar, options)
@dummy = Dummy.new
end
context "and assigning nil" do
setup do
@dummy.avatar = nil
@dummy.valid?
end
if validation == :presence
should "have an error on the attachment" do
assert @dummy.errors[:avatar]
assert @dummy.errors[:avatar_file_name]
end
else
should "not have an error on the attachment" do
assert @dummy.errors.blank?, @dummy.errors.full_messages.join(", ")
end
end
end
context "and assigned a valid file" do
setup do
@dummy.avatar = valid_file
@dummy.valid?
end
should "not have an error" do
assert_equal 0, @dummy.errors.size, @dummy.errors.full_messages.join(", ")
end
end
context "and assigned an invalid file" do
setup do
@dummy.avatar = invalid_file
@dummy.valid?
end
should "have an error" do
assert @dummy.errors.size > 0
end
end
end
end
[[:presence, {}, "5k.png", nil],
[:size, {:in => 1..10240}, "5k.png", "12k.png"],
[:size, {:less_than => 10240}, "5k.png", "12k.png"],
[:size, {:greater_than => 8096}, "12k.png", "5k.png"],
[:content_type, {:content_type => "image/png"}, "5k.png", "text.txt"],
[:content_type, {:content_type => "text/plain"}, "text.txt", "5k.png"],
[:content_type, {:content_type => %r{image/.*}}, "5k.png", "text.txt"]].each do |args|
validation, options, valid_file, invalid_file = args
valid_file &&= File.open(File.join(FIXTURES_DIR, valid_file), "rb")
invalid_file &&= File.open(File.join(FIXTURES_DIR, invalid_file), "rb")
should_validate validation, options, valid_file, invalid_file
end
context "with size validation and less_than 10240 option" do
context "and assigned an invalid file" do
setup do
Dummy.send(:"validates_attachment_size", :avatar, :less_than => 10240)
@dummy = Dummy.new
@dummy.avatar &&= File.open(File.join(FIXTURES_DIR, "12k.png"), "rb")
@dummy.valid?
end
should "have a file size min/max error message" do
assert_includes @dummy.errors[:avatar_file_size], "must be less than 10240 Bytes"
end
end
end
end
context "configuring a custom processor" do
......
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