public
Description: Treat an ActiveRecord model as a file attachment, storing its patch, size, content type, etc.
Homepage: http://weblog.techno-weenie.net
Clone URL: git://github.com/technoweenie/attachment_fu.git
Click here to lend your support to: attachment_fu and make a donation at www.pledgie.com !
attachment_fu / test / geometry_test.rb
100644 101 lines (88 sloc) 2.524 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
require 'test/unit'
require File.expand_path(File.join(File.dirname(__FILE__), '../lib/geometry')) unless Object.const_defined?(:Geometry)
 
class GeometryTest < Test::Unit::TestCase
  def test_should_resize
    assert_geometry 50, 64,
      "50x50" => [39, 50],
      "60x60" => [47, 60],
      "100x100" => [78, 100]
  end
  
  def test_should_resize_no_width
    assert_geometry 50, 64,
      "x50" => [39, 50],
      "x60" => [47, 60],
      "x100" => [78, 100]
  end
  
  def test_should_resize_no_height
    assert_geometry 50, 64,
      "50" => [50, 64],
      "60" => [60, 77],
      "100" => [100, 128]
  end
  
  def test_should_resize_with_percent
    assert_geometry 50, 64,
      "50x50%" => [25, 32],
      "60x60%" => [30, 38],
      "120x112%" => [60, 72]
  end
  
  def test_should_resize_with_percent_and_no_width
    assert_geometry 50, 64,
      "x50%" => [50, 32],
      "x60%" => [50, 38],
      "x112%" => [50, 72]
  end
  
  def test_should_resize_with_percent_and_no_height
    assert_geometry 50, 64,
      "50%" => [25, 32],
      "60%" => [30, 38],
      "120%" => [60, 77]
  end
  
  def test_should_resize_with_less
    assert_geometry 50, 64,
      "50x50<" => [50, 64],
      "60x60<" => [50, 64],
      "100x100<" => [78, 100],
      "100x112<" => [88, 112],
      "40x70<" => [50, 64]
  end
  
  def test_should_resize_with_less_and_no_width
    assert_geometry 50, 64,
      "x50<" => [50, 64],
      "x60<" => [50, 64],
      "x100<" => [78, 100]
  end
  
  def test_should_resize_with_less_and_no_height
    assert_geometry 50, 64,
      "50<" => [50, 64],
      "60<" => [60, 77],
      "100<" => [100, 128]
  end
 
  def test_should_resize_with_greater
    assert_geometry 50, 64,
      "50x50>" => [39, 50],
      "60x60>" => [47, 60],
      "100x100>" => [50, 64],
      "100x112>" => [50, 64],
      "40x70>" => [40, 51]
  end
  
  def test_should_resize_with_greater_and_no_width
    assert_geometry 50, 64,
      "x40>" => [31, 40],
      "x60>" => [47, 60],
      "x100>" => [50, 64]
  end
  
  def test_should_resize_with_greater_and_no_height
    assert_geometry 50, 64,
      "40>" => [40, 51],
      "60>" => [50, 64],
      "100>" => [50, 64]
  end
 
  protected
    def assert_geometry(width, height, values)
      values.each do |geo, result|
        # run twice to verify the Geometry string isn't modified after a run
        geo = Geometry.from_s(geo)
        2.times { assert_equal result, [width, height] / geo }
      end
    end
end