jr-paperclip 8.0.1 → 8.0.3

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.
Files changed (134) hide show
  1. checksums.yaml +4 -4
  2. data/NEWS +9 -0
  3. data/lib/paperclip/thumbnail.rb +18 -15
  4. data/lib/paperclip/version.rb +1 -1
  5. metadata +3 -245
  6. data/.github/FUNDING.yml +0 -3
  7. data/.github/ISSUE_TEMPLATE/bug_report.md +0 -18
  8. data/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
  9. data/.github/workflows/reviewdog.yml +0 -23
  10. data/.github/workflows/tests.yml +0 -56
  11. data/.gitignore +0 -19
  12. data/.qlty/.gitignore +0 -7
  13. data/.qlty/qlty.toml +0 -89
  14. data/Appraisals +0 -29
  15. data/Gemfile +0 -18
  16. data/bin/console +0 -11
  17. data/features/basic_integration.feature +0 -112
  18. data/features/migration.feature +0 -29
  19. data/features/rake_tasks.feature +0 -62
  20. data/features/step_definitions/attachment_steps.rb +0 -138
  21. data/features/step_definitions/html_steps.rb +0 -15
  22. data/features/step_definitions/rails_steps.rb +0 -271
  23. data/features/step_definitions/s3_steps.rb +0 -16
  24. data/features/step_definitions/web_steps.rb +0 -106
  25. data/features/support/env.rb +0 -12
  26. data/features/support/file_helpers.rb +0 -34
  27. data/features/support/fixtures/boot_config.txt +0 -15
  28. data/features/support/fixtures/gemfile.txt +0 -5
  29. data/features/support/fixtures/preinitializer.txt +0 -20
  30. data/features/support/paths.rb +0 -28
  31. data/features/support/rails.rb +0 -39
  32. data/features/support/selectors.rb +0 -19
  33. data/features/support/webmock_setup.rb +0 -8
  34. data/gemfiles/7.0.gemfile +0 -21
  35. data/gemfiles/7.1.gemfile +0 -21
  36. data/gemfiles/7.2.gemfile +0 -21
  37. data/gemfiles/8.0.gemfile +0 -21
  38. data/gemfiles/8.1.gemfile +0 -21
  39. data/paperclip.gemspec +0 -52
  40. data/spec/database.yml +0 -4
  41. data/spec/paperclip/attachment_definitions_spec.rb +0 -313
  42. data/spec/paperclip/attachment_processing_spec.rb +0 -79
  43. data/spec/paperclip/attachment_registry_spec.rb +0 -158
  44. data/spec/paperclip/attachment_spec.rb +0 -1617
  45. data/spec/paperclip/content_type_detector_spec.rb +0 -58
  46. data/spec/paperclip/file_command_content_type_detector_spec.rb +0 -40
  47. data/spec/paperclip/filename_cleaner_spec.rb +0 -13
  48. data/spec/paperclip/geometry_detector_spec.rb +0 -96
  49. data/spec/paperclip/geometry_parser_spec.rb +0 -73
  50. data/spec/paperclip/geometry_spec.rb +0 -270
  51. data/spec/paperclip/glue_spec.rb +0 -63
  52. data/spec/paperclip/has_attached_file_spec.rb +0 -78
  53. data/spec/paperclip/helpers_spec.rb +0 -49
  54. data/spec/paperclip/integration_spec.rb +0 -702
  55. data/spec/paperclip/interpolations_spec.rb +0 -270
  56. data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +0 -160
  57. data/spec/paperclip/io_adapters/attachment_adapter_spec.rb +0 -167
  58. data/spec/paperclip/io_adapters/data_uri_adapter_spec.rb +0 -88
  59. data/spec/paperclip/io_adapters/empty_string_adapter_spec.rb +0 -17
  60. data/spec/paperclip/io_adapters/file_adapter_spec.rb +0 -134
  61. data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +0 -142
  62. data/spec/paperclip/io_adapters/identity_adapter_spec.rb +0 -8
  63. data/spec/paperclip/io_adapters/nil_adapter_spec.rb +0 -25
  64. data/spec/paperclip/io_adapters/registry_spec.rb +0 -35
  65. data/spec/paperclip/io_adapters/stringio_adapter_spec.rb +0 -64
  66. data/spec/paperclip/io_adapters/uploaded_file_adapter_spec.rb +0 -146
  67. data/spec/paperclip/io_adapters/uri_adapter_spec.rb +0 -231
  68. data/spec/paperclip/lazy_thumbnail_compatibility_spec.rb +0 -266
  69. data/spec/paperclip/matchers/have_attached_file_matcher_spec.rb +0 -19
  70. data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +0 -108
  71. data/spec/paperclip/matchers/validate_attachment_presence_matcher_spec.rb +0 -69
  72. data/spec/paperclip/matchers/validate_attachment_size_matcher_spec.rb +0 -88
  73. data/spec/paperclip/media_type_spoof_detector_spec.rb +0 -126
  74. data/spec/paperclip/meta_class_spec.rb +0 -30
  75. data/spec/paperclip/migration_guide_example_spec.rb +0 -44
  76. data/spec/paperclip/paperclip_missing_attachment_styles_spec.rb +0 -88
  77. data/spec/paperclip/paperclip_spec.rb +0 -196
  78. data/spec/paperclip/plural_cache_spec.rb +0 -37
  79. data/spec/paperclip/processor_helpers_spec.rb +0 -57
  80. data/spec/paperclip/processor_spec.rb +0 -60
  81. data/spec/paperclip/rails_environment_spec.rb +0 -30
  82. data/spec/paperclip/rake_spec.rb +0 -103
  83. data/spec/paperclip/schema_spec.rb +0 -298
  84. data/spec/paperclip/storage/filesystem_spec.rb +0 -102
  85. data/spec/paperclip/storage/fog_spec.rb +0 -606
  86. data/spec/paperclip/storage/s3_live_spec.rb +0 -188
  87. data/spec/paperclip/storage/s3_spec.rb +0 -1974
  88. data/spec/paperclip/style_spec.rb +0 -309
  89. data/spec/paperclip/tempfile_factory_spec.rb +0 -33
  90. data/spec/paperclip/tempfile_spec.rb +0 -35
  91. data/spec/paperclip/thumbnail_custom_options_spec.rb +0 -225
  92. data/spec/paperclip/thumbnail_loader_options_spec.rb +0 -53
  93. data/spec/paperclip/thumbnail_security_spec.rb +0 -42
  94. data/spec/paperclip/thumbnail_spec.rb +0 -1460
  95. data/spec/paperclip/url_generator_spec.rb +0 -231
  96. data/spec/paperclip/validators/attachment_content_type_validator_spec.rb +0 -410
  97. data/spec/paperclip/validators/attachment_file_name_validator_spec.rb +0 -249
  98. data/spec/paperclip/validators/attachment_presence_validator_spec.rb +0 -85
  99. data/spec/paperclip/validators/attachment_size_validator_spec.rb +0 -325
  100. data/spec/paperclip/validators/media_type_spoof_detection_validator_spec.rb +0 -48
  101. data/spec/paperclip/validators_spec.rb +0 -179
  102. data/spec/spec_helper.rb +0 -52
  103. data/spec/support/assertions.rb +0 -84
  104. data/spec/support/fake_model.rb +0 -24
  105. data/spec/support/fake_rails.rb +0 -12
  106. data/spec/support/fixtures/12k.png +0 -0
  107. data/spec/support/fixtures/50x50.png +0 -0
  108. data/spec/support/fixtures/5k.png +0 -0
  109. data/spec/support/fixtures/animated +0 -0
  110. data/spec/support/fixtures/animated.gif +0 -0
  111. data/spec/support/fixtures/animated.unknown +0 -0
  112. data/spec/support/fixtures/aws_s3.yml +0 -13
  113. data/spec/support/fixtures/bad.png +0 -1
  114. data/spec/support/fixtures/empty.html +0 -1
  115. data/spec/support/fixtures/empty.xlsx +0 -0
  116. data/spec/support/fixtures/fog.yml +0 -8
  117. data/spec/support/fixtures/rotated.jpg +0 -0
  118. data/spec/support/fixtures/s3.yml +0 -8
  119. data/spec/support/fixtures/sample.xlsm +0 -0
  120. data/spec/support/fixtures/spaced file.jpg +0 -0
  121. data/spec/support/fixtures/spaced file.png +0 -0
  122. data/spec/support/fixtures/text.txt +0 -1
  123. data/spec/support/fixtures/twopage.pdf +0 -0
  124. data/spec/support/fixtures/uppercase.PNG +0 -0
  125. data/spec/support/matchers/accept.rb +0 -5
  126. data/spec/support/matchers/exist.rb +0 -5
  127. data/spec/support/matchers/have_column.rb +0 -23
  128. data/spec/support/mock_attachment.rb +0 -24
  129. data/spec/support/mock_interpolator.rb +0 -24
  130. data/spec/support/mock_url_generator_builder.rb +0 -26
  131. data/spec/support/model_reconstruction.rb +0 -72
  132. data/spec/support/reporting.rb +0 -11
  133. data/spec/support/test_data.rb +0 -13
  134. data/spec/support/version_helper.rb +0 -9
