paperclip 5.0.0.beta2 → 5.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +17 -0
  3. data/.hound.yml +5 -16
  4. data/.travis.yml +14 -15
  5. data/Appraisals +3 -23
  6. data/CONTRIBUTING.md +10 -4
  7. data/Gemfile +1 -0
  8. data/NEWS +78 -2
  9. data/README.md +175 -81
  10. data/Rakefile +1 -1
  11. data/UPGRADING +1 -1
  12. data/features/basic_integration.feature +2 -2
  13. data/features/step_definitions/attachment_steps.rb +6 -6
  14. data/features/step_definitions/rails_steps.rb +29 -22
  15. data/features/step_definitions/s3_steps.rb +1 -1
  16. data/features/support/env.rb +1 -0
  17. data/features/support/paths.rb +1 -1
  18. data/features/support/rails.rb +0 -24
  19. data/gemfiles/{4.2.awsv2.0.gemfile → 4.2.gemfile} +1 -1
  20. data/gemfiles/{5.0.awsv2.1.gemfile → 5.0.gemfile} +2 -2
  21. data/lib/generators/paperclip/paperclip_generator.rb +9 -1
  22. data/lib/generators/paperclip/templates/paperclip_migration.rb.erb +1 -1
  23. data/lib/paperclip.rb +13 -10
  24. data/lib/paperclip/attachment.rb +16 -6
  25. data/lib/paperclip/content_type_detector.rb +3 -2
  26. data/lib/paperclip/errors.rb +3 -1
  27. data/lib/paperclip/file_command_content_type_detector.rb +1 -1
  28. data/lib/paperclip/geometry_detector_factory.rb +2 -2
  29. data/lib/paperclip/helpers.rb +15 -12
  30. data/lib/paperclip/interpolations.rb +1 -1
  31. data/lib/paperclip/io_adapters/abstract_adapter.rb +29 -3
  32. data/lib/paperclip/io_adapters/attachment_adapter.rb +10 -5
  33. data/lib/paperclip/io_adapters/data_uri_adapter.rb +8 -8
  34. data/lib/paperclip/io_adapters/empty_string_adapter.rb +5 -4
  35. data/lib/paperclip/io_adapters/file_adapter.rb +12 -6
  36. data/lib/paperclip/io_adapters/http_url_proxy_adapter.rb +7 -7
  37. data/lib/paperclip/io_adapters/identity_adapter.rb +12 -6
  38. data/lib/paperclip/io_adapters/nil_adapter.rb +8 -5
  39. data/lib/paperclip/io_adapters/registry.rb +6 -2
  40. data/lib/paperclip/io_adapters/stringio_adapter.rb +9 -6
  41. data/lib/paperclip/io_adapters/uploaded_file_adapter.rb +10 -6
  42. data/lib/paperclip/io_adapters/uri_adapter.rb +41 -19
  43. data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +4 -4
  44. data/lib/paperclip/media_type_spoof_detector.rb +3 -2
  45. data/lib/paperclip/processor.rb +5 -4
  46. data/lib/paperclip/storage/filesystem.rb +13 -2
  47. data/lib/paperclip/storage/fog.rb +12 -7
  48. data/lib/paperclip/storage/s3.rb +46 -19
  49. data/lib/paperclip/thumbnail.rb +18 -8
  50. data/lib/paperclip/url_generator.rb +17 -13
  51. data/lib/paperclip/validators.rb +1 -1
  52. data/lib/paperclip/version.rb +3 -1
  53. data/lib/tasks/paperclip.rake +18 -4
  54. data/paperclip.gemspec +4 -5
  55. data/spec/paperclip/attachment_processing_spec.rb +2 -4
  56. data/spec/paperclip/attachment_spec.rb +40 -9
  57. data/spec/paperclip/content_type_detector_spec.rb +1 -1
  58. data/spec/paperclip/file_command_content_type_detector_spec.rb +15 -1
  59. data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +76 -22
  60. data/spec/paperclip/io_adapters/attachment_adapter_spec.rb +6 -3
  61. data/spec/paperclip/io_adapters/data_uri_adapter_spec.rb +7 -1
  62. data/spec/paperclip/io_adapters/file_adapter_spec.rb +2 -2
  63. data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +26 -6
  64. data/spec/paperclip/io_adapters/identity_adapter_spec.rb +1 -1
  65. data/spec/paperclip/io_adapters/registry_spec.rb +2 -2
  66. data/spec/paperclip/io_adapters/stringio_adapter_spec.rb +1 -1
  67. data/spec/paperclip/io_adapters/uploaded_file_adapter_spec.rb +5 -5
  68. data/spec/paperclip/io_adapters/uri_adapter_spec.rb +77 -7
  69. data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +10 -0
  70. data/spec/paperclip/media_type_spoof_detector_spec.rb +27 -3
  71. data/spec/paperclip/paperclip_spec.rb +13 -13
  72. data/spec/paperclip/processor_spec.rb +4 -4
  73. data/spec/paperclip/storage/fog_spec.rb +28 -0
  74. data/spec/paperclip/storage/s3_live_spec.rb +12 -10
  75. data/spec/paperclip/storage/s3_spec.rb +150 -39
  76. data/spec/paperclip/tempfile_spec.rb +35 -0
  77. data/spec/paperclip/thumbnail_spec.rb +38 -35
  78. data/spec/paperclip/url_generator_spec.rb +54 -43
  79. data/spec/paperclip/validators_spec.rb +3 -2
  80. data/spec/spec_helper.rb +3 -1
  81. data/spec/support/assertions.rb +5 -1
  82. data/spec/support/conditional_filter_helper.rb +5 -0
  83. data/spec/support/mock_attachment.rb +2 -0
  84. data/spec/support/mock_url_generator_builder.rb +2 -2
  85. metadata +37 -36
  86. data/gemfiles/4.2.awsv2.1.gemfile +0 -17
  87. data/gemfiles/4.2.awsv2.gemfile +0 -20
  88. data/gemfiles/5.0.awsv2.0.gemfile +0 -17
  89. data/gemfiles/5.0.awsv2.gemfile +0 -25
