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,31 +1,30 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Paperclip::ContentTypeDetector do
|
4
|
-
it
|
4
|
+
it "returns a meaningful content type for open xml spreadsheets" do
|
5
5
|
file = File.new(fixture_file("empty.xlsx"))
|
6
6
|
assert_equal "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
7
7
|
Paperclip::ContentTypeDetector.new(file.path).detect
|
8
8
|
end
|
9
9
|
|
10
|
-
it
|
10
|
+
it "gives a sensible default when the name is empty" do
|
11
11
|
assert_equal "application/octet-stream", Paperclip::ContentTypeDetector.new("").detect
|
12
12
|
end
|
13
13
|
|
14
|
-
it
|
14
|
+
it "returns the empty content type when the file is empty" do
|
15
15
|
tempfile = Tempfile.new("empty")
|
16
16
|
assert_equal "inode/x-empty", Paperclip::ContentTypeDetector.new(tempfile.path).detect
|
17
17
|
tempfile.close
|
18
18
|
end
|
19
19
|
|
20
|
-
it
|
21
|
-
MIME::Types.
|
22
|
-
Paperclip::ContentTypeDetector.
|
23
|
-
.stubs(:type_from_file_contents).returns("video/mp4")
|
20
|
+
it "returns content type of file if it is an acceptable type" do
|
21
|
+
allow(MIME::Types).to receive(:type_for).and_return([MIME::Type.new("application/mp4"), MIME::Type.new("video/mp4"), MIME::Type.new("audio/mp4")])
|
22
|
+
allow_any_instance_of(Paperclip::ContentTypeDetector).to receive(:type_from_file_contents).and_return("video/mp4")
|
24
23
|
@filename = "my_file.mp4"
|
25
24
|
assert_equal "video/mp4", Paperclip::ContentTypeDetector.new(@filename).detect
|
26
25
|
end
|
27
26
|
|
28
|
-
it
|
27
|
+
it "finds the right type in the list via the file command" do
|
29
28
|
@filename = "#{Dir.tmpdir}/something.hahalolnotreal"
|
30
29
|
File.open(@filename, "w+") do |file|
|
31
30
|
file.puts "This is a text file."
|
@@ -35,13 +34,13 @@ describe Paperclip::ContentTypeDetector do
|
|
35
34
|
FileUtils.rm @filename
|
36
35
|
end
|
37
36
|
|
38
|
-
it
|
37
|
+
it "returns a sensible default if something is wrong, like the file is gone" do
|
39
38
|
@filename = "/path/to/nothing"
|
40
39
|
assert_equal "application/octet-stream", Paperclip::ContentTypeDetector.new(@filename).detect
|
41
40
|
end
|
42
41
|
|
43
|
-
it
|
44
|
-
Paperclip.
|
42
|
+
it "returns a sensible default when the file command is missing" do
|
43
|
+
allow(Paperclip).to receive(:run).and_raise(Terrapin::CommandLineError.new)
|
45
44
|
@filename = "/path/to/something"
|
46
45
|
assert_equal "application/octet-stream", Paperclip::ContentTypeDetector.new(@filename).detect
|
47
46
|
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Paperclip::FileCommandContentTypeDetector do
|
4
|
-
it
|
4
|
+
it "returns a content type based on the content of the file" do
|
5
5
|
tempfile = Tempfile.new("something")
|
6
6
|
tempfile.write("This is a file.")
|
7
7
|
tempfile.rewind
|
@@ -11,29 +11,29 @@ describe Paperclip::FileCommandContentTypeDetector do
|
|
11
11
|
tempfile.close
|
12
12
|
end
|
13
13
|
|
14
|
-
it
|
15
|
-
Paperclip.
|
14
|
+
it "returns a sensible default when the file command is missing" do
|
15
|
+
allow(Paperclip).to receive(:run).and_raise(Terrapin::CommandLineError.new)
|
16
16
|
@filename = "/path/to/something"
|
17
17
|
assert_equal "application/octet-stream",
|
18
|
-
|
18
|
+
Paperclip::FileCommandContentTypeDetector.new(@filename).detect
|
19
19
|
end
|
20
20
|
|
21
|
-
it
|
22
|
-
Paperclip.
|
21
|
+
it "returns a sensible default on the odd chance that run returns nil" do
|
22
|
+
allow(Paperclip).to receive(:run).and_return(nil)
|
23
23
|
assert_equal "application/octet-stream",
|
24
|
-
|
24
|
+
Paperclip::FileCommandContentTypeDetector.new("windows").detect
|
25
25
|
end
|
26
26
|
|
27
27
|
context "#type_from_file_command" do
|
28
28
|
let(:detector) { Paperclip::FileCommandContentTypeDetector.new("html") }
|
29
29
|
|
30
30
|
it "does work with the output of old versions of file" do
|
31
|
-
Paperclip.
|
31
|
+
allow(Paperclip).to receive(:run).and_return("text/html charset=us-ascii")
|
32
32
|
expect(detector.detect).to eq("text/html")
|
33
33
|
end
|
34
34
|
|
35
35
|
it "does work with the output of new versions of file" do
|
36
|
-
Paperclip.
|
36
|
+
allow(Paperclip).to receive(:run).and_return("text/html; charset=us-ascii")
|
37
37
|
expect(detector.detect).to eq("text/html")
|
38
38
|
end
|
39
39
|
end
|
@@ -1,13 +1,12 @@
|
|
1
|
-
|
2
|
-
require 'spec_helper'
|
1
|
+
require "spec_helper"
|
3
2
|
|
4
3
|
describe Paperclip::FilenameCleaner do
|
5
|
-
it
|
4
|
+
it "converts invalid characters to underscores" do
|
6
5
|
cleaner = Paperclip::FilenameCleaner.new(/[aeiou]/)
|
7
6
|
expect(cleaner.call("baseball")).to eq "b_s_b_ll"
|
8
7
|
end
|
9
8
|
|
10
|
-
it
|
9
|
+
it "does not convert anything if the character regex is nil" do
|
11
10
|
cleaner = Paperclip::FilenameCleaner.new(nil)
|
12
11
|
expect(cleaner.call("baseball")).to eq "baseball"
|
13
12
|
end
|
@@ -1,8 +1,8 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Paperclip::GeometryDetector do
|
4
|
-
it
|
5
|
-
Paperclip::GeometryParser.
|
4
|
+
it "identifies an image and extract its dimensions" do
|
5
|
+
allow_any_instance_of(Paperclip::GeometryParser).to receive(:make).and_return(:correct)
|
6
6
|
file = fixture_file("5k.png")
|
7
7
|
factory = Paperclip::GeometryDetector.new(file)
|
8
8
|
|
@@ -11,8 +11,8 @@ describe Paperclip::GeometryDetector do
|
|
11
11
|
expect(output).to eq :correct
|
12
12
|
end
|
13
13
|
|
14
|
-
it
|
15
|
-
Paperclip::GeometryParser.
|
14
|
+
it "identifies an image and extract its dimensions and orientation" do
|
15
|
+
allow_any_instance_of(Paperclip::GeometryParser).to receive(:make).and_return(:correct)
|
16
16
|
file = fixture_file("rotated.jpg")
|
17
17
|
factory = Paperclip::GeometryDetector.new(file)
|
18
18
|
|
@@ -21,10 +21,10 @@ describe Paperclip::GeometryDetector do
|
|
21
21
|
expect(output).to eq :correct
|
22
22
|
end
|
23
23
|
|
24
|
-
it
|
24
|
+
it "avoids reading EXIF orientation if so configured" do
|
25
25
|
begin
|
26
26
|
Paperclip.options[:use_exif_orientation] = false
|
27
|
-
Paperclip::GeometryParser.
|
27
|
+
allow_any_instance_of(Paperclip::GeometryParser).to receive(:make).and_return(:correct)
|
28
28
|
file = fixture_file("rotated.jpg")
|
29
29
|
factory = Paperclip::GeometryDetector.new(file)
|
30
30
|
|
@@ -36,4 +36,3 @@ describe Paperclip::GeometryDetector do
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
39
|
-
|
@@ -1,13 +1,13 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Paperclip::GeometryParser do
|
4
|
-
it
|
5
|
-
Paperclip::Geometry.
|
6
|
-
height:
|
7
|
-
width:
|
4
|
+
it "identifies an image and extract its dimensions with no orientation" do
|
5
|
+
allow(Paperclip::Geometry).to receive(:new).with(
|
6
|
+
height: "73",
|
7
|
+
width: "434",
|
8
8
|
modifier: nil,
|
9
9
|
orientation: nil
|
10
|
-
).
|
10
|
+
).and_return(:correct)
|
11
11
|
factory = Paperclip::GeometryParser.new("434x73")
|
12
12
|
|
13
13
|
output = factory.make
|
@@ -15,13 +15,13 @@ describe Paperclip::GeometryParser do
|
|
15
15
|
assert_equal :correct, output
|
16
16
|
end
|
17
17
|
|
18
|
-
it
|
19
|
-
Paperclip::Geometry.
|
20
|
-
height:
|
21
|
-
width:
|
18
|
+
it "identifies an image and extract its dimensions with an empty orientation" do
|
19
|
+
allow(Paperclip::Geometry).to receive(:new).with(
|
20
|
+
height: "73",
|
21
|
+
width: "434",
|
22
22
|
modifier: nil,
|
23
|
-
orientation:
|
24
|
-
).
|
23
|
+
orientation: ""
|
24
|
+
).and_return(:correct)
|
25
25
|
factory = Paperclip::GeometryParser.new("434x73,")
|
26
26
|
|
27
27
|
output = factory.make
|
@@ -29,13 +29,13 @@ describe Paperclip::GeometryParser do
|
|
29
29
|
assert_equal :correct, output
|
30
30
|
end
|
31
31
|
|
32
|
-
it
|
33
|
-
Paperclip::Geometry.
|
34
|
-
height:
|
35
|
-
width:
|
32
|
+
it "identifies an image and extract its dimensions and orientation" do
|
33
|
+
allow(Paperclip::Geometry).to receive(:new).with(
|
34
|
+
height: "200",
|
35
|
+
width: "300",
|
36
36
|
modifier: nil,
|
37
|
-
orientation:
|
38
|
-
).
|
37
|
+
orientation: "6"
|
38
|
+
).and_return(:correct)
|
39
39
|
factory = Paperclip::GeometryParser.new("300x200,6")
|
40
40
|
|
41
41
|
output = factory.make
|
@@ -43,13 +43,13 @@ describe Paperclip::GeometryParser do
|
|
43
43
|
assert_equal :correct, output
|
44
44
|
end
|
45
45
|
|
46
|
-
it
|
47
|
-
Paperclip::Geometry.
|
48
|
-
height:
|
49
|
-
width:
|
50
|
-
modifier:
|
46
|
+
it "identifies an image and extract its dimensions and modifier" do
|
47
|
+
allow(Paperclip::Geometry).to receive(:new).with(
|
48
|
+
height: "64",
|
49
|
+
width: "64",
|
50
|
+
modifier: "#",
|
51
51
|
orientation: nil
|
52
|
-
).
|
52
|
+
).and_return(:correct)
|
53
53
|
factory = Paperclip::GeometryParser.new("64x64#")
|
54
54
|
|
55
55
|
output = factory.make
|
@@ -57,13 +57,13 @@ describe Paperclip::GeometryParser do
|
|
57
57
|
assert_equal :correct, output
|
58
58
|
end
|
59
59
|
|
60
|
-
it
|
61
|
-
Paperclip::Geometry.
|
62
|
-
height:
|
63
|
-
width:
|
64
|
-
modifier:
|
65
|
-
orientation:
|
66
|
-
).
|
60
|
+
it "identifies an image and extract its dimensions, orientation, and modifier" do
|
61
|
+
allow(Paperclip::Geometry).to receive(:new).with(
|
62
|
+
height: "50",
|
63
|
+
width: "100",
|
64
|
+
modifier: ">",
|
65
|
+
orientation: "7"
|
66
|
+
).and_return(:correct)
|
67
67
|
factory = Paperclip::GeometryParser.new("100x50,7>")
|
68
68
|
|
69
69
|
output = factory.make
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Paperclip::Geometry do
|
4
4
|
context "Paperclip::Geometry" do
|
@@ -82,7 +82,7 @@ describe Paperclip::Geometry do
|
|
82
82
|
assert_equal 456, @upper.height
|
83
83
|
end
|
84
84
|
|
85
|
-
[
|
85
|
+
[">", "<", "#", "@", "@>", ">@", "%", "^", "!", nil].each do |mod|
|
86
86
|
it "ensures the modifier #{description} is preserved" do
|
87
87
|
assert @geo = Paperclip::Geometry.parse("123x456#{mod}")
|
88
88
|
assert_equal mod, @geo.modifier
|
@@ -124,22 +124,22 @@ describe Paperclip::Geometry do
|
|
124
124
|
|
125
125
|
it "is generated from a file" do
|
126
126
|
file = fixture_file("5k.png")
|
127
|
-
file = File.new(file,
|
128
|
-
assert_nothing_raised{ @geo = Paperclip::Geometry.from_file(file) }
|
127
|
+
file = File.new(file, "rb")
|
128
|
+
assert_nothing_raised { @geo = Paperclip::Geometry.from_file(file) }
|
129
129
|
assert_equal 66, @geo.height
|
130
130
|
assert_equal 434, @geo.width
|
131
131
|
end
|
132
132
|
|
133
133
|
it "is generated from a file path" do
|
134
134
|
file = fixture_file("5k.png")
|
135
|
-
assert_nothing_raised{ @geo = Paperclip::Geometry.from_file(file) }
|
135
|
+
assert_nothing_raised { @geo = Paperclip::Geometry.from_file(file) }
|
136
136
|
assert_equal 66, @geo.height
|
137
137
|
assert_equal 434, @geo.width
|
138
138
|
end
|
139
139
|
|
140
|
-
it
|
140
|
+
it "calculates an EXIF-rotated image dimensions from a path" do
|
141
141
|
file = fixture_file("rotated.jpg")
|
142
|
-
assert_nothing_raised{ @geo = Paperclip::Geometry.from_file(file) }
|
142
|
+
assert_nothing_raised { @geo = Paperclip::Geometry.from_file(file) }
|
143
143
|
@geo.auto_orient
|
144
144
|
assert_equal 300, @geo.height
|
145
145
|
assert_equal 200, @geo.width
|
@@ -161,41 +161,41 @@ describe Paperclip::Geometry do
|
|
161
161
|
end
|
162
162
|
|
163
163
|
it "does not generate from a file with no path" do
|
164
|
-
file =
|
165
|
-
file.
|
164
|
+
file = double("file", path: "")
|
165
|
+
allow(file).to receive(:respond_to?).with(:path).and_return(true)
|
166
166
|
expect { @geo = Paperclip::Geometry.from_file(file) }.to raise_error(Paperclip::Errors::NotIdentifiedByImageMagickError)
|
167
167
|
end
|
168
168
|
|
169
169
|
it "lets us know when a command isn't found versus a processing error" do
|
170
|
-
old_path = ENV[
|
170
|
+
old_path = ENV["PATH"]
|
171
171
|
begin
|
172
|
-
ENV[
|
172
|
+
ENV["PATH"] = ""
|
173
173
|
assert_raises(Paperclip::Errors::CommandNotFoundError) do
|
174
174
|
file = fixture_file("5k.png")
|
175
175
|
@geo = Paperclip::Geometry.from_file(file)
|
176
176
|
end
|
177
177
|
ensure
|
178
|
-
ENV[
|
178
|
+
ENV["PATH"] = old_path
|
179
179
|
end
|
180
180
|
end
|
181
181
|
|
182
|
-
[[
|
183
|
-
[
|
184
|
-
[
|
182
|
+
[["vertical", 900, 1440, true, false, false, 1440, 900, 0.625],
|
183
|
+
["horizontal", 1024, 768, false, true, false, 1024, 768, 1.3333],
|
184
|
+
["square", 100, 100, false, false, true, 100, 100, 1]].each do |args|
|
185
185
|
context "performing calculations on a #{args[0]} viewport" do
|
186
186
|
before do
|
187
187
|
@geo = Paperclip::Geometry.new(args[1], args[2])
|
188
188
|
end
|
189
189
|
|
190
|
-
it "is #{args[3] ?
|
190
|
+
it "is #{args[3] ? '' : 'not'} vertical" do
|
191
191
|
assert_equal args[3], @geo.vertical?
|
192
192
|
end
|
193
193
|
|
194
|
-
it "is #{args[4] ?
|
194
|
+
it "is #{args[4] ? '' : 'not'} horizontal" do
|
195
195
|
assert_equal args[4], @geo.horizontal?
|
196
196
|
end
|
197
197
|
|
198
|
-
it "is #{args[5] ?
|
198
|
+
it "is #{args[5] ? '' : 'not'} square" do
|
199
199
|
assert_equal args[5], @geo.square?
|
200
200
|
end
|
201
201
|
|
@@ -213,9 +213,9 @@ describe Paperclip::Geometry do
|
|
213
213
|
end
|
214
214
|
end
|
215
215
|
|
216
|
-
[[
|
217
|
-
[
|
218
|
-
[
|
216
|
+
[[[1000, 100], [64, 64], "x64", "64x64+288+0"],
|
217
|
+
[[100, 1000], [50, 950], "x950", "50x950+22+0"],
|
218
|
+
[[100, 1000], [50, 25], "50x", "50x25+0+237"]]. each do |args|
|
219
219
|
context "of #{args[0].inspect} and given a Geometry #{args[1].inspect} and sent transform_to" do
|
220
220
|
before do
|
221
221
|
@geo = Paperclip::Geometry.new(*args[0])
|
@@ -233,9 +233,9 @@ describe Paperclip::Geometry do
|
|
233
233
|
end
|
234
234
|
end
|
235
235
|
|
236
|
-
[[
|
237
|
-
[
|
238
|
-
[
|
236
|
+
[["256x256", { "150x150!" => [150, 150], "150x150#" => [150, 150], "150x150>" => [150, 150], "150x150<" => [256, 256], "150x150" => [150, 150] }],
|
237
|
+
["256x256", { "512x512!" => [512, 512], "512x512#" => [512, 512], "512x512>" => [256, 256], "512x512<" => [512, 512], "512x512" => [512, 512] }],
|
238
|
+
["600x400", { "512x512!" => [512, 512], "512x512#" => [512, 512], "512x512>" => [512, 341], "512x512<" => [600, 400], "512x512" => [512, 341] }]].each do |original_size, options|
|
239
239
|
options.each_pair do |size, dimensions|
|
240
240
|
context "#{original_size} resize_to #{size}" do
|
241
241
|
before do
|
data/spec/paperclip/glue_spec.rb
CHANGED
@@ -14,7 +14,7 @@ describe Paperclip::Glue do
|
|
14
14
|
|
15
15
|
it "does not fail" do
|
16
16
|
NonActiveRecordModel = Class.new
|
17
|
-
NonActiveRecordModel.
|
17
|
+
NonActiveRecordModel.include Paperclip::Glue
|
18
18
|
Object.send :remove_const, "NonActiveRecordModel"
|
19
19
|
end
|
20
20
|
end
|
@@ -30,14 +30,12 @@ describe Paperclip::Glue do
|
|
30
30
|
end
|
31
31
|
|
32
32
|
after do
|
33
|
-
if @defined_active_record
|
34
|
-
Object.send :remove_const, "ActiveRecord"
|
35
|
-
end
|
33
|
+
Object.send :remove_const, "ActiveRecord" if @defined_active_record
|
36
34
|
end
|
37
35
|
|
38
36
|
it "does not fail" do
|
39
37
|
NonActiveRecordModel = Class.new
|
40
|
-
NonActiveRecordModel.
|
38
|
+
NonActiveRecordModel.include Paperclip::Glue
|
41
39
|
Object.send :remove_const, "NonActiveRecordModel"
|
42
40
|
end
|
43
41
|
end
|
@@ -1,158 +1,78 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Paperclip::HasAttachedFile do
|
4
|
-
|
5
|
-
it 'defines a setter on the class object' do
|
6
|
-
assert_adding_attachment('avatar').defines_method('avatar=')
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'defines a getter on the class object' do
|
10
|
-
assert_adding_attachment('avatar').defines_method('avatar')
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'defines a query on the class object' do
|
14
|
-
assert_adding_attachment('avatar').defines_method('avatar?')
|
15
|
-
end
|
4
|
+
let(:a_class) { spy("Class") }
|
16
5
|
|
17
|
-
|
18
|
-
|
6
|
+
context "#define_on" do
|
7
|
+
it "defines a setter on the class object" do
|
8
|
+
Paperclip::HasAttachedFile.define_on(a_class, "avatar", {})
|
9
|
+
expect(a_class).to have_received(:define_method).with("avatar=")
|
19
10
|
end
|
20
11
|
|
21
|
-
it
|
22
|
-
|
12
|
+
it "defines a getter on the class object" do
|
13
|
+
Paperclip::HasAttachedFile.define_on(a_class, "avatar", {})
|
14
|
+
expect(a_class).to have_received(:define_method).with("avatar")
|
23
15
|
end
|
24
16
|
|
25
|
-
it
|
26
|
-
|
17
|
+
it "defines a query on the class object" do
|
18
|
+
Paperclip::HasAttachedFile.define_on(a_class, "avatar", {})
|
19
|
+
expect(a_class).to have_received(:define_method).with("avatar?")
|
27
20
|
end
|
28
21
|
|
29
|
-
it
|
30
|
-
|
22
|
+
it "defines a method on the class to get all of its attachments" do
|
23
|
+
allow(a_class).to receive(:extend)
|
24
|
+
Paperclip::HasAttachedFile.define_on(a_class, "avatar", {})
|
25
|
+
expect(a_class).to have_received(:extend).with(Paperclip::HasAttachedFile::ClassMethods)
|
31
26
|
end
|
32
27
|
|
33
|
-
it
|
34
|
-
|
28
|
+
it "flushes errors as part of validations" do
|
29
|
+
Paperclip::HasAttachedFile.define_on(a_class, "avatar", {})
|
30
|
+
expect(a_class).to have_received(:validates_each).with("avatar")
|
35
31
|
end
|
36
32
|
|
37
|
-
it
|
38
|
-
|
33
|
+
it "registers the attachment with Paperclip::AttachmentRegistry" do
|
34
|
+
allow(Paperclip::AttachmentRegistry).to receive(:register)
|
35
|
+
Paperclip::HasAttachedFile.define_on(a_class, "avatar", size: 1)
|
36
|
+
expect(Paperclip::AttachmentRegistry).to have_received(:register).with(a_class, "avatar", size: 1)
|
39
37
|
end
|
40
38
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
'avatar',
|
45
|
-
unstub_methods: [:after_commit]
|
46
|
-
).defines_callback('after_destroy')
|
47
|
-
end
|
39
|
+
it "defines an after_save callback" do
|
40
|
+
Paperclip::HasAttachedFile.define_on(a_class, "avatar", {})
|
41
|
+
expect(a_class).to have_received("after_save")
|
48
42
|
end
|
49
43
|
|
50
|
-
it
|
51
|
-
|
44
|
+
it "defines a before_destroy callback" do
|
45
|
+
Paperclip::HasAttachedFile.define_on(a_class, "avatar", {})
|
46
|
+
expect(a_class).to have_received("before_destroy")
|
52
47
|
end
|
53
48
|
|
54
|
-
it
|
55
|
-
|
49
|
+
it "defines an after_commit callback" do
|
50
|
+
Paperclip::HasAttachedFile.define_on(a_class, "avatar", {})
|
51
|
+
expect(a_class).to have_received("after_commit")
|
56
52
|
end
|
57
53
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
private
|
64
|
-
|
65
|
-
def assert_adding_attachment(attachment_name, options={})
|
66
|
-
AttachmentAdder.new(attachment_name, options)
|
67
|
-
end
|
68
|
-
|
69
|
-
class AttachmentAdder
|
70
|
-
include Mocha::API
|
71
|
-
include RSpec::Matchers
|
72
|
-
|
73
|
-
def initialize(attachment_name, options = {})
|
74
|
-
@attachment_name = attachment_name
|
75
|
-
@stubbed_class = stub_class
|
76
|
-
if options.present?
|
77
|
-
options[:unstub_methods].each do |method|
|
78
|
-
@stubbed_class.unstub(method)
|
79
|
-
end
|
54
|
+
context "when the class does not allow after_commit callbacks" do
|
55
|
+
it "defines an after_destroy callback" do
|
56
|
+
a_class = double("class", after_destroy: nil, validates_each: nil, define_method: nil, after_save: nil, before_destroy: nil, define_paperclip_callbacks: nil, validates_media_type_spoof_detection: nil)
|
57
|
+
Paperclip::HasAttachedFile.define_on(a_class, "avatar", {})
|
58
|
+
expect(a_class).to have_received("after_destroy")
|
80
59
|
end
|
81
60
|
end
|
82
61
|
|
83
|
-
|
84
|
-
a_class
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
expect(a_class).to have_received(:define_method).with(method_name)
|
89
|
-
end
|
90
|
-
|
91
|
-
def defines_class_method(method_name)
|
92
|
-
a_class = @stubbed_class
|
93
|
-
a_class.class.stubs(:define_method)
|
94
|
-
|
95
|
-
Paperclip::HasAttachedFile.define_on(a_class, @attachment_name, {})
|
96
|
-
|
97
|
-
expect(a_class).to have_received(:extend).with(Paperclip::HasAttachedFile::ClassMethods)
|
98
|
-
end
|
99
|
-
|
100
|
-
def defines_validation
|
101
|
-
a_class = @stubbed_class
|
102
|
-
|
103
|
-
Paperclip::HasAttachedFile.define_on(a_class, @attachment_name, {})
|
104
|
-
|
105
|
-
expect(a_class).to have_received(:validates_each).with(@attachment_name)
|
106
|
-
end
|
107
|
-
|
108
|
-
def registers_attachment
|
109
|
-
a_class = @stubbed_class
|
110
|
-
Paperclip::AttachmentRegistry.stubs(:register)
|
111
|
-
|
112
|
-
Paperclip::HasAttachedFile.define_on(a_class, @attachment_name, {size: 1})
|
113
|
-
|
114
|
-
expect(Paperclip::AttachmentRegistry).to have_received(:register).with(a_class, @attachment_name, {size: 1})
|
115
|
-
end
|
116
|
-
|
117
|
-
def defines_callback(callback_name)
|
118
|
-
a_class = @stubbed_class
|
119
|
-
|
120
|
-
Paperclip::HasAttachedFile.define_on(a_class, @attachment_name, {})
|
121
|
-
|
122
|
-
expect(a_class).to have_received(callback_name.to_sym)
|
62
|
+
it "defines the Paperclip-specific callbacks" do
|
63
|
+
Paperclip::HasAttachedFile.define_on(a_class, "avatar", validate_media_type: false)
|
64
|
+
expect(a_class).to_not have_received(:validates_media_type_spoof_detection)
|
65
|
+
expect(a_class).to have_received("define_paperclip_callbacks")
|
123
66
|
end
|
124
67
|
|
125
|
-
|
126
|
-
a_class
|
127
|
-
|
128
|
-
Paperclip::HasAttachedFile.define_on(a_class, @attachment_name, { validate_media_type: false })
|
129
|
-
|
130
|
-
expect(a_class).to have_received(:validates_media_type_spoof_detection).never
|
68
|
+
it "does not define a media_type check if told not to" do
|
69
|
+
Paperclip::HasAttachedFile.define_on(a_class, "avatar", validate_media_type: false)
|
70
|
+
expect(a_class).to_not have_received(:validates_media_type_spoof_detection)
|
131
71
|
end
|
132
72
|
|
133
|
-
|
134
|
-
a_class
|
135
|
-
|
136
|
-
Paperclip::HasAttachedFile.define_on(a_class, @attachment_name, { validate_media_type: true })
|
137
|
-
|
73
|
+
it "does define a media_type check if told to" do
|
74
|
+
Paperclip::HasAttachedFile.define_on(a_class, "avatar", validate_media_type: true)
|
138
75
|
expect(a_class).to have_received(:validates_media_type_spoof_detection)
|
139
76
|
end
|
140
|
-
|
141
|
-
private
|
142
|
-
|
143
|
-
def stub_class
|
144
|
-
stub('class',
|
145
|
-
validates_each: nil,
|
146
|
-
define_method: nil,
|
147
|
-
after_save: nil,
|
148
|
-
before_destroy: nil,
|
149
|
-
after_commit: nil,
|
150
|
-
after_destroy: nil,
|
151
|
-
define_paperclip_callbacks: nil,
|
152
|
-
extend: nil,
|
153
|
-
name: 'Billy',
|
154
|
-
validates_media_type_spoof_detection: nil
|
155
|
-
)
|
156
|
-
end
|
157
77
|
end
|
158
78
|
end
|