bulldog 0.0.11 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/bulldog.gemspec +2 -2
- data/lib/bulldog/attachment/base.rb +14 -0
- data/lib/bulldog/attachment/image.rb +2 -3
- data/lib/bulldog/attachment/maybe.rb +3 -5
- data/lib/bulldog/attachment/pdf.rb +1 -2
- data/lib/bulldog/attachment/video.rb +2 -3
- data/spec/unit/attachment/image_spec.rb +132 -119
- data/spec/unit/attachment/pdf_spec.rb +102 -89
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.12
|
data/bulldog.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{bulldog}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.12"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["George Ogata"]
|
12
|
-
s.date = %q{2009-12-
|
12
|
+
s.date = %q{2009-12-11}
|
13
13
|
s.description = %q{= Bulldog
|
14
14
|
|
15
15
|
Flexible file attachments for active record.
|
@@ -145,6 +145,20 @@ module Bulldog
|
|
145
145
|
true
|
146
146
|
end
|
147
147
|
|
148
|
+
#
|
149
|
+
# Return the value of the given attribute from an instance
|
150
|
+
# variable set during file examination.
|
151
|
+
#
|
152
|
+
# If not set, runs a file examination first.
|
153
|
+
#
|
154
|
+
def from_examination(name)
|
155
|
+
ivar = :"@#{name}"
|
156
|
+
value = instance_variable_get(ivar) and
|
157
|
+
return value
|
158
|
+
examine
|
159
|
+
instance_variable_get(ivar)
|
160
|
+
end
|
161
|
+
|
148
162
|
private # -------------------------------------------------------
|
149
163
|
|
150
164
|
#
|
@@ -16,8 +16,7 @@ module Bulldog
|
|
16
16
|
#
|
17
17
|
def dimensions(style_name)
|
18
18
|
if style_name.equal?(:original)
|
19
|
-
|
20
|
-
@original_dimensions
|
19
|
+
from_examination :original_dimensions
|
21
20
|
else
|
22
21
|
style = reflection.styles[style_name]
|
23
22
|
target_dimensions = style[:size].split(/x/).map(&:to_i)
|
@@ -54,7 +53,7 @@ module Bulldog
|
|
54
53
|
if $?.success? && output.present?
|
55
54
|
width, height, orientation = *output.scan(/(\d+) (\d+) (\d?)/).first.map(&:to_i)
|
56
55
|
rotated = (orientation & 0x4).nonzero?
|
57
|
-
@original_dimensions
|
56
|
+
@original_dimensions = rotated ? [height, width] : [width, height]
|
58
57
|
true
|
59
58
|
else
|
60
59
|
Bulldog.logger.warn "command failed (#{$?.exitstatus})"
|
@@ -130,14 +130,12 @@ module Bulldog
|
|
130
130
|
if (column_name = reflection.column_name_for_stored_attribute(name))
|
131
131
|
value = record.send(column_name)
|
132
132
|
value = send("deserialize_#{name}", value) if storable_attribute.cast
|
133
|
-
ivar = :"@#{name}"
|
134
133
|
if storable_attribute.per_style?
|
135
|
-
|
136
|
-
instance_variable_set(ivar, {})
|
137
|
-
instance_variable_get(ivar)[name] = value
|
134
|
+
ivar = :"@original_#{name}"
|
138
135
|
else
|
139
|
-
|
136
|
+
ivar = :"@#{name}"
|
140
137
|
end
|
138
|
+
instance_variable_set(ivar, value)
|
141
139
|
end
|
142
140
|
end
|
143
141
|
end
|
@@ -16,8 +16,7 @@ module Bulldog
|
|
16
16
|
#
|
17
17
|
def dimensions(style_name)
|
18
18
|
if style_name.equal?(:original)
|
19
|
-
|
20
|
-
@original_dimensions
|
19
|
+
from_examination :original_dimensions
|
21
20
|
else
|
22
21
|
style = reflection.styles[style_name]
|
23
22
|
target_dimensions = style[:size].split(/x/).map(&:to_i)
|
@@ -30,8 +30,7 @@ module Bulldog
|
|
30
30
|
if stream.missing?
|
31
31
|
0
|
32
32
|
else
|
33
|
-
|
34
|
-
@original_duration
|
33
|
+
from_examination :original_duration
|
35
34
|
end
|
36
35
|
end
|
37
36
|
|
@@ -50,7 +49,7 @@ module Bulldog
|
|
50
49
|
if stream.missing?
|
51
50
|
[VideoTrack.new(:dimensions => [2, 2])]
|
52
51
|
else
|
53
|
-
examine
|
52
|
+
examine unless @original_video_tracks
|
54
53
|
if @original_video_tracks.empty?
|
55
54
|
@original_video_tracks << VideoTrack.new(:dimensions => [2, 2])
|
56
55
|
end
|
@@ -1,164 +1,177 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Attachment::Image do
|
4
|
-
use_model_class(:Thing,
|
5
|
-
:photo_file_name => :string,
|
6
|
-
:photo_width => :integer,
|
7
|
-
:photo_height => :integer,
|
8
|
-
:photo_aspect_ratio => :float,
|
9
|
-
:photo_dimensions => :string)
|
10
|
-
|
11
|
-
before do
|
12
|
-
Thing.has_attachment :photo do
|
13
|
-
style :double, :size => '80x60'
|
14
|
-
style :filled, :size => '60x60', :filled => true
|
15
|
-
style :unfilled, :size => '120x120'
|
16
|
-
default_style :double
|
17
|
-
end
|
18
|
-
@thing = Thing.new(:photo => test_image_file)
|
19
|
-
end
|
20
|
-
|
21
4
|
def run(command)
|
22
5
|
`#{command}`
|
23
6
|
$?.success? or
|
24
7
|
raise "command failed: #{command}"
|
25
8
|
end
|
26
9
|
|
27
|
-
describe "
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
10
|
+
describe "when file attributes are not stored" do
|
11
|
+
use_model_class(:Thing, :photo_file_name => :string)
|
12
|
+
|
13
|
+
describe "#dimensions" do
|
14
|
+
it "should return 1x1 if the file is missing" do
|
15
|
+
Thing.has_attachment :photo do
|
16
|
+
type :image
|
17
|
+
style :double, :size => '80x60'
|
18
|
+
style :filled, :size => '60x60', :filled => true
|
19
|
+
style :unfilled, :size => '120x120'
|
20
|
+
default_style :double
|
21
|
+
end
|
22
|
+
@thing = Thing.new(:photo => test_image_file)
|
23
|
+
@thing.save.should be_true
|
24
|
+
File.unlink(@thing.photo.path(:original))
|
25
|
+
@thing = Thing.find(@thing.id)
|
26
|
+
@thing.photo.is_a?(Attachment::Image) # sanity check
|
27
|
+
@thing.photo.stream.missing? # sanity check
|
28
|
+
@thing.photo.dimensions(:original).should == [1, 1]
|
29
|
+
end
|
38
30
|
end
|
31
|
+
end
|
39
32
|
|
40
|
-
|
41
|
-
|
42
|
-
|
33
|
+
describe "when file attributes are stored" do
|
34
|
+
use_model_class(:Thing,
|
35
|
+
:photo_file_name => :string,
|
36
|
+
:photo_width => :integer,
|
37
|
+
:photo_height => :integer,
|
38
|
+
:photo_aspect_ratio => :float,
|
39
|
+
:photo_dimensions => :string)
|
43
40
|
|
44
|
-
|
45
|
-
|
46
|
-
|
41
|
+
before do
|
42
|
+
Thing.has_attachment :photo do
|
43
|
+
style :double, :size => '80x60'
|
44
|
+
style :filled, :size => '60x60', :filled => true
|
45
|
+
style :unfilled, :size => '120x120'
|
46
|
+
default_style :double
|
47
|
+
end
|
48
|
+
@thing = Thing.new(:photo => test_image_file)
|
47
49
|
end
|
48
50
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
51
|
+
describe "#dimensions" do
|
52
|
+
it "should return the width and height of the default style if no style name is given" do
|
53
|
+
@thing.photo.dimensions.should == [80, 60]
|
54
|
+
end
|
53
55
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
run "exif --create-exif --ifd=EXIF --tag=Orientation --set-value=4 --output=#{rotated_path} #{path}"
|
58
|
-
open(rotated_path) do |file|
|
59
|
-
@thing.photo = file
|
60
|
-
@thing.photo.dimensions(:original).should == [30, 40]
|
56
|
+
it "should return the width and height of the given style" do
|
57
|
+
@thing.photo.dimensions(:original).should == [40, 30]
|
58
|
+
@thing.photo.dimensions(:double).should == [80, 60]
|
61
59
|
end
|
62
|
-
end
|
63
60
|
|
64
|
-
|
65
|
-
|
66
|
-
|
61
|
+
it "should return the calculated width according to style filledness" do
|
62
|
+
@thing.photo.dimensions(:filled).should == [60, 60]
|
63
|
+
@thing.photo.dimensions(:unfilled).should == [120, 90]
|
64
|
+
end
|
67
65
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
66
|
+
it "should honor the exif:Orientation header" do
|
67
|
+
path = create_image("#{temporary_directory}/test.jpg", :size => '40x30')
|
68
|
+
rotated_path = "#{temporary_directory}/rotated-test.jpg"
|
69
|
+
run "exif --create-exif --ifd=EXIF --tag=Orientation --set-value=4 --output=#{rotated_path} #{path}"
|
70
|
+
open(rotated_path) do |file|
|
71
|
+
@thing.photo = file
|
72
|
+
@thing.photo.dimensions(:original).should == [30, 40]
|
73
|
+
end
|
74
|
+
end
|
72
75
|
|
73
|
-
|
74
|
-
|
75
|
-
@thing.photo.width(:double).should == 80
|
76
|
+
it "should only invoke identify once"
|
77
|
+
it "should log the result"
|
76
78
|
end
|
77
|
-
end
|
78
79
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
80
|
+
describe "#width" do
|
81
|
+
it "should return the width of the default style if no style name is given" do
|
82
|
+
@thing.photo.width.should == 80
|
83
|
+
end
|
83
84
|
|
84
|
-
|
85
|
-
|
86
|
-
|
85
|
+
it "should return the width of the given style" do
|
86
|
+
@thing.photo.width(:original).should == 40
|
87
|
+
@thing.photo.width(:double).should == 80
|
88
|
+
end
|
87
89
|
end
|
88
|
-
end
|
89
90
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
91
|
+
describe "#height" do
|
92
|
+
it "should return the height of the default style if no style name is given" do
|
93
|
+
@thing.photo.height.should == 60
|
94
|
+
end
|
94
95
|
|
95
|
-
|
96
|
-
|
97
|
-
|
96
|
+
it "should return the height of the given style" do
|
97
|
+
@thing.photo.height(:original).should == 30
|
98
|
+
@thing.photo.height(:double).should == 60
|
99
|
+
end
|
98
100
|
end
|
99
|
-
end
|
100
101
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
@thing.photo_aspect_ratio.should be_close(4.0/3, 1e-5)
|
106
|
-
@thing.photo_dimensions.should == '40x30'
|
107
|
-
end
|
102
|
+
describe "#aspect_ratio" do
|
103
|
+
it "should return the aspect ratio of the default style if no style name is given" do
|
104
|
+
@thing.photo.aspect_ratio.should be_close(4.0/3, 1e-5)
|
105
|
+
end
|
108
106
|
|
109
|
-
|
110
|
-
|
111
|
-
@thing.
|
112
|
-
@thing = Thing.find(@thing.id)
|
107
|
+
it "should return the aspect ratio of the given style" do
|
108
|
+
@thing.photo.aspect_ratio(:original).should be_close(4.0/3, 1e-5)
|
109
|
+
@thing.photo.aspect_ratio(:filled).should be_close(1, 1e-5)
|
113
110
|
end
|
111
|
+
end
|
114
112
|
|
115
|
-
|
113
|
+
describe "storable attributes" do
|
114
|
+
it "should set the stored attributes on assignment" do
|
116
115
|
@thing.photo_width.should == 40
|
117
116
|
@thing.photo_height.should == 30
|
118
117
|
@thing.photo_aspect_ratio.should be_close(4.0/3, 1e-5)
|
119
118
|
@thing.photo_dimensions.should == '40x30'
|
120
119
|
end
|
121
120
|
|
122
|
-
|
123
|
-
|
124
|
-
|
121
|
+
describe "after roundtripping through the database" do
|
122
|
+
before do
|
123
|
+
@thing.save
|
124
|
+
@thing = Thing.find(@thing.id)
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should restore the stored attributes" do
|
128
|
+
@thing.photo_width.should == 40
|
129
|
+
@thing.photo_height.should == 30
|
130
|
+
@thing.photo_aspect_ratio.should be_close(4.0/3, 1e-5)
|
131
|
+
@thing.photo_dimensions.should == '40x30'
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should recalculate the dimensions correctly" do
|
135
|
+
@thing.photo.dimensions(:filled).should == [60, 60]
|
136
|
+
@thing.photo.dimensions(:unfilled).should == [120, 90]
|
137
|
+
end
|
125
138
|
end
|
126
139
|
end
|
127
|
-
end
|
128
140
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
141
|
+
describe "#reload" do
|
142
|
+
before do
|
143
|
+
thing = Thing.create(:photo => test_image_file('test.jpg'))
|
144
|
+
@thing = Thing.find(thing.id)
|
145
|
+
end
|
134
146
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
FileUtils.cp(test_path('test2.jpg'), @thing.photo.path(:original))
|
143
|
-
@thing.photo.reload
|
144
|
-
@thing.photo_width.should == 2
|
145
|
-
@thing.photo_height.should == 2
|
146
|
-
@thing.photo_aspect_ratio.should == 1
|
147
|
-
@thing.photo_dimensions.should == '2x2'
|
148
|
-
end
|
147
|
+
it "should update the stored attributes from the file" do
|
148
|
+
# Prime the cached values.
|
149
|
+
@thing.photo_width.should == 40
|
150
|
+
@thing.photo_height.should == 30
|
151
|
+
@thing.photo_aspect_ratio.should be_close(4.0/3, 1e-5)
|
152
|
+
@thing.photo_dimensions.should == '40x30'
|
149
153
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
154
|
+
FileUtils.cp(test_path('test2.jpg'), @thing.photo.path(:original))
|
155
|
+
@thing.photo.reload
|
156
|
+
@thing.photo_width.should == 2
|
157
|
+
@thing.photo_height.should == 2
|
158
|
+
@thing.photo_aspect_ratio.should == 1
|
159
|
+
@thing.photo_dimensions.should == '2x2'
|
160
|
+
end
|
156
161
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
+
it "should update the original dimensions from the file" do
|
163
|
+
@thing.photo.dimensions(:original).should == [40, 30]
|
164
|
+
FileUtils.cp(test_path('test2.jpg'), @thing.photo.path(:original))
|
165
|
+
@thing.photo.reload
|
166
|
+
@thing.photo.dimensions(:original).should == [2, 2]
|
167
|
+
end
|
168
|
+
|
169
|
+
it "should update the dimensions for each style from the file" do
|
170
|
+
@thing.photo.dimensions(:double).should == [80, 60]
|
171
|
+
FileUtils.cp(test_path('test2.jpg'), @thing.photo.path(:original))
|
172
|
+
@thing.photo.reload
|
173
|
+
@thing.photo.dimensions(:double).should == [60, 60]
|
174
|
+
end
|
162
175
|
end
|
163
176
|
end
|
164
177
|
end
|
@@ -1,23 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Attachment::Pdf do
|
4
|
-
use_model_class(:Thing,
|
5
|
-
:attachment_file_name => :string,
|
6
|
-
:attachment_width => :integer,
|
7
|
-
:attachment_height => :integer,
|
8
|
-
:attachment_aspect_ratio => :float,
|
9
|
-
:attachment_dimensions => :string)
|
10
|
-
|
11
|
-
before do
|
12
|
-
Thing.has_attachment :attachment do
|
13
|
-
style :double, :size => '1224x1584'
|
14
|
-
style :filled, :size => '500x500', :filled => true
|
15
|
-
style :unfilled, :size => '1000x1000'
|
16
|
-
default_style :double
|
17
|
-
end
|
18
|
-
@thing = Thing.new(:attachment => test_file)
|
19
|
-
end
|
20
|
-
|
21
4
|
def test_file
|
22
5
|
path = "#{temporary_directory}/test.pdf"
|
23
6
|
FileUtils.cp("#{ROOT}/spec/data/test.pdf", path)
|
@@ -28,109 +11,139 @@ describe Attachment::Pdf do
|
|
28
11
|
Thing.attachment_reflections[:attachment].configure(&block)
|
29
12
|
end
|
30
13
|
|
31
|
-
describe "
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
14
|
+
describe "when file attributes are not stored" do
|
15
|
+
use_model_class(:Thing, :attachment_file_name => :string)
|
16
|
+
|
17
|
+
describe "#dimensions" do
|
18
|
+
it "should return 1x1 if the file is missing" do
|
19
|
+
Thing.has_attachment :attachment do
|
20
|
+
type :pdf
|
21
|
+
style :double, :size => '1224x1584'
|
22
|
+
style :filled, :size => '500x500', :filled => true
|
23
|
+
style :unfilled, :size => '1000x1000'
|
24
|
+
default_style :double
|
38
25
|
end
|
26
|
+
@thing = Thing.new(:attachment => test_file)
|
27
|
+
@thing.save.should be_true
|
28
|
+
File.unlink(@thing.attachment.path(:original))
|
29
|
+
@thing = Thing.find(@thing.id)
|
30
|
+
@thing.attachment.is_a?(Attachment::Pdf) # sanity check
|
31
|
+
@thing.attachment.stream.missing? # sanity check
|
32
|
+
@thing.attachment.dimensions(:original).should == [1, 1]
|
39
33
|
end
|
40
|
-
|
41
|
-
@thing.attachment.process(:event)
|
42
|
-
context.should be_a(Processor::ImageMagick)
|
43
34
|
end
|
44
35
|
end
|
45
36
|
|
46
|
-
describe "
|
47
|
-
|
48
|
-
|
49
|
-
|
37
|
+
describe "when file attributes are stored" do
|
38
|
+
use_model_class(:Thing,
|
39
|
+
:attachment_file_name => :string,
|
40
|
+
:attachment_width => :integer,
|
41
|
+
:attachment_height => :integer,
|
42
|
+
:attachment_aspect_ratio => :float,
|
43
|
+
:attachment_dimensions => :string)
|
44
|
+
|
45
|
+
before do
|
46
|
+
Thing.has_attachment :attachment do
|
47
|
+
style :double, :size => '1224x1584'
|
48
|
+
style :filled, :size => '500x500', :filled => true
|
49
|
+
style :unfilled, :size => '1000x1000'
|
50
|
+
default_style :double
|
50
51
|
end
|
51
|
-
@thing.
|
52
|
-
File.unlink(@thing.attachment.path(:original))
|
53
|
-
@thing = Thing.find(@thing.id)
|
54
|
-
@thing.attachment.is_a?(Attachment::Pdf) # sanity check
|
55
|
-
@thing.attachment.stream.missing? # sanity check
|
56
|
-
@thing.attachment.dimensions(:original).should == [1, 1]
|
52
|
+
@thing = Thing.new(:attachment => test_file)
|
57
53
|
end
|
58
54
|
|
59
|
-
|
60
|
-
|
61
|
-
|
55
|
+
describe "#process" do
|
56
|
+
it "should be processed with ImageMagick by default" do
|
57
|
+
context = nil
|
58
|
+
configure do
|
59
|
+
style :output
|
60
|
+
process :on => :event do
|
61
|
+
context = self
|
62
|
+
end
|
63
|
+
end
|
62
64
|
|
63
|
-
|
64
|
-
|
65
|
-
|
65
|
+
@thing.attachment.process(:event)
|
66
|
+
context.should be_a(Processor::ImageMagick)
|
67
|
+
end
|
66
68
|
end
|
67
69
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
70
|
+
describe "#dimensions" do
|
71
|
+
it "should return the width and height of the default style if no style name is given" do
|
72
|
+
@thing.attachment.dimensions.should == [1224, 1584]
|
73
|
+
end
|
72
74
|
|
73
|
-
|
74
|
-
|
75
|
-
|
75
|
+
it "should return the width and height of the given style" do
|
76
|
+
@thing.attachment.dimensions(:original).should == [612, 792]
|
77
|
+
@thing.attachment.dimensions(:double).should == [1224, 1584]
|
78
|
+
end
|
76
79
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
80
|
+
it "should return the calculated width according to style filledness" do
|
81
|
+
@thing.attachment.dimensions(:filled).should == [500, 500]
|
82
|
+
@thing.attachment.dimensions(:unfilled).should == [773, 1000]
|
83
|
+
end
|
81
84
|
|
82
|
-
|
83
|
-
|
84
|
-
@thing.attachment.width(:double).should == 1224
|
85
|
+
it "should only invoke identify once"
|
86
|
+
it "should log the result"
|
85
87
|
end
|
86
|
-
end
|
87
88
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
89
|
+
describe "#width" do
|
90
|
+
it "should return the width of the default style if no style name is given" do
|
91
|
+
@thing.attachment.width.should == 1224
|
92
|
+
end
|
92
93
|
|
93
|
-
|
94
|
-
|
95
|
-
|
94
|
+
it "should return the width of the given style" do
|
95
|
+
@thing.attachment.width(:original).should == 612
|
96
|
+
@thing.attachment.width(:double).should == 1224
|
97
|
+
end
|
96
98
|
end
|
97
|
-
end
|
98
99
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
100
|
+
describe "#height" do
|
101
|
+
it "should return the height of the default style if no style name is given" do
|
102
|
+
@thing.attachment.height.should == 1584
|
103
|
+
end
|
103
104
|
|
104
|
-
|
105
|
-
|
106
|
-
|
105
|
+
it "should return the height of the given style" do
|
106
|
+
@thing.attachment.height(:original).should == 792
|
107
|
+
@thing.attachment.height(:double).should == 1584
|
108
|
+
end
|
107
109
|
end
|
108
|
-
end
|
109
110
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
@thing.attachment_aspect_ratio.should be_close(612.0/792, 1e-5)
|
115
|
-
@thing.attachment_dimensions.should == '612x792'
|
116
|
-
end
|
111
|
+
describe "#aspect_ratio" do
|
112
|
+
it "should return the aspect ratio of the default style if no style name is given" do
|
113
|
+
@thing.attachment.aspect_ratio.should be_close(612.0/792, 1e-5)
|
114
|
+
end
|
117
115
|
|
118
|
-
|
119
|
-
|
120
|
-
@thing.
|
121
|
-
@thing = Thing.find(@thing.id)
|
116
|
+
it "should return the aspect ratio of the given style" do
|
117
|
+
@thing.attachment.aspect_ratio(:original).should be_close(612.0/792, 1e-5)
|
118
|
+
@thing.attachment.aspect_ratio(:filled).should be_close(1, 1e-5)
|
122
119
|
end
|
120
|
+
end
|
123
121
|
|
124
|
-
|
122
|
+
describe "storable attributes" do
|
123
|
+
it "should set the stored attributes on assignment" do
|
125
124
|
@thing.attachment_width.should == 612
|
126
125
|
@thing.attachment_height.should == 792
|
127
126
|
@thing.attachment_aspect_ratio.should be_close(612.0/792, 1e-5)
|
128
127
|
@thing.attachment_dimensions.should == '612x792'
|
129
128
|
end
|
130
129
|
|
131
|
-
|
132
|
-
|
133
|
-
|
130
|
+
describe "after roundtripping through the database" do
|
131
|
+
before do
|
132
|
+
@thing.save
|
133
|
+
@thing = Thing.find(@thing.id)
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should restore the stored attributes" do
|
137
|
+
@thing.attachment_width.should == 612
|
138
|
+
@thing.attachment_height.should == 792
|
139
|
+
@thing.attachment_aspect_ratio.should be_close(612.0/792, 1e-5)
|
140
|
+
@thing.attachment_dimensions.should == '612x792'
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should recalculate the dimensions correctly" do
|
144
|
+
@thing.attachment.dimensions(:filled).should == [500, 500]
|
145
|
+
@thing.attachment.dimensions(:unfilled).should == [773, 1000]
|
146
|
+
end
|
134
147
|
end
|
135
148
|
end
|
136
149
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bulldog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- George Ogata
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-12-
|
12
|
+
date: 2009-12-11 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|