@@ -3,6 +3,6 @@ require 'spec_helper'
3
3
  describe Paperclip::IdentityAdapter do
4
4
  it "responds to #new by returning the argument" do
5
5
  adapter = Paperclip::IdentityAdapter.new
6
- assert_equal :target, adapter.new(:target)
6
+ assert_equal :target, adapter.new(:target, nil)
7
7
  end
8
8
  end
@@ -4,7 +4,7 @@ describe Paperclip::AttachmentRegistry do
4
4
  context "for" do
5
5
  before do
6
6
  class AdapterTest
7
- def initialize(target); end
7
+ def initialize(_target, _ = {}); end
8
8
  end
9
9
  @subject = Paperclip::AdapterRegistry.new
10
10
  @subject.register(AdapterTest){|t| Symbol === t }
@@ -18,7 +18,7 @@ describe Paperclip::AttachmentRegistry do
18
18
  context "registered?" do
19
19
  before do
20
20
  class AdapterTest
21
- def initialize(target); end
21
+ def initialize(_target, _ = {}); end
22
22
  end
23
23
  @subject = Paperclip::AdapterRegistry.new
24
24
  @subject.register(AdapterTest){|t| Symbol === t }
@@ -5,7 +5,7 @@ describe Paperclip::StringioAdapter do
5
5
  before do
6
6
  @contents = "abc123"
7
7
  @stringio = StringIO.new(@contents)
8
- @subject = Paperclip.io_adapters.for(@stringio)
8
+ @subject = Paperclip.io_adapters.for(@stringio, hash_digest: Digest::MD5)
9
9
  end
10
10
 
11
11
  it "returns a file name" do
@@ -17,7 +17,7 @@ describe Paperclip::UploadedFileAdapter do
17
17
  tempfile: tempfile,
18
18
  path: tempfile.path
19
19
  )
20
- @subject = Paperclip.io_adapters.for(@file)
20
+ @subject = Paperclip.io_adapters.for(@file, hash_digest: Digest::MD5)
21
21
  end
22
22
 
23
23
  it "gets the right filename" do
@@ -29,7 +29,7 @@ describe Paperclip::UploadedFileAdapter do
29
29
  end
30
30
 
31
31
  it "gets the content type" do
32
- assert_equal "image/x-png-by-browser", @subject.content_type
32
+ assert_equal "image/png", @subject.content_type
33
33
  end
34
34
 
35
35
  it "gets the file's size" do
@@ -63,7 +63,7 @@ describe Paperclip::UploadedFileAdapter do
63
63
  head: "",
64
64
  path: fixture_file("5k.png")
65
65
  )
66
- @subject = Paperclip.io_adapters.for(@file)
66
+ @subject = Paperclip.io_adapters.for(@file, hash_digest: Digest::MD5)
67
67
  end
68
68
 
69
69
  it "does not generate paths that include restricted characters" do
