card 1.19.3 → 1.19.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (190) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +1 -0
  3. data/VERSION +1 -1
  4. data/card.gemspec +1 -3
  5. data/db/migrate_core_cards/20160914132636_fix_mod_files.rb +25 -0
  6. data/lib/card.rb +0 -2
  7. data/lib/card/content/diff.rb +3 -4
  8. data/lib/card/format/error.rb +1 -1
  9. data/mod/admin/set/self/admin.rb +2 -2
  10. data/mod/admin/set/self/trash.rb +9 -3
  11. data/mod/basic_types/set/type/html.rb +1 -1
  12. data/mod/bootstrap/set/all/bootstrap/layout.rb +58 -0
  13. data/mod/bootstrap/spec/set/all/bootstrap/layout_spec.rb +32 -0
  14. data/mod/carrierwave/lib/carrier_wave/cardmount.rb +0 -2
  15. data/mod/carrierwave/set/abstract/attachment/upload_cache.rb +2 -1
  16. data/mod/core/set/all/stages.rb +6 -4
  17. data/mod/history/lib/card/act.rb +8 -7
  18. data/mod/history/set/all/history.rb +10 -8
  19. data/mod/machines/set/abstract/script.rb +1 -1
  20. data/mod/machines/set/type/css.rb +1 -1
  21. data/mod/pointer/set/abstract/01_pointer.rb +1 -1
  22. data/mod/standard/file/credit_image/image-icon.png +0 -0
  23. data/mod/standard/file/credit_image/image-large.png +0 -0
  24. data/mod/standard/file/credit_image/image-medium.png +0 -0
  25. data/mod/standard/file/credit_image/image-small.png +0 -0
  26. data/mod/standard/file/favicon/image-icon.png +0 -0
  27. data/mod/standard/file/favicon/image-large.png +0 -0
  28. data/mod/standard/file/favicon/image-medium.png +0 -0
  29. data/mod/standard/file/favicon/image-small.png +0 -0
  30. data/mod/standard/file/logo/image-icon.png +0 -0
  31. data/mod/standard/file/logo/image-large.png +0 -0
  32. data/mod/standard/file/logo/image-medium.png +0 -0
  33. data/mod/standard/file/logo/image-small.png +0 -0
  34. data/mod/standard/set/self/recent.rb +2 -2
  35. data/spec/lib/card/diff_spec.rb +9 -9
  36. metadata +19 -156
  37. data/vendor/carrierwave/.gitignore +0 -19
  38. data/vendor/carrierwave/.rubocop.yml +0 -262
  39. data/vendor/carrierwave/.travis.yml +0 -58
  40. data/vendor/carrierwave/CHANGELOG.md +0 -81
  41. data/vendor/carrierwave/CONTRIBUTING.md +0 -37
  42. data/vendor/carrierwave/Gemfile +0 -5
  43. data/vendor/carrierwave/README.md +0 -995
  44. data/vendor/carrierwave/Rakefile +0 -26
  45. data/vendor/carrierwave/carrierwave.gemspec +0 -45
  46. data/vendor/carrierwave/cucumber.yml +0 -2
  47. data/vendor/carrierwave/features/caching.feature +0 -28
  48. data/vendor/carrierwave/features/download.feature +0 -20
  49. data/vendor/carrierwave/features/file_storage.feature +0 -37
  50. data/vendor/carrierwave/features/file_storage_overridden_filename.feature +0 -38
  51. data/vendor/carrierwave/features/file_storage_overridden_store_dir.feature +0 -38
  52. data/vendor/carrierwave/features/file_storage_reversing_processor.feature +0 -43
  53. data/vendor/carrierwave/features/fixtures/bork.txt +0 -1
  54. data/vendor/carrierwave/features/fixtures/monkey.txt +0 -1
  55. data/vendor/carrierwave/features/fixtures/upcased_bork.txt +0 -1
  56. data/vendor/carrierwave/features/mount_activerecord.feature +0 -46
  57. data/vendor/carrierwave/features/step_definitions/activerecord_steps.rb +0 -20
  58. data/vendor/carrierwave/features/step_definitions/caching_steps.rb +0 -12
  59. data/vendor/carrierwave/features/step_definitions/datamapper_steps.rb +0 -27
  60. data/vendor/carrierwave/features/step_definitions/download_steps.rb +0 -8
  61. data/vendor/carrierwave/features/step_definitions/file_steps.rb +0 -51
  62. data/vendor/carrierwave/features/step_definitions/general_steps.rb +0 -102
  63. data/vendor/carrierwave/features/step_definitions/mount_steps.rb +0 -17
  64. data/vendor/carrierwave/features/step_definitions/store_steps.rb +0 -16
  65. data/vendor/carrierwave/features/support/activerecord.rb +0 -18
  66. data/vendor/carrierwave/features/support/env.rb +0 -19
  67. data/vendor/carrierwave/features/versions_basics.feature +0 -50
  68. data/vendor/carrierwave/features/versions_caching_from_versions.feature +0 -32
  69. data/vendor/carrierwave/features/versions_nested_versions.feature +0 -70
  70. data/vendor/carrierwave/features/versions_overridden_filename.feature +0 -51
  71. data/vendor/carrierwave/features/versions_overriden_store_dir.feature +0 -41
  72. data/vendor/carrierwave/gemfiles/rails-4-0-stable.gemfile +0 -5
  73. data/vendor/carrierwave/gemfiles/rails-4-1-stable.gemfile +0 -5
  74. data/vendor/carrierwave/gemfiles/rails-4-2-stable.gemfile +0 -5
  75. data/vendor/carrierwave/gemfiles/rails-master.gemfile +0 -11
  76. data/vendor/carrierwave/lib/carrierwave.rb +0 -93
  77. data/vendor/carrierwave/lib/carrierwave/compatibility/paperclip.rb +0 -103
  78. data/vendor/carrierwave/lib/carrierwave/error.rb +0 -8
  79. data/vendor/carrierwave/lib/carrierwave/locale/cs.yml +0 -14
  80. data/vendor/carrierwave/lib/carrierwave/locale/de.yml +0 -14
  81. data/vendor/carrierwave/lib/carrierwave/locale/el.yml +0 -14
  82. data/vendor/carrierwave/lib/carrierwave/locale/en.yml +0 -14
  83. data/vendor/carrierwave/lib/carrierwave/locale/es.yml +0 -14
  84. data/vendor/carrierwave/lib/carrierwave/locale/fr-CA.yml +0 -14
  85. data/vendor/carrierwave/lib/carrierwave/locale/fr.yml +0 -14
  86. data/vendor/carrierwave/lib/carrierwave/locale/id.yml +0 -14
  87. data/vendor/carrierwave/lib/carrierwave/locale/ja.yml +0 -14
  88. data/vendor/carrierwave/lib/carrierwave/locale/nb.yml +0 -14
  89. data/vendor/carrierwave/lib/carrierwave/locale/nl.yml +0 -14
  90. data/vendor/carrierwave/lib/carrierwave/locale/pl.yml +0 -14
  91. data/vendor/carrierwave/lib/carrierwave/locale/pt-BR.yml +0 -14
  92. data/vendor/carrierwave/lib/carrierwave/locale/pt-PT.yml +0 -14
  93. data/vendor/carrierwave/lib/carrierwave/locale/ru.yml +0 -14
  94. data/vendor/carrierwave/lib/carrierwave/locale/sk.yml +0 -14
  95. data/vendor/carrierwave/lib/carrierwave/locale/tr.yml +0 -14
  96. data/vendor/carrierwave/lib/carrierwave/locale/zh-CN.yml +0 -14
  97. data/vendor/carrierwave/lib/carrierwave/locale/zh-TW.yml +0 -14
  98. data/vendor/carrierwave/lib/carrierwave/mount.rb +0 -444
  99. data/vendor/carrierwave/lib/carrierwave/mounter.rb +0 -163
  100. data/vendor/carrierwave/lib/carrierwave/orm/activerecord.rb +0 -103
  101. data/vendor/carrierwave/lib/carrierwave/processing.rb +0 -2
  102. data/vendor/carrierwave/lib/carrierwave/processing/mini_magick.rb +0 -328
  103. data/vendor/carrierwave/lib/carrierwave/processing/rmagick.rb +0 -379
  104. data/vendor/carrierwave/lib/carrierwave/sanitized_file.rb +0 -348
  105. data/vendor/carrierwave/lib/carrierwave/storage.rb +0 -2
  106. data/vendor/carrierwave/lib/carrierwave/storage/abstract.rb +0 -43
  107. data/vendor/carrierwave/lib/carrierwave/storage/file.rb +0 -118
  108. data/vendor/carrierwave/lib/carrierwave/storage/fog.rb +0 -462
  109. data/vendor/carrierwave/lib/carrierwave/test/matchers.rb +0 -394
  110. data/vendor/carrierwave/lib/carrierwave/uploader.rb +0 -67
  111. data/vendor/carrierwave/lib/carrierwave/uploader/cache.rb +0 -207
  112. data/vendor/carrierwave/lib/carrierwave/uploader/callbacks.rb +0 -33
  113. data/vendor/carrierwave/lib/carrierwave/uploader/configuration.rb +0 -203
  114. data/vendor/carrierwave/lib/carrierwave/uploader/content_type_blacklist.rb +0 -48
  115. data/vendor/carrierwave/lib/carrierwave/uploader/content_type_whitelist.rb +0 -48
  116. data/vendor/carrierwave/lib/carrierwave/uploader/default_url.rb +0 -17
  117. data/vendor/carrierwave/lib/carrierwave/uploader/download.rb +0 -92
  118. data/vendor/carrierwave/lib/carrierwave/uploader/extension_blacklist.rb +0 -51
  119. data/vendor/carrierwave/lib/carrierwave/uploader/extension_whitelist.rb +0 -51
  120. data/vendor/carrierwave/lib/carrierwave/uploader/file_size.rb +0 -41
  121. data/vendor/carrierwave/lib/carrierwave/uploader/magic_mime_blacklist.rb +0 -94
  122. data/vendor/carrierwave/lib/carrierwave/uploader/magic_mime_whitelist.rb +0 -94
  123. data/vendor/carrierwave/lib/carrierwave/uploader/mountable.rb +0 -38
  124. data/vendor/carrierwave/lib/carrierwave/uploader/processing.rb +0 -88
  125. data/vendor/carrierwave/lib/carrierwave/uploader/proxy.rb +0 -86
  126. data/vendor/carrierwave/lib/carrierwave/uploader/remove.rb +0 -21
  127. data/vendor/carrierwave/lib/carrierwave/uploader/serialization.rb +0 -28
  128. data/vendor/carrierwave/lib/carrierwave/uploader/store.rb +0 -93
  129. data/vendor/carrierwave/lib/carrierwave/uploader/url.rb +0 -41
  130. data/vendor/carrierwave/lib/carrierwave/uploader/versions.rb +0 -295
  131. data/vendor/carrierwave/lib/carrierwave/utilities.rb +0 -6
  132. data/vendor/carrierwave/lib/carrierwave/utilities/uri.rb +0 -21
  133. data/vendor/carrierwave/lib/carrierwave/validations/active_model.rb +0 -78
  134. data/vendor/carrierwave/lib/carrierwave/version.rb +0 -3
  135. data/vendor/carrierwave/lib/generators/templates/uploader.rb +0 -49
  136. data/vendor/carrierwave/lib/generators/uploader_generator.rb +0 -7
  137. data/vendor/carrierwave/script/console +0 -10
  138. data/vendor/carrierwave/script/destroy +0 -14
  139. data/vendor/carrierwave/script/generate +0 -14
  140. data/vendor/carrierwave/spec/compatibility/paperclip_spec.rb +0 -138
  141. data/vendor/carrierwave/spec/fixtures/Uppercase.jpg +0 -1
  142. data/vendor/carrierwave/spec/fixtures/bork.ttxt +0 -1
  143. data/vendor/carrierwave/spec/fixtures/bork.txt +0 -1
  144. data/vendor/carrierwave/spec/fixtures/bork.txtt +0 -1
  145. data/vendor/carrierwave/spec/fixtures/case.JPG +0 -1
  146. data/vendor/carrierwave/spec/fixtures/landscape.jpg +0 -0
  147. data/vendor/carrierwave/spec/fixtures/multi_page.pdf +0 -0
  148. data/vendor/carrierwave/spec/fixtures/new.jpeg +0 -1
  149. data/vendor/carrierwave/spec/fixtures/new.txt +0 -1
  150. data/vendor/carrierwave/spec/fixtures/old.jpeg +0 -1
  151. data/vendor/carrierwave/spec/fixtures/old.txt +0 -1
  152. data/vendor/carrierwave/spec/fixtures/portrait.jpg +0 -0
  153. data/vendor/carrierwave/spec/fixtures/ruby.gif +0 -0
  154. data/vendor/carrierwave/spec/fixtures/sponsored.doc +0 -1
  155. data/vendor/carrierwave/spec/fixtures/test+.jpg +0 -1
  156. data/vendor/carrierwave/spec/fixtures/test.jpeg +0 -1
  157. data/vendor/carrierwave/spec/fixtures/test.jpg +0 -1
  158. data/vendor/carrierwave/spec/generators/uploader_generator_spec.rb +0 -19
  159. data/vendor/carrierwave/spec/mount_multiple_spec.rb +0 -913
  160. data/vendor/carrierwave/spec/mount_single_spec.rb +0 -793
  161. data/vendor/carrierwave/spec/orm/activerecord_spec.rb +0 -1556
  162. data/vendor/carrierwave/spec/processing/mini_magick_spec.rb +0 -210
  163. data/vendor/carrierwave/spec/processing/rmagick_spec.rb +0 -250
  164. data/vendor/carrierwave/spec/sanitized_file_spec.rb +0 -805
  165. data/vendor/carrierwave/spec/spec_helper.rb +0 -105
  166. data/vendor/carrierwave/spec/storage/file_spec.rb +0 -82
  167. data/vendor/carrierwave/spec/storage/fog_credentials.rb +0 -46
  168. data/vendor/carrierwave/spec/storage/fog_helper.rb +0 -428
  169. data/vendor/carrierwave/spec/storage/fog_spec.rb +0 -48
  170. data/vendor/carrierwave/spec/support/activerecord.rb +0 -31
  171. data/vendor/carrierwave/spec/support/file_utils_helper.rb +0 -15
  172. data/vendor/carrierwave/spec/uploader/cache_spec.rb +0 -324
  173. data/vendor/carrierwave/spec/uploader/callback_spec.rb +0 -30
  174. data/vendor/carrierwave/spec/uploader/configuration_spec.rb +0 -133
  175. data/vendor/carrierwave/spec/uploader/content_type_blacklist_spec.rb +0 -61
  176. data/vendor/carrierwave/spec/uploader/content_type_whitelist_spec.rb +0 -63
  177. data/vendor/carrierwave/spec/uploader/default_url_spec.rb +0 -77
  178. data/vendor/carrierwave/spec/uploader/download_spec.rb +0 -204
  179. data/vendor/carrierwave/spec/uploader/extension_blacklist_spec.rb +0 -112
  180. data/vendor/carrierwave/spec/uploader/extension_whitelist_spec.rb +0 -102
  181. data/vendor/carrierwave/spec/uploader/file_size_spec.rb +0 -52
  182. data/vendor/carrierwave/spec/uploader/mountable_spec.rb +0 -26
  183. data/vendor/carrierwave/spec/uploader/overrides_spec.rb +0 -71
  184. data/vendor/carrierwave/spec/uploader/paths_spec.rb +0 -18
  185. data/vendor/carrierwave/spec/uploader/processing_spec.rb +0 -159
  186. data/vendor/carrierwave/spec/uploader/proxy_spec.rb +0 -79
  187. data/vendor/carrierwave/spec/uploader/remove_spec.rb +0 -71
  188. data/vendor/carrierwave/spec/uploader/store_spec.rb +0 -400
  189. data/vendor/carrierwave/spec/uploader/url_spec.rb +0 -273
  190. data/vendor/carrierwave/spec/uploader/versions_spec.rb +0 -633
