image_squeeze 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/image_squeeze.rb CHANGED
@@ -20,7 +20,7 @@ class ImageSqueeze
20
20
  attr_reader :processors
21
21
  attr_reader :tmpdir
22
22
 
23
- VERSION = '0.1.1'
23
+ VERSION = '0.1.2'
24
24
 
25
25
  # Image Types
26
26
  GIF = 'gif'
@@ -85,10 +85,10 @@ class ImageSqueeze
85
85
  filename = output_filename = result.filename
86
86
  if File.extname(result.filename) != result.output_extension
87
87
  output_filename = filename.sub(Regexp.new(Regexp.escape(File.extname(result.filename)) + '$'), result.output_extension)
88
- FileUtils.cp(result.output_filename, output_filename)
88
+ FileUtils.mv(result.output_filename, output_filename)
89
89
  FileUtils.rm(result.filename)
90
90
  else
91
- FileUtils.cp(result.output_filename, result.filename)
91
+ FileUtils.mv(result.output_filename, result.filename)
92
92
  end
93
93
  output_filename
94
94
  end
@@ -45,7 +45,7 @@ class SqueezeTest < Test::Unit::TestCase
45
45
  image_squeezer = custom_image_squeezer(AlwaysOptimize)
46
46
  filename = fixtures('already_optimized_gif.gif')
47
47
  old_size = File.size(filename)
48
- result = image_squeezer.squeeze!(filename)
48
+ image_squeezer.squeeze!(filename)
49
49
 
50
50
  assert File.size(filename) < old_size
51
51
  end
@@ -53,7 +53,7 @@ class SqueezeTest < Test::Unit::TestCase
53
53
  def test_squeezebang_removes_old_file_when_extension_is_changed
54
54
  image_squeezer = custom_image_squeezer(PNGOutput)
55
55
  filename = fixtures('already_optimized_gif.gif')
56
- result = image_squeezer.squeeze!(filename)
56
+ image_squeezer.squeeze!(filename)
57
57
 
58
58
  assert !File.exists?(filename), "Old file should be gone"
59
59
  assert File.exists?(filename.gsub(/\.gif/, '.png')), "New file should exist"
@@ -62,7 +62,7 @@ class SqueezeTest < Test::Unit::TestCase
62
62
  def test_squeezebang_handles_changing_extension_when_dot_extension_is_repeated
63
63
  image_squeezer = custom_image_squeezer(PNGOutput)
64
64
  filename = fixtures('gif.gif.gif.gif')
65
- result = image_squeezer.squeeze!(filename)
65
+ image_squeezer.squeeze!(filename)
66
66
 
67
67
  assert !File.exists?(filename), "Old file should be gone"
68
68
  assert File.exists?(filename.gsub(/\.gif$/, '.png')), "New file should exist"
@@ -72,7 +72,7 @@ class SqueezeTest < Test::Unit::TestCase
72
72
  image_squeezer = custom_image_squeezer(AlwaysBigger)
73
73
  filename = fixtures('already_optimized_gif.gif')
74
74
  old_size = File.size(filename)
75
- result = image_squeezer.squeeze!(filename)
75
+ image_squeezer.squeeze!(filename)
76
76
  assert_equal old_size, File.size(filename)
77
77
  end
78
78
 
@@ -87,6 +87,26 @@ class SqueezeTest < Test::Unit::TestCase
87
87
  FileUtils.rm(result.output_filename) if result && result.output_filename && File.exists?(result.output_filename)
88
88
  end
89
89
 
90
+ def test_finalize_result_should_remove_old_file_when_extension_doesnt_change
91
+ image_squeezer = custom_image_squeezer(AlwaysOptimize)
92
+ filename = fixtures('already_optimized_gif.gif')
93
+ result = image_squeezer.squeeze(filename)
94
+
95
+ assert File.exists?(result.output_filename)
96
+ image_squeezer.finalize_result(result)
97
+ assert !File.exists?(result.output_filename)
98
+ end
99
+
100
+ def test_finalize_result_should_remove_old_file_when_extension_changes
101
+ image_squeezer = custom_image_squeezer(PNGOutput)
102
+ filename = fixtures('already_optimized_gif.gif')
103
+ result = image_squeezer.squeeze(filename)
104
+
105
+ assert File.exists?(result.output_filename)
106
+ image_squeezer.finalize_result(result)
107
+ assert !File.exists?(result.output_filename)
108
+ end
109
+
90
110
  private
91
111
  class AlwaysOptimize < ImageSqueeze::Processor
92
112
  def self.squeeze(filename, output_filename)
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 1
9
- version: 0.1.1
8
+ - 2
9
+ version: 0.1.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Andrew Grim