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,111 +0,0 @@
1
- require './test/helper'
2
-
3
- class ValidateAttachmentContentTypeMatcherTest < Test::Unit::TestCase
4
- context "validate_attachment_content_type" do
5
- setup do
6
- reset_table("dummies") do |d|
7
- d.string :title
8
- d.string :avatar_file_name
9
- d.string :avatar_content_type
10
- end
11
- reset_class "Dummy"
12
- Dummy.do_not_validate_attachment_file_type :avatar
13
- Dummy.has_attached_file :avatar
14
- @matcher = self.class.validate_attachment_content_type(:avatar).
15
- allowing(%w(image/png image/jpeg)).
16
- rejecting(%w(audio/mp3 application/octet-stream))
17
- end
18
-
19
- context "given a class with no validation" do
20
- should_reject_dummy_class
21
- end
22
-
23
- context "given a class with a validation that doesn't match" do
24
- setup do
25
- Dummy.validates_attachment_content_type :avatar, :content_type => %r{audio/.*}
26
- end
27
-
28
- should_reject_dummy_class
29
- end
30
-
31
- context "given a class with a matching validation" do
32
- setup do
33
- Dummy.validates_attachment_content_type :avatar, :content_type => %r{image/.*}
34
- end
35
-
36
- should_accept_dummy_class
37
- end
38
-
39
- context "given a class with other validations but matching types" do
40
- setup do
41
- Dummy.validates_presence_of :title
42
- Dummy.validates_attachment_content_type :avatar, :content_type => %r{image/.*}
43
- end
44
-
45
- should_accept_dummy_class
46
- end
47
-
48
- context "given a class that matches and a matcher that only specifies 'allowing'" do
49
- setup do
50
- Dummy.validates_attachment_content_type :avatar, :content_type => %r{image/.*}
51
- @matcher = self.class.validate_attachment_content_type(:avatar).
52
- allowing(%w(image/png image/jpeg))
53
- end
54
-
55
- should_accept_dummy_class
56
- end
57
-
58
- context "given a class that does not match and a matcher that only specifies 'allowing'" do
59
- setup do
60
- Dummy.validates_attachment_content_type :avatar, :content_type => %r{audio/.*}
61
- @matcher = self.class.validate_attachment_content_type(:avatar).
62
- allowing(%w(image/png image/jpeg))
63
- end
64
-
65
- should_reject_dummy_class
66
- end
67
-
68
- context "given a class that matches and a matcher that only specifies 'rejecting'" do
69
- setup do
70
- Dummy.validates_attachment_content_type :avatar, :content_type => %r{image/.*}
71
- @matcher = self.class.validate_attachment_content_type(:avatar).
72
- rejecting(%w(audio/mp3 application/octet-stream))
73
- end
74
-
75
- should_accept_dummy_class
76
- end
77
-
78
- context "given a class that does not match and a matcher that only specifies 'rejecting'" do
79
- setup do
80
- Dummy.validates_attachment_content_type :avatar, :content_type => %r{audio/.*}
81
- @matcher = self.class.validate_attachment_content_type(:avatar).
82
- rejecting(%w(audio/mp3 application/octet-stream))
83
- end
84
-
85
- should_reject_dummy_class
86
- end
87
-
88
- context "using an :if to control the validation" do
89
- setup do
90
- Dummy.class_eval do
91
- validates_attachment_content_type :avatar, :content_type => %r{image/*} , :if => :go
92
- attr_accessor :go
93
- end
94
- @matcher = self.class.validate_attachment_content_type(:avatar).
95
- allowing(%w(image/png image/jpeg)).
96
- rejecting(%w(audio/mp3 application/octet-stream))
97
- @dummy = Dummy.new
98
- end
99
-
100
- should "run the validation if the control is true" do
101
- @dummy.go = true
102
- assert_accepts @matcher, @dummy
103
- end
104
-
105
- should "not run the validation if the control is false" do
106
- @dummy.go = false
107
- assert_rejects @matcher, @dummy
108
- end
109
- end
110
- end
111
- end
@@ -1,70 +0,0 @@
1
- require './test/helper'
2
-
3
- class ValidateAttachmentPresenceMatcherTest < Test::Unit::TestCase
4
- context "validate_attachment_presence" do
5
- setup do
6
- reset_table("dummies") do |d|
7
- d.string :avatar_file_name
8
- end
9
- reset_class "Dummy"
10
- Dummy.has_attached_file :avatar
11
- Dummy.do_not_validate_attachment_file_type :avatar
12
- @matcher = self.class.validate_attachment_presence(:avatar)
13
- end
14
-
15
- context "given a class with no validation" do
16
- should_reject_dummy_class
17
- end
18
-
19
- context "given a class with a matching validation" do
20
- setup do
21
- Dummy.validates_attachment_presence :avatar
22
- end
23
-
24
- should_accept_dummy_class
25
- end
26
-
27
- context "given an instance with other attachment validations" do
28
- setup do
29
- reset_table("dummies") do |d|
30
- d.string :avatar_file_name
31
- d.string :avatar_content_type
32
- end
33
-
34
- Dummy.class_eval do
35
- validates_attachment_presence :avatar
36
- validates_attachment_content_type :avatar, :content_type => 'image/gif'
37
- end
38
-
39
- @dummy = Dummy.new
40
- @matcher = self.class.validate_attachment_presence(:avatar)
41
- end
42
-
43
- should "it should validate properly" do
44
- @dummy.avatar = File.new fixture_file('5k.png')
45
- assert_accepts @matcher, @dummy
46
- end
47
- end
48
-
49
- context "using an :if to control the validation" do
50
- setup do
51
- Dummy.class_eval do
52
- validates_attachment_presence :avatar, :if => :go
53
- attr_accessor :go
54
- end
55
- @dummy = Dummy.new
56
- @dummy.avatar = nil
57
- end
58
-
59
- should "run the validation if the control is true" do
60
- @dummy.go = true
61
- assert_accepts @matcher, @dummy
62
- end
63
-
64
- should "not run the validation if the control is false" do
65
- @dummy.go = false
66
- assert_rejects @matcher, @dummy
67
- end
68
- end
69
- end
70
- end
@@ -1,87 +0,0 @@
1
- require './test/helper'
2
-
3
- class ValidateAttachmentSizeMatcherTest < Test::Unit::TestCase
4
- context "validate_attachment_size" do
5
- setup do
6
- reset_table("dummies") do |d|
7
- d.string :avatar_file_name
8
- d.integer :avatar_file_size
9
- end
10
- reset_class "Dummy"
11
- Dummy.do_not_validate_attachment_file_type :avatar
12
- Dummy.has_attached_file :avatar
13
- end
14
-
15
- context "of limited size" do
16
- setup{ @matcher = self.class.validate_attachment_size(:avatar).in(256..1024) }
17
-
18
- context "given a class with no validation" do
19
- should_reject_dummy_class
20
- end
21
-
22
- context "given a class with a validation that's too high" do
23
- setup { Dummy.validates_attachment_size :avatar, :in => 256..2048 }
24
- should_reject_dummy_class
25
- end
26
-
27
- context "given a class with a validation that's too low" do
28
- setup { Dummy.validates_attachment_size :avatar, :in => 0..1024 }
29
- should_reject_dummy_class
30
- end
31
-
32
- context "given a class with a validation that matches" do
33
- setup { Dummy.validates_attachment_size :avatar, :in => 256..1024 }
34
- should_accept_dummy_class
35
- end
36
- end
37
-
38
- context "allowing anything" do
39
- setup{ @matcher = self.class.validate_attachment_size(:avatar) }
40
-
41
- context "given a class with an upper limit" do
42
- setup { Dummy.validates_attachment_size :avatar, :less_than => 1 }
43
- should_accept_dummy_class
44
- end
45
-
46
- context "given a class with a lower limit" do
47
- setup { Dummy.validates_attachment_size :avatar, :greater_than => 1 }
48
- should_accept_dummy_class
49
- end
50
- end
51
-
52
- context "using an :if to control the validation" do
53
- setup do
54
- Dummy.class_eval do
55
- validates_attachment_size :avatar, :greater_than => 1024, :if => :go
56
- attr_accessor :go
57
- end
58
- @dummy = Dummy.new
59
- @matcher = self.class.validate_attachment_size(:avatar).greater_than(1024)
60
- end
61
-
62
- should "run the validation if the control is true" do
63
- @dummy.go = true
64
- assert_accepts @matcher, @dummy
65
- end
66
-
67
- should "not run the validation if the control is false" do
68
- @dummy.go = false
69
- assert_rejects @matcher, @dummy
70
- end
71
- end
72
-
73
- context "post processing" do
74
- setup do
75
- Dummy.validates_attachment_size :avatar, :greater_than => 1024
76
-
77
- @dummy = Dummy.new
78
- @matcher = self.class.validate_attachment_size(:avatar).greater_than(1024)
79
- end
80
-
81
- should "be skipped" do
82
- @dummy.avatar.expects(:post_process).never
83
- assert_accepts @matcher, @dummy
84
- end
85
- end
86
- end
87
- end
@@ -1,32 +0,0 @@
1
- require './test/helper'
2
-
3
- class MetaClassTest < Test::Unit::TestCase
4
- context "A meta-class of dummy" do
5
- setup do
6
- rebuild_model
7
- @file = File.new(fixture_file("5k.png"), 'rb')
8
- end
9
-
10
- teardown { @file.close }
11
-
12
- should "be able to use Paperclip like a normal class" do
13
- reset_class("Dummy")
14
- @dummy = Dummy.new
15
-
16
- assert_nothing_raised do
17
- rebuild_meta_class_of(@dummy)
18
- end
19
- end
20
-
21
- should "work like any other instance" do
22
- reset_class("Dummy")
23
- @dummy = Dummy.new
24
- rebuild_meta_class_of(@dummy)
25
-
26
- assert_nothing_raised do
27
- @dummy.avatar = @file
28
- end
29
- assert @dummy.save
30
- end
31
- end
32
- end
@@ -1,90 +0,0 @@
1
- require './test/helper'
2
-
3
- class PaperclipMissingAttachmentStylesTest < Test::Unit::TestCase
4
- def setup
5
- Paperclip::AttachmentRegistry.clear
6
- end
7
-
8
- context "Paperclip" do
9
- setup do
10
- Paperclip::AttachmentRegistry.clear
11
- end
12
-
13
- teardown do
14
- File.unlink(Paperclip.registered_attachments_styles_path) rescue nil
15
- end
16
-
17
- should "enable to get and set path to registered styles file" do
18
- assert_equal ROOT.join('tmp/public/system/paperclip_attachments.yml').to_s, Paperclip.registered_attachments_styles_path
19
- Paperclip.registered_attachments_styles_path = '/tmp/config/paperclip_attachments.yml'
20
- assert_equal '/tmp/config/paperclip_attachments.yml', Paperclip.registered_attachments_styles_path
21
- Paperclip.registered_attachments_styles_path = nil
22
- assert_equal ROOT.join('tmp/public/system/paperclip_attachments.yml').to_s, Paperclip.registered_attachments_styles_path
23
- end
24
-
25
- should "be able to get current attachment styles" do
26
- assert_equal Hash.new, Paperclip.send(:current_attachments_styles)
27
- rebuild_model :styles => {:croppable => '600x600>', :big => '1000x1000>'}
28
- expected_hash = { :Dummy => {:avatar => [:big, :croppable]}}
29
- assert_equal expected_hash, Paperclip.send(:current_attachments_styles)
30
- end
31
-
32
- should "be able to save current attachment styles for further comparison" do
33
- rebuild_model :styles => {:croppable => '600x600>', :big => '1000x1000>'}
34
- Paperclip.save_current_attachments_styles!
35
- expected_hash = { :Dummy => {:avatar => [:big, :croppable]}}
36
- assert_equal expected_hash, YAML.load_file(Paperclip.registered_attachments_styles_path)
37
- end
38
-
39
- should "be able to read registered attachment styles from file" do
40
- rebuild_model :styles => {:croppable => '600x600>', :big => '1000x1000>'}
41
- Paperclip.save_current_attachments_styles!
42
- expected_hash = { :Dummy => {:avatar => [:big, :croppable]}}
43
- assert_equal expected_hash, Paperclip.send(:get_registered_attachments_styles)
44
- end
45
-
46
- should "be able to calculate differences between registered styles and current styles" do
47
- rebuild_model :styles => {:croppable => '600x600>', :big => '1000x1000>'}
48
- Paperclip.save_current_attachments_styles!
49
- rebuild_model :styles => {:thumb => 'x100', :export => 'x400>', :croppable => '600x600>', :big => '1000x1000>'}
50
- expected_hash = { :Dummy => {:avatar => [:export, :thumb]} }
51
- assert_equal expected_hash, Paperclip.missing_attachments_styles
52
-
53
- ActiveRecord::Base.connection.create_table :books, :force => true
54
- class ::Book < ActiveRecord::Base
55
- has_attached_file :cover, :styles => {:small => 'x100', :large => '1000x1000>'}
56
- has_attached_file :sample, :styles => {:thumb => 'x100'}
57
- end
58
-
59
- expected_hash = {
60
- :Dummy => {:avatar => [:export, :thumb]},
61
- :Book => {:sample => [:thumb], :cover => [:large, :small]}
62
- }
63
- assert_equal expected_hash, Paperclip.missing_attachments_styles
64
- Paperclip.save_current_attachments_styles!
65
- assert_equal Hash.new, Paperclip.missing_attachments_styles
66
- end
67
-
68
- should "be able to calculate differences when a new attachment is added to a model" do
69
- rebuild_model :styles => {:croppable => '600x600>', :big => '1000x1000>'}
70
- Paperclip.save_current_attachments_styles!
71
-
72
- class ::Dummy
73
- has_attached_file :photo, :styles => {:small => 'x100', :large => '1000x1000>'}
74
- end
75
-
76
- expected_hash = {
77
- :Dummy => {:photo => [:large, :small]}
78
- }
79
- assert_equal expected_hash, Paperclip.missing_attachments_styles
80
- Paperclip.save_current_attachments_styles!
81
- assert_equal Hash.new, Paperclip.missing_attachments_styles
82
- end
83
-
84
- # It's impossible to build styles hash without loading from database whole bunch of records
85
- should "skip lambda-styles" do
86
- rebuild_model :styles => lambda{ |attachment| attachment.instance.other == 'a' ? {:thumb => "50x50#"} : {:large => "400x400"} }
87
- assert_equal Hash.new, Paperclip.send(:current_attachments_styles)
88
- end
89
- end
90
- end
@@ -1,206 +0,0 @@
1
- require './test/helper'
2
- require 'paperclip/schema'
3
- require 'active_support/testing/deprecation'
4
-
5
- class SchemaTest < Test::Unit::TestCase
6
- include ActiveSupport::Testing::Deprecation
7
-
8
- def setup
9
- rebuild_class
10
- end
11
-
12
- def teardown
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
- setup do
19
- ActiveSupport::Deprecation.silenced = false
20
- end
21
- should "create 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
- assert_includes columns, ['avatar_file_name', :string]
32
- assert_includes columns, ['avatar_content_type', :string]
33
- assert_includes columns, ['avatar_file_size', :integer]
34
- assert_includes columns, ['avatar_updated_at', :datetime]
35
- end
36
-
37
- should "display 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
- setup do
48
- Dummy.connection.create_table :dummies, :force => true do |t|
49
- t.attachment :avatar
50
- end
51
- rebuild_class
52
- end
53
-
54
- should "create attachment columns" do
55
- columns = Dummy.columns.map{ |column| [column.name, column.type] }
56
-
57
- assert_includes columns, ['avatar_file_name', :string]
58
- assert_includes columns, ['avatar_content_type', :string]
59
- assert_includes columns, ['avatar_file_size', :integer]
60
- assert_includes columns, ['avatar_updated_at', :datetime]
61
- end
62
- end
63
- end
64
-
65
- context "within schema statement" do
66
- setup do
67
- Dummy.connection.create_table :dummies, :force => true
68
- end
69
-
70
- context "migrating up" do
71
- context "with single attachment" do
72
- setup do
73
- Dummy.connection.add_attachment :dummies, :avatar
74
- rebuild_class
75
- end
76
-
77
- should "create attachment columns" do
78
- columns = Dummy.columns.map{ |column| [column.name, column.type] }
79
-
80
- assert_includes columns, ['avatar_file_name', :string]
81
- assert_includes columns, ['avatar_content_type', :string]
82
- assert_includes columns, ['avatar_file_size', :integer]
83
- assert_includes columns, ['avatar_updated_at', :datetime]
84
- end
85
- end
86
-
87
- context "with multiple attachments" do
88
- setup do
89
- Dummy.connection.add_attachment :dummies, :avatar, :photo
90
- rebuild_class
91
- end
92
-
93
- should "create attachment columns" do
94
- columns = Dummy.columns.map{ |column| [column.name, column.type] }
95
-
96
- assert_includes columns, ['avatar_file_name', :string]
97
- assert_includes columns, ['avatar_content_type', :string]
98
- assert_includes columns, ['avatar_file_size', :integer]
99
- assert_includes columns, ['avatar_updated_at', :datetime]
100
- assert_includes columns, ['photo_file_name', :string]
101
- assert_includes columns, ['photo_content_type', :string]
102
- assert_includes columns, ['photo_file_size', :integer]
103
- assert_includes columns, ['photo_updated_at', :datetime]
104
- end
105
- end
106
-
107
- context "with no attachment" do
108
- should "raise an error" do
109
- assert_raise 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
- setup 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
- setup do
129
- ActiveSupport::Deprecation.silenced = false
130
- end
131
- should "remove 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
- assert_not_includes columns, ['avatar_file_name', :string]
140
- assert_not_includes columns, ['avatar_content_type', :string]
141
- assert_not_includes columns, ['avatar_file_size', :integer]
142
- assert_not_includes columns, ['avatar_updated_at', :datetime]
143
- end
144
-
145
- should "display 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
- setup do
155
- Dummy.connection.remove_attachment :dummies, :avatar
156
- rebuild_class
157
- end
158
-
159
- should "remove the attachment columns" do
160
- columns = Dummy.columns.map{ |column| [column.name, column.type] }
161
-
162
- assert_not_includes columns, ['avatar_file_name', :string]
163
- assert_not_includes columns, ['avatar_content_type', :string]
164
- assert_not_includes columns, ['avatar_file_size', :integer]
165
- assert_not_includes columns, ['avatar_updated_at', :datetime]
166
- end
167
- end
168
-
169
- context "with multiple attachments" do
170
- setup 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
- should "remove the attachment columns" do
183
- columns = Dummy.columns.map{ |column| [column.name, column.type] }
184
-
185
- assert_not_includes columns, ['avatar_file_name', :string]
186
- assert_not_includes columns, ['avatar_content_type', :string]
187
- assert_not_includes columns, ['avatar_file_size', :integer]
188
- assert_not_includes columns, ['avatar_updated_at', :datetime]
189
- assert_not_includes columns, ['photo_file_name', :string]
190
- assert_not_includes columns, ['photo_content_type', :string]
191
- assert_not_includes columns, ['photo_file_size', :integer]
192
- assert_not_includes columns, ['photo_updated_at', :datetime]
193
- end
194
- end
195
-
196
- context "with no attachment" do
197
- should "raise an error" do
198
- assert_raise ArgumentError do
199
- Dummy.connection.remove_attachment :dummies
200
- end
201
- end
202
- end
203
- end
204
- end
205
- end
206
- end