@@ -86,7 +86,7 @@ describe Paperclip::UploadedFileAdapter do
86
86
  head: "",
87
87
  path: fixture_file("5k.png")
88
88
  )
89
- @subject = Paperclip.io_adapters.for(@file)
89
+ @subject = Paperclip.io_adapters.for(@file, hash_digest: Digest::MD5)
90
90
  end
91
91
 
92
92
  it "gets the right filename" do
@@ -98,7 +98,7 @@ describe Paperclip::UploadedFileAdapter do
98
98
  end
99
99
 
100
100
  it "gets the content type" do
101
- assert_equal "image/x-png-by-browser", @subject.content_type
101
+ assert_equal "image/png", @subject.content_type
102
102
  end
103
103
 
104
104
  it "gets the file's size" do
@@ -1,13 +1,27 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Paperclip::UriAdapter do
4
+ let(:content_type) { "image/png" }
5
+ let(:meta) { {} }
6
+
7
+ before do
8
+ @open_return = StringIO.new("xxx")
9
+ @open_return.stubs(:content_type).returns(content_type)
10
+ @open_return.stubs(:meta).returns(meta)
11
+ Paperclip::UriAdapter.register
12
+ end
13
+
14
+ after do
15
+ Paperclip.io_adapters.unregister(described_class)
16
+ end
17
+
4
18
  context "a new instance" do
5
19
  before do
6
- @open_return = StringIO.new("xxx")
7
- @open_return.stubs(:content_type).returns("image/png")
8
- Paperclip::UriAdapter.any_instance.stubs(:download_content).returns(@open_return)
20
+ Paperclip::UriAdapter.any_instance.
21
+ stubs(:download_content).returns(@open_return)
22
+
9
23
  @uri = URI.parse("http://thoughtbot.com/images/thoughtbot-logo.png")
10
- @subject = Paperclip.io_adapters.for(@uri)
24
+ @subject = Paperclip.io_adapters.for(@uri, hash_digest: Digest::MD5)
11
25
  end
12
26
 
13
27
  it "returns a file name" do
@@ -56,8 +70,12 @@ describe Paperclip::UriAdapter do
56
70
  end
57
71
 
58
72
  context "a directory index url" do
73
+ let(:content_type) { "text/html" }
74
+
59
75
  before do
60
- Paperclip::UriAdapter.any_instance.stubs(:download_content).returns(StringIO.new("xxx"))
76
+ Paperclip::UriAdapter.any_instance.
77
+ stubs(:download_content).returns(@open_return)
78
+
61
79
  @uri = URI.parse("http://thoughtbot.com")
62
80
  @subject = Paperclip.io_adapters.for(@uri)
63
81
  end
@@ -73,7 +91,9 @@ describe Paperclip::UriAdapter do
73
91
 
74
92
  context "a url with query params" do
75
93
  before do
76
- Paperclip::UriAdapter.any_instance.stubs(:download_content).returns(StringIO.new("xxx"))
94
+ Paperclip::UriAdapter.any_instance.
95
+ stubs(:download_content).returns(@open_return)
96
+
77
97
  @uri = URI.parse("https://github.com/thoughtbot/paperclip?file=test")
78
98
  @subject = Paperclip.io_adapters.for(@uri)
79
99
  end
@@ -83,9 +103,32 @@ describe Paperclip::UriAdapter do
83
103
  end
84
104
  end
85
105
 
106
+ context "a url with content disposition headers" do
107
+ let(:file_name) { "test_document.pdf" }
108
+ let(:meta) do
109
+ {
110
+ "content-disposition" => "attachment; filename=\"#{file_name}\";",
111
+ }
112
+ end
113
+
114
+ before do
115
+ Paperclip::UriAdapter.any_instance.
116
+ stubs(:download_content).returns(@open_return)
117
+
118
+ @uri = URI.parse("https://github.com/thoughtbot/paperclip?file=test")
119
+ @subject = Paperclip.io_adapters.for(@uri)
120
+ end
121
+
122
+ it "returns a file name" do
123
+ assert_equal file_name, @subject.original_filename
124
+ end
125
+ end
126
+
86
127
  context "a url with restricted characters in the filename" do
87
128
  before do
88
- Paperclip::UriAdapter.any_instance.stubs(:download_content).returns(StringIO.new("xxx"))
129
+ Paperclip::UriAdapter.any_instance.
130
+ stubs(:download_content).returns(@open_return)
131
+
89
132
  @uri = URI.parse("https://github.com/thoughtbot/paper:clip.jpg")
