Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
Make the test pass on JRuby
Browse files Browse the repository at this point in the history
  • Loading branch information
sikachu committed Mar 23, 2012
1 parent 84d2d08 commit 8a758c2
Show file tree
Hide file tree
Showing 11 changed files with 128 additions and 83 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Expand Up @@ -3,3 +3,5 @@ source "http://rubygems.org"
gemspec

gem "jruby-openssl", :platform => :jruby
gem "activerecord-jdbcsqlite3-adapter", :platform => :jruby
gem "sqlite3", :platform => :ruby
118 changes: 67 additions & 51 deletions Gemfile.lock
Expand Up @@ -19,111 +19,127 @@ GEM
activesupport (= 3.2.2)
arel (~> 3.0.2)
tzinfo (~> 0.3.29)
activerecord-jdbc-adapter (1.2.2)
activerecord-jdbcsqlite3-adapter (1.2.2)
activerecord-jdbc-adapter (~> 1.2.2)
jdbc-sqlite3 (~> 3.7.2)
activesupport (3.2.2)
i18n (~> 0.6)
multi_json (~> 1.0)
appraisal (0.4.1)
bundler
rake
arel (3.0.2)
aruba (0.4.6)
bcat (>= 0.6.1)
childprocess (>= 0.2.0)
cucumber (>= 1.0.2)
rdiscount (>= 1.6.8)
rspec (>= 2.6.0)
aws-sdk (1.3.4)
aruba (0.4.11)
childprocess (>= 0.2.3)
cucumber (>= 1.1.1)
ffi (>= 1.0.11)
rspec (>= 2.7.0)
aws-sdk (1.3.8)
httparty (~> 0.7)
json (~> 1.4)
nokogiri (>= 1.4.4)
nokogiri (<= 1.5.0)
uuidtools (~> 2.1)
bcat (0.6.2)
rack (~> 1.0)
bouncy-castle-java (1.5.0146.1)
builder (3.0.0)
capybara (1.1.1)
capybara (1.1.2)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
selenium-webdriver (~> 2.0)
xpath (~> 0.1.4)
childprocess (0.2.2)
childprocess (0.3.1)
ffi (~> 1.0.6)
cocaine (0.2.0)
cucumber (1.1.4)
cocaine (0.2.1)
cucumber (1.1.9)
builder (>= 2.1.2)
diff-lcs (>= 1.1.2)
gherkin (~> 2.7.1)
gherkin (~> 2.9.0)
json (>= 1.4.6)
term-ansicolor (>= 1.0.6)
diff-lcs (1.1.3)
excon (0.6.6)
fakeweb (1.3.0)
ffi (1.0.9)
fog (0.11.0)
ffi (1.0.11)
ffi (1.0.11-java)
fog (0.9.0)
builder
excon (~> 0.6.5)
formatador (~> 0.2.0)
excon (~> 0.6.1)
formatador (>= 0.1.3)
json
mime-types
multi_json (~> 1.0.3)
net-scp (~> 1.0.4)
net-ssh (~> 2.1.4)
nokogiri (~> 1.5.0)
net-scp (>= 1.0.4)
net-ssh (>= 2.1.4)
nokogiri (>= 1.4.4)
ruby-hmac
formatador (0.2.1)
gherkin (2.7.1)
gherkin (2.9.1)
json (>= 1.4.6)
gherkin (2.9.1-java)
json (>= 1.4.6)
httparty (0.8.1)
multi_json
multi_xml
i18n (0.6.0)
jdbc-sqlite3 (3.7.2)
jruby-openssl (0.7.6.1)
bouncy-castle-java (>= 1.5.0146.1)
json (1.6.5)
json_pure (1.6.1)
json (1.6.5-java)
metaclass (0.0.1)
mime-types (1.16)
mocha (0.10.0)
mime-types (1.18)
mocha (0.10.5)
metaclass (~> 0.0.1)
multi_json (1.0.4)
multi_xml (0.4.1)
multi_json (1.1.0)
multi_xml (0.4.2)
net-scp (1.0.4)
net-ssh (>= 1.99.1)
net-ssh (2.1.4)
nokogiri (1.5.0)
rack (1.3.3)
net-ssh (2.3.0)
nokogiri (1.4.7)
nokogiri (1.4.7-java)
weakling (>= 0.0.3)
rack (1.4.1)
rack-test (0.6.1)
rack (>= 1.0)
rake (0.9.2.2)
rdiscount (1.6.8)
rspec (2.6.0)
rspec-core (~> 2.6.0)
rspec-expectations (~> 2.6.0)
rspec-mocks (~> 2.6.0)
rspec-core (2.6.4)
rspec-expectations (2.6.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.6.0)
rspec (2.9.0)
rspec-core (~> 2.9.0)
rspec-expectations (~> 2.9.0)
rspec-mocks (~> 2.9.0)
rspec-core (2.9.0)
rspec-expectations (2.9.0)
diff-lcs (~> 1.1.3)
rspec-mocks (2.9.0)
ruby-hmac (0.4.0)
rubyzip (0.9.4)
selenium-webdriver (2.7.0)
childprocess (>= 0.2.1)
ffi (>= 1.0.7)
json_pure
rubyzip (0.9.6.1)
selenium-webdriver (2.20.0)
childprocess (>= 0.2.5)
ffi (~> 1.0)
multi_json (~> 1.0)
rubyzip
shoulda (2.11.3)
sqlite3 (1.3.4)
shoulda (3.0.1)
shoulda-context (~> 1.0.0)
shoulda-matchers (~> 1.0.0)
shoulda-context (1.0.0)
shoulda-matchers (1.0.0)
sqlite3 (1.3.5)
term-ansicolor (1.0.7)
tzinfo (0.3.32)
uuidtools (2.1.2)
weakling (0.0.4-java)
xpath (0.1.4)
nokogiri (~> 1.3)

PLATFORMS
java
ruby

DEPENDENCIES
activerecord-jdbcsqlite3-adapter
appraisal (~> 0.4.0)
aruba
aws-sdk
aws-sdk (~> 1.3.8)
bundler
capybara
cocaine (~> 0.2)
Expand All @@ -132,7 +148,7 @@ DEPENDENCIES
fog
jruby-openssl
mocha
nokogiri (~> 1.4.7)
paperclip!
rake
shoulda
sqlite3 (~> 1.3.4)
sqlite3
12 changes: 6 additions & 6 deletions features/basic_integration.feature
Expand Up @@ -11,23 +11,23 @@ Feature: Rails integration
Scenario: Filesystem integration test
Given I add this snippet to the User model:
"""
has_attached_file :attachment
has_attached_file :attachment, :url => "/system/:attachment/:style/:filename"
"""
And I start the rails application
When I go to the new user page
And I fill in "Name" with "something"
And I attach the file "test/fixtures/5k.png" to "Attachment"
And I press "Submit"
Then I should see "Name: something"
And I should see an image with a path of "/system/users/attachments/000/000/001/original/5k.png"
And the file at "/system/users/attachments/000/000/001/original/5k.png" should be the same as "test/fixtures/5k.png"
And I should see an image with a path of "/system/attachments/original/5k.png"
And the file at "/system/attachments/original/5k.png" should be the same as "test/fixtures/5k.png"

