mender_paperclip 2.4.3
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +26 -0
- data/README.md +402 -0
- data/Rakefile +86 -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 +4 -0
- data/lib/generators/paperclip/USAGE +8 -0
- data/lib/generators/paperclip/paperclip_generator.rb +33 -0
- data/lib/generators/paperclip/templates/paperclip_migration.rb.erb +19 -0
- data/lib/paperclip/attachment.rb +454 -0
- data/lib/paperclip/callback_compatibility.rb +61 -0
- data/lib/paperclip/geometry.rb +120 -0
- data/lib/paperclip/interpolations.rb +181 -0
- data/lib/paperclip/iostream.rb +45 -0
- data/lib/paperclip/matchers/have_attached_file_matcher.rb +57 -0
- data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +81 -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/matchers.rb +33 -0
- data/lib/paperclip/missing_attachment_styles.rb +87 -0
- data/lib/paperclip/options.rb +79 -0
- data/lib/paperclip/processor.rb +58 -0
- data/lib/paperclip/railtie.rb +26 -0
- data/lib/paperclip/storage/filesystem.rb +81 -0
- data/lib/paperclip/storage/fog.rb +162 -0
- data/lib/paperclip/storage/s3.rb +262 -0
- data/lib/paperclip/storage.rb +3 -0
- data/lib/paperclip/style.rb +95 -0
- data/lib/paperclip/thumbnail.rb +105 -0
- data/lib/paperclip/upfile.rb +62 -0
- data/lib/paperclip/version.rb +3 -0
- data/lib/paperclip.rb +478 -0
- data/lib/tasks/paperclip.rake +97 -0
- data/rails/init.rb +2 -0
- data/shoulda_macros/paperclip.rb +124 -0
- data/test/attachment_test.rb +1120 -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/animated.gif +0 -0
- data/test/fixtures/bad.png +1 -0
- data/test/fixtures/fog.yml +8 -0
- data/test/fixtures/s3.yml +8 -0
- data/test/fixtures/spaced file.png +0 -0
- data/test/fixtures/text.txt +1 -0
- data/test/fixtures/twopage.pdf +0 -0
- data/test/fixtures/uppercase.PNG +0 -0
- data/test/fog_test.rb +191 -0
- data/test/geometry_test.rb +206 -0
- data/test/helper.rb +152 -0
- data/test/integration_test.rb +654 -0
- data/test/interpolations_test.rb +195 -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 +87 -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/options_test.rb +68 -0
- data/test/paperclip_missing_attachment_styles_test.rb +80 -0
- data/test/paperclip_test.rb +329 -0
- data/test/processor_test.rb +10 -0
- data/test/storage/filesystem_test.rb +52 -0
- data/test/storage/s3_live_test.rb +51 -0
- data/test/storage/s3_test.rb +633 -0
- data/test/style_test.rb +180 -0
- data/test/thumbnail_test.rb +383 -0
- data/test/upfile_test.rb +53 -0
- metadata +243 -0
@@ -0,0 +1,124 @@
|
|
1
|
+
require 'paperclip/matchers'
|
2
|
+
|
3
|
+
module Paperclip
|
4
|
+
# =Paperclip Shoulda Macros
|
5
|
+
#
|
6
|
+
# These macros are intended for use with shoulda, and will be included into
|
7
|
+
# your tests automatically. All of the macros use the standard shoulda
|
8
|
+
# assumption that the name of the test is based on the name of the model
|
9
|
+
# you're testing (that is, UserTest is the test for the User model), and
|
10
|
+
# will load that class for testing purposes.
|
11
|
+
module Shoulda
|
12
|
+
include Matchers
|
13
|
+
# This will test whether you have defined your attachment correctly by
|
14
|
+
# checking for all the required fields exist after the definition of the
|
15
|
+
# attachment.
|
16
|
+
def should_have_attached_file name
|
17
|
+
klass = self.name.gsub(/Test$/, '').constantize
|
18
|
+
matcher = have_attached_file name
|
19
|
+
should matcher.description do
|
20
|
+
assert_accepts(matcher, klass)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Tests for validations on the presence of the attachment.
|
25
|
+
def should_validate_attachment_presence name
|
26
|
+
klass = self.name.gsub(/Test$/, '').constantize
|
27
|
+
matcher = validate_attachment_presence name
|
28
|
+
should matcher.description do
|
29
|
+
assert_accepts(matcher, klass)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Tests that you have content_type validations specified. There are two
|
34
|
+
# options, :valid and :invalid. Both accept an array of strings. The
|
35
|
+
# strings should be a list of content types which will pass and fail
|
36
|
+
# validation, respectively.
|
37
|
+
def should_validate_attachment_content_type name, options = {}
|
38
|
+
klass = self.name.gsub(/Test$/, '').constantize
|
39
|
+
valid = [options[:valid]].flatten
|
40
|
+
invalid = [options[:invalid]].flatten
|
41
|
+
matcher = validate_attachment_content_type(name).allowing(valid).rejecting(invalid)
|
42
|
+
should matcher.description do
|
43
|
+
assert_accepts(matcher, klass)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Tests to ensure that you have file size validations turned on. You
|
48
|
+
# can pass the same options to this that you can to
|
49
|
+
# validate_attachment_file_size - :less_than, :greater_than, and :in.
|
50
|
+
# :less_than checks that a file is less than a certain size, :greater_than
|
51
|
+
# checks that a file is more than a certain size, and :in takes a Range or
|
52
|
+
# Array which specifies the lower and upper limits of the file size.
|
53
|
+
def should_validate_attachment_size name, options = {}
|
54
|
+
klass = self.name.gsub(/Test$/, '').constantize
|
55
|
+
min = options[:greater_than] || (options[:in] && options[:in].first) || 0
|
56
|
+
max = options[:less_than] || (options[:in] && options[:in].last) || (1.0/0)
|
57
|
+
range = (min..max)
|
58
|
+
matcher = validate_attachment_size(name).in(range)
|
59
|
+
should matcher.description do
|
60
|
+
assert_accepts(matcher, klass)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# Stubs the HTTP PUT for an attachment using S3 storage.
|
65
|
+
#
|
66
|
+
# @example
|
67
|
+
# stub_paperclip_s3('user', 'avatar', 'png')
|
68
|
+
def stub_paperclip_s3(model, attachment, extension)
|
69
|
+
definition = model.gsub(" ", "_").classify.constantize.
|
70
|
+
attachment_definitions[attachment.to_sym]
|
71
|
+
|
72
|
+
path = "http://s3.amazonaws.com/:id/#{definition[:path]}"
|
73
|
+
path.gsub!(/:([^\/\.]+)/) do |match|
|
74
|
+
"([^\/\.]+)"
|
75
|
+
end
|
76
|
+
|
77
|
+
begin
|
78
|
+
FakeWeb.register_uri(:put, Regexp.new(path), :body => "OK")
|
79
|
+
rescue NameError
|
80
|
+
raise NameError, "the stub_paperclip_s3 shoulda macro requires the fakeweb gem."
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
# Stub S3 and return a file for attachment. Best with Factory Girl.
|
85
|
+
# Uses a strict directory convention:
|
86
|
+
#
|
87
|
+
# features/support/paperclip
|
88
|
+
#
|
89
|
+
# This method is used by the Paperclip-provided Cucumber step:
|
90
|
+
#
|
91
|
+
# When I attach a "demo_tape" "mp3" file to a "band" on S3
|
92
|
+
#
|
93
|
+
# @example
|
94
|
+
# Factory.define :band_with_demo_tape, :parent => :band do |band|
|
95
|
+
# band.demo_tape { band.paperclip_fixture("band", "demo_tape", "png") }
|
96
|
+
# end
|
97
|
+
def paperclip_fixture(model, attachment, extension)
|
98
|
+
stub_paperclip_s3(model, attachment, extension)
|
99
|
+
base_path = File.join(File.dirname(__FILE__), "..", "..",
|
100
|
+
"features", "support", "paperclip")
|
101
|
+
File.new(File.join(base_path, model, "#{attachment}.#{extension}"))
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
if defined?(ActionController::Integration::Session)
|
107
|
+
class ActionController::Integration::Session #:nodoc:
|
108
|
+
include Paperclip::Shoulda
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
if defined?(FactoryGirl::Factory)
|
113
|
+
class FactoryGirl::Factory
|
114
|
+
include Paperclip::Shoulda #:nodoc:
|
115
|
+
end
|
116
|
+
else
|
117
|
+
class Factory
|
118
|
+
include Paperclip::Shoulda #:nodoc:
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
class Test::Unit::TestCase #:nodoc:
|
123
|
+
extend Paperclip::Shoulda
|
124
|
+
end
|