Navigation Menu

Skip to content

Commit

Permalink
Log commands with Paperclip.options[:log_command] = true
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Yurek committed May 10, 2009
1 parent af1ae00 commit 634864d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/paperclip.rb
Expand Up @@ -62,6 +62,7 @@ def options
:image_magick_path => nil,
:command_path => nil,
:log => true,
:log_command => false,
:swallow_stderr => true
}
end
Expand Down Expand Up @@ -90,6 +91,7 @@ def interpolates key, &block
def run cmd, params = "", expected_outcodes = 0
command = %Q<#{%Q[#{path_for_command(cmd)} #{params}].gsub(/\s+/, " ")}>
command = "#{command} 2>#{bit_bucket}" if Paperclip.options[:swallow_stderr]
Paperclip.log(command) if Paperclip.options[:log_command]
output = `#{command}`
unless [expected_outcodes].flatten.include?($?.exitstatus)
raise PaperclipCommandLineError, "Error while running #{cmd}"
Expand Down
8 changes: 8 additions & 0 deletions test/paperclip_test.rb
Expand Up @@ -30,6 +30,14 @@ class PaperclipTest < Test::Unit::TestCase
Paperclip.expects(:"`").with("convert one.jpg two.jpg 2>/dev/null")
Paperclip.run("convert", "one.jpg two.jpg")
end

should "log the command when :log_command is set" do
Paperclip.options[:log_command] = true
Paperclip.expects(:bit_bucket).returns("/dev/null")
Paperclip.expects(:log).with("this is the command 2>/dev/null")
Paperclip.expects(:"`").with("this is the command 2>/dev/null")
Paperclip.run("this","is the command")
end
end

should "raise when sent #processor and the name of a class that exists but isn't a subclass of Processor" do
Expand Down

0 comments on commit 634864d

Please sign in to comment.