90
133
  @subject = Paperclip.io_adapters.for(@uri)
91
134
  end
@@ -99,4 +142,31 @@ describe Paperclip::UriAdapter do
99
142
  end
100
143
  end
101
144
 
145
+ describe "#download_content" do
146
+ before do
147
+ Paperclip::UriAdapter.any_instance.stubs(:open).returns(@open_return)
148
+ @uri = URI.parse("https://github.com/thoughtbot/paper:clip.jpg")
149
+ @subject = Paperclip.io_adapters.for(@uri)
150
+ end
151
+
152
+ after do
153
+ @subject.send(:download_content)
154
+ end
155
+
156
+ context "with default read_timeout" do
157
+ it "calls open without options" do
158
+ @subject.expects(:open).with(@uri, {}).at_least_once
159
+ end
160
+ end
161
+
162
+ context "with custom read_timeout" do
163
+ before do
164
+ Paperclip.options[:read_timeout] = 120
165
+ end
166
+
167
+ it "calls open with read_timeout option" do
168
+ @subject.expects(:open).with(@uri, read_timeout: 120).at_least_once
169
+ end
170
+ end
171
+ end
102
172
  end
@@ -17,22 +17,26 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do
17
17
 
18
18
  it "rejects a class with no validation" do
19
19
  expect(matcher).to_not accept(Dummy)
20
+ expect { matcher.failure_message }.to_not raise_error
20
21
  end
21
22
 
22
23
  it 'rejects a class when the validation fails' do
23
24
  Dummy.validates_attachment_content_type :avatar, content_type: %r{audio/.*}
24
25
  expect(matcher).to_not accept(Dummy)
26
+ expect { matcher.failure_message }.to_not raise_error
25
27
  end
26
28
 
27
29
  it "accepts a class with a matching validation" do
28
30
  Dummy.validates_attachment_content_type :avatar, content_type: %r{image/.*}
29
31
  expect(matcher).to accept(Dummy)
32
+ expect { matcher.failure_message }.to_not raise_error
30
33
  end
31
34
 
32
35
  it "accepts a class with other validations but matching types" do
33
36
  Dummy.validates_presence_of :title
34
37
  Dummy.validates_attachment_content_type :avatar, content_type: %r{image/.*}
35
38
  expect(matcher).to accept(Dummy)
39
+ expect { matcher.failure_message }.to_not raise_error
36
40
  end
37
41
 
38
42
  it "accepts a class that matches and a matcher that only specifies 'allowing'" do
@@ -40,6 +44,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do
40
44
  matcher = plain_matcher.allowing(%w(image/png image/jpeg))
41
45
 
42
46
  expect(matcher).to accept(Dummy)
47
+ expect { matcher.failure_message }.to_not raise_error
43
48
  end
44
49
 
45
50
  it "rejects a class that does not match and a matcher that only specifies 'allowing'" do
@@ -47,6 +52,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do
47
52
  matcher = plain_matcher.allowing(%w(image/png image/jpeg))
48
53
 
49
54
  expect(matcher).to_not accept(Dummy)
55
+ expect { matcher.failure_message }.to_not raise_error
50
56
  end
51
57
 
52
58
  it "accepts a class that matches and a matcher that only specifies 'rejecting'" do
@@ -54,6 +60,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do
54
60
  matcher = plain_matcher.rejecting(%w(audio/mp3 application/octet-stream))
55
61
 
56
62
  expect(matcher).to accept(Dummy)
63
+ expect { matcher.failure_message }.to_not raise_error
57
64
  end
58
65
 
59
66
  it "rejects a class that does not match and a matcher that only specifies 'rejecting'" do
@@ -61,6 +68,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do
61
68
  matcher = plain_matcher.rejecting(%w(audio/mp3 application/octet-stream))
62
69
 
63
70
  expect(matcher).to_not accept(Dummy)
71
+ expect { matcher.failure_message }.to_not raise_error
64
72
  end
65
73
 
66
74
  context "using an :if to control the validation" do
@@ -75,12 +83,14 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do
75
83
  dummy = Dummy.new
76
84
  dummy.go = true
77
85
  expect(matcher).to accept(dummy)
86
+ expect { matcher.failure_message }.to_not raise_error
78
87
  end
79
88
 
80
89
  it "does not run the validation if the control is false" do
81
90
  dummy = Dummy.new
82
91
  dummy.go = false
83
92
  expect(matcher).to_not accept(dummy)
93
+ expect { matcher.failure_message }.to_not raise_error
84
94
  end
