paperclip 4.1.1 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of paperclip might be problematic. Click here for more details.

Files changed (152) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -6
  3. data/.travis.yml +4 -13
  4. data/Appraisals +0 -10
  5. data/CONTRIBUTING.md +10 -5
  6. data/Gemfile +8 -4
  7. data/NEWS +1 -1
  8. data/README.md +51 -10
  9. data/Rakefile +6 -8
  10. data/features/basic_integration.feature +5 -5
  11. data/features/step_definitions/attachment_steps.rb +4 -4
  12. data/features/step_definitions/rails_steps.rb +4 -4
  13. data/features/step_definitions/web_steps.rb +2 -2
  14. data/features/support/env.rb +2 -2
  15. data/features/support/fixtures/gemfile.txt +1 -1
  16. data/features/support/rails.rb +2 -1
  17. data/gemfiles/3.2.gemfile +5 -3
  18. data/gemfiles/4.0.gemfile +5 -3
  19. data/gemfiles/4.1.gemfile +5 -3
  20. data/lib/generators/paperclip/paperclip_generator.rb +0 -2
  21. data/lib/generators/paperclip/templates/paperclip_migration.rb.erb +1 -1
  22. data/lib/paperclip.rb +4 -1
  23. data/lib/paperclip/attachment.rb +90 -29
  24. data/lib/paperclip/content_type_detector.rb +1 -1
  25. data/lib/paperclip/geometry_detector_factory.rb +3 -1
  26. data/lib/paperclip/has_attached_file.rb +2 -1
  27. data/lib/paperclip/interpolations.rb +8 -0
  28. data/lib/paperclip/io_adapters/abstract_adapter.rb +1 -1
  29. data/lib/paperclip/io_adapters/data_uri_adapter.rb +1 -1
  30. data/lib/paperclip/io_adapters/stringio_adapter.rb +5 -11
  31. data/lib/paperclip/locales/de.yml +18 -0
  32. data/lib/paperclip/locales/es.yml +18 -0
  33. data/lib/paperclip/matchers/have_attached_file_matcher.rb +2 -1
  34. data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +2 -1
  35. data/lib/paperclip/matchers/validate_attachment_size_matcher.rb +2 -1
  36. data/lib/paperclip/media_type_spoof_detector.rb +10 -2
  37. data/lib/paperclip/storage/filesystem.rb +1 -1
  38. data/lib/paperclip/storage/s3.rb +26 -4
  39. data/lib/paperclip/style.rb +1 -1
  40. data/lib/paperclip/thumbnail.rb +6 -6
  41. data/lib/paperclip/validators.rb +5 -3
  42. data/lib/paperclip/validators/attachment_size_validator.rb +7 -3
  43. data/lib/paperclip/version.rb +1 -1
  44. data/lib/tasks/paperclip.rake +1 -2
  45. data/paperclip.gemspec +5 -3
  46. data/shoulda_macros/paperclip.rb +0 -1
  47. data/{test → spec}/database.yml +0 -0
  48. data/spec/paperclip/attachment_definitions_spec.rb +13 -0
  49. data/{test/attachment_processing_test.rb → spec/paperclip/attachment_processing_spec.rb} +20 -21
  50. data/{test/attachment_registry_test.rb → spec/paperclip/attachment_registry_spec.rb} +10 -11
  51. data/{test/attachment_test.rb → spec/paperclip/attachment_spec.rb} +367 -360
  52. data/{test/content_type_detector_test.rb → spec/paperclip/content_type_detector_spec.rb} +8 -8
  53. data/{test/file_command_content_type_detector_test.rb → spec/paperclip/file_command_content_type_detector_spec.rb} +5 -5
  54. data/spec/paperclip/filename_cleaner_spec.rb +14 -0
  55. data/spec/paperclip/geometry_detector_spec.rb +39 -0
  56. data/{test/geometry_parser_test.rb → spec/paperclip/geometry_parser_spec.rb} +27 -27
  57. data/{test/geometry_test.rb → spec/paperclip/geometry_spec.rb} +49 -51
  58. data/{test/has_attached_file_test.rb → spec/paperclip/has_attached_file_spec.rb} +18 -27
  59. data/{test/integration_test.rb → spec/paperclip/integration_spec.rb} +134 -126
  60. data/{test/interpolations_test.rb → spec/paperclip/interpolations_spec.rb} +54 -40
  61. data/{test/io_adapters/abstract_adapter_test.rb → spec/paperclip/io_adapters/abstract_adapter_spec.rb} +21 -10
  62. data/{test/io_adapters/attachment_adapter_test.rb → spec/paperclip/io_adapters/attachment_adapter_spec.rb} +27 -29
  63. data/{test/io_adapters/data_uri_adapter_test.rb → spec/paperclip/io_adapters/data_uri_adapter_spec.rb} +22 -18
  64. data/spec/paperclip/io_adapters/empty_string_adapter_spec.rb +17 -0
  65. data/{test/io_adapters/file_adapter_test.rb → spec/paperclip/io_adapters/file_adapter_spec.rb} +32 -28
  66. data/{test/io_adapters/http_url_proxy_adapter_test.rb → spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb} +22 -22
  67. data/spec/paperclip/io_adapters/identity_adapter_spec.rb +8 -0
  68. data/{test/io_adapters/nil_adapter_test.rb → spec/paperclip/io_adapters/nil_adapter_spec.rb} +7 -7
  69. data/{test/io_adapters/registry_test.rb → spec/paperclip/io_adapters/registry_spec.rb} +10 -7
  70. data/{test/io_adapters/stringio_adapter_test.rb → spec/paperclip/io_adapters/stringio_adapter_spec.rb} +16 -17
  71. data/{test/io_adapters/uploaded_file_adapter_test.rb → spec/paperclip/io_adapters/uploaded_file_adapter_spec.rb} +41 -41
  72. data/{test/io_adapters/uri_adapter_test.rb → spec/paperclip/io_adapters/uri_adapter_spec.rb} +22 -22
  73. data/spec/paperclip/matchers/have_attached_file_matcher_spec.rb +19 -0
  74. data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +99 -0
  75. data/spec/paperclip/matchers/validate_attachment_presence_matcher_spec.rb +69 -0
  76. data/spec/paperclip/matchers/validate_attachment_size_matcher_spec.rb +88 -0
  77. data/{test/media_type_spoof_detector_test.rb → spec/paperclip/media_type_spoof_detector_spec.rb} +13 -8
  78. data/spec/paperclip/meta_class_spec.rb +30 -0
  79. data/spec/paperclip/paperclip_missing_attachment_styles_spec.rb +84 -0
  80. data/{test/paperclip_test.rb → spec/paperclip/paperclip_spec.rb} +47 -47
  81. data/{test/plural_cache_test.rb → spec/paperclip/plural_cache_spec.rb} +6 -6
  82. data/{test/processor_test.rb → spec/paperclip/processor_spec.rb} +5 -5
  83. data/{test/rake_test.rb → spec/paperclip/rake_spec.rb} +15 -15
  84. data/spec/paperclip/schema_spec.rb +206 -0
  85. data/{test/storage/filesystem_test.rb → spec/paperclip/storage/filesystem_spec.rb} +18 -18
  86. data/{test/storage/fog_test.rb → spec/paperclip/storage/fog_spec.rb} +145 -140
  87. data/spec/paperclip/storage/s3_live_spec.rb +182 -0
  88. data/spec/paperclip/storage/s3_spec.rb +1475 -0
  89. data/spec/paperclip/style_spec.rb +255 -0
  90. data/spec/paperclip/tempfile_factory_spec.rb +29 -0
  91. data/{test/thumbnail_test.rb → spec/paperclip/thumbnail_spec.rb} +107 -107
  92. data/{test/url_generator_test.rb → spec/paperclip/url_generator_spec.rb} +55 -56
  93. data/spec/paperclip/validators/attachment_content_type_validator_spec.rb +322 -0
  94. data/spec/paperclip/validators/attachment_file_name_validator_spec.rb +160 -0
  95. data/{test/validators/attachment_presence_validator_test.rb → spec/paperclip/validators/attachment_presence_validator_spec.rb} +19 -19
  96. data/{test/validators/attachment_size_validator_test.rb → spec/paperclip/validators/attachment_size_validator_spec.rb} +65 -58
  97. data/{test/validators/media_type_spoof_detection_validator_test.rb → spec/paperclip/validators/media_type_spoof_detection_validator_spec.rb} +8 -8
  98. data/spec/paperclip/validators_spec.rb +164 -0
  99. data/spec/spec_helper.rb +40 -0
  100. data/spec/support/assertions.rb +71 -0
  101. data/spec/support/fake_model.rb +21 -0
  102. data/spec/support/fake_rails.rb +12 -0
  103. data/{test → spec/support}/fixtures/12k.png +0 -0
  104. data/{test → spec/support}/fixtures/50x50.png +0 -0
  105. data/{test → spec/support}/fixtures/5k.png +0 -0
  106. data/{test → spec/support}/fixtures/animated +0 -0
  107. data/{test → spec/support}/fixtures/animated.gif +0 -0
  108. data/{test → spec/support}/fixtures/animated.unknown +0 -0
  109. data/{test → spec/support}/fixtures/bad.png +0 -0
  110. data/{test → spec/support}/fixtures/empty.html +0 -0
  111. data/{test → spec/support}/fixtures/fog.yml +0 -0
  112. data/{test → spec/support}/fixtures/rotated.jpg +0 -0
  113. data/{test → spec/support}/fixtures/s3.yml +0 -0
  114. data/spec/support/fixtures/spaced file.jpg +0 -0
  115. data/test/fixtures/spaced file.png b/data/spec/support/fixtures/spaced → file.png +0 -0
  116. data/{test → spec/support}/fixtures/text.txt +0 -0
  117. data/{test → spec/support}/fixtures/twopage.pdf +0 -0
  118. data/{test → spec/support}/fixtures/uppercase.PNG +0 -0
  119. data/spec/support/matchers/accept.rb +5 -0
  120. data/spec/support/matchers/exist.rb +5 -0
  121. data/{test → spec}/support/mock_attachment.rb +0 -0
  122. data/{test → spec}/support/mock_interpolator.rb +0 -0
  123. data/{test → spec}/support/mock_model.rb +0 -0
  124. data/{test → spec}/support/mock_url_generator_builder.rb +0 -0
  125. data/spec/support/model_reconstruction.rb +60 -0
  126. data/spec/support/rails_helpers.rb +7 -0
  127. data/spec/support/test_data.rb +13 -0
  128. data/spec/support/version_helper.rb +9 -0
  129. metadata +256 -210
  130. data/gemfiles/3.0.gemfile +0 -11
  131. data/gemfiles/3.1.gemfile +0 -11
  132. data/test/attachment_definitions_test.rb +0 -13
  133. data/test/filename_cleaner_test.rb +0 -14
  134. data/test/generator_test.rb +0 -84
  135. data/test/geometry_detector_test.rb +0 -24
  136. data/test/helper.rb +0 -239
  137. data/test/io_adapters/empty_string_adapter_test.rb +0 -18
  138. data/test/io_adapters/identity_adapter_test.rb +0 -8
  139. data/test/matchers/have_attached_file_matcher_test.rb +0 -25
  140. data/test/matchers/validate_attachment_content_type_matcher_test.rb +0 -111
  141. data/test/matchers/validate_attachment_presence_matcher_test.rb +0 -70
  142. data/test/matchers/validate_attachment_size_matcher_test.rb +0 -87
  143. data/test/meta_class_test.rb +0 -32
  144. data/test/paperclip_missing_attachment_styles_test.rb +0 -90
  145. data/test/schema_test.rb +0 -206
  146. data/test/storage/s3_live_test.rb +0 -179
  147. data/test/storage/s3_test.rb +0 -1357
  148. data/test/style_test.rb +0 -251
  149. data/test/tempfile_factory_test.rb +0 -29
  150. data/test/validators/attachment_content_type_validator_test.rb +0 -324
  151. data/test/validators/attachment_file_name_validator_test.rb +0 -162
  152. data/test/validators_test.rb +0 -101
