kt-paperclip 5.4.0 → 7.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (159) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +3 -0
  3. data/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
  4. data/.github/ISSUE_TEMPLATE/custom.md +10 -0
  5. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  6. data/.hound.yml +3 -1055
  7. data/.rubocop.yml +1061 -1
  8. data/.travis.yml +23 -4
  9. data/Appraisals +23 -0
  10. data/CONTRIBUTING.md +4 -5
  11. data/Gemfile +10 -7
  12. data/NEWS +52 -0
  13. data/README.md +58 -46
  14. data/Rakefile +29 -21
  15. data/UPGRADING +3 -3
  16. data/features/basic_integration.feature +4 -0
  17. data/features/migration.feature +10 -51
  18. data/features/step_definitions/attachment_steps.rb +23 -13
  19. data/features/step_definitions/html_steps.rb +5 -5
  20. data/features/step_definitions/rails_steps.rb +29 -9
  21. data/features/step_definitions/s3_steps.rb +3 -3
  22. data/features/step_definitions/web_steps.rb +5 -6
  23. data/features/support/env.rb +4 -4
  24. data/features/support/fakeweb.rb +3 -5
  25. data/features/support/file_helpers.rb +2 -2
  26. data/features/support/paths.rb +4 -4
  27. data/features/support/rails.rb +7 -7
  28. data/features/support/selectors.rb +1 -1
  29. data/gemfiles/4.2.gemfile +7 -4
  30. data/gemfiles/5.0.gemfile +7 -4
  31. data/gemfiles/5.1.gemfile +20 -0
  32. data/gemfiles/5.2.gemfile +20 -0
  33. data/gemfiles/6.0.gemfile +20 -0
  34. data/gemfiles/6.1.gemfile +21 -0
  35. data/gemfiles/7.0.gemfile +21 -0
  36. data/lib/generators/paperclip/paperclip_generator.rb +6 -8
  37. data/lib/paperclip/attachment.rb +103 -105
  38. data/lib/paperclip/attachment_registry.rb +2 -2
  39. data/lib/paperclip/content_type_detector.rb +10 -5
  40. data/lib/paperclip/file_command_content_type_detector.rb +1 -3
  41. data/lib/paperclip/filename_cleaner.rb +0 -1
  42. data/lib/paperclip/geometry.rb +18 -19
  43. data/lib/paperclip/geometry_detector_factory.rb +13 -16
  44. data/lib/paperclip/geometry_parser_factory.rb +5 -5
  45. data/lib/paperclip/glue.rb +3 -3
  46. data/lib/paperclip/has_attached_file.rb +5 -4
  47. data/lib/paperclip/helpers.rb +3 -3
  48. data/lib/paperclip/interpolations.rb +42 -38
  49. data/lib/paperclip/io_adapters/abstract_adapter.rb +16 -14
  50. data/lib/paperclip/io_adapters/attachment_adapter.rb +12 -6
  51. data/lib/paperclip/io_adapters/data_uri_adapter.rb +1 -1
  52. data/lib/paperclip/io_adapters/file_adapter.rb +1 -3
  53. data/lib/paperclip/io_adapters/http_url_proxy_adapter.rb +1 -1
  54. data/lib/paperclip/io_adapters/identity_adapter.rb +1 -2
  55. data/lib/paperclip/io_adapters/registry.rb +1 -1
  56. data/lib/paperclip/io_adapters/stringio_adapter.rb +1 -1
  57. data/lib/paperclip/io_adapters/uploaded_file_adapter.rb +6 -8
  58. data/lib/paperclip/io_adapters/uri_adapter.rb +21 -9
  59. data/lib/paperclip/logger.rb +1 -1
  60. data/lib/paperclip/matchers/have_attached_file_matcher.rb +4 -4
  61. data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +19 -18
  62. data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +4 -4
  63. data/lib/paperclip/matchers/validate_attachment_size_matcher.rb +11 -10
  64. data/lib/paperclip/matchers.rb +4 -4
  65. data/lib/paperclip/media_type_spoof_detector.rb +13 -13
  66. data/lib/paperclip/missing_attachment_styles.rb +11 -6
  67. data/lib/paperclip/processor.rb +13 -6
  68. data/lib/paperclip/processor_helpers.rb +3 -1
  69. data/lib/paperclip/rails_environment.rb +1 -5
  70. data/lib/paperclip/railtie.rb +5 -5
  71. data/lib/paperclip/schema.rb +16 -12
  72. data/lib/paperclip/storage/filesystem.rb +6 -8
  73. data/lib/paperclip/storage/fog.rb +36 -32
  74. data/lib/paperclip/storage/s3.rb +68 -76
  75. data/lib/paperclip/style.rb +3 -6
  76. data/lib/paperclip/tempfile.rb +4 -5
  77. data/lib/paperclip/tempfile_factory.rb +0 -1
  78. data/lib/paperclip/thumbnail.rb +11 -11
  79. data/lib/paperclip/url_generator.rb +5 -5
  80. data/lib/paperclip/validators/attachment_content_type_validator.rb +11 -4
  81. data/lib/paperclip/validators/attachment_file_name_validator.rb +14 -12
  82. data/lib/paperclip/validators/attachment_file_type_ignorance_validator.rb +1 -2
  83. data/lib/paperclip/validators/attachment_presence_validator.rb +3 -5
  84. data/lib/paperclip/validators/attachment_size_validator.rb +28 -11
  85. data/lib/paperclip/validators/media_type_spoof_detection_validator.rb +3 -1
  86. data/lib/paperclip/validators.rb +16 -17
  87. data/lib/paperclip/version.rb +1 -3
  88. data/lib/paperclip.rb +49 -48
  89. data/lib/tasks/paperclip.rake +23 -24
  90. data/paperclip.gemspec +29 -33
  91. data/shoulda_macros/paperclip.rb +16 -16
  92. data/spec/paperclip/attachment_definitions_spec.rb +5 -5
  93. data/spec/paperclip/attachment_processing_spec.rb +22 -23
  94. data/spec/paperclip/attachment_registry_spec.rb +15 -15
  95. data/spec/paperclip/attachment_spec.rb +238 -196
  96. data/spec/paperclip/content_type_detector_spec.rb +18 -12
  97. data/spec/paperclip/file_command_content_type_detector_spec.rb +10 -10
  98. data/spec/paperclip/filename_cleaner_spec.rb +3 -4
  99. data/spec/paperclip/geometry_detector_spec.rb +7 -8
  100. data/spec/paperclip/geometry_parser_spec.rb +31 -31
  101. data/spec/paperclip/geometry_spec.rb +24 -24
  102. data/spec/paperclip/glue_spec.rb +3 -5
  103. data/spec/paperclip/has_attached_file_spec.rb +46 -126
  104. data/spec/paperclip/integration_spec.rb +111 -77
  105. data/spec/paperclip/interpolations_spec.rb +101 -93
  106. data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +41 -13
  107. data/spec/paperclip/io_adapters/attachment_adapter_spec.rb +8 -10
  108. data/spec/paperclip/io_adapters/data_uri_adapter_spec.rb +13 -14
  109. data/spec/paperclip/io_adapters/empty_string_adapter_spec.rb +4 -4
  110. data/spec/paperclip/io_adapters/file_adapter_spec.rb +12 -12
  111. data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +58 -37
  112. data/spec/paperclip/io_adapters/identity_adapter_spec.rb +1 -1
  113. data/spec/paperclip/io_adapters/nil_adapter_spec.rb +2 -2
  114. data/spec/paperclip/io_adapters/registry_spec.rb +4 -4
  115. data/spec/paperclip/io_adapters/stringio_adapter_spec.rb +10 -10
  116. data/spec/paperclip/io_adapters/uploaded_file_adapter_spec.rb +6 -6
  117. data/spec/paperclip/io_adapters/uri_adapter_spec.rb +90 -31
  118. data/spec/paperclip/matchers/have_attached_file_matcher_spec.rb +3 -3
  119. data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +4 -5
  120. data/spec/paperclip/matchers/validate_attachment_presence_matcher_spec.rb +4 -4
  121. data/spec/paperclip/matchers/validate_attachment_size_matcher_spec.rb +4 -4
  122. data/spec/paperclip/media_type_spoof_detector_spec.rb +50 -24
  123. data/spec/paperclip/meta_class_spec.rb +3 -3
  124. data/spec/paperclip/paperclip_missing_attachment_styles_spec.rb +28 -24
  125. data/spec/paperclip/paperclip_spec.rb +15 -11
  126. data/spec/paperclip/plural_cache_spec.rb +8 -8
  127. data/spec/paperclip/processor_helpers_spec.rb +35 -35
  128. data/spec/paperclip/processor_spec.rb +8 -8
  129. data/spec/paperclip/rails_environment_spec.rb +7 -10
  130. data/spec/paperclip/rake_spec.rb +39 -39
  131. data/spec/paperclip/schema_spec.rb +57 -53
  132. data/spec/paperclip/storage/filesystem_spec.rb +29 -6
  133. data/spec/paperclip/storage/fog_spec.rb +122 -82
  134. data/spec/paperclip/storage/s3_live_spec.rb +22 -22
  135. data/spec/paperclip/storage/s3_spec.rb +649 -583
  136. data/spec/paperclip/style_spec.rb +67 -71
  137. data/spec/paperclip/tempfile_factory_spec.rb +5 -5
  138. data/spec/paperclip/thumbnail_spec.rb +68 -67
  139. data/spec/paperclip/url_generator_spec.rb +18 -19
  140. data/spec/paperclip/validators/attachment_content_type_validator_spec.rb +115 -27
  141. data/spec/paperclip/validators/attachment_file_name_validator_spec.rb +105 -16
  142. data/spec/paperclip/validators/attachment_presence_validator_spec.rb +5 -5
  143. data/spec/paperclip/validators/attachment_size_validator_spec.rb +111 -21
  144. data/spec/paperclip/validators/media_type_spoof_detection_validator_spec.rb +9 -13
  145. data/spec/paperclip/validators_spec.rb +61 -46
  146. data/spec/spec_helper.rb +21 -23
  147. data/spec/support/assertions.rb +8 -6
  148. data/spec/support/fake_model.rb +1 -2
  149. data/spec/support/fake_rails.rb +1 -1
  150. data/spec/support/fixtures/aws_s3.yml +13 -0
  151. data/spec/support/fixtures/sample.xlsm +0 -0
  152. data/spec/support/matchers/exist.rb +1 -1
  153. data/spec/support/matchers/have_column.rb +1 -1
  154. data/spec/support/mock_url_generator_builder.rb +2 -3
  155. data/spec/support/model_reconstruction.rb +16 -12
  156. data/spec/support/reporting.rb +1 -1
  157. data/spec/support/test_data.rb +2 -2
  158. metadata +58 -106
  159. data/spec/support/conditional_filter_helper.rb +0 -5