85
95
  end
86
96
 
@@ -44,9 +44,18 @@ describe Paperclip::MediaTypeSpoofDetector do
44
44
  end
45
45
  end
46
46
 
47
- it "rejects a file if named .html and is as HTML, but we're told JPG" do
48
- file = File.open(fixture_file("empty.html"))
49
- assert Paperclip::MediaTypeSpoofDetector.using(file, "empty.html", "image/jpg").spoofed?
47
+ context "file named .html and is as HTML, but we're told JPG" do
48
+ let(:file) { File.open(fixture_file("empty.html")) }
49
+ let(:spoofed?) { Paperclip::MediaTypeSpoofDetector.using(file, "empty.html", "image/jpg").spoofed? }
50
+
51
+ it "rejects the file" do
52
+ assert spoofed?
53
+ end
54
+
55
+ it "logs info about the detected spoof" do
56
+ Paperclip.expects(:log).with('Content Type Spoof: Filename empty.html (image/jpg from Headers, ["text/html"] from Extension), content type discovered from file command: text/html. See documentation to allow this combination.')
57
+ spoofed?
58
+ end
50
59
  end
51
60
 
52
61
  it "does not reject if content_type is empty but otherwise checks out" do
@@ -67,4 +76,19 @@ describe Paperclip::MediaTypeSpoofDetector do
67
76
  Paperclip.options[:content_type_mappings] = {}
68
77
  end
69
78
  end
79
+
80
+ context "#type_from_file_command" do
81
+ let(:file) { File.new(fixture_file("empty.html")) }
82
+ let(:detector) { Paperclip::MediaTypeSpoofDetector.new(file, "html", "") }
83
+
84
+ it "does work with the output of old versions of file" do
85
+ Paperclip.stubs(:run).returns("text/html charset=us-ascii")
86
+ expect(detector.send(:type_from_file_command)).to eq("text/html")
87
+ end
88
+
89
+ it "does work with the output of new versions of file" do
90
+ Paperclip.stubs(:run).returns("text/html; charset=us-ascii")
91
+ expect(detector.send(:type_from_file_command)).to eq("text/html")
92
+ end
93
+ end
70
94
  end
@@ -4,40 +4,40 @@ describe Paperclip do
4
4
  context ".run" do
5
5
  before do
6
6
  Paperclip.options[:log_command] = false
7
- Cocaine::CommandLine.expects(:new).with("convert", "stuff", {}).returns(stub(:run))
8
- @original_command_line_path = Cocaine::CommandLine.path
7
+ Terrapin::CommandLine.expects(:new).with("convert", "stuff", {}).returns(stub(:run))
8
+ @original_command_line_path = Terrapin::CommandLine.path
9
9
  end
10
10
 
11
11
  after do
12
12
  Paperclip.options[:log_command] = true
13
- Cocaine::CommandLine.path = @original_command_line_path
13
+ Terrapin::CommandLine.path = @original_command_line_path
14
14
  end
15
15
 
16
- it "runs the command with Cocaine" do
16
+ it "runs the command with Terrapin" do
17
17
  Paperclip.run("convert", "stuff")
18
18
  end
19
19
 
20
- it "saves Cocaine::CommandLine.path that set before" do
21
- Cocaine::CommandLine.path = "/opt/my_app/bin"
20
+ it "saves Terrapin::CommandLine.path that set before" do
21
+ Terrapin::CommandLine.path = "/opt/my_app/bin"
22
22
  Paperclip.run("convert", "stuff")
23
- expect(Cocaine::CommandLine.path).to match("/opt/my_app/bin")
23
+ expect(Terrapin::CommandLine.path).to match("/opt/my_app/bin")
24
24
  end
25
25
 
26
- it "does not duplicate Cocaine::CommandLine.path on multiple runs" do
27
- Cocaine::CommandLine.expects(:new).with("convert", "more_stuff", {}).returns(stub(:run))
28
- Cocaine::CommandLine.path = nil
26
+ it "does not duplicate Terrapin::CommandLine.path on multiple runs" do
27
+ Terrapin::CommandLine.expects(:new).with("convert", "more_stuff", {}).returns(stub(:run))
28
+ Terrapin::CommandLine.path = nil
29
29
  Paperclip.options[:command_path] = "/opt/my_app/bin"
30
30
  Paperclip.run("convert", "stuff")
31
31
  Paperclip.run("convert", "more_stuff")
32
32
 
33
33
  cmd_path = Paperclip.options[:command_path]