@@ -1,7 +1,7 @@
1
- require './test/helper'
1
+ require 'spec_helper'
2
2
 
3
- class PluralCacheTest < Test::Unit::TestCase
4
- should 'cache pluralizations' do
3
+ describe 'Plural cache' do
4
+ it 'caches pluralizations' do
5
5
  cache = Paperclip::Interpolations::PluralCache.new
6
6
  word = "box"
7
7
 
@@ -11,7 +11,7 @@ class PluralCacheTest < Test::Unit::TestCase
11
11
  cache.pluralize(word)
12
12
  end
13
13
 
14
- should 'cache pluralizations and underscores' do
14
+ it 'caches pluralizations and underscores' do
15
15
  cache = Paperclip::Interpolations::PluralCache.new
16
16
  word = "BigBox"
17
17
 
@@ -22,13 +22,13 @@ class PluralCacheTest < Test::Unit::TestCase
22
22
  cache.underscore_and_pluralize(word)
23
23
  end
24
24
 
25
- should 'pluralize words' do
25
+ it 'pluralizes words' do
26
26
  cache = Paperclip::Interpolations::PluralCache.new
27
27
  word = "box"
28
28
  assert_equal "boxes", cache.pluralize(word)
29
29
  end
30
30
 
31
- should 'pluralize and underscore words' do
31
+ it 'pluralizes and underscore words' do
32
32
  cache = Paperclip::Interpolations::PluralCache.new
