Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Remove Rails 2 support from Paperclip

  • Loading branch information...
commit 5232b192ddd958844d756a229e7cbdab91d745db 1 parent 19aedbc
@sikachu sikachu authored
View
7 .travis.yml
@@ -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
View
18 Appraisals
@@ -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
-
View
1  features/rake_tasks.feature
@@ -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"
View
90 features/step_definitions/rails_steps.rb
@@ -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
@@ -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)
@@ -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?://}
@@ -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)
View
24 features/support/file_helpers.rb
@@ -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)
View
6 features/support/rails.rb
@@ -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)
View
2  gemfiles/rails2.gemfile → gemfiles/3.0.gemfile
@@ -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=>"../"
View
2  gemfiles/rails3_1.gemfile → gemfiles/3.1.gemfile
@@ -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=>"../"
View
2  gemfiles/rails3_2.gemfile → gemfiles/3.2.gemfile
@@ -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=>"../"
View
9 gemfiles/rails3.gemfile
@@ -1,9 +0,0 @@
-# This file was generated by Appraisal
-
-source "http://rubygems.org"
-
-gem "jruby-openssl", :platform=>:jruby
-gem "rails", "~> 3.0.10"
-gem "paperclip", :path=>"../"
-
-gemspec :path=>"../"
View
4 init.rb
@@ -1,4 +0,0 @@
-require File.join(File.dirname(__FILE__), "lib", "paperclip")
-require 'paperclip/railtie'
-
-Paperclip::Railtie.insert
View
43 lib/paperclip.rb
@@ -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'
@@ -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)
@@ -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.
@@ -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)
@@ -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
View
61 lib/paperclip/callback_compatibility.rb
@@ -1,61 +0,0 @@
-module Paperclip
- module CallbackCompatability
- module Rails21
- def self.included(base)
- base.extend(Defining)
- base.send(:include, Running)
- end
-
- module Defining
- def define_paperclip_callbacks(*args)
- args.each do |callback|
- define_callbacks("before_#{callback}")
- define_callbacks("after_#{callback}")
- end
- end
- end
-
- module Running
- def run_paperclip_callbacks(callback, opts = nil, &blk)
- # The overall structure of this isn't ideal since after callbacks run even if
- # befores return false. But this is how rails 3's callbacks work, unfortunately.
- if run_callbacks(:"before_#{callback}"){ |result, object| result == false } != false
- blk.call
- end
- run_callbacks(:"after_#{callback}"){ |result, object| result == false }
- end
- end
- end
-
- module Rails3
- def self.included(base)
- base.extend(Defining)
- base.send(:include, Running)
- end
-
- module Defining
- def define_paperclip_callbacks(*callbacks)
- define_callbacks *[callbacks, {:terminator => "result == false"}].flatten
- callbacks.each do |callback|
- eval <<-end_callbacks
- def before_#{callback}(*args, &blk)
- set_callback(:#{callback}, :before, *args, &blk)
- end
- def after_#{callback}(*args, &blk)
- set_callback(:#{callback}, :after, *args, &blk)
- end
- end_callbacks
- end
- end
- end
-
- module Running
- def run_paperclip_callbacks(callback, opts = nil, &block)
- run_callbacks(callback, opts, &block)
- end
- end
-
- end
-
- end
-end
View
30 lib/paperclip/callbacks.rb
@@ -0,0 +1,30 @@
+module Paperclip
+ module Callbacks
+ def self.included(base)
+ base.extend(Defining)
+ base.send(:include, Running)
+ end
+
+ module Defining
+ def define_paperclip_callbacks(*callbacks)
+ define_callbacks *[callbacks, {:terminator => "result == false"}].flatten
+ callbacks.each do |callback|
+ eval <<-end_callbacks
+ def before_#{callback}(*args, &blk)
+ set_callback(:#{callback}, :before, *args, &blk)
+ end
+ def after_#{callback}(*args, &blk)
+ set_callback(:#{callback}, :after, *args, &blk)
+ end
+ end_callbacks
+ end
+ end
+ end
+
+ module Running
+ def run_paperclip_callbacks(callback, opts = nil, &block)
+ run_callbacks(callback, opts, &block)
+ end
+ end
+ end
+end
View
11 lib/paperclip/glue.rb
@@ -0,0 +1,11 @@
+require 'paperclip/callbacks'
+
+module Paperclip
+ module Glue
+ def self.included base #:nodoc:
+ base.extend ClassMethods
+ base.send :include, Callbacks
+ base.class_attribute :attachment_definitions
+ end
+ end
+end
View
23 lib/paperclip/railtie.rb
@@ -2,28 +2,25 @@
require 'paperclip/schema'
module Paperclip
- if defined? Rails::Railtie
- require 'rails'
- class Railtie < Rails::Railtie
- initializer 'paperclip.insert_into_active_record' do
- ActiveSupport.on_load :active_record do
- Paperclip::Railtie.insert
- end
- end
- rake_tasks do
- load "tasks/paperclip.rake"
+ require 'rails'
+ class Railtie < Rails::Railtie
+ initializer 'paperclip.insert_into_active_record' do
+ ActiveSupport.on_load :active_record do
+ Paperclip::Railtie.insert
end
end
+ rake_tasks do
+ load "tasks/paperclip.rake"
+ end
end
class Railtie
def self.insert
Paperclip.options[:logger] = Rails.logger if defined?(Rails)
-
+
if defined?(ActiveRecord)
- ActiveRecord::Base.send(:include, Paperclip::Glue)
Paperclip.options[:logger] = ActiveRecord::Base.logger
-
+ ActiveRecord::Base.send(:include, Paperclip::Glue)
ActiveRecord::ConnectionAdapters::AbstractAdapter.send(:include, Paperclip::Schema)
ActiveRecord::ConnectionAdapters::Table.send(:include, Paperclip::Schema)
ActiveRecord::ConnectionAdapters::TableDefinition.send(:include, Paperclip::Schema)
View
6 test/helper.rb
@@ -66,7 +66,11 @@ def reset_class class_name
ActiveRecord::Base.send(:include, Paperclip::Glue)
Object.send(:remove_const, class_name) rescue nil
klass = Object.const_set(class_name, Class.new(ActiveRecord::Base))
- klass.class_eval{ include Paperclip::Glue }
+
+ klass.class_eval do
+ include Paperclip::Glue
+ end
+
klass
end
Please sign in to comment.
Something went wrong with that request. Please try again.