@@ -1,31 +1,37 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe Paperclip::ContentTypeDetector do
4
- it 'returns a meaningful content type for open xml spreadsheets' do
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 'gives a sensible default when the name is empty' do
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
11
18
  assert_equal "application/octet-stream", Paperclip::ContentTypeDetector.new("").detect
12
19
  end
13
20
 
14
- it 'returns the empty content type when the file is empty' do
21
+ it "returns the empty content type when the file is empty" do
15
22
  tempfile = Tempfile.new("empty")
16
23
  assert_equal "inode/x-empty", Paperclip::ContentTypeDetector.new(tempfile.path).detect
17
24
  tempfile.close
18
25
  end
19
26
 
20
- it 'returns content type of file if it is an acceptable type' do
21
- MIME::Types.stubs(:type_for).returns([MIME::Type.new('application/mp4'), MIME::Type.new('video/mp4'), MIME::Type.new('audio/mp4')])
22
- Paperclip::ContentTypeDetector.any_instance
23
- .stubs(:type_from_file_contents).returns("video/mp4")
27
+ it "returns content type of file if it is an acceptable type" do
28
+ allow(MIME::Types).to receive(:type_for).and_return([MIME::Type.new("application/mp4"), MIME::Type.new("video/mp4"), MIME::Type.new("audio/mp4")])
29
+ allow_any_instance_of(Paperclip::ContentTypeDetector).to receive(:type_from_file_contents).and_return("video/mp4")
24
30
  @filename = "my_file.mp4"