33
33
  word = "BigBox"
34
34
  assert_equal "big_boxes", cache.underscore_and_pluralize(word)
@@ -1,7 +1,7 @@
1
- require './test/helper'
1
+ require 'spec_helper'
2
2
 
3
- class ProcessorTest < Test::Unit::TestCase
4
- should "instantiate and call #make when sent #make to the class" do
3
+ describe Paperclip::Processor do
4
+ it "instantiates and call #make when sent #make to the class" do
5
5
  processor = mock
6
6
  processor.expects(:make).with()
7
7
  Paperclip::Processor.expects(:new).with(:one, :two, :three).returns(processor)
@@ -9,7 +9,7 @@ class ProcessorTest < Test::Unit::TestCase
9
9
  end
10
10
 
11
11
  context "Calling #convert" do
12
- should "run the convert command with Cocaine" do
12
+ it "runs the convert command with Cocaine" do
13
13
  Paperclip.options[:log_command] = false
14
14
  Cocaine::CommandLine.expects(:new).with("convert", "stuff", {}).returns(stub(:run))
15
15
  Paperclip::Processor.new('filename').convert("stuff")
@@ -17,7 +17,7 @@ class ProcessorTest < Test::Unit::TestCase
17
17
  end
18
18
 
19
19
  context "Calling #identify" do
