Skip to content

Commit

Permalink
Merge pull request #1 from mikz/master
Browse files Browse the repository at this point in the history
Ruby 1.8 compatability
  • Loading branch information
exviva committed Jun 15, 2012
2 parents e492b65 + 2a135d0 commit 58aff48
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Not released yet:

* Ruby 1.8 compatability: use `Tempfile#path` when opening new file
instead passing `Tempfile` directly.
* Rewind the file queued for write before returning it
* Unlink the file **and** close the file descriptor when clearing
the attachments
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ require "bundler/gem_tasks"
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)

task default: :spec
task :default => :spec
2 changes: 1 addition & 1 deletion lib/paperclip/storage/tmp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def to_file(style_name = default_style)
@queued_for_write[style_name].rewind
@queued_for_write[style_name]
elsif exists?(style_name)
File.new(Tmp.fs[path(style_name)], 'rb')
File.new(Tmp.fs[path(style_name)].path, 'rb')
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/user.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class User < ActiveRecord::Base
has_attached_file :avatar, storage: :tmp
has_attached_file :avatar, :storage => :tmp
end
14 changes: 7 additions & 7 deletions spec/lib/paperclip/storage/tmp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

[proc { user.avatar }, proc { user.reload.avatar }].each do |subject_proc|
describe 'assigning an attachment' do
let(:user) { User.create!(avatar: avatar_file) }
let(:user) { User.create!(:avatar => avatar_file) }
subject(&subject_proc)

it { should exist }
Expand All @@ -23,7 +23,7 @@
end

it 'copies the assigned file' do
File.read(subject.to_file).should eq(File.read(avatar_file))
File.read(subject.to_file.path).should eq(File.read(avatar_file.path))
end

it 'stores the file in an imagemagick-friendly way' do
Expand All @@ -39,17 +39,17 @@
end

it 'can handle assignment from File' do
new_user = User.new(avatar: avatar_file)
new_user = User.new(:avatar => avatar_file)
new_user.avatar_file_name.should eq('hey_mom_its_me.png')
end

it 'can persist assignment from File' do
new_user = User.create!(avatar: avatar_file)
new_user = User.create!(:avatar => avatar_file)
new_user.reload.avatar_file_name.should eq('hey_mom_its_me.png')
end

it 'can handle assignment from Paperclip::Attachment' do
new_user = User.new(avatar: subject)
new_user = User.new(:avatar => subject)
new_user.avatar_file_name.should eq('hey_mom_its_me.png')
end
end
Expand All @@ -67,7 +67,7 @@
end

describe 'destroying an attachment' do
let(:user) { User.create!(avatar: avatar_file) }
let(:user) { User.create!(:avatar => avatar_file) }
subject do
@path_before_destroy = user.avatar.to_file.path
user.destroy
Expand All @@ -84,7 +84,7 @@
end

describe 'clear' do
let(:user) { User.create!(avatar: avatar_file) }
let(:user) { User.create!(:avatar => avatar_file) }
subject { Paperclip::Storage::Tmp.clear }

it 'deletes files' do
Expand Down
2 changes: 1 addition & 1 deletion spec/support/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
ActiveRecord::Base.send(:include, Paperclip::Glue)
require 'fixtures/user'

ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')

ActiveRecord::Schema.define do
create_table :users do |t|
Expand Down

0 comments on commit 58aff48

Please sign in to comment.