Skip to content

Commit 488ffd2

Browse files
author
Jon Yurek
committed
Removed support for Rails 2.0.*, ensured support for 2.1.2
1 parent d8f45ee commit 488ffd2

File tree

6 files changed

+52
-55
lines changed

6 files changed

+52
-55
lines changed

lib/paperclip.rb

+6-1
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,12 @@ def validates_attachment_content_type name, options = {}
312312
types = [options.delete(:content_type)].flatten
313313
validates_each(:"#{name}_content_type", options) do |record, attr, value|
314314
unless types.any?{|t| t === value }
315-
record.errors.add(:"#{name}_content_type", :inclusion, :default => options[:message], :value => value)
315+
if record.errors.method(:add).arity == -2
316+
message = options[:message] || "is not one of #{types.join(", ")}"
317+
record.errors.add(:"#{name}_content_type", message)
318+
else
319+
record.errors.add(:"#{name}_content_type", :inclusion, :default => options[:message], :value => value)
320+
end
316321
end
317322
end
318323
end

lib/paperclip/callback_compatability.rb

-20
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,5 @@
11
module Paperclip
2-
# This module is intended as a compatability shim for the differences in
3-
# callbacks between Rails 2.0 and Rails 2.1.
42
module CallbackCompatability
5-
module Rails20
6-
def self.included(base)
7-
base.extend(Defining)
8-
base.send(:include, Running)
9-
puts "Including Rails 2.0 Compatability"
10-
end
11-
12-
module Defining
13-
def define_paperclip_callbacks(*args)
14-
end
15-
end
16-
17-
module Running
18-
def run_paperclip_callbacks(callback, opts = nil, &blk)
19-
end
20-
end
21-
end
22-
233
module Rails21
244
def self.included(base)
255
base.extend(Defining)

shoulda_macros/paperclip.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,10 @@ def paperclip_fixture(model, attachment, extension)
104104
end
105105
end
106106

107-
class ActionController::Integration::Session #:nodoc:
108-
include Paperclip::Shoulda
107+
if defined?(ActionController::Integration::Session)
108+
class ActionController::Integration::Session #:nodoc:
109+
include Paperclip::Shoulda
110+
end
109111
end
110112

111113
class Factory

test/attachment_test.rb

-5
Original file line numberDiff line numberDiff line change
@@ -399,17 +399,12 @@ def do_after_all; end
399399
end
400400

401401
should "cancel the processing if a before_post_process returns false" do
402-
begin
403-
$DEBUG = true
404402
@dummy.expects(:do_before_avatar).never
405403
@dummy.expects(:do_after_avatar).never
406404
@dummy.expects(:do_before_all).with().returns(false)
407405
@dummy.expects(:do_after_all)
408406
Paperclip::Thumbnail.expects(:make).never
409407
@dummy.avatar = @file
410-
ensure
411-
$DEBUG = false
412-
end
413408
end
414409

415410
should "cancel the processing if a before_avatar_post_process returns false" do

test/helper.rb

+34-9
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,45 @@
11
require 'rubygems'
2-
require 'test/unit'
3-
require 'shoulda'
42
require 'tempfile'
3+
require 'test/unit'
4+
require 'bundler'
55

6-
gem 'jferris-mocha'
6+
require 'shoulda'
77
require 'mocha'
88

9-
gem 'sqlite3-ruby'
9+
case ENV['RAILS_VERSION']
10+
when '2.1' then
11+
puts "Using Rails 2.1.2"
12+
gem 'activerecord', '2.1.2'
13+
gem 'activesupport', '2.1.2'
14+
gem 'actionpack', '2.1.2'
15+
16+
require 'activerecord'
17+
require 'activesupport'
18+
require 'actionpack'
19+
when '3.0' then
20+
puts "Using Rails 3.0.0.beta3"
21+
gem 'activerecord', '3.0.0.beta3'
22+
gem 'activesupport', '3.0.0.beta3'
23+
gem 'actionpack', '3.0.0.beta3'
24+
25+
require 'active_record'
26+
require 'active_support'
27+
require 'action_pack'
28+
else
29+
puts "Using Rails 2.3.5"
30+
gem 'activerecord', '2.3.5'
31+
gem 'activesupport', '2.3.5'
32+
gem 'actionpack', '2.3.5'
33+
34+
require 'active_record'
35+
require 'active_support'
36+
require 'action_pack'
37+
end
1038

11-
require 'activerecord'
12-
require 'activesupport'
13-
require 'actionpack'
1439
begin
1540
require 'ruby-debug'
16-
rescue LoadError
17-
puts "ruby-debug not loaded"
41+
rescue LoadError => e
42+
puts "debugger disabled"
1843
end
1944

2045
ROOT = File.join(File.dirname(__FILE__), '..')

test/paperclip_test.rb

+8-18
Original file line numberDiff line numberDiff line change
@@ -41,34 +41,24 @@ class PaperclipTest < Test::Unit::TestCase
4141
end
4242

4343
context "Calling Paperclip.run and logging" do
44-
setup do
44+
should "log the command when :log_command is true" do
4545
Paperclip.options[:image_magick_path] = nil
4646
Paperclip.options[:command_path] = nil
4747
Paperclip.stubs(:bit_bucket).returns("/dev/null")
48-
Paperclip.stubs(:log)
49-
Paperclip.stubs(:"`").with("this is the command 2>/dev/null")
50-
end
51-
52-
should "log the command when :log_command is true" do
48+
Paperclip.expects(:log).with("this is the command 2>/dev/null")
49+
Paperclip.expects(:"`").with("this is the command 2>/dev/null")
5350
Paperclip.options[:log_command] = true
5451
Paperclip.run("this","is the command")
55-
assert_received(Paperclip, :log) do |p|
56-
p.with("this is the command 2>/dev/null")
57-
end
58-
assert_received(Paperclip, :`) do |p|
59-
p.with("this is the command 2>/dev/null")
60-
end
6152
end
6253

6354
should "not log the command when :log_command is false" do
55+
Paperclip.options[:image_magick_path] = nil
56+
Paperclip.options[:command_path] = nil
57+
Paperclip.stubs(:bit_bucket).returns("/dev/null")
58+
Paperclip.expects(:log).with("this is the command 2>/dev/null").never
59+
Paperclip.expects(:"`").with("this is the command 2>/dev/null")
6460
Paperclip.options[:log_command] = false
6561
Paperclip.run("this","is the command")
66-
assert_received(Paperclip, :log) do |p|
67-
p.with("this is the command 2>/dev/null").never
68-
end
69-
assert_received(Paperclip, :`) do |p|
70-
p.with("this is the command 2>/dev/null")
71-
end
7262
end
7363
end
7464

0 commit comments

Comments
 (0)