20
- should "run the identify command with Cocaine" do
20
+ it "runs the identify command with Cocaine" do
21
21
  Paperclip.options[:log_command] = false
22
22
  Cocaine::CommandLine.expects(:new).with("identify", "stuff", {}).returns(stub(:run))
23
23
  Paperclip::Processor.new('filename').identify("stuff")
@@ -1,10 +1,10 @@
1
- require './test/helper'
1
+ require 'spec_helper'
2
2
  require 'rake'
3
3
  load './lib/tasks/paperclip.rake'
4
4
 
5
- class RakeTest < Test::Unit::TestCase
5
+ describe Rake do
6
6
  context "calling `rake paperclip:refresh:thumbnails`" do
7
- setup do
7
+ before do
8
8
  rebuild_model
9
9
  Paperclip::Task.stubs(:obtain_class).returns('Dummy')
10
10
  @bogus_instance = Dummy.new
@@ -16,22 +16,22 @@ class RakeTest < Test::Unit::TestCase
16
16
  Paperclip.stubs(:each_instance_with_attachment).multiple_yields @bogus_instance, @valid_instance
17
17
  end
18
18
  context "when there is an exception in reprocess!" do
19
- setup do
19
+ before do
20
20
  @bogus_instance.avatar.stubs(:reprocess!).raises
