diff options
Diffstat (limited to 'vendor/plugins/paperclip/test/geometry_test.rb')
| -rw-r--r-- | vendor/plugins/paperclip/test/geometry_test.rb | 168 |
1 files changed, 0 insertions, 168 deletions
diff --git a/vendor/plugins/paperclip/test/geometry_test.rb b/vendor/plugins/paperclip/test/geometry_test.rb deleted file mode 100644 index 134372d..0000000 --- a/vendor/plugins/paperclip/test/geometry_test.rb +++ /dev/null | |||
| @@ -1,168 +0,0 @@ | |||
| 1 | require 'test/helper' | ||
| 2 | |||
| 3 | class GeometryTest < Test::Unit::TestCase | ||
| 4 | context "Paperclip::Geometry" do | ||
| 5 | should "correctly report its given dimensions" do | ||
| 6 | assert @geo = Paperclip::Geometry.new(1024, 768) | ||
| 7 | assert_equal 1024, @geo.width | ||
| 8 | assert_equal 768, @geo.height | ||
| 9 | end | ||
| 10 | |||
| 11 | should "set height to 0 if height dimension is missing" do | ||
| 12 | assert @geo = Paperclip::Geometry.new(1024) | ||
| 13 | assert_equal 1024, @geo.width | ||
| 14 | assert_equal 0, @geo.height | ||
| 15 | end | ||
| 16 | |||
| 17 | should "set width to 0 if width dimension is missing" do | ||
| 18 | assert @geo = Paperclip::Geometry.new(nil, 768) | ||
| 19 | assert_equal 0, @geo.width | ||
| 20 | assert_equal 768, @geo.height | ||
| 21 | end | ||
| 22 | |||
| 23 | should "be generated from a WxH-formatted string" do | ||
| 24 | assert @geo = Paperclip::Geometry.parse("800x600") | ||
| 25 | assert_equal 800, @geo.width | ||
| 26 | assert_equal 600, @geo.height | ||
| 27 | end | ||
| 28 | |||
| 29 | should "be generated from a xH-formatted string" do | ||
| 30 | assert @geo = Paperclip::Geometry.parse("x600") | ||
| 31 | assert_equal 0, @geo.width | ||
| 32 | assert_equal 600, @geo.height | ||
| 33 | end | ||
| 34 | |||
| 35 | should "be generated from a Wx-formatted string" do | ||
| 36 | assert @geo = Paperclip::Geometry.parse("800x") | ||
| 37 | assert_equal 800, @geo.width | ||
| 38 | assert_equal 0, @geo.height | ||
| 39 | end | ||
| 40 | |||
| 41 | should "be generated from a W-formatted string" do | ||
| 42 | assert @geo = Paperclip::Geometry.parse("800") | ||
| 43 | assert_equal 800, @geo.width | ||
| 44 | assert_equal 0, @geo.height | ||
| 45 | end | ||
| 46 | |||
| 47 | should "ensure the modifier is nil if not present" do | ||
| 48 | assert @geo = Paperclip::Geometry.parse("123x456") | ||
| 49 | assert_nil @geo.modifier | ||
| 50 | end | ||
| 51 | |||
| 52 | ['>', '<', '#', '@', '%', '^', '!', nil].each do |mod| | ||
| 53 | should "ensure the modifier #{mod.inspect} is preserved" do | ||
| 54 | assert @geo = Paperclip::Geometry.parse("123x456#{mod}") | ||
| 55 | assert_equal mod, @geo.modifier | ||
| 56 | assert_equal "123x456#{mod}", @geo.to_s | ||
| 57 | end | ||
| 58 | end | ||
| 59 | |||
| 60 | ['>', '<', '#', '@', '%', '^', '!', nil].each do |mod| | ||
| 61 | should "ensure the modifier #{mod.inspect} is preserved with no height" do | ||
| 62 | assert @geo = Paperclip::Geometry.parse("123x#{mod}") | ||
| 63 | assert_equal mod, @geo.modifier | ||
| 64 | assert_equal "123#{mod}", @geo.to_s | ||
| 65 | end | ||
| 66 | end | ||
| 67 | |||
| 68 | should "make sure the modifier gets passed during transformation_to" do | ||
| 69 | assert @src = Paperclip::Geometry.parse("123x456") | ||
| 70 | assert @dst = Paperclip::Geometry.parse("123x456>") | ||
| 71 | assert_equal "123x456>", @src.transformation_to(@dst).to_s | ||
| 72 | end | ||
| 73 | |||
| 74 | should "generate correct ImageMagick formatting string for W-formatted string" do | ||
| 75 | assert @geo = Paperclip::Geometry.parse("800") | ||
| 76 | assert_equal "800", @geo.to_s | ||
| 77 | end | ||
| 78 | |||
| 79 | should "generate correct ImageMagick formatting string for Wx-formatted string" do | ||
| 80 | assert @geo = Paperclip::Geometry.parse("800x") | ||
| 81 | assert_equal "800", @geo.to_s | ||
| 82 | end | ||
| 83 | |||
| 84 | should "generate correct ImageMagick formatting string for xH-formatted string" do | ||
| 85 | assert @geo = Paperclip::Geometry.parse("x600") | ||
| 86 | assert_equal "x600", @geo.to_s | ||
| 87 | end | ||
| 88 | |||
| 89 | should "generate correct ImageMagick formatting string for WxH-formatted string" do | ||
| 90 | assert @geo = Paperclip::Geometry.parse("800x600") | ||
| 91 | assert_equal "800x600", @geo.to_s | ||
| 92 | end | ||
| 93 | |||
| 94 | should "be generated from a file" do | ||
| 95 | file = File.join(File.dirname(__FILE__), "fixtures", "5k.png") | ||
| 96 | file = File.new(file, 'rb') | ||
| 97 | assert_nothing_raised{ @geo = Paperclip::Geometry.from_file(file) } | ||
| 98 | assert @geo.height > 0 | ||
| 99 | assert @geo.width > 0 | ||
| 100 | end | ||
| 101 | |||
| 102 | should "be generated from a file path" do | ||
| 103 | file = File.join(File.dirname(__FILE__), "fixtures", "5k.png") | ||
| 104 | assert_nothing_raised{ @geo = Paperclip::Geometry.from_file(file) } | ||
| 105 | assert @geo.height > 0 | ||
| 106 | assert @geo.width > 0 | ||
| 107 | end | ||
| 108 | |||
| 109 | should "not generate from a bad file" do | ||
| 110 | file = "/home/This File Does Not Exist.omg" | ||
| 111 | assert_raise(Paperclip::NotIdentifiedByImageMagickError){ @geo = Paperclip::Geometry.from_file(file) } | ||
| 112 | end | ||
| 113 | |||
| 114 | [['vertical', 900, 1440, true, false, false, 1440, 900, 0.625], | ||
| 115 | ['horizontal', 1024, 768, false, true, false, 1024, 768, 1.3333], | ||
| 116 | ['square', 100, 100, false, false, true, 100, 100, 1]].each do |args| | ||
| 117 | context "performing calculations on a #{args[0]} viewport" do | ||
| 118 | setup do | ||
| 119 | @geo = Paperclip::Geometry.new(args[1], args[2]) | ||
| 120 | end | ||
| 121 | |||
| 122 | should "#{args[3] ? "" : "not"} be vertical" do | ||
| 123 | assert_equal args[3], @geo.vertical? | ||
| 124 | end | ||
| 125 | |||
| 126 | should "#{args[4] ? "" : "not"} be horizontal" do | ||
| 127 | assert_equal args[4], @geo.horizontal? | ||
| 128 | end | ||
| 129 | |||
| 130 | should "#{args[5] ? "" : "not"} be square" do | ||
| 131 | assert_equal args[5], @geo.square? | ||
| 132 | end | ||
| 133 | |||
| 134 | should "report that #{args[6]} is the larger dimension" do | ||
| 135 | assert_equal args[6], @geo.larger | ||
| 136 | end | ||
| 137 | |||
| 138 | should "report that #{args[7]} is the smaller dimension" do | ||
| 139 | assert_equal args[7], @geo.smaller | ||
| 140 | end | ||
| 141 | |||
| 142 | should "have an aspect ratio of #{args[8]}" do | ||
| 143 | assert_in_delta args[8], @geo.aspect, 0.0001 | ||
| 144 | end | ||
| 145 | end | ||
| 146 | end | ||
| 147 | |||
| 148 | [[ [1000, 100], [64, 64], "x64", "64x64+288+0" ], | ||
| 149 | [ [100, 1000], [50, 950], "x950", "50x950+22+0" ], | ||
| 150 | [ [100, 1000], [50, 25], "50x", "50x25+0+237" ]]. each do |args| | ||
| 151 | context "of #{args[0].inspect} and given a Geometry #{args[1].inspect} and sent transform_to" do | ||
| 152 | setup do | ||
| 153 | @geo = Paperclip::Geometry.new(*args[0]) | ||
| 154 | @dst = Paperclip::Geometry.new(*args[1]) | ||
| 155 | @scale, @crop = @geo.transformation_to @dst, true | ||
| 156 | end | ||
| 157 | |||
| 158 | should "be able to return the correct scaling transformation geometry #{args[2]}" do | ||
| 159 | assert_equal args[2], @scale | ||
| 160 | end | ||
| 161 | |||
| 162 | should "be able to return the correct crop transformation geometry #{args[3]}" do | ||
| 163 | assert_equal args[3], @crop | ||
| 164 | end | ||
| 165 | end | ||
| 166 | end | ||
| 167 | end | ||
| 168 | end | ||