25
31
  assert_equal "video/mp4", Paperclip::ContentTypeDetector.new(@filename).detect
26
32
  end
27
33
 
28
- it 'finds the right type in the list via the file command' do
34
+ it "finds the right type in the list via the file command" do
29
35
  @filename = "#{Dir.tmpdir}/something.hahalolnotreal"
30
36
  File.open(@filename, "w+") do |file|
31
37
  file.puts "This is a text file."
@@ -35,13 +41,13 @@ describe Paperclip::ContentTypeDetector do
35
41
  FileUtils.rm @filename
36
42
  end
37
43
 
38
- it 'returns a sensible default if something is wrong, like the file is gone' do
44
+ it "returns a sensible default if something is wrong, like the file is gone" do
39
45
  @filename = "/path/to/nothing"
40
46
  assert_equal "application/octet-stream", Paperclip::ContentTypeDetector.new(@filename).detect
41
47
  end
42
48
 
43
- it 'returns a sensible default when the file command is missing' do
44
- Paperclip.stubs(:run).raises(Terrapin::CommandLineError.new)
49
+ it "returns a sensible default when the file command is missing" do
50
+ allow(Paperclip).to receive(:run).and_raise(Terrapin::CommandLineError.new)
45
51
  @filename = "/path/to/something"
46
52
  assert_equal "application/octet-stream", Paperclip::ContentTypeDetector.new(@filename).detect
