Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Ruby 1.8 compatability #1

Merged
merged 1 commit into from

2 participants

@mikz

Hi!

I found issue when using Ruby 1.8 -

File.new Tempfile.new("bla") raises can't convert Tempfile into String exception

calling #path on tempfile ensures that File.new is called with String.

Tmp.fs should always return Tempfile right?

@exviva
Owner

Thanks @mikz. I've enabled 1.8.7 on Travis, and it won't even start the build (due to using 1.9 hash syntax): http://travis-ci.org/#!/exviva/paperclip-storage-tmp/jobs/1622507.

If you can get the build to run on 1.8.7, and fail, and your fix will make it pass, then I'll gladly merge it in.

@exviva
Owner

One last thing: please add a changelog entry. Then I'll merge. Thanks!

@mikz

@exviva done. Thanks for cooperation!

@exviva
Owner

Oh man...sorry I'm being so pedantic, but could you put the changelog entry on the very top and squash your commits? :)

@mikz

No problem :)

@mikz mikz Ruby 1.8 compatability
* use Ruby 1.8 hash syntax in tests
* make it Ruby 1.8 compatible
* fix spec to work in Ruby 1.8
* add changelog entry
2a135d0
@mikz

Like this? @exviva

@exviva exviva merged commit 58aff48 into from
@exviva
Owner

Perfect! Thanks

@exviva
Owner

I've released it as 0.0.4.

@mikz

Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 15, 2012
  1. @mikz

    Ruby 1.8 compatability

    mikz authored mikz committed
    * use Ruby 1.8 hash syntax in tests
    * make it Ruby 1.8 compatible
    * fix spec to work in Ruby 1.8
    * add changelog entry
This page is out of date. Refresh to see the latest.
View
2  CHANGELOG.md
@@ -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
View
2  Rakefile
@@ -4,4 +4,4 @@ require "bundler/gem_tasks"
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
-task default: :spec
+task :default => :spec
View
2  lib/paperclip/storage/tmp.rb
@@ -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
View
2  spec/fixtures/user.rb
@@ -1,3 +1,3 @@
class User < ActiveRecord::Base
- has_attached_file :avatar, storage: :tmp
+ has_attached_file :avatar, :storage => :tmp
end
View
14 spec/lib/paperclip/storage/tmp_spec.rb
@@ -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 }
@@ -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
@@ -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
@@ -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
@@ -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
View
2  spec/support/active_record.rb
@@ -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|
Something went wrong with that request. Please try again.