Commit 52fb528a by jyurek

Fixed regexp that was losing the geometry modifiers.

git-svn-id: https://svn.thoughtbot.com/plugins/paperclip/trunk@419 7bbfaf0e-4d1d-0410-9690-a8bb5f8ef2aa
parent 0be5d250
......@@ -12,6 +12,12 @@ Rake::TestTask.new(:test) do |t|
t.verbose = true
end
desc 'Start an IRB session with all necessary files required.'
task :shell do |t|
chdir File.dirname(__FILE__)
exec 'irb -I lib/ -I lib/paperclip -r rubygems -r active_record -r tempfile -r init'
end
desc 'Generate documentation for the paperclip plugin.'
Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'doc'
......
......@@ -23,7 +23,7 @@ module Paperclip
# Parses a "WxH" formatted string, where W is the width and H is the height.
def self.parse string
if match = (string && string.match(/\b(\d*)x(\d*)([><\#\@\%^!])?\b/))
if match = (string && string.match(/\b(\d*)x(\d*)\b([\>\<\#\@\%^!])?/))
Geometry.new(*match[1,3])
end
end
......
......@@ -4,7 +4,7 @@ require 'shoulda'
require File.join(File.dirname(__FILE__), '..', 'lib', 'paperclip', 'geometry.rb')
class PaperclipTest < Test::Unit::TestCase
class GeometryTest < Test::Unit::TestCase
context "Paperclip::Geometry" do
should "correctly report its given dimensions" do
assert @geo = Paperclip::Geometry.new(1024, 768)
......@@ -42,6 +42,23 @@ class PaperclipTest < Test::Unit::TestCase
assert_equal 800, @geo.height
end
should "ensure the modifier is nil if only one dimension present" do
assert @geo = Paperclip::Geometry.parse("123x")
assert_nil mod, @geo.modifier
end
should "ensure the modifier is nil if not present" do
assert @geo = Paperclip::Geometry.parse("123x456")
assert_nil mod, @geo.modifier
end
['>', '<', '#', '@', '%', '^', '!'].each do |mod|
should "ensure the modifier #{mod} is preserved" do
assert @geo = Paperclip::Geometry.parse("123x456#{mod}")
assert_equal mod, @geo.modifier
end
end
should "be generated from a file" do
file = Dir.glob("/Users/jyurek/Pictures/*.jpg").first
file = File.new(file)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment