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

Commit

Permalink
Remove Rails 2 support from Paperclip
Browse files Browse the repository at this point in the history
  • Loading branch information
sikachu committed Mar 23, 2012
1 parent 19aedbc commit 5232b19
Show file tree
Hide file tree
Showing 17 changed files with 113 additions and 226 deletions.
7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ before_script: "sudo ntpdate -ub ntp.ubuntu.com pool.ntp.org; true"
script: "bundle exec rake clean test cucumber"

gemfile:
- gemfiles/rails2.gemfile
- gemfiles/rails3.gemfile
- gemfiles/rails3_1.gemfile
- gemfiles/rails3_2.gemfile
- gemfiles/3.0.gemfile
- gemfiles/3.1.gemfile
- gemfiles/3.2.gemfile
18 changes: 6 additions & 12 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
appraise "rails2" do
gem "rails", "~> 2.3.14"
appraise "3.0" do
gem "rails", "~> 3.0.12"
gem "paperclip", :path => "../"
end

appraise "rails3" do
gem "rails", "~> 3.0.10"
appraise "3.1" do
gem "rails", "~> 3.1.4"
gem "paperclip", :path => "../"
end

appraise "rails3_1" do
gem "rails", "~> 3.1.0"
appraise "3.2" do
gem "rails", "~> 3.2.2"
gem "paperclip", :path => "../"
end

appraise "rails3_2" do
gem "rails", "~> 3.2.0"
gem "paperclip", :path => "../"
end