@@ -1,58 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Paperclip::ContentTypeDetector do
4
- it "returns a meaningful content type for open xml spreadsheets" do
5
- file = File.new(fixture_file("empty.xlsx"))
6
- assert_equal "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
7
- Paperclip::ContentTypeDetector.new(file.path).detect
8
- end
9
-
10
- it 'returns a more specific content type based on the filename if it matches
11
- multiple content types' do
12
- file = File.new(fixture_file('sample.xlsm'))
13
- assert_equal 'application/vnd.ms-excel.sheet.macroenabled.12',
14
- Paperclip::ContentTypeDetector.new(file.path).detect
15
- end
16
-
17
- it "gives a sensible default when the name is empty" do
18
- assert_equal "application/octet-stream", Paperclip::ContentTypeDetector.new("").detect
19
- end
20
-
21
- it "returns the empty content type when the file is empty" do
22
- tempfile = Tempfile.new("empty")
23
- assert_equal "inode/x-empty", Paperclip::ContentTypeDetector.new(tempfile.path).detect
24
- tempfile.close
25
- end
26
-
27
- it "returns content type of file if it is an acceptable type" do
28
- allow(MIME::Types).to receive(:type_for).and_return([
29
- MIME::Type.new("content-type" => "application/mp4"),
30
- MIME::Type.new("content-type" => "video/mp4"),
31
- MIME::Type.new("content-type" => "audio/mp4"),
32
- ])
33
- allow_any_instance_of(Paperclip::ContentTypeDetector).to receive(:type_from_file_contents).and_return("video/mp4")
34
- @filename = "my_file.mp4"
35
- assert_equal "video/mp4", Paperclip::ContentTypeDetector.new(@filename).detect
36
- end
37
-
38
- it "finds the right type in the list via the file command" do
39
- @filename = "#{Dir.tmpdir}/something.hahalolnotreal"
40
- File.open(@filename, "w+") do |file|
41
- file.puts "This is a text file."
42
- file.rewind
43
- assert_equal "text/plain", Paperclip::ContentTypeDetector.new(file.path).detect
44
- end
45
- FileUtils.rm @filename
46
- end
47
-
48
- it "returns a sensible default if something is wrong, like the file is gone" do
49
- @filename = "/path/to/nothing"
50
- assert_equal "application/octet-stream", Paperclip::ContentTypeDetector.new(@filename).detect
51
- end
52
-
53
- it "returns a sensible default when the file command is missing" do
54
- allow(Paperclip).to receive(:run).and_raise(Terrapin::CommandLineError.new)
55
- @filename = "/path/to/something"
56
- assert_equal "application/octet-stream", Paperclip::ContentTypeDetector.new(@filename).detect
57
- end
58
- end
@@ -1,40 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Paperclip::FileCommandContentTypeDetector do
4
- it "returns a content type based on the content of the file" do
5
- tempfile = Tempfile.new("something")
6
- tempfile.write("This is a file.")
7
- tempfile.rewind
8
-
9
- assert_equal "text/plain", Paperclip::FileCommandContentTypeDetector.new(tempfile.path).detect
10
-
11
- tempfile.close
12
- end
13
-
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
- @filename = "/path/to/something"
17
- assert_equal "application/octet-stream",
18
- Paperclip::FileCommandContentTypeDetector.new(@filename).detect
19
- end
20
-
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
- assert_equal "application/octet-stream",
24
- Paperclip::FileCommandContentTypeDetector.new("windows").detect
25
- end
26
-
27
- context "#type_from_file_command" do
28
- let(:detector) { Paperclip::FileCommandContentTypeDetector.new("html") }
29
-
30
- it "does work with the output of old versions of file" do
31
- allow(Paperclip).to receive(:run).and_return("text/html charset=us-ascii")
32
- expect(detector.detect).to eq("text/html")
33
- end
34
-
35
- it "does work with the output of new versions of file" do
36
- allow(Paperclip).to receive(:run).and_return("text/html; charset=us-ascii")
37
- expect(detector.detect).to eq("text/html")
38
- end
39
- end
40
- end
@@ -1,13 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Paperclip::FilenameCleaner do
4
- it "converts invalid characters to underscores" do
5
- cleaner = Paperclip::FilenameCleaner.new(/[aeiou]/)
6
- expect(cleaner.call("baseball")).to eq "b_s_b_ll"
7
- end
8
-
9
- it "does not convert anything if the character regex is nil" do
10
- cleaner = Paperclip::FilenameCleaner.new(nil)
11
- expect(cleaner.call("baseball")).to eq "baseball"
12
- end
13
- end
@@ -1,96 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Paperclip::GeometryDetector do
4
- [:image_magick, :vips].each do |backend|
5
- context "when configured to use #{backend}" do
6
- let(:original_backend) { Paperclip.options[:backend] }
7
-
8
- before do
9
- Paperclip.options[:backend] = backend
10
- end
11
-
12
- after do
13
- Paperclip.options[:backend] = original_backend
14
- end
15
-
16
- it "identifies an image and extract its dimensions" do
17
- allow_any_instance_of(Paperclip::GeometryParser).to receive(:make).and_return(:correct)
18
- file = fixture_file("5k.png")
19
- factory = Paperclip::GeometryDetector.new(file)
20
-
21
- output = factory.make
22
-
23
- expect(output).to eq :correct
24
- end
25
-
26
- it "identifies an image and extract its dimensions and orientation" do
27
- allow_any_instance_of(Paperclip::GeometryParser).to receive(:make).and_return(:correct)
28
- file = fixture_file("rotated.jpg")
29
- factory = Paperclip::GeometryDetector.new(file)
30
-
31
- output = factory.make
32
-
33
- expect(output).to eq :correct
34
- end
35
-
36
- it "avoids reading EXIF orientation if so configured" do
37
- begin
38
- Paperclip.options[:use_exif_orientation] = false
39
- allow_any_instance_of(Paperclip::GeometryParser).to receive(:make).and_return(:correct)
40
- file = fixture_file("rotated.jpg")
41
- factory = Paperclip::GeometryDetector.new(file)
42
-
43
- output = factory.make
44
-
45
- expect(output).to eq :correct
46
- ensure
47
- Paperclip.options[:use_exif_orientation] = true
48
- end
49
- end
50
-
51
- it "raises an exception with a message when the file is not an image" do
52
- file = fixture_file("text.txt")
53
- factory = Paperclip::GeometryDetector.new(file)
54
-
55
- expect do
56
- factory.make
57
- end.to raise_error(Paperclip::Errors::NotIdentifiedByBackendError, "Could not identify image size")
58
- end
59
-
60
- it "uses the correct backend to identify the image" do
61
- if backend == :vips
62
- begin
63
- require "vips"
64
- rescue LoadError
65
- skip "ruby-vips gem not available"
66
- end
67
- expect(Vips::Image).to receive(:new_from_file).and_call_original
68
- expect(Paperclip).not_to receive(:run).with(include("identify"), any_args)
69
- else
70
- expect(Paperclip).to receive(:run).with(include("identify"), any_args).and_call_original
71
- end
72
-
73
- file = fixture_file("5k.png")
74
- factory = Paperclip::GeometryDetector.new(file)
75
-
76
- geometry = factory.make
77
- expect(geometry.width).to eq(434)
78
- expect(geometry.height).to eq(66)
79
- end
80
-
81
- if backend == :vips
82
- it "raises CommandNotFoundError (and not NameError) when vips is missing" do
83
- hide_const("Vips")
84
- allow_any_instance_of(Paperclip::GeometryDetector).to receive(:require).with("vips").and_raise(LoadError)
85
-
86
- file = fixture_file("5k.png")
87
- factory = Paperclip::GeometryDetector.new(file)
88
-
89
- expect {
90
- factory.make
91
- }.to raise_error(Paperclip::Errors::CommandNotFoundError, /Could not load ruby-vips/)
92
- end
93
- end
94
- end
95
- end
96
- end
@@ -1,73 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Paperclip::GeometryParser do
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
- modifier: nil,
9
- orientation: nil
10
- ).and_return(:correct)
11
- factory = Paperclip::GeometryParser.new("434x73")
12
-
13
- output = factory.make
14
-
15
- assert_equal :correct, output
16
- end
17
-
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
- modifier: nil,
23
- orientation: ""
24
- ).and_return(:correct)
25
- factory = Paperclip::GeometryParser.new("434x73,")
26
-
27
- output = factory.make
28
-
29
- assert_equal :correct, output
30
- end
31
-
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
- modifier: nil,
37
- orientation: "6"
38
- ).and_return(:correct)
39
- factory = Paperclip::GeometryParser.new("300x200,6")
40
-
41
- output = factory.make
42
-
43
- assert_equal :correct, output
44
- end
45
-
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
- orientation: nil
52
- ).and_return(:correct)
53
- factory = Paperclip::GeometryParser.new("64x64#")
54
-
55
- output = factory.make
56
-
57
- assert_equal :correct, output
58
- end
59
-
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
- factory = Paperclip::GeometryParser.new("100x50,7>")
68
-
69
- output = factory.make
70
-
71
- assert_equal :correct, output
72
- end
73
- end
@@ -1,270 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Paperclip::Geometry do
4
- context "Paperclip::Geometry" do
5
- it "correctly reports 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
- it "sets 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
- it "sets 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
- it "is 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
- it "is 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
- it "is 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
- it "is 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
- it "ensures the modifier is nil if not present" do
48
- assert @geo = Paperclip::Geometry.parse("123x456")
49
- assert_nil @geo.modifier
50
- end
51
-
52
- it "recognizes an EXIF orientation and not rotate with auto_orient if not necessary" do
53
- geo = Paperclip::Geometry.new(width: 1024, height: 768, orientation: 1)
54
- assert geo
55
- assert_equal 1024, geo.width
56
- assert_equal 768, geo.height
57
-
58
- geo.auto_orient
59
-
60
- assert_equal 1024, geo.width
61
- assert_equal 768, geo.height
62
- end
63
-
64
- it "recognizes an EXIF orientation and rotate with auto_orient if necessary" do
65
- geo = Paperclip::Geometry.new(width: 1024, height: 768, orientation: 6)
66
- assert geo
67
- assert_equal 1024, geo.width
68
- assert_equal 768, geo.height
69
-
70
- geo.auto_orient
71
-
72
- assert_equal 768, geo.width
73
- assert_equal 1024, geo.height
74
- end
75
-
76
- it "treats x and X the same in geometries" do
77
- @lower = Paperclip::Geometry.parse("123x456")
78
- @upper = Paperclip::Geometry.parse("123X456")
79
- assert_equal 123, @lower.width
80
- assert_equal 123, @upper.width
81
- assert_equal 456, @lower.height
82
- assert_equal 456, @upper.height
83
- end
84
-
85
- [">", "<", "#", "@", "@>", ">@", "%", "^", "!", nil].each do |mod|
86
- it "ensures the modifier #{description} is preserved" do
87
- assert @geo = Paperclip::Geometry.parse("123x456#{mod}")
88
- assert_equal mod, @geo.modifier
89
- assert_equal "123x456#{mod}", @geo.to_s
90
- end
91
-
92
- it "ensures the modifier #{description} is preserved with no height" do
93
- assert @geo = Paperclip::Geometry.parse("123x#{mod}")
94
- assert_equal mod, @geo.modifier
95
- assert_equal "123#{mod}", @geo.to_s
96
- end
97
- end
98
-
99
- it "makes sure the modifier gets passed during transformation_to" do
100
- assert @src = Paperclip::Geometry.parse("123x456")
101
- assert @dst = Paperclip::Geometry.parse("123x456>")
102
- assert_equal ["123x456>", nil], @src.transformation_to(@dst)
103
- end
104
-
105
- it "generates correct ImageMagick formatting string for W-formatted string" do
106
- assert @geo = Paperclip::Geometry.parse("800")
107
- assert_equal "800", @geo.to_s
108
- end
109
-
110
- it "generates correct ImageMagick formatting string for Wx-formatted string" do
111
- assert @geo = Paperclip::Geometry.parse("800x")
112
- assert_equal "800", @geo.to_s
113
- end
114
-
115
- it "generates correct ImageMagick formatting string for xH-formatted string" do
116
- assert @geo = Paperclip::Geometry.parse("x600")
117
- assert_equal "x600", @geo.to_s
118
- end
119
-
120
- it "generates correct ImageMagick formatting string for WxH-formatted string" do
121
- assert @geo = Paperclip::Geometry.parse("800x600")
122
- assert_equal "800x600", @geo.to_s
123
- end
124
-
125
- it "is generated from a file" do
126
- file = fixture_file("5k.png")
127
- file = File.new(file, "rb")
128
- assert_nothing_raised { @geo = Paperclip::Geometry.from_file(file) }
129
- assert_equal 66, @geo.height
130
- assert_equal 434, @geo.width
131
- end
132
-
133
- it "is generated from a file path" do
134
- file = fixture_file("5k.png")
135
- assert_nothing_raised { @geo = Paperclip::Geometry.from_file(file) }
136
- assert_equal 66, @geo.height
137
- assert_equal 434, @geo.width
138
- end
139
-
140
- it "calculates an EXIF-rotated image dimensions from a path" do
141
- file = fixture_file("rotated.jpg")
142
- assert_nothing_raised { @geo = Paperclip::Geometry.from_file(file) }
143
- @geo.auto_orient
144
- assert_equal 300, @geo.height
145
- assert_equal 200, @geo.width
146
- end
147
-
148
- it "does not generate from a bad file" do
149
- file = "/home/This File Does Not Exist.omg"
150
- expect do
151
- @geo = Paperclip::Geometry.from_file(file)
152
- end.to raise_error(Paperclip::Errors::NotIdentifiedByBackendError,
153
- "Could not identify image size")
154
- end
155
-
156
- it "does not generate from a blank filename" do
157
- file = ""
158
- expect do
159
- @geo = Paperclip::Geometry.from_file(file)
160
- end.to raise_error(Paperclip::Errors::NotIdentifiedByBackendError,
161
- "Cannot find the geometry of a file with a blank name")
162
- end
163
-
164
- it "does not generate from a nil file" do
165
- file = nil
166
- expect do
167
- @geo = Paperclip::Geometry.from_file(file)
168
- end.to raise_error(Paperclip::Errors::NotIdentifiedByBackendError,
169
- "Cannot find the geometry of a file with a blank name")
170
- end
171
-
172
- it "does not generate from a file with no path" do
173
- file = double("file", path: "")
174
- allow(file).to receive(:respond_to?).with(:path).and_return(true)
175
- expect do
176
- @geo = Paperclip::Geometry.from_file(file)
177
- end.to raise_error(Paperclip::Errors::NotIdentifiedByBackendError,
178
- "Cannot find the geometry of a file with a blank name")
179
- end
180
-
181
- it "lets us know when a command isn't found versus a processing error when using imagemagick" do
182
- old_path = ENV["PATH"]
183
- old_backend = Paperclip.options[:backend]
184
- begin
185
- Paperclip.options[:backend] = :image_magick
186
- ENV["PATH"] = ""
187
- assert_raises(Paperclip::Errors::CommandNotFoundError) do
188
- file = fixture_file("5k.png")
189
- @geo = Paperclip::Geometry.from_file(file)
190
- end
191
- ensure
192
- ENV["PATH"] = old_path
193
- Paperclip.options[:backend] = old_backend
194
- end
195
- end
196
-
197
- [["vertical", 900, 1440, true, false, false, 1440, 900, 0.625],
198
- ["horizontal", 1024, 768, false, true, false, 1024, 768, 1.3333],
199
- ["square", 100, 100, false, false, true, 100, 100, 1]].each do |args|
200
- context "performing calculations on a #{args[0]} viewport" do
201
- before do
202
- @geo = Paperclip::Geometry.new(args[1], args[2])
203
- end
204
-
205
- it "is #{args[3] ? '' : 'not'} vertical" do
206
- assert_equal args[3], @geo.vertical?
207
- end
208
-
209
- it "is #{args[4] ? '' : 'not'} horizontal" do
210
- assert_equal args[4], @geo.horizontal?
211
- end
212
-
213
- it "is #{args[5] ? '' : 'not'} square" do
214
- assert_equal args[5], @geo.square?
215
- end
216
-
217
- it "reports that #{args[6]} is the larger dimension" do
218
- assert_equal args[6], @geo.larger
219
- end
220
-
221
- it "reports that #{args[7]} is the smaller dimension" do
222
- assert_equal args[7], @geo.smaller
223
- end
224
-
225
- it "has an aspect ratio of #{args[8]}" do
226
- expect(@geo.aspect).to be_within(0.0001).of(args[8])
227
- end
228
- end
229
- end
230
-
231
- [[[1000, 100], [64, 64], "x64", "64x64+288+0"],
232
- [[100, 1000], [50, 950], "x950", "50x950+22+0"],
233
- [[100, 1000], [50, 25], "50x", "50x25+0+237"]]. each do |args|
234
- context "of #{args[0].inspect} and given a Geometry #{args[1].inspect} and sent transform_to" do
235
- before do
236
- @geo = Paperclip::Geometry.new(*args[0])
237
- @dst = Paperclip::Geometry.new(*args[1])
238
- @scale, @crop = @geo.transformation_to @dst, true
239
- end
240
-
241
- it "is able to return the correct scaling transformation geometry #{args[2]}" do
242
- assert_equal args[2], @scale
243
- end
244
-
245
- it "is able to return the correct crop transformation geometry #{args[3]}" do
246
- assert_equal args[3], @crop
247
- end
248
- end
249
- end
250
-
251
- [["256x256", { "150x150!" => [150, 150], "150x150#" => [150, 150], "150x150>" => [150, 150], "150x150<" => [256, 256], "150x150" => [150, 150] }],
252
- ["256x256", { "512x512!" => [512, 512], "512x512#" => [512, 512], "512x512>" => [256, 256], "512x512<" => [512, 512], "512x512" => [512, 512] }],
253
- ["600x400", { "512x512!" => [512, 512], "512x512#" => [512, 512], "512x512>" => [512, 341], "512x512<" => [600, 400], "512x512" => [512, 341] }]].each do |original_size, options|
254
- options.each_pair do |size, dimensions|
255
- context "#{original_size} resize_to #{size}" do
256
- before do
257
- @source = Paperclip::Geometry.parse original_size
258
- @new_geometry = @source.resize_to size
259
- end
260
- it "has #{dimensions.first} width" do
261
- assert_equal dimensions.first, @new_geometry.width
262
- end
263
- it "has #{dimensions.last} height" do
264
- assert_equal dimensions.last, @new_geometry.height
265
- end
266
- end
267
- end
268
- end
269
- end
270
- end
@@ -1,63 +0,0 @@
1
- # require "spec_helper"
2
-
3
- describe Paperclip::Glue do
4
- describe "when ActiveRecord does not exist" do
5
- before do
6
- ActiveRecordSaved = ActiveRecord
7
- Object.send :remove_const, "ActiveRecord"
8
- end
9
-
10
- after do
11
- ActiveRecord = ActiveRecordSaved
12
- Object.send :remove_const, "ActiveRecordSaved"
13
- end
14
-
15
- it "does not fail" do
16
- NonActiveRecordModel = Class.new
17
- NonActiveRecordModel.include Paperclip::Glue
18
- Object.send :remove_const, "NonActiveRecordModel"
19
- end
20
- end
21
-
22
- describe "when ActiveRecord does exist" do
23
- before do
24
- if Object.const_defined?("ActiveRecord")
25
- @defined_active_record = false
26
- else
27
- ActiveRecord = :defined
28
- @defined_active_record = true
29
- end
30
- end
31
-
32
- after do
33
- Object.send :remove_const, "ActiveRecord" if @defined_active_record
34
- end
35
-
36
- it "does not fail" do
37
- NonActiveRecordModel = Class.new
38
- NonActiveRecordModel.include Paperclip::Glue
39
- Object.send :remove_const, "NonActiveRecordModel"
40
- end
41
- end
42
-
43
- describe "when included" do
44
- it "does not mutate I18n.load_path more than once" do
45
- before_load_path = I18n.load_path
46
- I18n.load_path = []
47
-
48
- # expect twice because the load_path is reset after creating the classes
49
- expect(I18n.config).to receive(:load_path=).and_call_original.twice
50
-
51
- FirstModel = Class.new
52
- FirstModel.include Paperclip::Glue
53
-
54
- SecondModel = Class.new
55
- SecondModel.include Paperclip::Glue
56
-
57
- ThirdModel = Class.new
58
- ThirdModel.include Paperclip::Glue
59
-
60
- I18n.load_path = before_load_path
61
- end
62
- end
63
- end