test/paperclip_test.rb in paperclip-cloudfiles-2.3.1.1.6 vs test/paperclip_test.rb in paperclip-cloudfiles-2.3.2

- old
+ new

@@ -14,12 +14,12 @@ end should "execute the right command" do Paperclip.expects(:path_for_command).with("convert").returns("/usr/bin/convert") Paperclip.expects(:bit_bucket).returns("/dev/null") - Paperclip.expects(:"`").with("/usr/bin/convert one.jpg two.jpg 2>/dev/null") - Paperclip.run("convert", "one.jpg two.jpg") + Paperclip.expects(:"`").with("/usr/bin/convert 'one.jpg' 'two.jpg' 2>/dev/null") + Paperclip.run("convert", "one.jpg", "two.jpg") end end end context "Calling Paperclip.run with no path specified" do @@ -33,47 +33,46 @@ end should "execute the right command" do Paperclip.expects(:path_for_command).with("convert").returns("convert") Paperclip.expects(:bit_bucket).returns("/dev/null") - Paperclip.expects(:"`").with("convert one.jpg two.jpg 2>/dev/null") - Paperclip.run("convert", "one.jpg two.jpg") + Paperclip.expects(:"`").with("convert 'one.jpg' 'two.jpg' 2>/dev/null") + Paperclip.run("convert", "one.jpg", "two.jpg") end end context "Calling Paperclip.run and logging" do - setup do + should "log the command when :log_command is true" do Paperclip.options[:image_magick_path] = nil Paperclip.options[:command_path] = nil Paperclip.stubs(:bit_bucket).returns("/dev/null") - Paperclip.stubs(:log) - Paperclip.stubs(:"`").with("this is the command 2>/dev/null") - end - - should "log the command when :log_command is true" do + Paperclip.expects(:log).with("this 'is the command' 2>/dev/null") + Paperclip.expects(:"`").with("this 'is the command' 2>/dev/null") Paperclip.options[:log_command] = true Paperclip.run("this","is the command") - assert_received(Paperclip, :log) do |p| - p.with("this is the command 2>/dev/null") - end - assert_received(Paperclip, :`) do |p| - p.with("this is the command 2>/dev/null") - end end should "not log the command when :log_command is false" do + Paperclip.options[:image_magick_path] = nil + Paperclip.options[:command_path] = nil + Paperclip.stubs(:bit_bucket).returns("/dev/null") + Paperclip.expects(:log).with("this 'is the command' 2>/dev/null").never + Paperclip.expects(:"`").with("this 'is the command' 2>/dev/null") Paperclip.options[:log_command] = false Paperclip.run("this","is the command") - assert_received(Paperclip, :log) do |p| - p.with("this is the command 2>/dev/null").never - end - assert_received(Paperclip, :`) do |p| - p.with("this is the command 2>/dev/null") - end end end + should "prevent dangerous characters in the command via quoting" do + Paperclip.options[:image_magick_path] = nil + Paperclip.options[:command_path] = nil + Paperclip.options[:log_command] = false + Paperclip.options[:swallow_stderr] = false + Paperclip.expects(:"`").with(%q[this 'is' 'jack'\''s' '`command`' 'line!']) + Paperclip.run("this", "is", "jack's", "`command`", "line!") + end + context "Paperclip.bit_bucket" do context "on systems without /dev/null" do setup do File.expects(:exists?).with("/dev/null").returns(false) end @@ -255,15 +254,15 @@ @dummy.avatar = nil @dummy.valid? end if validation == :presence should "have an error on the attachment" do - assert @dummy.errors.on(:avatar_file_name) + assert @dummy.errors[:avatar_file_name] end else should "not have an error on the attachment" do - assert_nil @dummy.errors.on(:avatar_file_name), @dummy.errors.full_messages.join(", ") + assert @dummy.errors[:avatar_file_name].blank?, @dummy.errors.full_messages.join(", ") end end end context "and assigned a valid file" do setup do @@ -308,10 +307,10 @@ @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_match %r/between 0 and 10240 bytes/, @dummy.errors.on(:avatar_file_size) + assert @dummy.errors[:avatar_file_size].any?{|e| e.match %r/between 0 and 10240 bytes/ } end end end end