21
21
  end
22
22
 
23
- should "catch the exception" do
23
+ it "catches the exception" do
24
24
  assert_nothing_raised do
25
25
  ::Rake::Task['paperclip:refresh:thumbnails'].execute
26
26
  end
27
27
  end
28
28
 
29
- should "continue to the next instance" do
29
+ it "continues to the next instance" do
30
30
  @valid_instance.avatar.expects(:reprocess!)
31
31
  ::Rake::Task['paperclip:refresh:thumbnails'].execute
32
32
  end
33
33
 
34
- should "print the exception" do
34
+ it "prints the exception" do
35
35
  exception_msg = 'Some Exception'
36
36
  @bogus_instance.avatar.stubs(:reprocess!).raises(exception_msg)
37
37
  Paperclip::Task.expects(:log_error).with do |str|
@@ -40,14 +40,14 @@ class RakeTest < Test::Unit::TestCase
40
40
  ::Rake::Task['paperclip:refresh:thumbnails'].execute
41
41
  end
42
42
 
43
- should "print the class name" do
43
+ it "prints the class name" do
44
44
  Paperclip::Task.expects(:log_error).with do |str|
45
45
  str.match 'Dummy'
46
46
  end
47
47
  ::Rake::Task['paperclip:refresh:thumbnails'].execute
48
48
  end
49
49
 
50
- should "print the instance ID" do
50
+ it "prints the instance ID" do
51
51
  Paperclip::Task.expects(:log_error).with do |str|
52
52
  str.match "ID #{@bogus_instance.id}"
53
53
  end
@@ -56,19 +56,19 @@ class RakeTest < Test::Unit::TestCase
56
56
  end
57
57
 
58
58
  context "when there is an error in reprocess!" do
59
- setup do
59
+ before do
60
60
  @errors = mock('errors')
61
61
  @errors.stubs(:full_messages).returns([''])
62
62
  @errors.stubs(:blank?).returns(false)
63
63
  @bogus_instance.stubs(:errors).returns(@errors)
64
64
  end
65
65
 
66
- should "continue to the next instance" do
66
+ it "continues to the next instance" do
67
67
  @valid_instance.avatar.expects(:reprocess!)
68
68
  ::Rake::Task['paperclip:refresh:thumbnails'].execute
69
69
  end
70
70
 
71
- should "print the error" do
71
+ it "prints the error" do
72
72
  error_msg = 'Some Error'
73
73
  @errors.stubs(:full_messages).returns([error_msg])
74
74
  Paperclip::Task.expects(:log_error).with do |str|
@@ -77,14 +77,14 @@ class RakeTest < Test::Unit::TestCase
77
77
  ::Rake::Task['paperclip:refresh:thumbnails'].execute
78
78
  end
79
79
 
80
- should "print the class name" do
80
+ it "prints the class name" do
81
81
  Paperclip::Task.expects(:log_error).with do |str|
82
82
  str.match 'Dummy'
83
83
  end
84
84
  ::Rake::Task['paperclip:refresh:thumbnails'].execute
85
85
  end
86
86
 
87
- should "print the instance ID" do
87
+ it "prints the instance ID" do
88
88
  Paperclip::Task.expects(:log_error).with do |str|
89
89
  str.match "ID #{@bogus_instance.id}"
90
90
  end
