paperclip-youtube 2.3.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +26 -0
- data/README.md +91 -0
- data/Rakefile +80 -0
- data/generators/paperclip/USAGE +5 -0
- data/generators/paperclip/paperclip_generator.rb +27 -0
- data/generators/paperclip/templates/paperclip_migration.rb.erb +19 -0
- data/init.rb +1 -0
- data/lib/generators/paperclip/USAGE +8 -0
- data/lib/generators/paperclip/paperclip_generator.rb +31 -0
- data/lib/generators/paperclip/templates/paperclip_migration.rb.erb +19 -0
- data/lib/paperclip.rb +378 -0
- data/lib/paperclip/attachment.rb +376 -0
- data/lib/paperclip/callback_compatability.rb +61 -0
- data/lib/paperclip/command_line.rb +86 -0
- data/lib/paperclip/geometry.rb +115 -0
- data/lib/paperclip/interpolations.rb +130 -0
- data/lib/paperclip/iostream.rb +45 -0
- data/lib/paperclip/matchers.rb +33 -0
- data/lib/paperclip/matchers/have_attached_file_matcher.rb +57 -0
- data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +75 -0
- data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +54 -0
- data/lib/paperclip/matchers/validate_attachment_size_matcher.rb +95 -0
- data/lib/paperclip/processor.rb +58 -0
- data/lib/paperclip/railtie.rb +24 -0
- data/lib/paperclip/storage.rb +3 -0
- data/lib/paperclip/storage/filesystem.rb +73 -0
- data/lib/paperclip/storage/s3.rb +192 -0
- data/lib/paperclip/storage/youtube.rb +331 -0
- data/lib/paperclip/style.rb +90 -0
- data/lib/paperclip/thumbnail.rb +79 -0
- data/lib/paperclip/upfile.rb +55 -0
- data/lib/paperclip/version.rb +3 -0
- data/lib/tasks/paperclip.rake +72 -0
- data/rails/init.rb +2 -0
- data/shoulda_macros/paperclip.rb +118 -0
- data/test/attachment_test.rb +921 -0
- data/test/command_line_test.rb +138 -0
- data/test/database.yml +4 -0
- data/test/fixtures/12k.png +0 -0
- data/test/fixtures/50x50.png +0 -0
- data/test/fixtures/5k.png +0 -0
- data/test/fixtures/bad.png +1 -0
- data/test/fixtures/s3.yml +8 -0
- data/test/fixtures/text.txt +0 -0
- data/test/fixtures/twopage.pdf +0 -0
- data/test/fixtures/uppercase.PNG +0 -0
- data/test/geometry_test.rb +177 -0
- data/test/helper.rb +146 -0
- data/test/integration_test.rb +570 -0
- data/test/interpolations_test.rb +143 -0
- data/test/iostream_test.rb +71 -0
- data/test/matchers/have_attached_file_matcher_test.rb +24 -0
- data/test/matchers/validate_attachment_content_type_matcher_test.rb +47 -0
- data/test/matchers/validate_attachment_presence_matcher_test.rb +26 -0
- data/test/matchers/validate_attachment_size_matcher_test.rb +51 -0
- data/test/paperclip_test.rb +301 -0
- data/test/processor_test.rb +10 -0
- data/test/storage_test.rb +386 -0
- data/test/style_test.rb +141 -0
- data/test/thumbnail_test.rb +227 -0
- data/test/upfile_test.rb +36 -0
- metadata +195 -0
@@ -0,0 +1,138 @@
|
|
1
|
+
require './test/helper'
|
2
|
+
|
3
|
+
class CommandLineTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
Paperclip::CommandLine.path = nil
|
6
|
+
File.stubs(:exist?).with("/dev/null").returns(true)
|
7
|
+
end
|
8
|
+
|
9
|
+
should "allow colons in parameters" do
|
10
|
+
cmd = Paperclip::CommandLine.new("convert", "'a.jpg' -resize 175x220> -size 175x220 xc:black +swap -gravity center -composite 'b.jpg'", :swallow_stderr => false)
|
11
|
+
assert_equal "convert 'a.jpg' -resize 175x220> -size 175x220 xc:black +swap -gravity center -composite 'b.jpg'", cmd.command
|
12
|
+
end
|
13
|
+
|
14
|
+
should "take a command and parameters and produce a shell command for bash" do
|
15
|
+
cmd = Paperclip::CommandLine.new("convert", "a.jpg b.png", :swallow_stderr => false)
|
16
|
+
assert_equal "convert a.jpg b.png", cmd.command
|
17
|
+
end
|
18
|
+
|
19
|
+
should "be able to set a path and produce commands with that path" do
|
20
|
+
Paperclip::CommandLine.path = "/opt/bin"
|
21
|
+
cmd = Paperclip::CommandLine.new("convert", "a.jpg b.png", :swallow_stderr => false)
|
22
|
+
assert_equal "/opt/bin/convert a.jpg b.png", cmd.command
|
23
|
+
end
|
24
|
+
|
25
|
+
should "be able to interpolate quoted variables into the parameters" do
|
26
|
+
cmd = Paperclip::CommandLine.new("convert",
|
27
|
+
":one :{two}",
|
28
|
+
:one => "a.jpg",
|
29
|
+
:two => "b.png",
|
30
|
+
:swallow_stderr => false)
|
31
|
+
assert_equal "convert 'a.jpg' 'b.png'", cmd.command
|
32
|
+
end
|
33
|
+
|
34
|
+
should "quote command line options differently if we're on windows" do
|
35
|
+
File.stubs(:exist?).with("/dev/null").returns(false)
|
36
|
+
cmd = Paperclip::CommandLine.new("convert",
|
37
|
+
":one :{two}",
|
38
|
+
:one => "a.jpg",
|
39
|
+
:two => "b.png",
|
40
|
+
:swallow_stderr => false)
|
41
|
+
assert_equal 'convert "a.jpg" "b.png"', cmd.command
|
42
|
+
end
|
43
|
+
|
44
|
+
should "be able to quote and interpolate dangerous variables" do
|
45
|
+
cmd = Paperclip::CommandLine.new("convert",
|
46
|
+
":one :two",
|
47
|
+
:one => "`rm -rf`.jpg",
|
48
|
+
:two => "ha'ha.png",
|
49
|
+
:swallow_stderr => false)
|
50
|
+
assert_equal "convert '`rm -rf`.jpg' 'ha'\\''ha.png'", cmd.command
|
51
|
+
end
|
52
|
+
|
53
|
+
should "be able to quote and interpolate dangerous variables even on windows" do
|
54
|
+
File.stubs(:exist?).with("/dev/null").returns(false)
|
55
|
+
cmd = Paperclip::CommandLine.new("convert",
|
56
|
+
":one :two",
|
57
|
+
:one => "`rm -rf`.jpg",
|
58
|
+
:two => "ha'ha.png",
|
59
|
+
:swallow_stderr => false)
|
60
|
+
assert_equal %{convert "`rm -rf`.jpg" "ha'ha.png"}, cmd.command
|
61
|
+
end
|
62
|
+
|
63
|
+
should "add redirection to get rid of stderr in bash" do
|
64
|
+
File.stubs(:exist?).with("/dev/null").returns(true)
|
65
|
+
cmd = Paperclip::CommandLine.new("convert",
|
66
|
+
"a.jpg b.png",
|
67
|
+
:swallow_stderr => true)
|
68
|
+
|
69
|
+
assert_equal "convert a.jpg b.png 2>/dev/null", cmd.command
|
70
|
+
end
|
71
|
+
|
72
|
+
should "add redirection to get rid of stderr in cmd.exe" do
|
73
|
+
File.stubs(:exist?).with("/dev/null").returns(false)
|
74
|
+
cmd = Paperclip::CommandLine.new("convert",
|
75
|
+
"a.jpg b.png",
|
76
|
+
:swallow_stderr => true)
|
77
|
+
|
78
|
+
assert_equal "convert a.jpg b.png 2>NUL", cmd.command
|
79
|
+
end
|
80
|
+
|
81
|
+
should "raise if trying to interpolate :swallow_stderr or :expected_outcodes" do
|
82
|
+
cmd = Paperclip::CommandLine.new("convert",
|
83
|
+
":swallow_stderr :expected_outcodes",
|
84
|
+
:swallow_stderr => false,
|
85
|
+
:expected_outcodes => [0, 1])
|
86
|
+
assert_raise(Paperclip::PaperclipCommandLineError) do
|
87
|
+
cmd.command
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
should "run the #command it's given and return the output" do
|
92
|
+
cmd = Paperclip::CommandLine.new("convert", "a.jpg b.png", :swallow_stderr => false)
|
93
|
+
cmd.class.stubs(:"`").with("convert a.jpg b.png").returns(:correct_value)
|
94
|
+
with_exitstatus_returning(0) do
|
95
|
+
assert_equal :correct_value, cmd.run
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
should "raise a PaperclipCommandLineError if the result code isn't expected" do
|
100
|
+
cmd = Paperclip::CommandLine.new("convert", "a.jpg b.png", :swallow_stderr => false)
|
101
|
+
cmd.class.stubs(:"`").with("convert a.jpg b.png").returns(:correct_value)
|
102
|
+
with_exitstatus_returning(1) do
|
103
|
+
assert_raises(Paperclip::PaperclipCommandLineError) do
|
104
|
+
cmd.run
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
should "not raise a PaperclipCommandLineError if the result code is expected" do
|
110
|
+
cmd = Paperclip::CommandLine.new("convert",
|
111
|
+
"a.jpg b.png",
|
112
|
+
:expected_outcodes => [0, 1],
|
113
|
+
:swallow_stderr => false)
|
114
|
+
cmd.class.stubs(:"`").with("convert a.jpg b.png").returns(:correct_value)
|
115
|
+
with_exitstatus_returning(1) do
|
116
|
+
assert_nothing_raised do
|
117
|
+
cmd.run
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
should "log the command" do
|
123
|
+
cmd = Paperclip::CommandLine.new("convert", "a.jpg b.png", :swallow_stderr => false)
|
124
|
+
cmd.class.stubs(:'`')
|
125
|
+
Paperclip.expects(:log).with("convert a.jpg b.png")
|
126
|
+
cmd.run
|
127
|
+
end
|
128
|
+
|
129
|
+
should "detect that the system is unix or windows based on presence of /dev/null" do
|
130
|
+
File.stubs(:exist?).returns(true)
|
131
|
+
assert Paperclip::CommandLine.unix?
|
132
|
+
end
|
133
|
+
|
134
|
+
should "detect that the system is not unix or windows based on absence of /dev/null" do
|
135
|
+
File.stubs(:exist?).returns(false)
|
136
|
+
assert ! Paperclip::CommandLine.unix?
|
137
|
+
end
|
138
|
+
end
|
data/test/database.yml
ADDED
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1 @@
|
|
1
|
+
This is not an image.
|
File without changes
|
Binary file
|
Binary file
|
@@ -0,0 +1,177 @@
|
|
1
|
+
require './test/helper'
|
2
|
+
|
3
|
+
class GeometryTest < Test::Unit::TestCase
|
4
|
+
context "Paperclip::Geometry" do
|
5
|
+
should "correctly report its given dimensions" do
|
6
|
+
assert @geo = Paperclip::Geometry.new(1024, 768)
|
7
|
+
assert_equal 1024, @geo.width
|
8
|
+
assert_equal 768, @geo.height
|
9
|
+
end
|
10
|
+
|
11
|
+
should "set height to 0 if height dimension is missing" do
|
12
|
+
assert @geo = Paperclip::Geometry.new(1024)
|
13
|
+
assert_equal 1024, @geo.width
|
14
|
+
assert_equal 0, @geo.height
|
15
|
+
end
|
16
|
+
|
17
|
+
should "set width to 0 if width dimension is missing" do
|
18
|
+
assert @geo = Paperclip::Geometry.new(nil, 768)
|
19
|
+
assert_equal 0, @geo.width
|
20
|
+
assert_equal 768, @geo.height
|
21
|
+
end
|
22
|
+
|
23
|
+
should "be generated from a WxH-formatted string" do
|
24
|
+
assert @geo = Paperclip::Geometry.parse("800x600")
|
25
|
+
assert_equal 800, @geo.width
|
26
|
+
assert_equal 600, @geo.height
|
27
|
+
end
|
28
|
+
|
29
|
+
should "be generated from a xH-formatted string" do
|
30
|
+
assert @geo = Paperclip::Geometry.parse("x600")
|
31
|
+
assert_equal 0, @geo.width
|
32
|
+
assert_equal 600, @geo.height
|
33
|
+
end
|
34
|
+
|
35
|
+
should "be generated from a Wx-formatted string" do
|
36
|
+
assert @geo = Paperclip::Geometry.parse("800x")
|
37
|
+
assert_equal 800, @geo.width
|
38
|
+
assert_equal 0, @geo.height
|
39
|
+
end
|
40
|
+
|
41
|
+
should "be generated from a W-formatted string" do
|
42
|
+
assert @geo = Paperclip::Geometry.parse("800")
|
43
|
+
assert_equal 800, @geo.width
|
44
|
+
assert_equal 0, @geo.height
|
45
|
+
end
|
46
|
+
|
47
|
+
should "ensure the modifier is nil if not present" do
|
48
|
+
assert @geo = Paperclip::Geometry.parse("123x456")
|
49
|
+
assert_nil @geo.modifier
|
50
|
+
end
|
51
|
+
|
52
|
+
should "treat x and X the same in geometries" do
|
53
|
+
@lower = Paperclip::Geometry.parse("123x456")
|
54
|
+
@upper = Paperclip::Geometry.parse("123X456")
|
55
|
+
assert_equal 123, @lower.width
|
56
|
+
assert_equal 123, @upper.width
|
57
|
+
assert_equal 456, @lower.height
|
58
|
+
assert_equal 456, @upper.height
|
59
|
+
end
|
60
|
+
|
61
|
+
['>', '<', '#', '@', '%', '^', '!', nil].each do |mod|
|
62
|
+
should "ensure the modifier #{mod.inspect} is preserved" do
|
63
|
+
assert @geo = Paperclip::Geometry.parse("123x456#{mod}")
|
64
|
+
assert_equal mod, @geo.modifier
|
65
|
+
assert_equal "123x456#{mod}", @geo.to_s
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
['>', '<', '#', '@', '%', '^', '!', nil].each do |mod|
|
70
|
+
should "ensure the modifier #{mod.inspect} is preserved with no height" do
|
71
|
+
assert @geo = Paperclip::Geometry.parse("123x#{mod}")
|
72
|
+
assert_equal mod, @geo.modifier
|
73
|
+
assert_equal "123#{mod}", @geo.to_s
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
should "make sure the modifier gets passed during transformation_to" do
|
78
|
+
assert @src = Paperclip::Geometry.parse("123x456")
|
79
|
+
assert @dst = Paperclip::Geometry.parse("123x456>")
|
80
|
+
assert_equal ["123x456>", nil], @src.transformation_to(@dst)
|
81
|
+
end
|
82
|
+
|
83
|
+
should "generate correct ImageMagick formatting string for W-formatted string" do
|
84
|
+
assert @geo = Paperclip::Geometry.parse("800")
|
85
|
+
assert_equal "800", @geo.to_s
|
86
|
+
end
|
87
|
+
|
88
|
+
should "generate correct ImageMagick formatting string for Wx-formatted string" do
|
89
|
+
assert @geo = Paperclip::Geometry.parse("800x")
|
90
|
+
assert_equal "800", @geo.to_s
|
91
|
+
end
|
92
|
+
|
93
|
+
should "generate correct ImageMagick formatting string for xH-formatted string" do
|
94
|
+
assert @geo = Paperclip::Geometry.parse("x600")
|
95
|
+
assert_equal "x600", @geo.to_s
|
96
|
+
end
|
97
|
+
|
98
|
+
should "generate correct ImageMagick formatting string for WxH-formatted string" do
|
99
|
+
assert @geo = Paperclip::Geometry.parse("800x600")
|
100
|
+
assert_equal "800x600", @geo.to_s
|
101
|
+
end
|
102
|
+
|
103
|
+
should "be generated from a file" do
|
104
|
+
file = File.join(File.dirname(__FILE__), "fixtures", "5k.png")
|
105
|
+
file = File.new(file, 'rb')
|
106
|
+
assert_nothing_raised{ @geo = Paperclip::Geometry.from_file(file) }
|
107
|
+
assert @geo.height > 0
|
108
|
+
assert @geo.width > 0
|
109
|
+
end
|
110
|
+
|
111
|
+
should "be generated from a file path" do
|
112
|
+
file = File.join(File.dirname(__FILE__), "fixtures", "5k.png")
|
113
|
+
assert_nothing_raised{ @geo = Paperclip::Geometry.from_file(file) }
|
114
|
+
assert @geo.height > 0
|
115
|
+
assert @geo.width > 0
|
116
|
+
end
|
117
|
+
|
118
|
+
should "not generate from a bad file" do
|
119
|
+
file = "/home/This File Does Not Exist.omg"
|
120
|
+
assert_raise(Paperclip::NotIdentifiedByImageMagickError){ @geo = Paperclip::Geometry.from_file(file) }
|
121
|
+
end
|
122
|
+
|
123
|
+
[['vertical', 900, 1440, true, false, false, 1440, 900, 0.625],
|
124
|
+
['horizontal', 1024, 768, false, true, false, 1024, 768, 1.3333],
|
125
|
+
['square', 100, 100, false, false, true, 100, 100, 1]].each do |args|
|
126
|
+
context "performing calculations on a #{args[0]} viewport" do
|
127
|
+
setup do
|
128
|
+
@geo = Paperclip::Geometry.new(args[1], args[2])
|
129
|
+
end
|
130
|
+
|
131
|
+
should "#{args[3] ? "" : "not"} be vertical" do
|
132
|
+
assert_equal args[3], @geo.vertical?
|
133
|
+
end
|
134
|
+
|
135
|
+
should "#{args[4] ? "" : "not"} be horizontal" do
|
136
|
+
assert_equal args[4], @geo.horizontal?
|
137
|
+
end
|
138
|
+
|
139
|
+
should "#{args[5] ? "" : "not"} be square" do
|
140
|
+
assert_equal args[5], @geo.square?
|
141
|
+
end
|
142
|
+
|
143
|
+
should "report that #{args[6]} is the larger dimension" do
|
144
|
+
assert_equal args[6], @geo.larger
|
145
|
+
end
|
146
|
+
|
147
|
+
should "report that #{args[7]} is the smaller dimension" do
|
148
|
+
assert_equal args[7], @geo.smaller
|
149
|
+
end
|
150
|
+
|
151
|
+
should "have an aspect ratio of #{args[8]}" do
|
152
|
+
assert_in_delta args[8], @geo.aspect, 0.0001
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
[[ [1000, 100], [64, 64], "x64", "64x64+288+0" ],
|
158
|
+
[ [100, 1000], [50, 950], "x950", "50x950+22+0" ],
|
159
|
+
[ [100, 1000], [50, 25], "50x", "50x25+0+237" ]]. each do |args|
|
160
|
+
context "of #{args[0].inspect} and given a Geometry #{args[1].inspect} and sent transform_to" do
|
161
|
+
setup do
|
162
|
+
@geo = Paperclip::Geometry.new(*args[0])
|
163
|
+
@dst = Paperclip::Geometry.new(*args[1])
|
164
|
+
@scale, @crop = @geo.transformation_to @dst, true
|
165
|
+
end
|
166
|
+
|
167
|
+
should "be able to return the correct scaling transformation geometry #{args[2]}" do
|
168
|
+
assert_equal args[2], @scale
|
169
|
+
end
|
170
|
+
|
171
|
+
should "be able to return the correct crop transformation geometry #{args[3]}" do
|
172
|
+
assert_equal args[3], @crop
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'tempfile'
|
3
|
+
require 'test/unit'
|
4
|
+
|
5
|
+
require 'shoulda'
|
6
|
+
require 'mocha'
|
7
|
+
|
8
|
+
require 'active_record'
|
9
|
+
require 'active_record/version'
|
10
|
+
require 'active_support'
|
11
|
+
|
12
|
+
puts "Testing against version #{ActiveRecord::VERSION::STRING}"
|
13
|
+
|
14
|
+
`ruby -e 'exit 0'` # Prime $? with a value.
|
15
|
+
|
16
|
+
begin
|
17
|
+
require 'ruby-debug'
|
18
|
+
rescue LoadError => e
|
19
|
+
puts "debugger disabled"
|
20
|
+
end
|
21
|
+
|
22
|
+
ROOT = File.join(File.dirname(__FILE__), '..')
|
23
|
+
|
24
|
+
def silence_warnings
|
25
|
+
old_verbose, $VERBOSE = $VERBOSE, nil
|
26
|
+
yield
|
27
|
+
ensure
|
28
|
+
$VERBOSE = old_verbose
|
29
|
+
end
|
30
|
+
|
31
|
+
class Test::Unit::TestCase
|
32
|
+
def setup
|
33
|
+
silence_warnings do
|
34
|
+
Object.const_set(:Rails, stub('Rails', :root => ROOT, :env => 'test'))
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
$LOAD_PATH << File.join(ROOT, 'lib')
|
40
|
+
$LOAD_PATH << File.join(ROOT, 'lib', 'paperclip')
|
41
|
+
|
42
|
+
require File.join(ROOT, 'lib', 'paperclip.rb')
|
43
|
+
|
44
|
+
require './shoulda_macros/paperclip'
|
45
|
+
|
46
|
+
FIXTURES_DIR = File.join(File.dirname(__FILE__), "fixtures")
|
47
|
+
config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
|
48
|
+
ActiveRecord::Base.logger = ActiveSupport::BufferedLogger.new(File.dirname(__FILE__) + "/debug.log")
|
49
|
+
ActiveRecord::Base.establish_connection(config['test'])
|
50
|
+
|
51
|
+
def reset_class class_name
|
52
|
+
ActiveRecord::Base.send(:include, Paperclip::Glue)
|
53
|
+
Object.send(:remove_const, class_name) rescue nil
|
54
|
+
klass = Object.const_set(class_name, Class.new(ActiveRecord::Base))
|
55
|
+
klass.class_eval{ include Paperclip::Glue }
|
56
|
+
klass
|
57
|
+
end
|
58
|
+
|
59
|
+
def reset_table table_name, &block
|
60
|
+
block ||= lambda { |table| true }
|
61
|
+
ActiveRecord::Base.connection.create_table :dummies, {:force => true}, &block
|
62
|
+
end
|
63
|
+
|
64
|
+
def modify_table table_name, &block
|
65
|
+
ActiveRecord::Base.connection.change_table :dummies, &block
|
66
|
+
end
|
67
|
+
|
68
|
+
def rebuild_model options = {}
|
69
|
+
ActiveRecord::Base.connection.create_table :dummies, :force => true do |table|
|
70
|
+
table.column :other, :string
|
71
|
+
table.column :avatar_file_name, :string
|
72
|
+
table.column :avatar_content_type, :string
|
73
|
+
table.column :avatar_file_size, :integer
|
74
|
+
table.column :avatar_updated_at, :datetime
|
75
|
+
table.column :avatar_fingerprint, :string
|
76
|
+
end
|
77
|
+
rebuild_class options
|
78
|
+
end
|
79
|
+
|
80
|
+
def rebuild_class options = {}
|
81
|
+
ActiveRecord::Base.send(:include, Paperclip::Glue)
|
82
|
+
Object.send(:remove_const, "Dummy") rescue nil
|
83
|
+
Object.const_set("Dummy", Class.new(ActiveRecord::Base))
|
84
|
+
Dummy.class_eval do
|
85
|
+
include Paperclip::Glue
|
86
|
+
has_attached_file :avatar, options
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
class FakeModel
|
91
|
+
attr_accessor :avatar_file_name,
|
92
|
+
:avatar_file_size,
|
93
|
+
:avatar_updated_at,
|
94
|
+
:avatar_content_type,
|
95
|
+
:avatar_fingerprint,
|
96
|
+
:id
|
97
|
+
|
98
|
+
def errors
|
99
|
+
@errors ||= []
|
100
|
+
end
|
101
|
+
|
102
|
+
def run_paperclip_callbacks name, *args
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
def attachment options
|
108
|
+
Paperclip::Attachment.new(:avatar, FakeModel.new, options)
|
109
|
+
end
|
110
|
+
|
111
|
+
def silence_warnings
|
112
|
+
old_verbose, $VERBOSE = $VERBOSE, nil
|
113
|
+
yield
|
114
|
+
ensure
|
115
|
+
$VERBOSE = old_verbose
|
116
|
+
end
|
117
|
+
|
118
|
+
def should_accept_dummy_class
|
119
|
+
should "accept the class" do
|
120
|
+
assert_accepts @matcher, @dummy_class
|
121
|
+
end
|
122
|
+
|
123
|
+
should "accept an instance of that class" do
|
124
|
+
assert_accepts @matcher, @dummy_class.new
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def should_reject_dummy_class
|
129
|
+
should "reject the class" do
|
130
|
+
assert_rejects @matcher, @dummy_class
|
131
|
+
end
|
132
|
+
|
133
|
+
should "reject an instance of that class" do
|
134
|
+
assert_rejects @matcher, @dummy_class.new
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def with_exitstatus_returning(code)
|
139
|
+
saved_exitstatus = $?.nil? ? 0 : $?.exitstatus
|
140
|
+
begin
|
141
|
+
`ruby -e 'exit #{code.to_i}'`
|
142
|
+
yield
|
143
|
+
ensure
|
144
|
+
`ruby -e 'exit #{saved_exitstatus.to_i}'`
|
145
|
+
end
|
146
|
+
end
|