@@ -1,793 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe CarrierWave::Mount do
4
-
5
- after do
6
- FileUtils.rm_rf(public_path)
7
- end
8
-
9
- describe '.mount_uploader' do
10
-
11
- before do
12
- @class = Class.new
13
- @class.send(:extend, CarrierWave::Mount)
14
-
15
- @uploader = Class.new(CarrierWave::Uploader::Base)
16
-
17
- @class.mount_uploader(:image, @uploader)
18
- @instance = @class.new
19
- end
20
-
21
- it "should maintain the ability to super" do
22
- @class.class_eval do
23
- def image_uploader
24
- super
25
- end
26
-
27
- def image=(val)
28
- super
29
- end
30
- end
31
-
32
- @instance.image = stub_file('test.jpg')
33
- expect(@instance.image).to be_an_instance_of(@uploader)
34
- end
35
-
36
- it "should inherit uploaders to subclasses" do
37
- @subclass = Class.new(@class)
38
- @subclass_instance = @subclass.new
39
- @subclass_instance.image = stub_file('test.jpg')
40
- expect(@subclass_instance.image).to be_an_instance_of(@uploader)
41
- end
42
-
43
- it "should allow marshalling uploaders and versions" do
44
- Object.const_set("MyClass#{@class.object_id}".tr('-', '_'), @class)
45
- Object.const_set("Uploader#{@uploader.object_id}".tr('-', '_'), @uploader)
46
- @uploader.class_eval do
47
- def rotate
48
- end
49
- end
50
- @uploader.version :thumb do
51
- process :rotate
52
- end
53
- @instance.image = stub_file('test.jpg')
54
- expect { Marshal.dump @instance.image }.not_to raise_error
55
- end
56
-
57
- describe "expected behavior with subclassed uploaders" do
58
- before do
59
- @class = Class.new
60
- @class.send(:extend, CarrierWave::Mount)
61
- @uploader1 = Class.new(CarrierWave::Uploader::Base)
62
- @uploader1.process :rotate
63
- @uploader1.version :thumb do
64
- process :compress
65
- end
66
- @uploader2 = Class.new(@uploader1)
67
- @uploader2.process :shrink
68
- @uploader2.version :secret do
69
- process :encrypt
70
- end
71
- @class.mount_uploader(:image1, @uploader1)
72
- @class.mount_uploader(:image2, @uploader2)
73
- @instance = @class.new
74
- end
75
-
76
- it "should inherit defined versions" do
77
- expect(@instance.image1).to respond_to(:thumb)
78
- expect(@instance.image2).to respond_to(:thumb)
79
- end
80
-
81
- it "should not inherit versions defined in subclasses" do
82
- expect(@instance.image1).not_to respond_to(:secret)
83
- expect(@instance.image2).to respond_to(:secret)
84
- end
85
-
86
- it "should inherit defined processors properly" do
87
- expect(@uploader1.processors).to eq([[:rotate, [], nil]])
88
- expect(@uploader2.processors).to eq([[:rotate, [], nil], [:shrink, [], nil]])
89
- expect(@uploader1.versions[:thumb].processors).to eq([[:compress, [], nil]])
90
- expect(@uploader2.versions[:thumb].processors).to eq([[:compress, [], nil]])
91
- expect(@uploader2.versions[:secret].processors).to eq([[:encrypt, [], nil]])
92
- end
93
- end
94
-
95
- describe '#image' do
96
-
97
- it "should return a blank uploader when nothing has been assigned" do
98
- expect(@instance).to receive(:read_uploader).with(:image).and_return(nil)
99
- expect(@instance.image).to be_an_instance_of(@uploader)
100
- expect(@instance.image).to be_blank
101
- end
102
-
103
- it "should return the same object every time when nothing has been assigned" do
104
- expect(@instance).to receive(:read_uploader).with(:image).and_return(nil)
105
- expect(@instance.image.object_id).to eq @instance.image.object_id
106
- end
107
-
108
- it "should return a blank uploader when an empty string has been assigned" do
109
- expect(@instance).to receive(:read_uploader).with(:image).and_return('')
110
- expect(@instance.image).to be_an_instance_of(@uploader)
111
- expect(@instance.image).to be_blank
112
- end
113
-
114
- it "should retrieve a file from the storage if a value is stored in the database" do
115
- expect(@instance).to receive(:read_uploader).with(:image).at_least(:once).and_return('test.jpg')
116
- expect(@instance.image).to be_an_instance_of(@uploader)
117
- end
118
-
119
- it "should set the path to the store dir" do
120
- expect(@instance).to receive(:read_uploader).with(:image).at_least(:once).and_return('test.jpg')
121
- expect(@instance.image.current_path).to eq(public_path('uploads/test.jpg'))
122
- end
123
-
124
- end
125
-
126
- describe '#image=' do
127
-
128
- it "should cache a file" do
129
- @instance.image = stub_file('test.jpg')
130
- expect(@instance.image).to be_an_instance_of(@uploader)
131
- end
132
-
133
- it "should copy a file into into the cache directory" do
134
- @instance.image = stub_file('test.jpg')
135
- expect(@instance.image.current_path).to match(/^#{public_path('uploads/tmp')}/)
136
- end
137
-
138
- it "should do nothing when nil is assigned" do
139
- expect(@instance).not_to receive(:write_uploader)
140
- @instance.image = nil
141
- end
142
-
143
- it "should do nothing when an empty string is assigned" do
144
- expect(@instance).not_to receive(:write_uploader)
145
- @instance.image = stub_file('test.jpg')
146
- end
147
-
148
- it "should fail silently if the image fails a white list integrity check" do
149
- @uploader.class_eval do
150
- def extension_whitelist
151
- %w(txt)
152
- end
153
- end
154
- @instance.image = stub_file('test.jpg')
155
- expect(@instance.image).to be_blank
156
- end
157
-
158
- it "should fail silently if the image fails a black list integrity check" do
159
- @uploader.class_eval do
160
- def extension_blacklist
161
- %w(jpg)
162
- end
163
- end
164
- @instance.image = stub_file('test.jpg')
165
- expect(@instance.image).to be_blank
166
- end
167
-
168
- it "should fail silently if the image fails to be processed" do
169
- @uploader.class_eval do
170
- process :monkey
171
- def monkey
172
- raise CarrierWave::ProcessingError, "Ohh noez!"
173
- end
174
- end
175
- @instance.image = stub_file('test.jpg')
176
- end
177
-
178
- end
179
-
180
- describe '#image?' do
181
-
182
- it "should be false when nothing has been assigned" do
183
- @instance.image = nil
184
- expect(@instance.image?).to be_falsey
185
- end
186
-
187
- it "should be false when an empty string has been assigned" do
188
- @instance.image = ''
189
- expect(@instance.image?).to be_falsey
190
- end
191
-
192
- it "should be true when a file has been cached" do
193
- @instance.image = stub_file('test.jpg')
194
- expect(@instance.image?).to be_truthy
195
- end
196
-
197
- end
198
-
199
- describe '#image_url' do
200
-
201
- it "should return nil when nothing has been assigned" do
202
- expect(@instance).to receive(:read_uploader).with(:image).and_return(nil)
203
- expect(@instance.image_url).to be_nil
204
- end
205
-
206
- it "should return fallback url when nothing has been assigned" do
207
- @uploader.class_eval do
208
- def default_url
209
- "foo/bar.jpg"
210
- end
211
- end
212
- expect(@instance).to receive(:read_uploader).with(:image).and_return(nil)
213
- expect(@instance.image_url).to eq("foo/bar.jpg")
214
- end
215
-
216
- it "should return nil when an empty string has been assigned" do
217
- expect(@instance).to receive(:read_uploader).with(:image).and_return('')
218
- expect(@instance.image_url).to be_nil
219
- end
220
-
221
- it "should get the url from a retrieved file" do
222
- expect(@instance).to receive(:read_uploader).at_least(:once).with(:image).and_return('test.jpg')
223
- expect(@instance.image_url).to eq('/uploads/test.jpg')
224
- end
225
-
226
- it "should get the url from a cached file" do
227
- @instance.image = stub_file('test.jpg')
228
- expect(@instance.image_url).to match(%r{uploads/tmp/[\d\-]+/test.jpg})
229
- end
230
-
231
- it "should get the url from a cached file's version" do
232
- @uploader.version(:thumb)
233
- @instance.image = stub_file('test.jpg')
234
- expect(@instance.image_url(:thumb)).to match(%r{uploads/tmp/[\d\-]+/thumb_test.jpg})
235
- end
236
-
237
- end
238
-
239
- describe '#image_cache' do
240
-
241
- before do
242
- allow(@instance).to receive(:write_uploader)
243
- allow(@instance).to receive(:read_uploader).and_return(nil)
244
- end
245
-
246
- it "should return nil when nothing has been assigned" do
247
- expect(@instance.image_cache).to be_nil
248
- end
249
-
250
- it "should be nil when a file has been stored" do
251
- @instance.image = stub_file('test.jpg')
252
- @instance.image.store!
253
- expect(@instance.image_cache).to be_nil
254
- end
255
-
256
- it "should be the cache name when a file has been cached" do
257
- @instance.image = stub_file('test.jpg')
258
- expect(@instance.image_cache).to match(%r(^[\d]+\-[\d]+\-[\d]{4}\-[\d]{4}/test\.jpg$))
259
- end
260
-
261
- end
262
-
263
- describe '#image_cache=' do
264
-
265
- before do
266
- allow(@instance).to receive(:write_uploader)
267
- allow(@instance).to receive(:read_uploader).and_return(nil)
268
- CarrierWave::SanitizedFile.new(file_path('test.jpg')).copy_to(public_path('uploads/tmp/1369894322-123-0123-1234/test.jpg'))
269
- end
270
-
271
- it "should do nothing when nil is assigned" do
272
- @instance.image_cache = nil
273
- expect(@instance.image).to be_blank
274
- end
275
-
276
- it "should do nothing when an empty string is assigned" do
277
- @instance.image_cache = ''
278
- expect(@instance.image).to be_blank
279
- end
280
-
281
- it "retrieve from cache when a cache name is assigned" do
282
- @instance.image_cache = '1369894322-123-0123-1234/test.jpg'
283
- expect(@instance.image.current_path).to eq(public_path('uploads/tmp/1369894322-123-0123-1234/test.jpg'))
284
- end
285
-
286
- it "should not write over a previously assigned file" do
287
- @instance.image = stub_file('test.jpg')
288
- @instance.image_cache = '1369894322-123-0123-1234/monkey.jpg'
289
- expect(@instance.image.current_path).to match(/test.jpg$/)
290
- end
291
- end
292
-
293
- describe "#remote_image_url" do
294
- before do
295
- stub_request(:get, "www.example.com/test.jpg").to_return(body: File.read(file_path("test.jpg")))
296
- end
297
-
298
- it "returns nil" do
299
- expect(@instance.remote_image_url).to be_nil
300
- end
301
-
302
- it "returns previously cached URL" do
303
- @instance.remote_image_url = "http://www.example.com/test.jpg"
304
-
305
- expect(@instance.remote_image_url).to eq("http://www.example.com/test.jpg")
306
- end
307
- end
308
-
309
- describe "#remote_image_url=" do
310
- before do
311
- stub_request(:get, "www.example.com/test.jpg").to_return(body: File.read(file_path("test.jpg")))
312
- end
313
-
314
- it "does nothing when nil is assigned" do
315
- @instance.remote_image_url = nil
316
-
317
- expect(@instance.image).to be_blank
318
- end
319
-
320
- it "does nothing when an empty string is assigned" do
321
- @instance.remote_image_url = ""
322
-
323
- expect(@instance.image).to be_blank
324
- end
325
-
326
- it "retrieves from cache when a cache name is assigned" do
327
- @instance.remote_image_url = "http://www.example.com/test.jpg"
328
-
329
- expect(@instance.image.current_path).to match(/test.jpg$/)
330
- end
331
-
332
- it "writes over a previously assigned file" do
333
- @instance.image = stub_file("portrait.jpg")
334
- @instance.remote_image_url = "http://www.example.com/test.jpg"
335
-
336
- expect(@instance.image.current_path).to match(/test.jpg$/)
337
- end
338
- end
339
-
340
- describe '#store_image!' do
341
-
342
- before do
343
- allow(@instance).to receive(:write_uploader)
344
- allow(@instance).to receive(:read_uploader).and_return(nil)
345
- end
346
-
347
- it "should do nothing when no file has been uploaded" do
348
- @instance.store_image!
349
- expect(@instance.image).to be_blank
350
- end
351
-
352
- it "store an assigned file" do
353
- @instance.image = stub_file('test.jpg')
354
- @instance.store_image!
355
- expect(@instance.image.current_path).to eq(public_path('uploads/test.jpg'))
356
- end
357
-
358
- it "should remove an uploaded file when remove_image? returns true" do
359
- @instance.image = stub_file('test.jpg')
360
- path = @instance.image.current_path
361
- @instance.remove_image = true
362
- @instance.store_image!
363
- expect(@instance.image).to be_blank
364
- expect(File.exist?(path)).to be_falsey
365
- end
366
- end
367
-
368
- describe '#remove_image!' do
369
-
370
- before do
371
- allow(@instance).to receive(:write_uploader)
372
- allow(@instance).to receive(:read_uploader).and_return(nil)
373
- end
374
-
375
- it "should do nothing when no file has been uploaded" do
376
- @instance.remove_image!
377
- expect(@instance.image).to be_blank
378
- end
379
-
380
- it "should remove an uploaded file" do
381
- @instance.image = stub_file('test.jpg')
382
- path = @instance.image.current_path
383
- @instance.remove_image!
384
- expect(@instance.image).to be_blank
385
- expect(File.exist?(path)).to be_falsey
386
- end
387
- end
388
-
389
- describe '#remove_image' do
390
-
391
- it "should store a value" do
392
- @instance.remove_image = true
393
- expect(@instance.remove_image).to be_truthy
394
- end
395
-
396
- end
397
-
398
- describe '#remove_image?' do
399
-
400
- it "should be true when the value is truthy" do
401
- @instance.remove_image = true
402
- expect(@instance.remove_image?).to be_truthy
403
- end
404
-
405
- it "should be false when the value is falsey" do
406
- @instance.remove_image = false
407
- expect(@instance.remove_image?).to be_falsey
408
- end
409
-
410
- it "should be false when the value is ''" do
411
- @instance.remove_image = ''
412
- expect(@instance.remove_image?).to be_falsey
413
- end
414
-
415
- it "should be false when the value is '0'" do
416
- @instance.remove_image = '0'
417
- expect(@instance.remove_image?).to be_falsey
418
- end
419
-
420
- it "should be false when the value is 'false'" do
421
- @instance.remove_image = 'false'
422
- expect(@instance.remove_image?).to be_falsey
423
- end
424
-
425
- end
426
-
427
- describe '#image_integrity_error' do
428
-
429
- it "should be nil by default" do
430
- expect(@instance.image_integrity_error).to be_nil
431
- end
432
-
433
- it "should be nil after a file is cached" do
434
- @instance.image = stub_file('test.jpg')
435
- expect(@instance.image_integrity_error).to be_nil
436
- end
437
-
438
- describe "when an integrity check fails" do
439
- before do
440
- @uploader.class_eval do
441
- def extension_whitelist
442
- %w(txt)
443
- end
444
- end
445
- end
446
-
447
- it "should be an error instance if file was cached" do
448
- @instance.image = stub_file('test.jpg')
449
- e = @instance.image_integrity_error
450
- expect(e).to be_an_instance_of(CarrierWave::IntegrityError)
451
- expect(e.message.lines.grep(/^You are not allowed to upload/)).to be_truthy
452
- end
453
-
454
- it "should be an error instance if file was downloaded" do
455
- stub_request(:get, "www.example.com/test.jpg").to_return(body: File.read(file_path("test.jpg")))
456
- @instance.remote_image_url = "http://www.example.com/test.jpg"
457
- e = @instance.image_integrity_error
458
-
459
- expect(e).to be_an_instance_of(CarrierWave::IntegrityError)
460
- expect(e.message.lines.grep(/^You are not allowed to upload/)).to be_truthy
461
- end
462
-
463
- it "should be an error instance when image file is assigned and remote_image_url is blank" do
464
- @instance.image = stub_file('test.jpg')
465
- @instance.remote_image_url = ""
466
- e = @instance.image_integrity_error
467
- expect(e).to be_an_instance_of(CarrierWave::IntegrityError)
468
- expect(e.message.lines.grep(/^You are not allowed to upload/)).to be_truthy
469
- end
470
- end
471
- end
472
-
473
- describe '#image_processing_error' do
474
-
475
- it "should be nil by default" do
476
- expect(@instance.image_processing_error).to be_nil
477
- end
478
-
479
- it "should be nil after a file is cached" do
480
- @instance.image = stub_file('test.jpg')
481
- expect(@instance.image_processing_error).to be_nil
482
- end
483
-
484
- describe "when an processing error occurs" do
485
- before do
486
- @uploader.class_eval do
487
- process :monkey
488
- def monkey
489
- raise CarrierWave::ProcessingError, "Ohh noez!"
490
- end
491
- end
492
- end
493
-
494
- it "should be an error instance if file was cached" do
495
- @instance.image = stub_file('test.jpg')
496
- expect(@instance.image_processing_error).to be_an_instance_of(CarrierWave::ProcessingError)
497
- end
498
-
499
- it "should be an error instance if file was downloaded" do
500
- stub_request(:get, "www.example.com/test.jpg").to_return(body: File.read(file_path("test.jpg")))
501
- @instance.remote_image_url = "http://www.example.com/test.jpg"
502
-
503
- expect(@instance.image_processing_error).to be_an_instance_of(CarrierWave::ProcessingError)
504
- end
505
- end
506
- end
507
-
508
- describe '#image_download_error' do
509
- before do
510
- stub_request(:get, "www.example.com/test.jpg").to_return(body: File.read(file_path("test.jpg")))
511
- stub_request(:get, "www.example.com/missing.jpg").to_return(status: 404)
512
- end
513
-
514
- it "should be nil by default" do
515
- expect(@instance.image_download_error).to be_nil
516
- end
517
-
518
- it "should be nil if file download was successful" do
519
- @instance.remote_image_url = "http://www.example.com/test.jpg"
520
- expect(@instance.image_download_error).to be_nil
521
- end
522
-
523
- it "should be an error instance if file could not be found" do
524
- @instance.remote_image_url = "http://www.example.com/missing.jpg"
525
- expect(@instance.image_download_error).to be_an_instance_of(CarrierWave::DownloadError)
526
- end
527
- end
528
-
529
- describe '#image_download_error' do
530
- before do
531
- stub_request(:get, "www.example.com/test.jpg").to_return(body: File.read(file_path("test.jpg")))
532
- stub_request(:get, "www.example.com/missing.jpg").to_return(status: 404)
533
- end
534
-
535
- it "should be nil by default" do
536
- expect(@instance.image_download_error).to be_nil
537
- end
538
-
539
- it "should be nil if file download was successful" do
540
- @instance.remote_image_url = "http://www.example.com/test.jpg"
541
- expect(@instance.image_download_error).to be_nil
542
- end
543
-
544
- it "should be an error instance if file could not be found" do
545
- @instance.remote_image_url = "http://www.example.com/missing.jpg"
546
- expect(@instance.image_download_error).to be_an_instance_of(CarrierWave::DownloadError)
547
- end
548
- end
549
-
550
- describe '#write_image_identifier' do
551
- it "should write to the column" do
552
- expect(@instance).to receive(:write_uploader).with(:image, "test.jpg")
553
- @instance.image = stub_file('test.jpg')
554
- @instance.write_image_identifier
555
- end
556
-
557
- it "should remove from the column when remove_image is true" do
558
- @instance.image = stub_file('test.jpg')
559
- @instance.store_image!
560
- @instance.remove_image = true
561
- expect(@instance).to receive(:write_uploader).with(:image, nil)
562
- @instance.write_image_identifier
563
- end
564
- end
565
-
566
- describe '#image_identifier' do
567
- it "should return the identifier from the mounted column" do
568
- expect(@instance).to receive(:read_uploader).with(:image).and_return("test.jpg")
569
- expect(@instance.image_identifier).to eq('test.jpg')
570
- end
571
- end
572
-
573
- end
574
-
575
- describe '#mount_uploader without an uploader' do
576
-
577
- before do
578
- @class = Class.new
579
- @class.send(:extend, CarrierWave::Mount)
580
- @class.mount_uploader(:image)
581
- @instance = @class.new
582
- end
583
-
584
- describe '#image' do
585
-
586
- before do
587
- allow(@instance).to receive(:read_uploader).and_return('test.jpg')
588
- end
589
-
590
- it "should return an instance of a subclass of CarrierWave::Uploader::Base" do
591
- expect(@instance.image).to be_a(CarrierWave::Uploader::Base)
592
- end
593
-
594
- it "should set the path to the store dir" do
595
- expect(@instance.image.current_path).to eq(public_path('uploads/test.jpg'))
596
- end
597
-
598
- end
599
-
600
- end
601
-
602
- describe '#mount_uploader with a block' do
603
- describe 'and no uploader given' do
604
- before do
605
- @class = Class.new
606
- @class.send(:extend, CarrierWave::Mount)
607
- @class.mount_uploader(:image) do
608
- def monkey
609
- 'blah'
610
- end
611
- end
612
- @instance = @class.new
613
- end
614
-
615
- it "should return an instance of a subclass of CarrierWave::Uploader::Base" do
616
- expect(@instance.image).to be_a(CarrierWave::Uploader::Base)
617
- end
618
-
619
- it "should apply any custom modifications" do
620
- expect(@instance.image.monkey).to eq("blah")
621
- end
622
- end
623
-
624
- describe 'and an uploader given' do
625
- before do
626
- @class = Class.new
627
- @class.send(:extend, CarrierWave::Mount)
628
- @uploader = Class.new(CarrierWave::Uploader::Base)
629
- @uploader.version :thumb do
630
- version :mini
631
- version :maxi
632
- end
633
- @class.mount_uploader(:image, @uploader) do
634
- def fish
635
- 'blub'
636
- end
637
- end
638
- @instance = @class.new
639
- end
640
-
641
- it "should return an instance of the uploader specified" do
642
- expect(@instance.image).to be_a_kind_of(@uploader)
643
- end
644
-
645
- it "should apply any custom modifications to the instance" do
646
- expect(@instance.image.fish).to eq("blub")
647
- end
648
-
649
- it "should apply any custom modifications to all defined versions" do
650
- expect(@instance.image.thumb.fish).to eq("blub")
651
- expect(@instance.image.thumb.mini.fish).to eq("blub")
652
- expect(@instance.image.thumb.maxi.fish).to eq("blub")
653
- end
654
-
655
- it "should not apply any custom modifications to the uploader class" do
656
- expect(@uploader.new).not_to respond_to(:fish)
657
- end
658
- end
659
- end
660
-
661
- describe '#mount_uploader with :ignore_integrity_errors => false' do
662
-
663
- before do
664
- @class = Class.new
665
- @class.send(:extend, CarrierWave::Mount)
666
-
667
- @uploader = Class.new(CarrierWave::Uploader::Base)
668
-
669
- @class.mount_uploader(:image, @uploader, :ignore_integrity_errors => false)
670
- @instance = @class.new
671
-
672
- @uploader.class_eval do
673
- def extension_whitelist
674
- %w(txt)
675
- end
676
- end
677
- end
678
-
679
- it "should raise an error if the image fails an integrity check when cached" do
680
- expect(running {
681
- @instance.image = stub_file('test.jpg')
682
- }).to raise_error(CarrierWave::IntegrityError)
683
- end
684
-
685
- it "should raise an error if the image fails an integrity check when downloaded" do
686
- stub_request(:get, "www.example.com/test.jpg").to_return(body: File.read(file_path("test.jpg")))
687
-
688
- expect(running {
689
- @instance.remote_image_url = "http://www.example.com/test.jpg"
690
- }).to raise_error(CarrierWave::IntegrityError)
691
- end
692
- end
693
-
694
- describe '#mount_uploader with :ignore_processing_errors => false' do
695
-
696
- before do
697
- @class = Class.new
698
- @class.send(:extend, CarrierWave::Mount)
699
-
700
- @uploader = Class.new(CarrierWave::Uploader::Base)
701
-
702
- @class.mount_uploader(:image, @uploader, :ignore_processing_errors => false)
703
- @instance = @class.new
704
-
705
- @uploader.class_eval do
706
- process :monkey
707
- def monkey
708
- raise CarrierWave::ProcessingError, "Ohh noez!"
709
- end
710
- end
711
- end
712
-
713
- it "should raise an error if the image fails to be processed when cached" do
714
- expect(running {
715
- @instance.image = stub_file('test.jpg')
716
- }).to raise_error(CarrierWave::ProcessingError)
717
- end
718
-
719
- it "should raise an error if the image fails to be processed when downloaded" do
720
- stub_request(:get, "www.example.com/test.jpg").to_return(body: File.read(file_path("test.jpg")))
721
-
722
- expect(running {
723
- @instance.remote_image_url = "http://www.example.com/test.jpg"
724
- }).to raise_error(CarrierWave::ProcessingError)
725
- end
726
-
727
- end
728
-
729
- describe '#mount_uploader with :ignore_download_errors => false' do
730
-
731
- before do
732
- @class = Class.new
733
- @class.send(:extend, CarrierWave::Mount)
734
-
735
- @uploader = Class.new(CarrierWave::Uploader::Base)
736
-
737
- @class.mount_uploader(:image, @uploader, :ignore_download_errors => false)
738
- @instance = @class.new
739
- end
740
-
741
- it "should raise an error if the image fails to be processed" do
742
- @uploader.class_eval do
743
- def download! uri
744
- raise CarrierWave::DownloadError
745
- end
746
- end
747
-
748
- expect(running {
749
- @instance.remote_image_url = "http://www.example.com/test.jpg"
750
- }).to raise_error(CarrierWave::DownloadError)
751
- end
752
-
753
- end
754
-
755
- describe '#mount_uploader with :mount_on => :monkey' do
756
-
757
- before do
758
- @class = Class.new
759
- @class.send(:extend, CarrierWave::Mount)
760
-
761
- @uploader = Class.new(CarrierWave::Uploader::Base)
762
-
763
- @class.mount_uploader(:image, @uploader, :mount_on => :monkey)
764
- @instance = @class.new
765
- end
766
-
767
- describe '#image' do
768
- it "should retrieve a file from the storage if a value is stored in the database" do
769
- expect(@instance).to receive(:read_uploader).at_least(:once).with(:monkey).and_return('test.jpg')
770
- expect(@instance.image).to be_an_instance_of(@uploader)
771
- expect(@instance.image.current_path).to eq(public_path('uploads/test.jpg'))
772
- end
773
- end
774
-
775
- describe '#write_image_identifier' do
776
- it "should write to the given column" do
777
- expect(@instance).to receive(:write_uploader).with(:monkey, "test.jpg")
778
- @instance.image = stub_file('test.jpg')
779
- @instance.write_image_identifier
780
- end
781
-
782
- it "should remove from the given column when remove_image is true" do
783
- @instance.image = stub_file('test.jpg')
784
- @instance.store_image!
785
- @instance.remove_image = true
786
- expect(@instance).to receive(:write_uploader).with(:monkey, nil)
787
- @instance.write_image_identifier
788
- end
789
- end
790
-
791
- end
792
-
793
- end