1 change: 0 additions & 1 deletion features/rake_tasks.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ Feature: Rake tasks
And I run a rails generator to generate a "User" scaffold with "name:string"
And I run a paperclip generator to add a paperclip "attachment" to the "User" model
And I run a migration
And I add the paperclip rake task to a Rails 2.3 application
And I add this snippet to the User model:
"""
has_attached_file :attachment, :path => ":rails_root/public/system/:attachment/:style/:filename"
Expand Down
90 changes: 13 additions & 77 deletions features/step_definitions/rails_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,33 +31,18 @@
end

Given /^I update my new user view to include the file upload field$/ do
if framework_version?("3")
steps %{
Given I overwrite "app/views/users/new.html.erb" with:
"""
<%= form_for @user, :html => { :multipart => true } do |f| %>
<%= f.label :name %>
<%= f.text_field :name %>
<%= f.label :attachment %>
<%= f.file_field :attachment %>
<%= submit_tag "Submit" %>
<% end %>
"""
}
else
steps %{
Given I overwrite "app/views/users/new.html.erb" with:
"""
<% form_for @user, :html => { :multipart => true } do |f| %>
<%= f.label :name %>
<%= f.text_field :name %>
<%= f.label :attachment %>
<%= f.file_field :attachment %>
<%= submit_tag "Submit" %>
<% end %>
"""
}
end
steps %{
Given I overwrite "app/views/users/new.html.erb" with:
"""
<%= form_for @user, :html => { :multipart => true } do |f| %>
<%= f.label :name %>
<%= f.text_field :name %>
<%= f.label :attachment %>
<%= f.file_field :attachment %>
<%= submit_tag "Submit" %>
<% end %>
"""
}
end

Given /^I update my user view to include the attachment$/ do
Expand Down Expand Up @@ -89,7 +74,7 @@
Rails::Application.reload!
end

When %r{I turn off class caching} do
When /^I turn off class caching$/ do
in_current_dir do
file = "config/environments/test.rb"
config = IO.read(file)
Expand All @@ -99,30 +84,6 @@
end
end

Given /^I update my application to use Bundler$/ do
if framework_version?("2")
boot_config_template = File.read('features/support/fixtures/boot_config.txt')
preinitializer_template = File.read('features/support/fixtures/preinitializer.txt')
gemfile_template = File.read('features/support/fixtures/gemfile.txt')
in_current_dir do
content = File.read("config/boot.rb").sub(/Rails\.boot!/, boot_config_template)
File.open("config/boot.rb", "w") { |file| file.write(content) }
File.open("config/preinitializer.rb", "w") { |file| file.write(preinitializer_template) }
File.open("Gemfile", "w") { |file| file.write(gemfile_template.sub(/RAILS_VERSION/, framework_version)) }
end
end
end

Given /^I add the paperclip rake task to a Rails 2.3 application$/ do
if framework_version?("2.3")
require 'fileutils'
source = File.expand_path('lib/tasks/paperclip.rake')
destination = in_current_dir { File.expand_path("lib/tasks") }
FileUtils.cp source, destination
append_to "Rakefile", "require 'paperclip'"
end
end

Then /^the file at "([^"]*)" should be the same as "([^"]*)"$/ do |web_file, path|
expected = IO.read(path)
actual = if web_file.match %r{^https?://}
Expand Down Expand Up @@ -155,28 +116,3 @@
When /^I comment out the gem "([^"]*)" from the Gemfile$/ do |gemname|
comment_out_gem_in_gemfile gemname
end

module FileHelpers
def append_to(path, contents)
in_current_dir do
File.open(path, "a") do |file|
file.puts
file.puts contents
end
end
end

def append_to_gemfile(contents)
append_to('Gemfile', contents)
end

def comment_out_gem_in_gemfile(gemname)
in_current_dir do
gemfile = File.read("Gemfile")
gemfile.sub!(/^(\s*)(gem\s*['"]#{gemname})/, "\\1# \\2")
File.open("Gemfile", 'w'){ |file| file.write(gemfile) }
end
end
end

World(FileHelpers)
24 changes: 24 additions & 0 deletions features/support/file_helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module FileHelpers
def append_to(path, contents)
in_current_dir do
File.open(path, "a") do |file|
file.puts
file.puts contents
end
end
end

def append_to_gemfile(contents)
append_to('Gemfile', contents)
end

def comment_out_gem_in_gemfile(gemname)
in_current_dir do
gemfile = File.read("Gemfile")
gemfile.sub!(/^(\s*)(gem\s*['"]#{gemname})/, "\\1# \\2")
File.open("Gemfile", 'w'){ |file| file.write(gemfile) }
end
end
end

World(FileHelpers)
6 changes: 3 additions & 3 deletions features/support/rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ def framework_version
end

def new_application_command
framework_version?("3") ? "rails new" : "rails"
"rails new"
end

def generator_command
framework_version?("3") ? "script/rails generate" : "script/generate"
"script/rails generate"
end

def runner_command
framework_version?("3") ? "script/rails runner" : "script/runner"
"script/rails runner"
end
end
World(RailsCommandHelpers)
2 changes: 1 addition & 1 deletion gemfiles/rails2.gemfile → gemfiles/3.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
source "http://rubygems.org"

gem "jruby-openssl", :platform=>:jruby
gem "rails", "~> 2.3.14"
gem "rails", "~> 3.0.12"
gem "paperclip", :path=>"../"

gemspec :path=>"../"
2 changes: 1 addition & 1 deletion gemfiles/rails3_1.gemfile → gemfiles/3.1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
source "http://rubygems.org"

gem "jruby-openssl", :platform=>:jruby
gem "rails", "~> 3.1.0"
gem "rails", "~> 3.1.4"
gem "paperclip", :path=>"../"

gemspec :path=>"../"
2 changes: 1 addition & 1 deletion gemfiles/rails3_2.gemfile → gemfiles/3.2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
source "http://rubygems.org"

gem "jruby-openssl", :platform=>:jruby
gem "rails", "~> 3.2.0"
gem "rails", "~> 3.2.2"
gem "paperclip", :path=>"../"

gemspec :path=>"../"
9 changes: 0 additions & 9 deletions gemfiles/rails3.gemfile

This file was deleted.

4 changes: 0 additions & 4 deletions init.rb

This file was deleted.

43 changes: 5 additions & 38 deletions lib/paperclip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
require 'paperclip/attachment'
require 'paperclip/attachment_options'
require 'paperclip/storage'
require 'paperclip/callback_compatibility'
require 'paperclip/callbacks'
require 'paperclip/glue'
require 'paperclip/missing_attachment_styles'
require 'paperclip/railtie'
require 'logger'
Expand Down Expand Up @@ -175,16 +176,6 @@ def class_for(class_name)
klass.const_defined?(partial_class_name) ? klass.const_get(partial_class_name, false) : klass.const_missing(partial_class_name)
end
end
rescue ArgumentError => e
# Sadly, we need to capture ArgumentError here because Rails 2.3.x
# ActiveSupport dependency management will try to the constant inherited
# from Object, and fail miserably with "Object is not missing constant X" error
# https://github.com/rails/rails/blob/v2.3.12/activesupport/lib/active_support/dependencies.rb#L124
if e.message =~ /is not missing constant/
raise NameError, "uninitialized constant #{class_name}"
else
raise e
end
end

def check_for_url_clash(name,url,klass)
Expand Down Expand Up @@ -216,18 +207,6 @@ class NotIdentifiedByImageMagickError < PaperclipError #:nodoc:
class InfiniteInterpolationError < PaperclipError #:nodoc:
end

module Glue
def self.included base #:nodoc:
base.extend ClassMethods
base.class_attribute :attachment_definitions if base.respond_to?(:class_attribute)
if base.respond_to?(:set_callback)
base.send :include, Paperclip::CallbackCompatability::Rails3
else
base.send :include, Paperclip::CallbackCompatability::Rails21
end
end
end

module ClassMethods
# +has_attached_file+ gives the class it is called on an attribute that maps to a file. This
# is typically a file stored somewhere on the filesystem and has been uploaded by a user.
Expand Down Expand Up @@ -312,17 +291,9 @@ def has_attached_file name, options = {}
include InstanceMethods

if attachment_definitions.nil?
if respond_to?(:class_attribute)
self.attachment_definitions = {}
else
write_inheritable_attribute(:attachment_definitions, {})
end
self.attachment_definitions = {}
else
if respond_to?(:class_attribute)
self.attachment_definitions = self.attachment_definitions.dup
else
write_inheritable_attribute(:attachment_definitions, self.attachment_definitions.dup)
end
self.attachment_definitions = self.attachment_definitions.dup
end

attachment_definitions[name] = Paperclip::AttachmentOptions.new(options)
Expand Down Expand Up @@ -433,11 +404,7 @@ def validates_attachment_content_type name, options = {}
# Returns the attachment definitions defined by each call to
# has_attached_file.
def attachment_definitions
if respond_to?(:class_attribute)
self.attachment_definitions
else
read_inheritable_attribute(:attachment_definitions)
end
self.attachment_definitions
end
end

Expand Down
61 changes: 0 additions & 61 deletions lib/paperclip/callback_compatibility.rb

This file was deleted.

Loading

0 comments on commit 5232b19

Please sign in to comment.