@@ -94,7 +94,7 @@ class RakeTest < Test::Unit::TestCase
94
94
  end
95
95
 
96
96
  context "Paperclip::Task.log_error method" do
97
- should "print its argument to STDERR" do
97
+ it "prints its argument to STDERR" do
98
98
  msg = 'Some Message'
99
99
  $stderr.expects(:puts).with(msg)
100
100
  Paperclip::Task.log_error(msg)
@@ -0,0 +1,206 @@
1
+ require 'spec_helper'
2
+ require 'paperclip/schema'
3
+ require 'active_support/testing/deprecation'
4
+
5
+ describe Paperclip::Schema do
6
+ include ActiveSupport::Testing::Deprecation
7
+
8
+ before do
9
+ rebuild_class
10
+ end
11
+
12
+ after do
13
+ Dummy.connection.drop_table :dummies rescue nil
14
+ end
15
+
16
+ context "within table definition" do
17
+ context "using #has_attached_file" do
18
+ before do
19
+ ActiveSupport::Deprecation.silenced = false
20
+ end
21
+ it "creates attachment columns" do
22
+ Dummy.connection.create_table :dummies, force: true do |t|
23
+ ActiveSupport::Deprecation.silence do
24
+ t.has_attached_file :avatar
25
+ end
26
+ end
27
+ rebuild_class
28
+
29
+ columns = Dummy.columns.map{ |column| [column.name, column.type] }
30
+
31
+ expect(columns).to include(['avatar_file_name', :string])
32
+ expect(columns).to include(['avatar_content_type', :string])
33
+ expect(columns).to include(['avatar_file_size', :integer])
34
+ expect(columns).to include(['avatar_updated_at', :datetime])
35
+ end
36
+
37
+ it "displays deprecation warning" do
38
+ Dummy.connection.create_table :dummies, force: true do |t|
39
+ assert_deprecated do
40
+ t.has_attached_file :avatar
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ context "using #attachment" do
47
+ before do
48
+ Dummy.connection.create_table :dummies, force: true do |t|
49
+ t.attachment :avatar
50
+ end
51
+ rebuild_class
52
+ end
53
+
54
+ it "creates attachment columns" do
55
+ columns = Dummy.columns.map{ |column| [column.name, column.type] }
56
+
57
+ expect(columns).to include(['avatar_file_name', :string])
58
+ expect(columns).to include(['avatar_content_type', :string])
59
+ expect(columns).to include(['avatar_file_size', :integer])
60
+ expect(columns).to include(['avatar_updated_at', :datetime])
61
+ end
62
+ end
63
+ end
64
+
65
+ context "within schema statement" do
66
+ before do
67
+ Dummy.connection.create_table :dummies, force: true
68
+ end
69
+
70
+ context "migrating up" do
71
+ context "with single attachment" do
72
+ before do
73
+ Dummy.connection.add_attachment :dummies, :avatar
74
+ rebuild_class
75
+ end
76
+
77
+ it "creates attachment columns" do
78
+ columns = Dummy.columns.map{ |column| [column.name, column.type] }
79
+
80
+ expect(columns).to include(['avatar_file_name', :string])
81
+ expect(columns).to include(['avatar_content_type', :string])
82
+ expect(columns).to include(['avatar_file_size', :integer])
83
+ expect(columns).to include(['avatar_updated_at', :datetime])
84
+ end
85
+ end
86
+
87
+ context "with multiple attachments" do
88
+ before do
89
+ Dummy.connection.add_attachment :dummies, :avatar, :photo
90
+ rebuild_class
91
+ end
92
+
93
+ it "creates attachment columns" do
94
+ columns = Dummy.columns.map{ |column| [column.name, column.type] }
95
+
96
+ expect(columns).to include(['avatar_file_name', :string])
97
+ expect(columns).to include(['avatar_content_type', :string])
98
+ expect(columns).to include(['avatar_file_size', :integer])
99
+ expect(columns).to include(['avatar_updated_at', :datetime])
100
+ expect(columns).to include(['photo_file_name', :string])
101
+ expect(columns).to include(['photo_content_type', :string])
102
+ expect(columns).to include(['photo_file_size', :integer])
103
+ expect(columns).to include(['photo_updated_at', :datetime])
104
+ end
105
+ end
106
+
107
+ context "with no attachment" do
108
+ it "raises an error" do
109
+ assert_raises ArgumentError do
110
+ Dummy.connection.add_attachment :dummies
111
+ rebuild_class
112
+ end
113
+ end
114
+ end
115
+ end
116
+
117
+ context "migrating down" do
118
+ before do
119
+ Dummy.connection.change_table :dummies do |t|
120
+ t.column :avatar_file_name, :string
121
+ t.column :avatar_content_type, :string
122
+ t.column :avatar_file_size, :integer
123
+ t.column :avatar_updated_at, :datetime
124
+ end
125
+ end
126
+
127
+ context "using #drop_attached_file" do
128
+ before do
129
+ ActiveSupport::Deprecation.silenced = false
130
+ end
131
+ it "removes the attachment columns" do
132
+ ActiveSupport::Deprecation.silence do
133
+ Dummy.connection.drop_attached_file :dummies, :avatar
134
+ end
135
+ rebuild_class
136
+
137
+ columns = Dummy.columns.map{ |column| [column.name, column.type] }
138
+
139
+ expect(columns).to_not include(['avatar_file_name', :string])
140
+ expect(columns).to_not include(['avatar_content_type', :string])
141
+ expect(columns).to_not include(['avatar_file_size', :integer])
142
+ expect(columns).to_not include(['avatar_updated_at', :datetime])
143
+ end
144
+
145
+ it "displays a deprecation warning" do
146
+ assert_deprecated do
147
+ Dummy.connection.drop_attached_file :dummies, :avatar
148
+ end
149
+ end
150
+ end
151
+
152
+ context "using #remove_attachment" do
153
+ context "with single attachment" do
154
+ before do
155
+ Dummy.connection.remove_attachment :dummies, :avatar
156
+ rebuild_class
157
+ end
158
+
159
+ it "removes the attachment columns" do
160
+ columns = Dummy.columns.map{ |column| [column.name, column.type] }
161
+
162
+ expect(columns).to_not include(['avatar_file_name', :string])
163
+ expect(columns).to_not include(['avatar_content_type', :string])
164
+ expect(columns).to_not include(['avatar_file_size', :integer])
165
+ expect(columns).to_not include(['avatar_updated_at', :datetime])
166
+ end
167
+ end
168
+
169
+ context "with multiple attachments" do
170
+ before do
171
+ Dummy.connection.change_table :dummies do |t|
172
+ t.column :photo_file_name, :string
173
+ t.column :photo_content_type, :string
174
+ t.column :photo_file_size, :integer
175
+ t.column :photo_updated_at, :datetime
176
+ end
177
+
178
+ Dummy.connection.remove_attachment :dummies, :avatar, :photo
179
+ rebuild_class
180
+ end
181
+
182
+ it "removes the attachment columns" do
183
+ columns = Dummy.columns.map{ |column| [column.name, column.type] }
184
+
185
+ expect(columns).to_not include(['avatar_file_name', :string])
186
+ expect(columns).to_not include(['avatar_content_type', :string])
187
+ expect(columns).to_not include(['avatar_file_size', :integer])
188
+ expect(columns).to_not include(['avatar_updated_at', :datetime])
189
+ expect(columns).to_not include(['photo_file_name', :string])
190
+ expect(columns).to_not include(['photo_content_type', :string])
191
+ expect(columns).to_not include(['photo_file_size', :integer])
192
+ expect(columns).to_not include(['photo_updated_at', :datetime])
193
+ end
194
+ end
195
+
196
+ context "with no attachment" do
197
+ it "raises an error" do
198
+ assert_raises ArgumentError do
199
+ Dummy.connection.remove_attachment :dummies
200
+ end
201
+ end
202
+ end
203
+ end
204
+ end
205
+ end
206
+ end
@@ -1,33 +1,33 @@
1
- require './test/helper'
1
+ require 'spec_helper'
2
2
 
