Skip to content

Commit

Permalink
Merge branch 'master' of git@github.com:thoughtbot/paperclip
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Yurek committed Jul 31, 2009
2 parents ac86bb9 + e430afe commit b3f26a6
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lib/paperclip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
# documentation for Paperclip::ClassMethods for more useful information.
module Paperclip

VERSION = "2.2.9.2"
VERSION = "2.3.0"

class << self
# Provides configurability to Paperclip. There are a number of options available, such as:
Expand Down
3 changes: 2 additions & 1 deletion lib/paperclip/attachment.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# encoding: utf-8
module Paperclip
# The Attachment class manages the files for a given attachment. It saves
# when the model saves, deletes when the model is destroyed, and processes
Expand Down Expand Up @@ -76,7 +77,7 @@ def assign uploaded_file
return nil if uploaded_file.nil?

@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(:file_size, uploaded_file.size.to_i)
instance_write(:updated_at, Time.now)
Expand Down
2 changes: 1 addition & 1 deletion lib/paperclip/matchers/have_attached_file_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def description
protected

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}?")
Expand Down
2 changes: 1 addition & 1 deletion paperclip.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Gem::Specification.new do |s|
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.authors = ["Jon Yurek"]
Expand Down
19 changes: 9 additions & 10 deletions test/attachment_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# encoding: utf-8
require 'test/helper'

class Dummy
Expand Down Expand Up @@ -498,12 +499,10 @@ def do_after_all; end
rebuild_model
@instance = Dummy.new
@attachment = Paperclip::Attachment.new(:avatar, @instance)
@file = File.new(File.join(File.dirname(__FILE__),
"fixtures",
"5k.png"), 'rb')
@file = File.new(File.join(File.dirname(__FILE__), "fixtures", "5k.png"), 'rb')
end

teardown do
teardown do
@file.close
Paperclip::Attachment.default_options.merge!(@old_defaults)
end
Expand All @@ -520,13 +519,13 @@ def do_after_all; end
assert_equal "/avatars/original/missing.png", @attachment.url
assert_equal "/avatars/blah/missing.png", @attachment.url(:blah)
end

should "return nil as path when no file assigned" do
assert @attachment.to_file.nil?
assert_equal nil, @attachment.path
assert_equal nil, @attachment.path(:blah)
end

context "with a file assigned in the database" do
setup do
@attachment.stubs(:instance_read).with(:file_name).returns("5k.png")
Expand All @@ -545,7 +544,7 @@ def do_after_all; end
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)
end

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)
end
Expand All @@ -561,12 +560,12 @@ def do_after_all; end
end

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

should "return the proper path when filename has multiple .'s" do
@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
@attachment.stubs(:instance_read).with(:file_name).returns("5k.old.png")
assert_equal File.expand_path("./test/../tmp/avatars/dummies/original/#{@instance.id}/5k.old.png"), File.expand_path(@attachment.path)
end

context "when expecting three styles" do
Expand Down
2 changes: 1 addition & 1 deletion test/geometry_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class GeometryTest < Test::Unit::TestCase
should "make sure the modifier gets passed during transformation_to" do
assert @src = 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

should "generate correct ImageMagick formatting string for W-formatted string" do
Expand Down
3 changes: 1 addition & 2 deletions test/helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require 'rubygems'
require 'test/unit'
gem 'thoughtbot-shoulda', ">= 2.9.0"
require 'shoulda'
require 'mocha'
require 'tempfile'
Expand Down Expand Up @@ -40,7 +39,7 @@ def reset_class class_name
end

def reset_table table_name, &block
block ||= lambda{ true }
block ||= lambda { |table| true }
ActiveRecord::Base.connection.create_table :dummies, {:force => true}, &block
end

Expand Down

0 comments on commit b3f26a6

Please sign in to comment.