Commit b3f26a69 by Jon Yurek

Merge branch 'master' of git@github.com:thoughtbot/paperclip

parents ac86bb9d e430afe4
...@@ -44,7 +44,7 @@ end ...@@ -44,7 +44,7 @@ end
# documentation for Paperclip::ClassMethods for more useful information. # documentation for Paperclip::ClassMethods for more useful information.
module Paperclip module Paperclip
VERSION = "2.2.9.2" VERSION = "2.3.0"
class << self class << self
# Provides configurability to Paperclip. There are a number of options available, such as: # Provides configurability to Paperclip. There are a number of options available, such as:
......
# encoding: utf-8
module Paperclip module Paperclip
# The Attachment class manages the files for a given attachment. It saves # The Attachment class manages the files for a given attachment. It saves
# when the model saves, deletes when the model is destroyed, and processes # when the model saves, deletes when the model is destroyed, and processes
...@@ -76,7 +77,7 @@ module Paperclip ...@@ -76,7 +77,7 @@ module Paperclip
return nil if uploaded_file.nil? return nil if uploaded_file.nil?
@queued_for_write[:original] = uploaded_file.to_tempfile @queued_for_write[:original] = uploaded_file.to_tempfile
instance_write(:file_name, uploaded_file.original_filename.strip.gsub(/[^\w\d\.\-]+/, '_')) instance_write(:file_name, uploaded_file.original_filename.strip.gsub(/[^A-Za-z\d\.\-_]+/, '_'))
instance_write(:content_type, uploaded_file.content_type.to_s.strip) instance_write(:content_type, uploaded_file.content_type.to_s.strip)
instance_write(:file_size, uploaded_file.size.to_i) instance_write(:file_size, uploaded_file.size.to_i)
instance_write(:updated_at, Time.now) instance_write(:updated_at, Time.now)
......
...@@ -30,7 +30,7 @@ module Paperclip ...@@ -30,7 +30,7 @@ module Paperclip
protected protected
def responds? def responds?
methods = @subject.instance_methods methods = @subject.instance_methods.map(&:to_s)
methods.include?("#{@attachment_name}") && methods.include?("#{@attachment_name}") &&
methods.include?("#{@attachment_name}=") && methods.include?("#{@attachment_name}=") &&
methods.include?("#{@attachment_name}?") methods.include?("#{@attachment_name}?")
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
Gem::Specification.new do |s| Gem::Specification.new do |s|
s.name = %q{paperclip} s.name = %q{paperclip}
s.version = "2.2.9.2" s.version = "2.3.0"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Jon Yurek"] s.authors = ["Jon Yurek"]
......
# encoding: utf-8
require 'test/helper' require 'test/helper'
class Dummy class Dummy
...@@ -498,12 +499,10 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -498,12 +499,10 @@ class AttachmentTest < Test::Unit::TestCase
rebuild_model rebuild_model
@instance = Dummy.new @instance = Dummy.new
@attachment = Paperclip::Attachment.new(:avatar, @instance) @attachment = Paperclip::Attachment.new(:avatar, @instance)
@file = File.new(File.join(File.dirname(__FILE__), @file = File.new(File.join(File.dirname(__FILE__), "fixtures", "5k.png"), 'rb')
"fixtures",
"5k.png"), 'rb')
end end
teardown do teardown do
@file.close @file.close
Paperclip::Attachment.default_options.merge!(@old_defaults) Paperclip::Attachment.default_options.merge!(@old_defaults)
end end
...@@ -520,13 +519,13 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -520,13 +519,13 @@ class AttachmentTest < Test::Unit::TestCase
assert_equal "/avatars/original/missing.png", @attachment.url assert_equal "/avatars/original/missing.png", @attachment.url
assert_equal "/avatars/blah/missing.png", @attachment.url(:blah) assert_equal "/avatars/blah/missing.png", @attachment.url(:blah)
end end
should "return nil as path when no file assigned" do should "return nil as path when no file assigned" do
assert @attachment.to_file.nil? assert @attachment.to_file.nil?
assert_equal nil, @attachment.path assert_equal nil, @attachment.path
assert_equal nil, @attachment.path(:blah) assert_equal nil, @attachment.path(:blah)
end end
context "with a file assigned in the database" do context "with a file assigned in the database" do
setup do setup do
@attachment.stubs(:instance_read).with(:file_name).returns("5k.png") @attachment.stubs(:instance_read).with(:file_name).returns("5k.png")
...@@ -545,7 +544,7 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -545,7 +544,7 @@ class AttachmentTest < Test::Unit::TestCase
should "make sure the updated_at mtime is in the url if it is defined" do should "make sure the updated_at mtime is in the url if it is defined" do
assert_match %r{#{Time.now.to_i}$}, @attachment.url(:blah) assert_match %r{#{Time.now.to_i}$}, @attachment.url(:blah)
end end
should "make sure the updated_at mtime is NOT in the url if false is passed to the url method" do should "make sure the updated_at mtime is NOT in the url if false is passed to the url method" do
assert_no_match %r{#{Time.now.to_i}$}, @attachment.url(:blah, false) assert_no_match %r{#{Time.now.to_i}$}, @attachment.url(:blah, false)
end end
...@@ -561,12 +560,12 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -561,12 +560,12 @@ class AttachmentTest < Test::Unit::TestCase
end end
should "return the proper path when filename has a single .'s" do should "return the proper path when filename has a single .'s" do
assert_equal "./test/../tmp/avatars/dummies/original/#{@instance.id}/5k.png", @attachment.path assert_equal File.expand_path("./test/../tmp/avatars/dummies/original/#{@instance.id}/5k.png"), File.expand_path(@attachment.path)
end end
should "return the proper path when filename has multiple .'s" do should "return the proper path when filename has multiple .'s" do
@attachment.stubs(:instance_read).with(:file_name).returns("5k.old.png") @attachment.stubs(:instance_read).with(:file_name).returns("5k.old.png")
assert_equal "./test/../tmp/avatars/dummies/original/#{@instance.id}/5k.old.png", @attachment.path assert_equal File.expand_path("./test/../tmp/avatars/dummies/original/#{@instance.id}/5k.old.png"), File.expand_path(@attachment.path)
end end
context "when expecting three styles" do context "when expecting three styles" do
......
...@@ -77,7 +77,7 @@ class GeometryTest < Test::Unit::TestCase ...@@ -77,7 +77,7 @@ class GeometryTest < Test::Unit::TestCase
should "make sure the modifier gets passed during transformation_to" do should "make sure the modifier gets passed during transformation_to" do
assert @src = Paperclip::Geometry.parse("123x456") assert @src = Paperclip::Geometry.parse("123x456")
assert @dst = Paperclip::Geometry.parse("123x456>") assert @dst = Paperclip::Geometry.parse("123x456>")
assert_equal "123x456>", @src.transformation_to(@dst).to_s assert_equal ["123x456>", nil], @src.transformation_to(@dst)
end end
should "generate correct ImageMagick formatting string for W-formatted string" do should "generate correct ImageMagick formatting string for W-formatted string" do
......
require 'rubygems' require 'rubygems'
require 'test/unit' require 'test/unit'
gem 'thoughtbot-shoulda', ">= 2.9.0"
require 'shoulda' require 'shoulda'
require 'mocha' require 'mocha'
require 'tempfile' require 'tempfile'
...@@ -40,7 +39,7 @@ def reset_class class_name ...@@ -40,7 +39,7 @@ def reset_class class_name
end end
def reset_table table_name, &block def reset_table table_name, &block
block ||= lambda{ true } block ||= lambda { |table| true }
ActiveRecord::Base.connection.create_table :dummies, {:force => true}, &block ActiveRecord::Base.connection.create_table :dummies, {:force => true}, &block
end end
......
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