47
53
  end
@@ -1,7 +1,7 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe Paperclip::FileCommandContentTypeDetector do
4
- it 'returns a content type based on the content of the file' do
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 'returns a sensible default when the file command is missing' do
15
- Paperclip.stubs(:run).raises(Terrapin::CommandLineError.new)
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
- Paperclip::FileCommandContentTypeDetector.new(@filename).detect
18
+ Paperclip::FileCommandContentTypeDetector.new(@filename).detect
19
19
  end
20
20
 
21
- it 'returns a sensible default on the odd chance that run returns nil' do
22
- Paperclip.stubs(:run).returns(nil)
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
- Paperclip::FileCommandContentTypeDetector.new("windows").detect
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.stubs(:run).returns("text/html charset=us-ascii")
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.stubs(:run).returns("text/html; charset=us-ascii")
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
- # encoding: utf-8
2
- require 'spec_helper'
1
+ require "spec_helper"
3
2
 
4
3
  describe Paperclip::FilenameCleaner do
5
- it 'converts invalid characters to underscores' do
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 'does not convert anything if the character regex is nil' do
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 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe Paperclip::GeometryDetector do
4
- it 'identifies an image and extract its dimensions' do
5
- Paperclip::GeometryParser.stubs(:new).with("434x66,").returns(stub(make: :correct))
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 'identifies an image and extract its dimensions and orientation' do
15
- Paperclip::GeometryParser.stubs(:new).with("300x200,6").returns(stub(make: :correct))
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 'avoids reading EXIF orientation if so configured' do
24
+ it "avoids reading EXIF orientation if so configured" do
25
25
  begin
26
26
  Paperclip.options[:use_exif_orientation] = false