Scenario: S3 Integration test
Given I add this snippet to the User model:
"""
has_attached_file :attachment,
:storage => :s3,
:path => "/:attachment/:id/:style/:filename",
:path => "/:attachment/:style/:filename",
:s3_credentials => Rails.root.join("config/s3.yml")
"""
And I write to "config/s3.yml" with:
Expand All @@ -42,5 +42,5 @@ Feature: Rails integration
And I attach the file "test/fixtures/5k.png" to "Attachment" on S3
And I press "Submit"
Then I should see "Name: something"
And I should see an image with a path of "http://s3.amazonaws.com/paperclip/attachments/1/original/5k.png"
And the file at "http://s3.amazonaws.com/paperclip/attachments/1/original/5k.png" should be uploaded to S3
And I should see an image with a path of "http://s3.amazonaws.com/paperclip/attachments/original/5k.png"
And the file at "http://s3.amazonaws.com/paperclip/attachments/original/5k.png" should be uploaded to S3
4 changes: 3 additions & 1 deletion features/step_definitions/rails_steps.rb
Expand Up @@ -7,7 +7,9 @@
"""
source "http://rubygems.org"
gem "rails", "#{framework_version}"
gem "sqlite3"
gem "sqlite3", :platform => :ruby
gem "activerecord-jdbcsqlite3-adapter", :platform => :jruby
gem "jruby-openssl", :platform => :jruby
gem "capybara"
gem "gherkin"
gem "aws-sdk"
Expand Down
2 changes: 2 additions & 0 deletions gemfiles/3.0.gemfile
Expand Up @@ -3,6 +3,8 @@
source "http://rubygems.org"

gem "jruby-openssl", :platform=>:jruby
gem "activerecord-jdbcsqlite3-adapter", :platform=>:jruby
gem "sqlite3", :platform=>:ruby
gem "rails", "~> 3.0.12"
gem "paperclip", :path=>"../"

Expand Down
2 changes: 2 additions & 0 deletions gemfiles/3.1.gemfile
Expand Up @@ -3,6 +3,8 @@
source "http://rubygems.org"

gem "jruby-openssl", :platform=>:jruby
gem "activerecord-jdbcsqlite3-adapter", :platform=>:jruby
gem "sqlite3", :platform=>:ruby
gem "rails", "~> 3.1.4"
gem "paperclip", :path=>"../"

Expand Down
2 changes: 2 additions & 0 deletions gemfiles/3.2.gemfile
Expand Up @@ -3,6 +3,8 @@
source "http://rubygems.org"

gem "jruby-openssl", :platform=>:jruby
gem "activerecord-jdbcsqlite3-adapter", :platform=>:jruby
gem "sqlite3", :platform=>:ruby
gem "rails", "~> 3.2.2"
gem "paperclip", :path=>"../"

Expand Down
1 change: 1 addition & 0 deletions lib/paperclip.rb
Expand Up @@ -33,6 +33,7 @@
require 'paperclip/iostream'
require 'paperclip/geometry'
require 'paperclip/processor'
require 'paperclip/tempfile'
require 'paperclip/thumbnail'
require 'paperclip/interpolations'
require 'paperclip/style'
Expand Down
22 changes: 0 additions & 22 deletions lib/paperclip/processor.rb
Expand Up @@ -70,26 +70,4 @@ def register_processor(name, processor)
@known_processors[name.to_s] = processor
end
end

# Due to how ImageMagick handles its image format conversion and how Tempfile
# handles its naming scheme, it is necessary to override how Tempfile makes
# its names so as to allow for file extensions. Idea taken from the comments
# on this blog post:
# http://marsorange.com/archives/of-mogrify-ruby-tempfile-dynamic-class-definitions
class Tempfile < ::Tempfile
# This is Ruby 1.8.7's implementation.
if RUBY_PLATFORM =~ /java/
def make_tmpname(basename, n)
case basename
when Array
prefix, suffix = *basename
else
prefix, suffix = basename, ''
end

t = Time.now.strftime("%y%m%d")
path = "#{prefix}#{t}-#{$$}-#{rand(0x100000000).to_s(36)}-#{n}#{suffix}"
end
end
end
end
41 changes: 41 additions & 0 deletions lib/paperclip/tempfile.rb
@@ -0,0 +1,41 @@
module Paperclip
# Overriding some implementation of Tempfile
class Tempfile < ::Tempfile
# Due to how ImageMagick handles its image format conversion and how
# Tempfile handles its naming scheme, it is necessary to override how
# Tempfile makes # its names so as to allow for file extensions. Idea
# taken from the comments on this blog post:
# http://marsorange.com/archives/of-mogrify-ruby-tempfile-dynamic-class-definitions
#
# This is Ruby 1.8.7's implementation.
def make_tmpname(basename, n)
if RUBY_PLATFORM =~ /java/
case basename
when Array
prefix, suffix = *basename
else
prefix, suffix = basename, ''
end

t = Time.now.strftime("%y%m%d")
path = "#{prefix}#{t}-#{$$}-#{rand(0x100000000).to_s(36)}-#{n}#{suffix}"
else
super
end
end
end

module TempfileEncoding
# This overrides Tempfile#binmode to make sure that the extenal encoding
# for binary mode is ASCII-8BIT. This behavior is what's in CRuby, but not
# in JRuby
def binmode
set_encoding('ASCII-8BIT')
super
end
end
end

if RUBY_PLATFORM =~ /java/
::Tempfile.send :include, Paperclip::TempfileEncoding
end
5 changes: 2 additions & 3 deletions paperclip.gemspec
Expand Up @@ -29,14 +29,13 @@ Gem::Specification.new do |s|
s.add_development_dependency('shoulda')
s.add_development_dependency('appraisal', '~> 0.4.0')
s.add_development_dependency('mocha')
s.add_development_dependency('aws-sdk')
s.add_development_dependency('sqlite3', '~> 1.3.4')
s.add_development_dependency('aws-sdk', '~> 1.3.8')
s.add_development_dependency('cucumber', '~> 1.1.0')
s.add_development_dependency('aruba')
s.add_development_dependency('nokogiri', '~> 1.4.7')
s.add_development_dependency('capybara')
s.add_development_dependency('bundler')
s.add_development_dependency('cocaine', '~> 0.2')
s.add_development_dependency('fog')
s.add_development_dependency('rake')
s.add_development_dependency('fakeweb')
end

0 comments on commit 8a758c2

Please sign in to comment.