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

Commit

Permalink
Removed support for Rails 2.0.*, ensured support for 2.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Yurek committed Apr 26, 2010
1 parent d8f45ee commit 488ffd2
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 55 deletions.
7 changes: 6 additions & 1 deletion lib/paperclip.rb
Expand Up @@ -312,7 +312,12 @@ def validates_attachment_content_type name, options = {}
types = [options.delete(:content_type)].flatten
validates_each(:"#{name}_content_type", options) do |record, attr, value|
unless types.any?{|t| t === value }
record.errors.add(:"#{name}_content_type", :inclusion, :default => options[:message], :value => value)
if record.errors.method(:add).arity == -2
message = options[:message] || "is not one of #{types.join(", ")}"
record.errors.add(:"#{name}_content_type", message)
else
record.errors.add(:"#{name}_content_type", :inclusion, :default => options[:message], :value => value)
end
end
end
end
Expand Down
20 changes: 0 additions & 20 deletions lib/paperclip/callback_compatability.rb
@@ -1,25 +1,5 @@
module Paperclip
# This module is intended as a compatability shim for the differences in
# callbacks between Rails 2.0 and Rails 2.1.
module CallbackCompatability
module Rails20
def self.included(base)
base.extend(Defining)
base.send(:include, Running)
puts "Including Rails 2.0 Compatability"
end

module Defining
def define_paperclip_callbacks(*args)
end
end

module Running
def run_paperclip_callbacks(callback, opts = nil, &blk)
end
end
end

module Rails21
def self.included(base)
base.extend(Defining)
Expand Down
6 changes: 4 additions & 2 deletions shoulda_macros/paperclip.rb
Expand Up @@ -104,8 +104,10 @@ def paperclip_fixture(model, attachment, extension)
end
end

class ActionController::Integration::Session #:nodoc:
include Paperclip::Shoulda
if defined?(ActionController::Integration::Session)
class ActionController::Integration::Session #:nodoc:
include Paperclip::Shoulda
end
end

class Factory
Expand Down
5 changes: 0 additions & 5 deletions test/attachment_test.rb
Expand Up @@ -399,17 +399,12 @@ def do_after_all; end
end

should "cancel the processing if a before_post_process returns false" do
begin
$DEBUG = true
@dummy.expects(:do_before_avatar).never
@dummy.expects(:do_after_avatar).never
@dummy.expects(:do_before_all).with().returns(false)
@dummy.expects(:do_after_all)
Paperclip::Thumbnail.expects(:make).never
@dummy.avatar = @file
ensure
$DEBUG = false
end
end

should "cancel the processing if a before_avatar_post_process returns false" do
Expand Down
43 changes: 34 additions & 9 deletions test/helper.rb
@@ -1,20 +1,45 @@
require 'rubygems'
require 'test/unit'
require 'shoulda'
require 'tempfile'
require 'test/unit'
require 'bundler'

gem 'jferris-mocha'
require 'shoulda'
require 'mocha'

gem 'sqlite3-ruby'
case ENV['RAILS_VERSION']
when '2.1' then
puts "Using Rails 2.1.2"
gem 'activerecord', '2.1.2'
gem 'activesupport', '2.1.2'
gem 'actionpack', '2.1.2'

require 'activerecord'
require 'activesupport'
require 'actionpack'
when '3.0' then
puts "Using Rails 3.0.0.beta3"
gem 'activerecord', '3.0.0.beta3'
gem 'activesupport', '3.0.0.beta3'
gem 'actionpack', '3.0.0.beta3'

require 'active_record'
require 'active_support'
require 'action_pack'
else
puts "Using Rails 2.3.5"
gem 'activerecord', '2.3.5'
gem 'activesupport', '2.3.5'
gem 'actionpack', '2.3.5'

require 'active_record'
require 'active_support'
require 'action_pack'
end

require 'activerecord'
require 'activesupport'
require 'actionpack'
begin
require 'ruby-debug'
rescue LoadError
puts "ruby-debug not loaded"
rescue LoadError => e
puts "debugger disabled"
end

ROOT = File.join(File.dirname(__FILE__), '..')
Expand Down
26 changes: 8 additions & 18 deletions test/paperclip_test.rb
Expand Up @@ -41,34 +41,24 @@ class PaperclipTest < Test::Unit::TestCase
end

context "Calling Paperclip.run and logging" do
setup do
should "log the command when :log_command is true" do
Paperclip.options[:image_magick_path] = nil
Paperclip.options[:command_path] = nil
Paperclip.stubs(:bit_bucket).returns("/dev/null")
Paperclip.stubs(:log)
Paperclip.stubs(:"`").with("this is the command 2>/dev/null")
end

should "log the command when :log_command is true" do
Paperclip.expects(:log).with("this is the command 2>/dev/null")
Paperclip.expects(:"`").with("this is the command 2>/dev/null")
Paperclip.options[:log_command] = true
Paperclip.run("this","is the command")
assert_received(Paperclip, :log) do |p|
p.with("this is the command 2>/dev/null")
end
assert_received(Paperclip, :`) do |p|
p.with("this is the command 2>/dev/null")
end
end

should "not log the command when :log_command is false" do
Paperclip.options[:image_magick_path] = nil
Paperclip.options[:command_path] = nil
Paperclip.stubs(:bit_bucket).returns("/dev/null")
Paperclip.expects(:log).with("this is the command 2>/dev/null").never
Paperclip.expects(:"`").with("this is the command 2>/dev/null")
Paperclip.options[:log_command] = false
Paperclip.run("this","is the command")
assert_received(Paperclip, :log) do |p|
p.with("this is the command 2>/dev/null").never
end
assert_received(Paperclip, :`) do |p|
p.with("this is the command 2>/dev/null")
end
end
end

Expand Down

0 comments on commit 488ffd2

Please sign in to comment.