27
- Paperclip::GeometryParser.stubs(:new).with("300x200,1").returns(stub(make: :correct))
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 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe Paperclip::GeometryParser do
4
- it 'identifies an image and extract its dimensions with no orientation' do
5
- Paperclip::Geometry.stubs(:new).with(
6
- height: '73',
7
- width: '434',
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
- ).returns(:correct)
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 'identifies an image and extract its dimensions with an empty orientation' do
19
- Paperclip::Geometry.stubs(:new).with(
20
- height: '73',
21
- width: '434',
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
- ).returns(:correct)
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 'identifies an image and extract its dimensions and orientation' do
33
- Paperclip::Geometry.stubs(:new).with(
34
- height: '200',
35
- width: '300',
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: '6'
38
- ).returns(:correct)
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 'identifies an image and extract its dimensions and modifier' do
47
- Paperclip::Geometry.stubs(:new).with(
48
- height: '64',
49
- width: '64',
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
- ).returns(:correct)
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 'identifies an image and extract its dimensions, orientation, and modifier' do
61
- Paperclip::Geometry.stubs(:new).with(
62
- height: '50',
63
- width: '100',
64
- modifier: '>',
65
- orientation: '7'
66
- ).returns(:correct)
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 'spec_helper'
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
- ['>', '<', '#', '@', '@>', '>@', '%', '^', '!', nil].each do |mod|
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, 'rb')
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 'calculates an EXIF-rotated image dimensions from a path' do
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 = mock("file", path: "")
165
- file.stubs(:respond_to?).with(:path).returns(true)
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['PATH']
170
+ old_path = ENV["PATH"]
171
171
  begin
172
- ENV['PATH'] = ''
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['PATH'] = old_path
178
+ ENV["PATH"] = old_path
179
179
  end
180
180
  end
181
181
 
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|
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] ? "" : "not"} vertical" do
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] ? "" : "not"} horizontal" do
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] ? "" : "not"} square" do
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
- [[ [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|
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
- [['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|
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
@@ -14,7 +14,7 @@ describe Paperclip::Glue do
14
14
 
15
15
  it "does not fail" do
16
16
  NonActiveRecordModel = Class.new
17
- NonActiveRecordModel.send :include, Paperclip::Glue
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.send :include, Paperclip::Glue
38
+ NonActiveRecordModel.include Paperclip::Glue
41
39
  Object.send :remove_const, "NonActiveRecordModel"
42
40
  end
43
41
  end
@@ -1,158 +1,78 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe Paperclip::HasAttachedFile do
4
- context '#define_on' do
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
- it 'defines a method on the class to get all of its attachments' do
18
- assert_adding_attachment('avatar').defines_class_method('attachment_definitions')
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 'flushes errors as part of validations' do
22
- assert_adding_attachment('avatar').defines_validation
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 'registers the attachment with Paperclip::AttachmentRegistry' do
26
- assert_adding_attachment('avatar').registers_attachment
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 'defines an after_save callback' do
30
- assert_adding_attachment('avatar').defines_callback('after_save')
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 'defines a before_destroy callback' do
34
- assert_adding_attachment('avatar').defines_callback('before_destroy')
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 'defines an after_commit callback' do
38
- assert_adding_attachment('avatar').defines_callback('after_commit')
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
- context 'when the class does not allow after_commit callbacks' do
42
- it 'defines an after_destroy callback' do
43
- assert_adding_attachment(
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 'defines the Paperclip-specific callbacks' do
51
- assert_adding_attachment('avatar').defines_callback('define_paperclip_callbacks')
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 'does not define a media_type check if told not to' do
55
- assert_adding_attachment('avatar').does_not_set_up_media_type_check_validation
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
- it 'does define a media_type check if told to' do
59
- assert_adding_attachment('avatar').sets_up_media_type_check_validation
60
- end
61
- end
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
- def defines_method(method_name)
84
- a_class = @stubbed_class
85
-
86
- Paperclip::HasAttachedFile.define_on(a_class, @attachment_name, {})
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
- def does_not_set_up_media_type_check_validation
126
- a_class = stub_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
- def sets_up_media_type_check_validation
134
- a_class = stub_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