34
- assert_equal 1, Cocaine::CommandLine.path.scan(cmd_path).count
34
+ assert_equal 1, Terrapin::CommandLine.path.scan(cmd_path).count
35
35
  end
36
36
  end
37
37
 
38
38
  it 'does not raise errors when doing a lot of running' do
39
39
  Paperclip.options[:command_path] = ["/usr/local/bin"] * 1024
40
- Cocaine::CommandLine.path = "/something/else"
40
+ Terrapin::CommandLine.path = "/something/else"
41
41
  100.times do |x|
42
42
  Paperclip.run("echo", x.to_s)
43
43
  end
@@ -63,7 +63,7 @@ describe Paperclip do
63
63
  context "Calling Paperclip.run with a logger" do
64
64
  it "passes the defined logger if :log_command is set" do
65
65
  Paperclip.options[:log_command] = true
66
- Cocaine::CommandLine.expects(:new).with("convert", "stuff", logger: Paperclip.logger).returns(stub(:run))
66
+ Terrapin::CommandLine.expects(:new).with("convert", "stuff", logger: Paperclip.logger).returns(stub(:run))
67
67
  Paperclip.run("convert", "stuff")
68
68
  end
69
69
  end
@@ -9,17 +9,17 @@ describe Paperclip::Processor do
9
9
  end
10
10
 
11
11
  context "Calling #convert" do
12
- it "runs the convert command with Cocaine" do
12
+ it "runs the convert command with Terrapin" do
13
13
  Paperclip.options[:log_command] = false
14
- Cocaine::CommandLine.expects(:new).with("convert", "stuff", {}).returns(stub(:run))
14
+ Terrapin::CommandLine.expects(:new).with("convert", "stuff", {}).returns(stub(:run))
15
15
  Paperclip::Processor.new('filename').convert("stuff")
16
16
  end
17
17
  end
18
18
 
19
19
  context "Calling #identify" do
20
- it "runs the identify command with Cocaine" do
20
+ it "runs the identify command with Terrapin" do
21
21
  Paperclip.options[:log_command] = false
22
- Cocaine::CommandLine.expects(:new).with("identify", "stuff", {}).returns(stub(:run))
22
+ Terrapin::CommandLine.expects(:new).with("identify", "stuff", {}).returns(stub(:run))
23
23
  Paperclip::Processor.new('filename').identify("stuff")
24
24
  end
25
25
  end
@@ -183,6 +183,13 @@ describe Paperclip::Storage::Fog do
183
183
  tempfile.close
184
184
  end
185
185
 
186
+ it 'is able to be handled when missing while copying to a local file' do
187
+ tempfile = Tempfile.new("known_location")
188
+ tempfile.binmode
189
+ assert_equal false, @dummy.avatar.copy_to_local_file(:original, tempfile.path)
190
+ tempfile.close
191
+ end
192
+
186
193
  it "passes the content type to the Fog::Storage::AWS::Files instance" do
187
194
  Fog::Storage::AWS::Files.any_instance.expects(:create).with do |hash|
188
195
  hash[:content_type]
@@ -199,6 +206,11 @@ describe Paperclip::Storage::Fog do
199
206
  assert @dummy.save
200
207
  assert @connection.directories.get(@fog_directory)
201
208
  end
209
+
210
+ it "sucessfully rewinds the file during bucket creation" do
211
+ assert @dummy.save
212
+ expect(Paperclip.io_adapters.for(@dummy.avatar).read.length).to be > 0
213
+ end
202
214
  end
203
215
 
204
216
  context "with a bucket" do
@@ -266,6 +278,22 @@ describe Paperclip::Storage::Fog do
266
278
  end
267
279
  end
268
280
 
281
+ context "with fog_public as a proc" do
282
+ let(:proc) { ->(attachment) { !attachment } }
283
+
284
+ before do
285
+ rebuild_model(@options.merge(fog_public: proc))
286
+ @dummy = Dummy.new
287
+ @dummy.avatar = StringIO.new(".")
288
+ @dummy.save
289
+ end
290
+
291
+ it "sets the @fog_public instance variable to false" do
292
+ assert_equal proc, @dummy.avatar.instance_variable_get("@options")[:fog_public]
293
+ assert_equal false, @dummy.avatar.fog_public
294
+ end
295
+ end
296
+
269
297
  context "with styles set and fog_public set to false" do
270
298
  before do
271
299
  rebuild_model(@options.merge(fog_public: false, styles: { medium: "300x300>", thumb: "100x100>" }))