kt-paperclip 5.4.0 → 6.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/issue_template.md +3 -0
- data/.hound.yml +27 -32
- data/.travis.yml +23 -2
- data/Appraisals +17 -0
- data/Gemfile +9 -7
- data/NEWS +21 -0
- data/README.md +27 -37
- data/Rakefile +29 -21
- data/UPGRADING +3 -3
- data/features/basic_integration.feature +4 -0
- data/features/migration.feature +10 -51
- data/features/step_definitions/attachment_steps.rb +12 -12
- data/features/step_definitions/html_steps.rb +5 -5
- data/features/step_definitions/rails_steps.rb +29 -9
- data/features/step_definitions/s3_steps.rb +3 -3
- data/features/step_definitions/web_steps.rb +5 -6
- data/features/support/env.rb +4 -4
- data/features/support/fakeweb.rb +3 -5
- data/features/support/file_helpers.rb +2 -2
- data/features/support/paths.rb +4 -4
- data/features/support/rails.rb +7 -7
- data/features/support/selectors.rb +1 -1
- data/gemfiles/4.2.gemfile +7 -4
- data/gemfiles/5.0.gemfile +7 -4
- 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/paperclip_generator.rb +6 -8
- data/lib/paperclip/attachment.rb +102 -104
- data/lib/paperclip/attachment_registry.rb +2 -2
- data/lib/paperclip/file_command_content_type_detector.rb +1 -3
- data/lib/paperclip/filename_cleaner.rb +0 -1
- data/lib/paperclip/geometry.rb +18 -19
- data/lib/paperclip/geometry_detector_factory.rb +13 -16
- data/lib/paperclip/geometry_parser_factory.rb +5 -5
- data/lib/paperclip/glue.rb +3 -3
- data/lib/paperclip/has_attached_file.rb +5 -4
- data/lib/paperclip/helpers.rb +3 -3
- data/lib/paperclip/interpolations.rb +42 -38
- data/lib/paperclip/io_adapters/abstract_adapter.rb +16 -14
- data/lib/paperclip/io_adapters/attachment_adapter.rb +12 -6
- data/lib/paperclip/io_adapters/data_uri_adapter.rb +1 -1
- data/lib/paperclip/io_adapters/file_adapter.rb +1 -3
- data/lib/paperclip/io_adapters/http_url_proxy_adapter.rb +3 -3
- data/lib/paperclip/io_adapters/identity_adapter.rb +1 -2
- data/lib/paperclip/io_adapters/registry.rb +1 -1
- data/lib/paperclip/io_adapters/stringio_adapter.rb +1 -1
- data/lib/paperclip/io_adapters/uploaded_file_adapter.rb +6 -8
- data/lib/paperclip/io_adapters/uri_adapter.rb +9 -7
- data/lib/paperclip/logger.rb +1 -1
- data/lib/paperclip/matchers/have_attached_file_matcher.rb +4 -4
- data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +19 -18
- data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +4 -4
- data/lib/paperclip/matchers/validate_attachment_size_matcher.rb +11 -10
- data/lib/paperclip/matchers.rb +4 -4
- data/lib/paperclip/media_type_spoof_detector.rb +13 -13
- data/lib/paperclip/missing_attachment_styles.rb +11 -6
- data/lib/paperclip/processor.rb +13 -6
- data/lib/paperclip/processor_helpers.rb +3 -1
- data/lib/paperclip/rails_environment.rb +1 -5
- data/lib/paperclip/railtie.rb +5 -5
- data/lib/paperclip/schema.rb +18 -14
- data/lib/paperclip/storage/filesystem.rb +5 -7
- data/lib/paperclip/storage/fog.rb +36 -32
- data/lib/paperclip/storage/s3.rb +67 -75
- data/lib/paperclip/style.rb +3 -6
- data/lib/paperclip/tempfile.rb +4 -5
- data/lib/paperclip/tempfile_factory.rb +0 -1
- data/lib/paperclip/thumbnail.rb +11 -11
- data/lib/paperclip/url_generator.rb +5 -12
- data/lib/paperclip/validators/attachment_content_type_validator.rb +3 -3
- data/lib/paperclip/validators/attachment_file_name_validator.rb +5 -10
- data/lib/paperclip/validators/attachment_file_type_ignorance_validator.rb +1 -2
- data/lib/paperclip/validators/attachment_presence_validator.rb +3 -5
- data/lib/paperclip/validators/attachment_size_validator.rb +8 -8
- data/lib/paperclip/validators/media_type_spoof_detection_validator.rb +3 -1
- data/lib/paperclip/validators.rb +12 -13
- data/lib/paperclip/version.rb +1 -3
- data/lib/paperclip.rb +49 -48
- data/lib/tasks/paperclip.rake +23 -24
- data/paperclip.gemspec +29 -33
- data/shoulda_macros/paperclip.rb +16 -16
- data/spec/paperclip/attachment_definitions_spec.rb +5 -5
- data/spec/paperclip/attachment_processing_spec.rb +22 -23
- data/spec/paperclip/attachment_registry_spec.rb +15 -15
- data/spec/paperclip/attachment_spec.rb +238 -196
- data/spec/paperclip/content_type_detector_spec.rb +11 -12
- data/spec/paperclip/file_command_content_type_detector_spec.rb +10 -10
- data/spec/paperclip/filename_cleaner_spec.rb +3 -4
- data/spec/paperclip/geometry_detector_spec.rb +7 -8
- data/spec/paperclip/geometry_parser_spec.rb +31 -31
- data/spec/paperclip/geometry_spec.rb +24 -24
- data/spec/paperclip/glue_spec.rb +3 -5
- data/spec/paperclip/has_attached_file_spec.rb +46 -126
- data/spec/paperclip/integration_spec.rb +111 -77
- data/spec/paperclip/interpolations_spec.rb +101 -93
- data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +41 -13
- data/spec/paperclip/io_adapters/attachment_adapter_spec.rb +8 -10
- data/spec/paperclip/io_adapters/data_uri_adapter_spec.rb +13 -14
- data/spec/paperclip/io_adapters/empty_string_adapter_spec.rb +4 -4
- data/spec/paperclip/io_adapters/file_adapter_spec.rb +12 -12
- data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +42 -26
- data/spec/paperclip/io_adapters/identity_adapter_spec.rb +1 -1
- data/spec/paperclip/io_adapters/nil_adapter_spec.rb +2 -2
- data/spec/paperclip/io_adapters/registry_spec.rb +4 -4
- data/spec/paperclip/io_adapters/stringio_adapter_spec.rb +10 -10
- data/spec/paperclip/io_adapters/uploaded_file_adapter_spec.rb +6 -6
- data/spec/paperclip/io_adapters/uri_adapter_spec.rb +80 -31
- data/spec/paperclip/matchers/have_attached_file_matcher_spec.rb +3 -3
- data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +4 -5
- data/spec/paperclip/matchers/validate_attachment_presence_matcher_spec.rb +4 -4
- data/spec/paperclip/matchers/validate_attachment_size_matcher_spec.rb +4 -4
- data/spec/paperclip/media_type_spoof_detector_spec.rb +50 -24
- data/spec/paperclip/meta_class_spec.rb +3 -3
- data/spec/paperclip/paperclip_missing_attachment_styles_spec.rb +28 -24
- data/spec/paperclip/paperclip_spec.rb +15 -11
- data/spec/paperclip/plural_cache_spec.rb +8 -8
- data/spec/paperclip/processor_helpers_spec.rb +35 -35
- data/spec/paperclip/processor_spec.rb +8 -8
- data/spec/paperclip/rails_environment_spec.rb +7 -10
- data/spec/paperclip/rake_spec.rb +39 -39
- data/spec/paperclip/schema_spec.rb +57 -53
- data/spec/paperclip/storage/filesystem_spec.rb +6 -6
- data/spec/paperclip/storage/fog_spec.rb +76 -82
- data/spec/paperclip/storage/s3_live_spec.rb +22 -22
- data/spec/paperclip/storage/s3_spec.rb +585 -583
- data/spec/paperclip/style_spec.rb +67 -71
- data/spec/paperclip/tempfile_factory_spec.rb +5 -5
- data/spec/paperclip/thumbnail_spec.rb +68 -67
- data/spec/paperclip/url_generator_spec.rb +18 -29
- data/spec/paperclip/validators/attachment_content_type_validator_spec.rb +27 -27
- data/spec/paperclip/validators/attachment_file_name_validator_spec.rb +15 -16
- data/spec/paperclip/validators/attachment_presence_validator_spec.rb +5 -5
- data/spec/paperclip/validators/attachment_size_validator_spec.rb +21 -21
- data/spec/paperclip/validators/media_type_spoof_detection_validator_spec.rb +9 -13
- data/spec/paperclip/validators_spec.rb +40 -40
- data/spec/spec_helper.rb +21 -23
- data/spec/support/assertions.rb +8 -6
- data/spec/support/fake_model.rb +1 -2
- data/spec/support/fake_rails.rb +1 -1
- data/spec/support/matchers/exist.rb +1 -1
- data/spec/support/matchers/have_column.rb +1 -1
- data/spec/support/mock_url_generator_builder.rb +2 -3
- data/spec/support/model_reconstruction.rb +16 -12
- data/spec/support/reporting.rb +1 -1
- data/spec/support/test_data.rb +2 -2
- metadata +49 -105
- data/lib/kt-paperclip.rb +0 -1
- data/spec/support/conditional_filter_helper.rb +0 -5
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Paperclip::Validators::MediaTypeSpoofDetectionValidator do
|
4
4
|
before do
|
@@ -8,17 +8,17 @@ describe Paperclip::Validators::MediaTypeSpoofDetectionValidator do
|
|
8
8
|
|
9
9
|
def build_validator(options = {})
|
10
10
|
@validator = Paperclip::Validators::MediaTypeSpoofDetectionValidator.new(options.merge(
|
11
|
-
|
12
|
-
|
11
|
+
attributes: :avatar
|
12
|
+
))
|
13
13
|
end
|
14
14
|
|
15
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 }
|
16
|
+
assert Dummy.validators_on(:avatar).any? { |validator| validator.kind == :media_type_spoof_detection }
|
17
17
|
end
|
18
18
|
|
19
19
|
it "is not on the attachment when explicitly rejected" do
|
20
20
|
rebuild_model validate_media_type: false
|
21
|
-
assert Dummy.validators_on(:avatar).none?{ |validator| validator.kind == :media_type_spoof_detection }
|
21
|
+
assert Dummy.validators_on(:avatar).none? { |validator| validator.kind == :media_type_spoof_detection }
|
22
22
|
end
|
23
23
|
|
24
24
|
it "returns default error message for spoofed media type" do
|
@@ -26,8 +26,8 @@ describe Paperclip::Validators::MediaTypeSpoofDetectionValidator do
|
|
26
26
|
file = File.new(fixture_file("5k.png"), "rb")
|
27
27
|
@dummy.avatar.assign(file)
|
28
28
|
|
29
|
-
detector =
|
30
|
-
Paperclip::MediaTypeSpoofDetector.
|
29
|
+
detector = double("detector", spoofed?: true)
|
30
|
+
allow(Paperclip::MediaTypeSpoofDetector).to receive(:using).and_return(detector)
|
31
31
|
@validator.validate(@dummy)
|
32
32
|
|
33
33
|
assert_equal I18n.t("errors.messages.spoofed_media_type"), @dummy.errors[:avatar].first
|
@@ -37,16 +37,12 @@ describe Paperclip::Validators::MediaTypeSpoofDetectionValidator do
|
|
37
37
|
build_validator
|
38
38
|
file = File.new(fixture_file("5k.png"), "rb")
|
39
39
|
@dummy.avatar.assign(file)
|
40
|
-
Paperclip::MediaTypeSpoofDetector.
|
41
|
-
|
40
|
+
expect(Paperclip::MediaTypeSpoofDetector).to receive(:using).once.and_return(double("detector", spoofed?: false))
|
42
41
|
@dummy.valid?
|
43
|
-
|
44
|
-
assert_received(Paperclip::MediaTypeSpoofDetector, :using){|e| e.once }
|
45
42
|
end
|
46
43
|
|
47
44
|
it "does not run when attachment is not dirty" do
|
48
|
-
Paperclip::MediaTypeSpoofDetector.
|
45
|
+
expect(Paperclip::MediaTypeSpoofDetector).to_not receive(:using)
|
49
46
|
@dummy.valid?
|
50
|
-
assert_received(Paperclip::MediaTypeSpoofDetector, :using){|e| e.never }
|
51
47
|
end
|
52
48
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Paperclip::Validators do
|
4
4
|
context "using the helper" do
|
@@ -8,65 +8,65 @@ describe Paperclip::Validators do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
it "adds the attachment_presence validator to the class" do
|
11
|
-
assert Dummy.validators_on(:avatar).any?{ |validator| validator.kind == :attachment_presence }
|
11
|
+
assert Dummy.validators_on(:avatar).any? { |validator| validator.kind == :attachment_presence }
|
12
12
|
end
|
13
13
|
|
14
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 }
|
15
|
+
assert Dummy.validators_on(:avatar).any? { |validator| validator.kind == :attachment_content_type }
|
16
16
|
end
|
17
17
|
|
18
18
|
it "adds the attachment_size validator to the class" do
|
19
|
-
assert Dummy.validators_on(:avatar).any?{ |validator| validator.kind == :attachment_size }
|
19
|
+
assert Dummy.validators_on(:avatar).any? { |validator| validator.kind == :attachment_size }
|
20
20
|
end
|
21
21
|
|
22
|
-
it
|
23
|
-
Dummy.class_eval{ validate(:name) { raise "DO NOT RUN THIS" } }
|
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
24
|
dummy = Dummy.new(avatar: File.new(fixture_file("12k.png")))
|
25
25
|
expect(dummy.errors.keys).to match_array [:avatar_content_type, :avatar, :avatar_file_size]
|
26
|
-
assert_raises(RuntimeError){ dummy.valid? }
|
26
|
+
assert_raises(RuntimeError) { dummy.valid? }
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
context
|
30
|
+
context "using the helper with array of validations" do
|
31
31
|
before do
|
32
32
|
rebuild_class
|
33
33
|
Dummy.validates_attachment :avatar, file_type_ignorance: true, file_name: [
|
34
|
-
|
35
|
-
|
34
|
+
{ matches: /\A.*\.jpe?g\z/i, message: :invalid_extension },
|
35
|
+
{ matches: /\A.{,8}\..+\z/i, message: [:too_long, count: 8] },
|
36
36
|
]
|
37
37
|
end
|
38
38
|
|
39
|
-
it
|
40
|
-
assert Dummy.validators_on(:avatar).any?{ |validator| validator.kind == :attachment_file_name }
|
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
41
|
end
|
42
42
|
|
43
|
-
it
|
44
|
-
assert_equal 2, Dummy.validators_on(:avatar).select{ |validator| validator.kind == :attachment_file_name }.size
|
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
45
|
end
|
46
46
|
|
47
|
-
it
|
48
|
-
Dummy.class_eval{ validate(:name) { raise
|
49
|
-
dummy = Dummy.new(avatar: File.new(fixture_file(
|
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
50
|
expect(dummy.errors.keys).to match_array [:avatar, :avatar_file_name]
|
51
|
-
assert_raises(RuntimeError){ dummy.valid? }
|
51
|
+
assert_raises(RuntimeError) { dummy.valid? }
|
52
52
|
end
|
53
53
|
|
54
|
-
it
|
55
|
-
Dummy.class_eval{ validate(:name) { raise
|
56
|
-
dummy = Dummy.new(avatar: File.new(fixture_file(
|
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
57
|
expect(dummy.errors.keys).to match_array [:avatar, :avatar_file_name]
|
58
|
-
assert_raises(RuntimeError){ dummy.valid? }
|
58
|
+
assert_raises(RuntimeError) { dummy.valid? }
|
59
59
|
end
|
60
60
|
|
61
|
-
it
|
62
|
-
Dummy.class_eval{ validate(:name) { raise
|
63
|
-
dummy = Dummy.new(avatar: File.new(fixture_file(
|
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
64
|
expect(dummy.errors.keys).to match_array [:avatar, :avatar_file_name]
|
65
|
-
assert_raises(RuntimeError){ dummy.valid? }
|
65
|
+
assert_raises(RuntimeError) { dummy.valid? }
|
66
66
|
end
|
67
67
|
|
68
|
-
it
|
69
|
-
dummy = Dummy.new(avatar: File.new(fixture_file(
|
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
70
|
expect(dummy.errors.full_messages).to be_empty
|
71
71
|
assert dummy.valid?
|
72
72
|
end
|
@@ -76,9 +76,9 @@ describe Paperclip::Validators do
|
|
76
76
|
before do
|
77
77
|
rebuild_class
|
78
78
|
Dummy.validates_attachment :avatar, presence: true,
|
79
|
-
|
80
|
-
|
81
|
-
|
79
|
+
content_type: { content_type: "image/jpeg" },
|
80
|
+
size: { in: 0..10240 },
|
81
|
+
if: :title_present?
|
82
82
|
end
|
83
83
|
|
84
84
|
it "validates the attachment if title is present" do
|
@@ -102,20 +102,20 @@ describe Paperclip::Validators do
|
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
105
|
-
context
|
105
|
+
context "with no other validations on the Dummy#avatar attachment" do
|
106
106
|
before do
|
107
107
|
reset_class("Dummy")
|
108
108
|
Dummy.has_attached_file :avatar
|
109
109
|
Paperclip.reset_duplicate_clash_check!
|
110
110
|
end
|
111
111
|
|
112
|
-
it
|
112
|
+
it "raises an error when no content_type validation exists" do
|
113
113
|
assert_raises(Paperclip::Errors::MissingRequiredValidatorError) do
|
114
114
|
Dummy.new(avatar: File.new(fixture_file("12k.png")))
|
115
115
|
end
|
116
116
|
end
|
117
117
|
|
118
|
-
it
|
118
|
+
it "does not raise an error when a content_type validation exists" do
|
119
119
|
Dummy.validates_attachment :avatar, content_type: { content_type: "image/jpeg" }
|
120
120
|
|
121
121
|
assert_nothing_raised do
|
@@ -123,18 +123,18 @@ describe Paperclip::Validators do
|
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
126
|
-
it
|
127
|
-
Dummy.validates_with Paperclip::Validators::AttachmentContentTypeValidator, attributes: :attachment, content_type:
|
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
128
|
|
129
129
|
assert_nothing_raised do
|
130
130
|
Dummy.new(avatar: File.new(fixture_file("12k.png")))
|
131
131
|
end
|
132
132
|
end
|
133
133
|
|
134
|
-
it
|
134
|
+
it "does not raise an error when an inherited validator is used" do
|
135
135
|
class MyValidator < Paperclip::Validators::AttachmentContentTypeValidator
|
136
136
|
def initialize(options)
|
137
|
-
options[:content_type] = "images/jpeg" unless options.
|
137
|
+
options[:content_type] = "images/jpeg" unless options.key?(:content_type)
|
138
138
|
super
|
139
139
|
end
|
140
140
|
end
|
@@ -145,7 +145,7 @@ describe Paperclip::Validators do
|
|
145
145
|
end
|
146
146
|
end
|
147
147
|
|
148
|
-
it
|
148
|
+
it "does not raise an error when a file_name validation exists" do
|
149
149
|
Dummy.validates_attachment :avatar, file_name: { matches: /png$/ }
|
150
150
|
|
151
151
|
assert_nothing_raised do
|
@@ -153,7 +153,7 @@ describe Paperclip::Validators do
|
|
153
153
|
end
|
154
154
|
end
|
155
155
|
|
156
|
-
it
|
156
|
+
it "does not raise an error when a the validation has been explicitly rejected" do
|
157
157
|
Dummy.validates_attachment :avatar, file_type_ignorance: true
|
158
158
|
|
159
159
|
assert_nothing_raised do
|
data/spec/spec_helper.rb
CHANGED
@@ -1,36 +1,35 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
|
12
|
-
|
13
|
-
ROOT = Pathname(File.expand_path(File.join(File.dirname(__FILE__), '..')))
|
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__), "..")))
|
14
13
|
|
15
14
|
puts "Testing against version #{ActiveRecord::VERSION::STRING}"
|
16
15
|
|
17
|
-
$LOAD_PATH << File.join(ROOT,
|
18
|
-
$LOAD_PATH << File.join(ROOT,
|
19
|
-
require File.join(ROOT,
|
16
|
+
$LOAD_PATH << File.join(ROOT, "lib")
|
17
|
+
$LOAD_PATH << File.join(ROOT, "lib", "paperclip")
|
18
|
+
require File.join(ROOT, "lib", "paperclip.rb")
|
20
19
|
|
21
20
|
FIXTURES_DIR = File.join(File.dirname(__FILE__), "fixtures")
|
22
|
-
config = YAML::
|
21
|
+
config = YAML::safe_load(IO.read(File.dirname(__FILE__) + "/database.yml"))
|
23
22
|
ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
|
24
|
-
ActiveRecord::Base.establish_connection(config[
|
23
|
+
ActiveRecord::Base.establish_connection(config["test"])
|
25
24
|
if ActiveRecord::VERSION::STRING >= "4.2" &&
|
26
|
-
|
25
|
+
ActiveRecord::VERSION::STRING < "5.0"
|
27
26
|
ActiveRecord::Base.raise_in_transactional_callbacks = true
|
28
27
|
end
|
29
28
|
Paperclip.options[:logger] = ActiveRecord::Base.logger
|
30
29
|
|
31
|
-
Dir[File.join(ROOT,
|
30
|
+
Dir[File.join(ROOT, "spec", "support", "**", "*.rb")].each { |f| require f }
|
32
31
|
|
33
|
-
Rails = FakeRails.new(
|
32
|
+
Rails = FakeRails.new("test", Pathname.new(ROOT).join("tmp"))
|
34
33
|
ActiveSupport::Deprecation.silenced = true
|
35
34
|
|
36
35
|
RSpec.configure do |config|
|
@@ -39,8 +38,7 @@ RSpec.configure do |config|
|
|
39
38
|
config.include TestData
|
40
39
|
config.include Reporting
|
41
40
|
config.extend VersionHelper
|
42
|
-
|
43
|
-
config.mock_framework = :mocha
|
41
|
+
|
44
42
|
config.before(:all) do
|
45
43
|
rebuild_model
|
46
44
|
end
|
data/spec/support/assertions.rb
CHANGED
@@ -51,8 +51,8 @@ module Assertions
|
|
51
51
|
url = "http:#{url}" unless url =~ /http/
|
52
52
|
Net::HTTP.get_response(URI.parse(url)) do |response|
|
53
53
|
assert_equal "200",
|
54
|
-
|
55
|
-
|
54
|
+
response.code,
|
55
|
+
"Expected HTTP response code 200, got #{response.code}"
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
@@ -60,7 +60,7 @@ module Assertions
|
|
60
60
|
url = "http:#{url}" unless url =~ /http/
|
61
61
|
Net::HTTP.get_response(URI.parse(url)) do |response|
|
62
62
|
assert_equal "404", response.code,
|
63
|
-
|
63
|
+
"Expected HTTP response code 404, got #{response.code}"
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
@@ -68,14 +68,16 @@ module Assertions
|
|
68
68
|
url = "http:#{url}" unless url =~ /http/
|
69
69
|
Net::HTTP.get_response(URI.parse(url)) do |response|
|
70
70
|
assert_equal "403", response.code,
|
71
|
-
|
71
|
+
"Expected HTTP response code 403, got #{response.code}"
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
75
|
def assert_frame_dimensions(range, frames)
|
76
76
|
frames.each_with_index do |frame, frame_index|
|
77
|
-
frame.split(
|
78
|
-
assert range.include?(dimension.to_i),
|
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}"
|
79
81
|
end
|
80
82
|
end
|
81
83
|
end
|
data/spec/support/fake_model.rb
CHANGED
data/spec/support/fake_rails.rb
CHANGED
@@ -4,7 +4,7 @@ RSpec::Matchers.define :have_column do |column_name|
|
|
4
4
|
end
|
5
5
|
|
6
6
|
match do |columns|
|
7
|
-
column = columns.detect{|column| column.name == column_name }
|
7
|
+
column = columns.detect { |column| column.name == column_name }
|
8
8
|
column && column.default.to_s == @default.to_s
|
9
9
|
end
|
10
10
|
|
@@ -1,6 +1,5 @@
|
|
1
1
|
class MockUrlGeneratorBuilder
|
2
|
-
def initializer
|
3
|
-
end
|
2
|
+
def initializer; end
|
4
3
|
|
5
4
|
def new(attachment)
|
6
5
|
@attachment = attachment
|
@@ -16,7 +15,7 @@ class MockUrlGeneratorBuilder
|
|
16
15
|
|
17
16
|
def has_generated_url_with_options?(options)
|
18
17
|
# options.is_a_subhash_of(@generated_url_with_options)
|
19
|
-
options.inject(true) do |acc,(k,v)|
|
18
|
+
options.inject(true) do |acc, (k, v)|
|
20
19
|
acc && @generated_url_with_options[k] == v
|
21
20
|
end
|
22
21
|
end
|
@@ -1,7 +1,11 @@
|
|
1
1
|
module ModelReconstruction
|
2
|
-
def reset_class
|
3
|
-
ActiveRecord::Base.
|
4
|
-
|
2
|
+
def reset_class(class_name)
|
3
|
+
ActiveRecord::Base.include Paperclip::Glue
|
4
|
+
begin
|
5
|
+
Object.send(:remove_const, class_name)
|
6
|
+
rescue StandardError
|
7
|
+
nil
|
8
|
+
end
|
5
9
|
klass = Object.const_set(class_name, Class.new(ActiveRecord::Base))
|
6
10
|
|
7
11
|
klass.class_eval do
|
@@ -22,29 +26,29 @@ module ModelReconstruction
|
|
22
26
|
klass
|
23
27
|
end
|
24
28
|
|
25
|
-
def reset_table
|
26
|
-
block ||= lambda { |
|
27
|
-
ActiveRecord::Base.connection.create_table :dummies,
|
29
|
+
def reset_table(_table_name, &block)
|
30
|
+
block ||= lambda { |_table| true }
|
31
|
+
ActiveRecord::Base.connection.create_table :dummies, { force: true }, &block
|
28
32
|
end
|
29
33
|
|
30
|
-
def modify_table
|
34
|
+
def modify_table(&block)
|
31
35
|
ActiveRecord::Base.connection.change_table :dummies, &block
|
32
36
|
end
|
33
37
|
|
34
|
-
def rebuild_model
|
35
|
-
ActiveRecord::Base.connection.create_table :dummies,
|
38
|
+
def rebuild_model(options = {})
|
39
|
+
ActiveRecord::Base.connection.create_table :dummies, force: true do |table|
|
36
40
|
table.column :title, :string
|
37
41
|
table.column :other, :string
|
38
42
|
table.column :avatar_file_name, :string
|
39
43
|
table.column :avatar_content_type, :string
|
40
|
-
table.column :avatar_file_size, :
|
44
|
+
table.column :avatar_file_size, :bigint
|
41
45
|
table.column :avatar_updated_at, :datetime
|
42
46
|
table.column :avatar_fingerprint, :string
|
43
47
|
end
|
44
48
|
rebuild_class options
|
45
49
|
end
|
46
50
|
|
47
|
-
def rebuild_class
|
51
|
+
def rebuild_class(options = {})
|
48
52
|
reset_class("Dummy").tap do |klass|
|
49
53
|
klass.has_attached_file :avatar, options
|
50
54
|
klass.do_not_validate_attachment_file_type :avatar
|
@@ -52,7 +56,7 @@ module ModelReconstruction
|
|
52
56
|
end
|
53
57
|
end
|
54
58
|
|
55
|
-
def rebuild_meta_class_of
|
59
|
+
def rebuild_meta_class_of(obj, options = {})
|
56
60
|
meta_class_of(obj).tap do |metaklass|
|
57
61
|
metaklass.has_attached_file :avatar, options
|
58
62
|
metaklass.do_not_validate_attachment_file_type :avatar
|
data/spec/support/reporting.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Reporting
|
2
2
|
def silence_stream(stream)
|
3
3
|
old_stream = stream.dup
|
4
|
-
stream.reopen(RbConfig::CONFIG[
|
4
|
+
stream.reopen(RbConfig::CONFIG["host_os"] =~ /mswin|mingw/ ? "NUL:" : "/dev/null")
|
5
5
|
stream.sync = true
|
6
6
|
yield
|
7
7
|
ensure
|
data/spec/support/test_data.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module TestData
|
2
|
-
def attachment(options={})
|
2
|
+
def attachment(options = {})
|
3
3
|
Paperclip::Attachment.new(:avatar, FakeModel.new, options)
|
4
4
|
end
|
5
5
|
|
@@ -8,6 +8,6 @@ module TestData
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def fixture_file(filename)
|
11
|
-
File.join(File.dirname(__FILE__),
|
11
|
+
File.join(File.dirname(__FILE__), "fixtures", filename)
|
12
12
|
end
|
13
13
|
end
|