3
- class FileSystemTest < Test::Unit::TestCase
3
+ describe Paperclip::Storage::Filesystem do
4
4
  context "Filesystem" do
5
5
  context "normal file" do
6
- setup do
7
- rebuild_model :styles => { :thumbnail => "25x25#" }
6
+ before do
7
+ rebuild_model styles: { thumbnail: "25x25#" }
8
8
  @dummy = Dummy.create!
9
9
 
10
10
  @file = File.open(fixture_file('5k.png'))
11
11
  @dummy.avatar = @file
12
12
  end
13
13
 
14
- teardown { @file.close }
14
+ after { @file.close }
15
15
 
16
- should "allow file assignment" do
16
+ it "allows file assignment" do
17
17
  assert @dummy.save
18
18
  end
19
19
 
20
- should "store the original" do
20
+ it "stores the original" do
21
21
  @dummy.save
22
22
  assert_file_exists(@dummy.avatar.path)
23
23
  end
24
24
 
25
- should "store the thumbnail" do
25
+ it "stores the thumbnail" do
26
26
  @dummy.save
27
27
  assert_file_exists(@dummy.avatar.path(:thumbnail))
28
28
  end
29
29
 
30
- should "be rewinded after flush_writes" do
30
+ it "is rewinded after flush_writes" do
31
31
  @dummy.avatar.instance_eval "def after_flush_writes; end"
