kt-paperclip 6.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.codeclimate.yml +17 -0
- data/.github/issue_template.md +3 -0
- data/.gitignore +19 -0
- data/.hound.yml +1050 -0
- data/.rubocop.yml +1 -0
- data/.travis.yml +47 -0
- data/Appraisals +24 -0
- data/CONTRIBUTING.md +86 -0
- data/Gemfile +18 -0
- data/LICENSE +24 -0
- data/NEWS +515 -0
- data/README.md +1053 -0
- data/RELEASING.md +17 -0
- data/Rakefile +52 -0
- data/UPGRADING +17 -0
- data/features/basic_integration.feature +85 -0
- data/features/migration.feature +29 -0
- data/features/rake_tasks.feature +62 -0
- data/features/step_definitions/attachment_steps.rb +110 -0
- data/features/step_definitions/html_steps.rb +15 -0
- data/features/step_definitions/rails_steps.rb +257 -0
- data/features/step_definitions/s3_steps.rb +14 -0
- data/features/step_definitions/web_steps.rb +106 -0
- data/features/support/env.rb +12 -0
- data/features/support/fakeweb.rb +11 -0
- data/features/support/file_helpers.rb +34 -0
- data/features/support/fixtures/boot_config.txt +15 -0
- data/features/support/fixtures/gemfile.txt +5 -0
- data/features/support/fixtures/preinitializer.txt +20 -0
- data/features/support/paths.rb +28 -0
- data/features/support/rails.rb +39 -0
- data/features/support/selectors.rb +19 -0
- data/gemfiles/4.2.gemfile +20 -0
- data/gemfiles/5.0.gemfile +20 -0
- data/gemfiles/5.1.gemfile +20 -0
- data/gemfiles/5.2.gemfile +20 -0
- data/gemfiles/6.0.gemfile +20 -0
- data/lib/generators/paperclip/USAGE +8 -0
- data/lib/generators/paperclip/paperclip_generator.rb +36 -0
- data/lib/generators/paperclip/templates/paperclip_migration.rb.erb +15 -0
- data/lib/paperclip.rb +215 -0
- data/lib/paperclip/attachment.rb +617 -0
- data/lib/paperclip/attachment_registry.rb +60 -0
- data/lib/paperclip/callbacks.rb +42 -0
- data/lib/paperclip/content_type_detector.rb +80 -0
- data/lib/paperclip/errors.rb +34 -0
- data/lib/paperclip/file_command_content_type_detector.rb +28 -0
- data/lib/paperclip/filename_cleaner.rb +15 -0
- data/lib/paperclip/geometry.rb +157 -0
- data/lib/paperclip/geometry_detector_factory.rb +45 -0
- data/lib/paperclip/geometry_parser_factory.rb +31 -0
- data/lib/paperclip/glue.rb +17 -0
- data/lib/paperclip/has_attached_file.rb +116 -0
- data/lib/paperclip/helpers.rb +60 -0
- data/lib/paperclip/interpolations.rb +201 -0
- data/lib/paperclip/interpolations/plural_cache.rb +18 -0
- data/lib/paperclip/io_adapters/abstract_adapter.rb +75 -0
- data/lib/paperclip/io_adapters/attachment_adapter.rb +47 -0
- data/lib/paperclip/io_adapters/data_uri_adapter.rb +22 -0
- data/lib/paperclip/io_adapters/empty_string_adapter.rb +19 -0
- data/lib/paperclip/io_adapters/file_adapter.rb +26 -0
- data/lib/paperclip/io_adapters/http_url_proxy_adapter.rb +16 -0
- data/lib/paperclip/io_adapters/identity_adapter.rb +17 -0
- data/lib/paperclip/io_adapters/nil_adapter.rb +37 -0
- data/lib/paperclip/io_adapters/registry.rb +36 -0
- data/lib/paperclip/io_adapters/stringio_adapter.rb +36 -0
- data/lib/paperclip/io_adapters/uploaded_file_adapter.rb +44 -0
- data/lib/paperclip/io_adapters/uri_adapter.rb +68 -0
- data/lib/paperclip/locales/en.yml +18 -0
- data/lib/paperclip/logger.rb +21 -0
- data/lib/paperclip/matchers.rb +64 -0
- data/lib/paperclip/matchers/have_attached_file_matcher.rb +54 -0
- data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +101 -0
- data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +59 -0
- data/lib/paperclip/matchers/validate_attachment_size_matcher.rb +97 -0
- data/lib/paperclip/media_type_spoof_detector.rb +90 -0
- data/lib/paperclip/missing_attachment_styles.rb +84 -0
- data/lib/paperclip/processor.rb +56 -0
- data/lib/paperclip/processor_helpers.rb +52 -0
- data/lib/paperclip/rails_environment.rb +21 -0
- data/lib/paperclip/railtie.rb +31 -0
- data/lib/paperclip/schema.rb +81 -0
- data/lib/paperclip/storage.rb +3 -0
- data/lib/paperclip/storage/filesystem.rb +99 -0
- data/lib/paperclip/storage/fog.rb +252 -0
- data/lib/paperclip/storage/s3.rb +461 -0
- data/lib/paperclip/style.rb +106 -0
- data/lib/paperclip/tempfile.rb +42 -0
- data/lib/paperclip/tempfile_factory.rb +22 -0
- data/lib/paperclip/thumbnail.rb +131 -0
- data/lib/paperclip/url_generator.rb +76 -0
- data/lib/paperclip/validators.rb +73 -0
- data/lib/paperclip/validators/attachment_content_type_validator.rb +88 -0
- data/lib/paperclip/validators/attachment_file_name_validator.rb +75 -0
- data/lib/paperclip/validators/attachment_file_type_ignorance_validator.rb +28 -0
- data/lib/paperclip/validators/attachment_presence_validator.rb +28 -0
- data/lib/paperclip/validators/attachment_size_validator.rb +109 -0
- data/lib/paperclip/validators/media_type_spoof_detection_validator.rb +29 -0
- data/lib/paperclip/version.rb +3 -0
- data/lib/tasks/paperclip.rake +140 -0
- data/paperclip.gemspec +50 -0
- data/shoulda_macros/paperclip.rb +134 -0
- data/spec/database.yml +4 -0
- data/spec/paperclip/attachment_definitions_spec.rb +13 -0
- data/spec/paperclip/attachment_processing_spec.rb +79 -0
- data/spec/paperclip/attachment_registry_spec.rb +158 -0
- data/spec/paperclip/attachment_spec.rb +1590 -0
- data/spec/paperclip/content_type_detector_spec.rb +47 -0
- data/spec/paperclip/file_command_content_type_detector_spec.rb +40 -0
- data/spec/paperclip/filename_cleaner_spec.rb +13 -0
- data/spec/paperclip/geometry_detector_spec.rb +38 -0
- data/spec/paperclip/geometry_parser_spec.rb +73 -0
- data/spec/paperclip/geometry_spec.rb +255 -0
- data/spec/paperclip/glue_spec.rb +42 -0
- data/spec/paperclip/has_attached_file_spec.rb +78 -0
- data/spec/paperclip/integration_spec.rb +702 -0
- data/spec/paperclip/interpolations_spec.rb +270 -0
- data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +160 -0
- data/spec/paperclip/io_adapters/attachment_adapter_spec.rb +140 -0
- data/spec/paperclip/io_adapters/data_uri_adapter_spec.rb +88 -0
- data/spec/paperclip/io_adapters/empty_string_adapter_spec.rb +17 -0
- data/spec/paperclip/io_adapters/file_adapter_spec.rb +131 -0
- data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +137 -0
- data/spec/paperclip/io_adapters/identity_adapter_spec.rb +8 -0
- data/spec/paperclip/io_adapters/nil_adapter_spec.rb +25 -0
- data/spec/paperclip/io_adapters/registry_spec.rb +35 -0
- data/spec/paperclip/io_adapters/stringio_adapter_spec.rb +64 -0
- data/spec/paperclip/io_adapters/uploaded_file_adapter_spec.rb +146 -0
- data/spec/paperclip/io_adapters/uri_adapter_spec.rb +221 -0
- data/spec/paperclip/matchers/have_attached_file_matcher_spec.rb +19 -0
- data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +108 -0
- data/spec/paperclip/matchers/validate_attachment_presence_matcher_spec.rb +69 -0
- data/spec/paperclip/matchers/validate_attachment_size_matcher_spec.rb +88 -0
- data/spec/paperclip/media_type_spoof_detector_spec.rb +120 -0
- data/spec/paperclip/meta_class_spec.rb +30 -0
- data/spec/paperclip/paperclip_missing_attachment_styles_spec.rb +88 -0
- data/spec/paperclip/paperclip_spec.rb +196 -0
- data/spec/paperclip/plural_cache_spec.rb +37 -0
- data/spec/paperclip/processor_helpers_spec.rb +57 -0
- data/spec/paperclip/processor_spec.rb +26 -0
- data/spec/paperclip/rails_environment_spec.rb +30 -0
- data/spec/paperclip/rake_spec.rb +103 -0
- data/spec/paperclip/schema_spec.rb +252 -0
- data/spec/paperclip/storage/filesystem_spec.rb +79 -0
- data/spec/paperclip/storage/fog_spec.rb +560 -0
- data/spec/paperclip/storage/s3_live_spec.rb +188 -0
- data/spec/paperclip/storage/s3_spec.rb +1695 -0
- data/spec/paperclip/style_spec.rb +251 -0
- data/spec/paperclip/tempfile_factory_spec.rb +33 -0
- data/spec/paperclip/tempfile_spec.rb +35 -0
- data/spec/paperclip/thumbnail_spec.rb +504 -0
- data/spec/paperclip/url_generator_spec.rb +221 -0
- data/spec/paperclip/validators/attachment_content_type_validator_spec.rb +322 -0
- data/spec/paperclip/validators/attachment_file_name_validator_spec.rb +159 -0
- data/spec/paperclip/validators/attachment_presence_validator_spec.rb +85 -0
- data/spec/paperclip/validators/attachment_size_validator_spec.rb +235 -0
- data/spec/paperclip/validators/media_type_spoof_detection_validator_spec.rb +48 -0
- data/spec/paperclip/validators_spec.rb +164 -0
- data/spec/spec_helper.rb +45 -0
- data/spec/support/assertions.rb +84 -0
- data/spec/support/fake_model.rb +24 -0
- data/spec/support/fake_rails.rb +12 -0
- data/spec/support/fixtures/12k.png +0 -0
- data/spec/support/fixtures/50x50.png +0 -0
- data/spec/support/fixtures/5k.png +0 -0
- data/spec/support/fixtures/animated +0 -0
- data/spec/support/fixtures/animated.gif +0 -0
- data/spec/support/fixtures/animated.unknown +0 -0
- data/spec/support/fixtures/bad.png +1 -0
- data/spec/support/fixtures/empty.html +1 -0
- data/spec/support/fixtures/empty.xlsx +0 -0
- data/spec/support/fixtures/fog.yml +8 -0
- data/spec/support/fixtures/rotated.jpg +0 -0
- data/spec/support/fixtures/s3.yml +8 -0
- data/spec/support/fixtures/spaced file.jpg +0 -0
- data/spec/support/fixtures/spaced file.png +0 -0
- data/spec/support/fixtures/text.txt +1 -0
- data/spec/support/fixtures/twopage.pdf +0 -0
- data/spec/support/fixtures/uppercase.PNG +0 -0
- data/spec/support/matchers/accept.rb +5 -0
- data/spec/support/matchers/exist.rb +5 -0
- data/spec/support/matchers/have_column.rb +23 -0
- data/spec/support/mock_attachment.rb +24 -0
- data/spec/support/mock_interpolator.rb +24 -0
- data/spec/support/mock_url_generator_builder.rb +26 -0
- data/spec/support/model_reconstruction.rb +72 -0
- data/spec/support/reporting.rb +11 -0
- data/spec/support/test_data.rb +13 -0
- data/spec/support/version_helper.rb +9 -0
- metadata +586 -0
@@ -0,0 +1,48 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Paperclip::Validators::MediaTypeSpoofDetectionValidator do
|
4
|
+
before do
|
5
|
+
rebuild_model
|
6
|
+
@dummy = Dummy.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def build_validator(options = {})
|
10
|
+
@validator = Paperclip::Validators::MediaTypeSpoofDetectionValidator.new(options.merge(
|
11
|
+
attributes: :avatar
|
12
|
+
))
|
13
|
+
end
|
14
|
+
|
15
|
+
it "is on the attachment without being explicitly added" do
|
16
|
+
assert Dummy.validators_on(:avatar).any? { |validator| validator.kind == :media_type_spoof_detection }
|
17
|
+
end
|
18
|
+
|
19
|
+
it "is not on the attachment when explicitly rejected" do
|
20
|
+
rebuild_model validate_media_type: false
|
21
|
+
assert Dummy.validators_on(:avatar).none? { |validator| validator.kind == :media_type_spoof_detection }
|
22
|
+
end
|
23
|
+
|
24
|
+
it "returns default error message for spoofed media type" do
|
25
|
+
build_validator
|
26
|
+
file = File.new(fixture_file("5k.png"), "rb")
|
27
|
+
@dummy.avatar.assign(file)
|
28
|
+
|
29
|
+
detector = double("detector", spoofed?: true)
|
30
|
+
allow(Paperclip::MediaTypeSpoofDetector).to receive(:using).and_return(detector)
|
31
|
+
@validator.validate(@dummy)
|
32
|
+
|
33
|
+
assert_equal I18n.t("errors.messages.spoofed_media_type"), @dummy.errors[:avatar].first
|
34
|
+
end
|
35
|
+
|
36
|
+
it "runs when attachment is dirty" do
|
37
|
+
build_validator
|
38
|
+
file = File.new(fixture_file("5k.png"), "rb")
|
39
|
+
@dummy.avatar.assign(file)
|
40
|
+
expect(Paperclip::MediaTypeSpoofDetector).to receive(:using).once.and_return(double("detector", spoofed?: false))
|
41
|
+
@dummy.valid?
|
42
|
+
end
|
43
|
+
|
44
|
+
it "does not run when attachment is not dirty" do
|
45
|
+
expect(Paperclip::MediaTypeSpoofDetector).to_not receive(:using)
|
46
|
+
@dummy.valid?
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,164 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Paperclip::Validators do
|
4
|
+
context "using the helper" do
|
5
|
+
before do
|
6
|
+
rebuild_class
|
7
|
+
Dummy.validates_attachment :avatar, presence: true, content_type: { content_type: "image/jpeg" }, size: { in: 0..10240 }
|
8
|
+
end
|
9
|
+
|
10
|
+
it "adds the attachment_presence validator to the class" do
|
11
|
+
assert Dummy.validators_on(:avatar).any? { |validator| validator.kind == :attachment_presence }
|
12
|
+
end
|
13
|
+
|
14
|
+
it "adds the attachment_content_type validator to the class" do
|
15
|
+
assert Dummy.validators_on(:avatar).any? { |validator| validator.kind == :attachment_content_type }
|
16
|
+
end
|
17
|
+
|
18
|
+
it "adds the attachment_size validator to the class" do
|
19
|
+
assert Dummy.validators_on(:avatar).any? { |validator| validator.kind == :attachment_size }
|
20
|
+
end
|
21
|
+
|
22
|
+
it "prevents you from attaching a file that violates that validation" do
|
23
|
+
Dummy.class_eval { validate(:name) { raise "DO NOT RUN THIS" } }
|
24
|
+
dummy = Dummy.new(avatar: File.new(fixture_file("12k.png")))
|
25
|
+
expect(dummy.errors.keys).to match_array [:avatar_content_type, :avatar, :avatar_file_size]
|
26
|
+
assert_raises(RuntimeError) { dummy.valid? }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "using the helper with array of validations" do
|
31
|
+
before do
|
32
|
+
rebuild_class
|
33
|
+
Dummy.validates_attachment :avatar, file_type_ignorance: true, file_name: [
|
34
|
+
{ matches: /\A.*\.jpe?g\z/i, message: :invalid_extension },
|
35
|
+
{ matches: /\A.{,8}\..+\z/i, message: [:too_long, count: 8] },
|
36
|
+
]
|
37
|
+
end
|
38
|
+
|
39
|
+
it "adds the attachment_file_name validator to the class" do
|
40
|
+
assert Dummy.validators_on(:avatar).any? { |validator| validator.kind == :attachment_file_name }
|
41
|
+
end
|
42
|
+
|
43
|
+
it "adds the attachment_file_name validator with two validations" do
|
44
|
+
assert_equal 2, Dummy.validators_on(:avatar).select { |validator| validator.kind == :attachment_file_name }.size
|
45
|
+
end
|
46
|
+
|
47
|
+
it "prevents you from attaching a file that violates all of these validations" do
|
48
|
+
Dummy.class_eval { validate(:name) { raise "DO NOT RUN THIS" } }
|
49
|
+
dummy = Dummy.new(avatar: File.new(fixture_file("spaced file.png")))
|
50
|
+
expect(dummy.errors.keys).to match_array [:avatar, :avatar_file_name]
|
51
|
+
assert_raises(RuntimeError) { dummy.valid? }
|
52
|
+
end
|
53
|
+
|
54
|
+
it "prevents you from attaching a file that violates only first of these validations" do
|
55
|
+
Dummy.class_eval { validate(:name) { raise "DO NOT RUN THIS" } }
|
56
|
+
dummy = Dummy.new(avatar: File.new(fixture_file("5k.png")))
|
57
|
+
expect(dummy.errors.keys).to match_array [:avatar, :avatar_file_name]
|
58
|
+
assert_raises(RuntimeError) { dummy.valid? }
|
59
|
+
end
|
60
|
+
|
61
|
+
it "prevents you from attaching a file that violates only second of these validations" do
|
62
|
+
Dummy.class_eval { validate(:name) { raise "DO NOT RUN THIS" } }
|
63
|
+
dummy = Dummy.new(avatar: File.new(fixture_file("spaced file.jpg")))
|
64
|
+
expect(dummy.errors.keys).to match_array [:avatar, :avatar_file_name]
|
65
|
+
assert_raises(RuntimeError) { dummy.valid? }
|
66
|
+
end
|
67
|
+
|
68
|
+
it "allows you to attach a file that does not violate these validations" do
|
69
|
+
dummy = Dummy.new(avatar: File.new(fixture_file("rotated.jpg")))
|
70
|
+
expect(dummy.errors.full_messages).to be_empty
|
71
|
+
assert dummy.valid?
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context "using the helper with a conditional" do
|
76
|
+
before do
|
77
|
+
rebuild_class
|
78
|
+
Dummy.validates_attachment :avatar, presence: true,
|
79
|
+
content_type: { content_type: "image/jpeg" },
|
80
|
+
size: { in: 0..10240 },
|
81
|
+
if: :title_present?
|
82
|
+
end
|
83
|
+
|
84
|
+
it "validates the attachment if title is present" do
|
85
|
+
Dummy.class_eval do
|
86
|
+
def title_present?
|
87
|
+
true
|
88
|
+
end
|
89
|
+
end
|
90
|
+
dummy = Dummy.new(avatar: File.new(fixture_file("12k.png")))
|
91
|
+
expect(dummy.errors.keys).to match_array [:avatar_content_type, :avatar, :avatar_file_size]
|
92
|
+
end
|
93
|
+
|
94
|
+
it "does not validate attachment if title is not present" do
|
95
|
+
Dummy.class_eval do
|
96
|
+
def title_present?
|
97
|
+
false
|
98
|
+
end
|
99
|
+
end
|
100
|
+
dummy = Dummy.new(avatar: File.new(fixture_file("12k.png")))
|
101
|
+
assert_equal [], dummy.errors.keys
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context "with no other validations on the Dummy#avatar attachment" do
|
106
|
+
before do
|
107
|
+
reset_class("Dummy")
|
108
|
+
Dummy.has_attached_file :avatar
|
109
|
+
Paperclip.reset_duplicate_clash_check!
|
110
|
+
end
|
111
|
+
|
112
|
+
it "raises an error when no content_type validation exists" do
|
113
|
+
assert_raises(Paperclip::Errors::MissingRequiredValidatorError) do
|
114
|
+
Dummy.new(avatar: File.new(fixture_file("12k.png")))
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
it "does not raise an error when a content_type validation exists" do
|
119
|
+
Dummy.validates_attachment :avatar, content_type: { content_type: "image/jpeg" }
|
120
|
+
|
121
|
+
assert_nothing_raised do
|
122
|
+
Dummy.new(avatar: File.new(fixture_file("12k.png")))
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
it "does not raise an error when a content_type validation exists using validates_with" do
|
127
|
+
Dummy.validates_with Paperclip::Validators::AttachmentContentTypeValidator, attributes: :attachment, content_type: "images/jpeg"
|
128
|
+
|
129
|
+
assert_nothing_raised do
|
130
|
+
Dummy.new(avatar: File.new(fixture_file("12k.png")))
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
it "does not raise an error when an inherited validator is used" do
|
135
|
+
class MyValidator < Paperclip::Validators::AttachmentContentTypeValidator
|
136
|
+
def initialize(options)
|
137
|
+
options[:content_type] = "images/jpeg" unless options.key?(:content_type)
|
138
|
+
super
|
139
|
+
end
|
140
|
+
end
|
141
|
+
Dummy.validates_with MyValidator, attributes: :attachment
|
142
|
+
|
143
|
+
assert_nothing_raised do
|
144
|
+
Dummy.new(avatar: File.new(fixture_file("12k.png")))
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
it "does not raise an error when a file_name validation exists" do
|
149
|
+
Dummy.validates_attachment :avatar, file_name: { matches: /png$/ }
|
150
|
+
|
151
|
+
assert_nothing_raised do
|
152
|
+
Dummy.new(avatar: File.new(fixture_file("12k.png")))
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
it "does not raise an error when a the validation has been explicitly rejected" do
|
157
|
+
Dummy.validates_attachment :avatar, file_type_ignorance: true
|
158
|
+
|
159
|
+
assert_nothing_raised do
|
160
|
+
Dummy.new(avatar: File.new(fixture_file("12k.png")))
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "rspec"
|
3
|
+
require "active_record"
|
4
|
+
require "active_record/version"
|
5
|
+
require "active_support"
|
6
|
+
require "active_support/core_ext"
|
7
|
+
require "ostruct"
|
8
|
+
require "pathname"
|
9
|
+
require "activerecord-import"
|
10
|
+
require "yaml"
|
11
|
+
|
12
|
+
ROOT = Pathname(File.expand_path(File.join(File.dirname(__FILE__), "..")))
|
13
|
+
|
14
|
+
puts "Testing against version #{ActiveRecord::VERSION::STRING}"
|
15
|
+
|
16
|
+
$LOAD_PATH << File.join(ROOT, "lib")
|
17
|
+
$LOAD_PATH << File.join(ROOT, "lib", "paperclip")
|
18
|
+
require File.join(ROOT, "lib", "paperclip.rb")
|
19
|
+
|
20
|
+
FIXTURES_DIR = File.join(File.dirname(__FILE__), "fixtures")
|
21
|
+
config = YAML::safe_load(IO.read(File.dirname(__FILE__) + "/database.yml"))
|
22
|
+
ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
|
23
|
+
ActiveRecord::Base.establish_connection(config["test"])
|
24
|
+
if ActiveRecord::VERSION::STRING >= "4.2" &&
|
25
|
+
ActiveRecord::VERSION::STRING < "5.0"
|
26
|
+
ActiveRecord::Base.raise_in_transactional_callbacks = true
|
27
|
+
end
|
28
|
+
Paperclip.options[:logger] = ActiveRecord::Base.logger
|
29
|
+
|
30
|
+
Dir[File.join(ROOT, "spec", "support", "**", "*.rb")].each { |f| require f }
|
31
|
+
|
32
|
+
Rails = FakeRails.new("test", Pathname.new(ROOT).join("tmp"))
|
33
|
+
ActiveSupport::Deprecation.silenced = true
|
34
|
+
|
35
|
+
RSpec.configure do |config|
|
36
|
+
config.include Assertions
|
37
|
+
config.include ModelReconstruction
|
38
|
+
config.include TestData
|
39
|
+
config.include Reporting
|
40
|
+
config.extend VersionHelper
|
41
|
+
|
42
|
+
config.before(:all) do
|
43
|
+
rebuild_model
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module Assertions
|
2
|
+
def assert(truthy, message = nil)
|
3
|
+
expect(!!truthy).to(eq(true), message)
|
4
|
+
end
|
5
|
+
|
6
|
+
def assert_equal(expected, actual, message = nil)
|
7
|
+
expect(actual).to(eq(expected), message)
|
8
|
+
end
|
9
|
+
|
10
|
+
def assert_not_equal(expected, actual, message = nil)
|
11
|
+
expect(actual).to_not(eq(expected), message)
|
12
|
+
end
|
13
|
+
|
14
|
+
def assert_raises(exception_class, message = nil, &block)
|
15
|
+
expect(&block).to raise_error(exception_class, message)
|
16
|
+
end
|
17
|
+
|
18
|
+
def assert_nothing_raised(&block)
|
19
|
+
expect(&block).to_not raise_error
|
20
|
+
end
|
21
|
+
|
22
|
+
def assert_nil(thing)
|
23
|
+
expect(thing).to be_nil
|
24
|
+
end
|
25
|
+
|
26
|
+
def assert_contains(haystack, needle)
|
27
|
+
expect(haystack).to include(needle)
|
28
|
+
end
|
29
|
+
|
30
|
+
def assert_match(pattern, value)
|
31
|
+
expect(value).to match(pattern)
|
32
|
+
end
|
33
|
+
|
34
|
+
def assert_no_match(pattern, value)
|
35
|
+
expect(value).to_not match(pattern)
|
36
|
+
end
|
37
|
+
|
38
|
+
def assert_file_exists(path_to_file)
|
39
|
+
expect(path_to_file).to exist
|
40
|
+
end
|
41
|
+
|
42
|
+
def assert_file_not_exists(path_to_file)
|
43
|
+
expect(path_to_file).to_not exist
|
44
|
+
end
|
45
|
+
|
46
|
+
def assert_empty(object)
|
47
|
+
expect(object).to be_empty
|
48
|
+
end
|
49
|
+
|
50
|
+
def assert_success_response(url)
|
51
|
+
url = "http:#{url}" unless url =~ /http/
|
52
|
+
Net::HTTP.get_response(URI.parse(url)) do |response|
|
53
|
+
assert_equal "200",
|
54
|
+
response.code,
|
55
|
+
"Expected HTTP response code 200, got #{response.code}"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def assert_not_found_response(url)
|
60
|
+
url = "http:#{url}" unless url =~ /http/
|
61
|
+
Net::HTTP.get_response(URI.parse(url)) do |response|
|
62
|
+
assert_equal "404", response.code,
|
63
|
+
"Expected HTTP response code 404, got #{response.code}"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def assert_forbidden_response(url)
|
68
|
+
url = "http:#{url}" unless url =~ /http/
|
69
|
+
Net::HTTP.get_response(URI.parse(url)) do |response|
|
70
|
+
assert_equal "403", response.code,
|
71
|
+
"Expected HTTP response code 403, got #{response.code}"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def assert_frame_dimensions(range, frames)
|
76
|
+
frames.each_with_index do |frame, frame_index|
|
77
|
+
frame.split("x").each_with_index do |dimension, dimension_index|
|
78
|
+
assert range.include?(dimension.to_i),
|
79
|
+
"Frame #{frame_index}[#{dimension_index}] should have been within #{range.inspect},
|
80
|
+
but was #{dimension}"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class FakeModel
|
2
|
+
attr_accessor(
|
3
|
+
:avatar_file_name,
|
4
|
+
:avatar_file_size,
|
5
|
+
:avatar_updated_at,
|
6
|
+
:avatar_content_type,
|
7
|
+
:avatar_fingerprint,
|
8
|
+
:id
|
9
|
+
)
|
10
|
+
|
11
|
+
def errors
|
12
|
+
@errors ||= []
|
13
|
+
end
|
14
|
+
|
15
|
+
def run_paperclip_callbacks(name, *args); end
|
16
|
+
|
17
|
+
def valid?
|
18
|
+
errors.empty?
|
19
|
+
end
|
20
|
+
|
21
|
+
def new_record?
|
22
|
+
false
|
23
|
+
end
|
24
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1 @@
|
|
1
|
+
This is not an image.
|
@@ -0,0 +1 @@
|
|
1
|
+
<html></html>
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1 @@
|
|
1
|
+
paperclip!
|
Binary file
|
Binary file
|