Skip to content

Commit

Permalink
Adding method to find template width and height w/ test. Part of #37.
Browse files Browse the repository at this point in the history
  • Loading branch information
bamnet committed Mar 7, 2012
1 parent 7a55d01 commit 12f1ef0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
13 changes: 13 additions & 0 deletions app/models/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,17 @@ def import_xml(xml)
end
return self.valid?
end


# Update the original_width and original_height
# fields using the orignal image.
def update_original_sizes
original_media = self.media.original.first
unless original_media.nil?
image = Magick::Image.from_blob(original_media.file_contents).first
self.original_width = image.columns
self.original_height = image.rows
end
return true
end
end
12 changes: 12 additions & 0 deletions test/unit/template_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,16 @@ class TemplateTest < ActiveSupport::TestCase
file = fixture_file_upload("/files/no_fields_template.xml", 'text/xml')
assert t.import_xml(file.read)
end

# Do we correctly find the original height and orignal width?
test "find original height and width" do
t = Template.new
file = fixture_file_upload("/files/concerto_background.jpg", 'image/jpeg')
t.save
media = t.media.build(:file => file, :key => 'original')
media.save
assert t.update_original_sizes
assert_equal t.original_width, 1920
assert_equal t.original_height, 1200
end
end

0 comments on commit 12f1ef0

Please sign in to comment.