32
32
 
33
33
  files = @dummy.avatar.queued_for_write.values
@@ -35,14 +35,14 @@ class FileSystemTest < Test::Unit::TestCase
35
35
  assert files.none?(&:eof?), "Expect all the files to be rewinded."
36
36
  end
37
37
 
38
- should "be removed after after_flush_writes" do
38
+ it "is removed after after_flush_writes" do
39
39
  paths = @dummy.avatar.queued_for_write.values.map(&:path)
40
40
  @dummy.save
41
- assert paths.none?{ |path| File.exists?(path) },
41
+ assert paths.none?{ |path| File.exist?(path) },
42
42
  "Expect all the files to be deleted."
43
43
  end
44
44
 
45
- should 'copy the file to a known location with copy_to_local_file' do
45
+ it 'copies the file to a known location with copy_to_local_file' do
46
46
  tempfile = Tempfile.new("known_location")
47
47
  @dummy.avatar.copy_to_local_file(:original, tempfile.path)
48
48
  tempfile.rewind
@@ -52,8 +52,8 @@ class FileSystemTest < Test::Unit::TestCase
52
52
  end
53
53
 
54
54
  context "with file that has space in file name" do
55
- setup do
56
- rebuild_model :styles => { :thumbnail => "25x25#" }
55
+ before do
56
+ rebuild_model styles: { thumbnail: "25x25#" }
57
57
  @dummy = Dummy.create!
58
58
 
59
59
  @file = File.open(fixture_file('spaced file.png'))
@@ -61,17 +61,17 @@ class FileSystemTest < Test::Unit::TestCase
61
61
  @dummy.save
62
62
  end
63
63
 
64
- teardown { @file.close }
64
+ after { @file.close }
65
65
 
66
- should "store the file" do
66
+ it "stores the file" do
67
67
  assert_file_exists(@dummy.avatar.path)
68
68
  end
69
69
 
70
- should "return a replaced version for path" do
70
+ it "returns a replaced version for path" do
71
71
  assert_match /.+\/spaced_file\.png/, @dummy.avatar.path
72
72
  end
73
73
 
74
- should "return a replaced version for url" do
74
+ it "returns a replaced version for url" do
75
75
  assert_match /.+\/spaced_file\.png/, @dummy.avatar.url
76
76
  end
77
77
  end