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,273 +0,0 @@
1
- require 'spec_helper'
2
- require 'active_support/json'
3
-
4
- describe CarrierWave::Uploader do
5
-
6
- let(:uploader) { MyCoolUploader.new }
7
-
8
- before { class MyCoolUploader < CarrierWave::Uploader::Base; end }
9
-
10
- after do
11
- FileUtils.rm_rf(public_path)
12
- Object.send(:remove_const, "MyCoolUploader") if defined?(::MyCoolUploader)
13
- end
14
-
15
- let(:cache_id) { '1369894322-345-1234-2255' }
16
- let(:test_file) { File.open(file_path(test_file_name)) }
17
- let(:test_file_name) { 'test.jpg' }
18
-
19
- before { allow(CarrierWave).to receive(:generate_cache_id).and_return(cache_id) }
20
-
21
- describe '#url' do
22
- subject(:url) { uploader.url }
23
-
24
- it { is_expected.to be_nil }
25
-
26
- it "doesn't raise exception when hash specified as argument" do
27
- expect { uploader.url({}) }.not_to raise_error
28
- end
29
-
30
- it "encodes the path of a file without an asset host" do
31
- uploader.cache!(File.open(file_path('test+.jpg')))
32
- is_expected.to eq("/uploads/tmp/#{cache_id}/test%2B.jpg")
33
- end
34
-
35
- context "with a cached file" do
36
- before { uploader.cache!(test_file) }
37
-
38
- it "gets the directory relative to public, prepending a slash" do
39
- is_expected.to eq("/uploads/tmp/#{cache_id}/#{test_file_name}")
40
- end
41
-
42
- describe "File#url" do
43
- before do
44
- allow(uploader.file).to receive(:url).and_return(file_url)
45
- end
46
-
47
- context "when present" do
48
- let(:file_url) { 'http://www.example.com/someurl.jpg' }
49
-
50
- it { is_expected.to eq(file_url) }
51
- end
52
-
53
- context "when blank" do
54
- let(:file_url) { '' }
55
-
56
- it "returns the relative path" do
57
- is_expected.to eq("/uploads/tmp/#{cache_id}/#{test_file_name}")
58
- end
59
- end
60
- end
61
- end
62
-
63
- context "when File#url method doesn't get params" do
64
- before do
65
- module StorageX
66
- class File
67
- def url
68
- true
69
- end
70
- end
71
- end
72
-
73
- allow(uploader).to receive(:file).and_return(StorageX::File.new)
74
- end
75
-
76
- it "raises ArgumentError" do
77
- expect { uploader.url }.not_to raise_error
78
- end
79
- end
80
-
81
- describe "(:thumb)" do
82
- subject { uploader.url(:thumb) }
83
-
84
- it "raises ArgumentError when version doesn't exist" do
85
- expect { uploader.url(:thumb) }.to raise_error(ArgumentError)
86
- end
87
-
88
- context "when version is specified" do
89
- before do
90
- MyCoolUploader.version(:thumb)
91
- uploader.cache!(test_file)
92
- end
93
-
94
- it "doesn't raise ArgumentError when versions version exists" do
95
- expect { uploader.url(:thumb) }.not_to raise_error
96
- end
97
-
98
- it "gets the directory relative to public for a specific version" do
99
- is_expected.to eq("/uploads/tmp/#{cache_id}/thumb_#{test_file_name}")
100
- end
101
-
102
- describe "asset_host" do
103
- before { uploader.class.configure { |config| config.asset_host = asset_host } }
104
-
105
- context "when set as a string" do
106
- let(:asset_host) { "http://foo.bar" }
107
-
108
- it "prepends the string" do
109
- is_expected.to eq("#{asset_host}/uploads/tmp/#{cache_id}/thumb_#{test_file_name}")
110
- end
111
-
112
- describe "encoding" do
113
- let(:test_file_name) { 'test+.jpg' }
114
-
115
- it "encodes the path of a file" do
116
- is_expected.to eq("#{asset_host}/uploads/tmp/#{cache_id}/thumb_test%2B.jpg")
117
- end
118
-
119
- it "double-encodes the path of an available File#url" do
120
- url = 'http://www.example.com/directory%2Bname/another%2Bdirectory/some%2Burl.jpg'
121
- allow(uploader.file).to receive(:url).and_return(url)
122
-
123
- expect(uploader.url).to eq(url)
124
- end
125
- end
126
- end
127
-
128
- context "when set as a proc" do
129
- let(:asset_host) { proc { "http://foo.bar" } }
130
-
131
- it "prepends the result of proc" do
132
- is_expected.to eq("#{asset_host.call}/uploads/tmp/#{cache_id}/thumb_#{test_file_name}")
133
- end
134
-
135
- describe "encoding" do
136
- let(:test_file_name) { 'test+.jpg' }
137
-
138
- it { is_expected.to eq("#{asset_host.call}/uploads/tmp/#{cache_id}/thumb_test%2B.jpg") }
139
- end
140
- end
141
-
142
- context "when set as nil" do
143
- let(:asset_host) { nil }
144
-
145
- context "when base_path is set" do
146
- let(:base_path) { "/base_path" }
147
-
148
- before do
149
- uploader.class.configure do |config|
150
- config.base_path = base_path
151
- end
152
- end
153
-
154
- it "prepends the config option 'base_path'" do
155
- is_expected.to eq("#{base_path}/uploads/tmp/#{cache_id}/thumb_#{test_file_name}")
156
- end
157
- end
158
- end
159
- end
160
- end
161
-
162
- context "when the version is nested" do
163
- subject { uploader.url(:thumb, :mini) }
164
-
165
- before do
166
- MyCoolUploader.version(:thumb) { version(:mini) }
167
- uploader.cache!(test_file)
168
- end
169
-
170
- it "gets the directory relative to public for a nested version" do
171
- is_expected.to eq("/uploads/tmp/#{cache_id}/thumb_mini_#{test_file_name}")
172
- end
173
- end
174
- end
175
- end
176
-
177
- describe '#to_json' do
178
- subject(:parsed_json) { JSON.parse(to_json) }
179
-
180
- let(:to_json) { uploader.to_json }
181
-
182
- context "(:thumb)" do
183
- before { MyCoolUploader.version(:thumb) }
184
-
185
- it { expect(parsed_json.keys).to include("url") }
186
- it { expect(parsed_json.keys).to include("thumb") }
187
- it { expect(parsed_json["url"]).to be_nil }
188
- it { expect(parsed_json["thumb"].keys).to include("url") }
189
- it { expect(parsed_json["thumb"]["url"]).to be_nil }
190
-
191
- context "with a cached_file" do
192
- before { uploader.cache!(test_file) }
193
-
194
- it { expect(parsed_json.keys).to include("thumb") }
195
- it { expect(parsed_json["thumb"]).to eq({"url" => "/uploads/tmp/#{cache_id}/thumb_#{test_file_name}"}) }
196
- end
197
- end
198
-
199
- context "with cached file" do
200
- before { uploader.cache!(test_file) }
201
-
202
- it "returns a hash including a cached URL" do
203
- is_expected.to eq({"url" => "/uploads/tmp/#{cache_id}/#{test_file_name}"})
204
- end
205
- end
206
-
207
- it "allows an options parameter to be passed in" do
208
- expect { uploader.to_json({:some => 'options'}) }.not_to raise_error
209
- end
210
- end
211
-
212
- describe '#to_xml' do
213
- subject(:parsed_xml) { Hash.from_xml(to_xml) }
214
-
215
- let(:to_xml) { uploader.to_xml }
216
-
217
- it "returns a hash with a blank URL" do
218
- is_expected.to eq({"uploader" => {"url" => nil}})
219
- end
220
-
221
- context "with cached file" do
222
- before { uploader.cache!(test_file) }
223
-
224
- it "returns a hash including a cached URL" do
225
- is_expected.to eq({"uploader" => {"url" => "/uploads/tmp/#{cache_id}/#{test_file_name}"}})
226
- end
227
-
228
- context "with an array of uploaders" do
229
- let(:to_xml) { [uploader].to_xml }
230
-
231
- it "returns a hash including an array with a cached URL" do
232
- is_expected.to have_value([{"url"=>"/uploads/tmp/#{cache_id}/#{test_file_name}"}])
233
- end
234
- end
235
- end
236
-
237
- describe "(:thumb)" do
238
- before { MyCoolUploader.version(:thumb) }
239
-
240
- context "with cached file" do
241
- before { uploader.cache!(test_file) }
242
-
243
- it "returns a hash including a cached URL of a version" do
244
- expect(parsed_xml["uploader"]["thumb"]).to eq({"url" => "/uploads/tmp/#{cache_id}/thumb_#{test_file_name}"})
245
- end
246
- end
247
- end
248
- end
249
-
250
- describe '#to_s' do
251
- subject { uploader.to_s }
252
-
253
- it { is_expected.to eq('') }
254
-
255
- context "with cached file" do
256
- before { uploader.cache!(test_file) }
257
-
258
- it "gets the directory relative to public, prepending a slash" do
259
- is_expected.to eq("/uploads/tmp/#{cache_id}/#{test_file_name}")
260
- end
261
-
262
- describe "File#url" do
263
- before { allow(uploader.file).to receive(:url).and_return(url) }
264
-
265
- context "when present" do
266
- let(:url) { 'http://www.example.com/someurl.jpg' }
267
-
268
- it { is_expected.to eq(url) }
269
- end
270
- end
271
- end
272
- end
273
- end
@@ -1,633 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe CarrierWave::Uploader do
4
-
5
- before do
6
- @uploader_class = Class.new(CarrierWave::Uploader::Base)
7
- @uploader = @uploader_class.new
8
- end
9
-
10
- after do
11
- FileUtils.rm_rf(public_path)
12
- end
13
-
14
- describe '.version' do
15
- it "should add it to .versions" do
16
- @uploader_class.version :thumb
17
- expect(@uploader_class.versions[:thumb]).to be_a(Class)
18
- expect(@uploader_class.versions[:thumb].ancestors).to include(@uploader_class)
19
- end
20
-
21
- it "should only assign versions to parent" do
22
- @uploader_class.version :large
23
- @uploader_class.version :thumb do
24
- version :mini do
25
- version :micro
26
- end
27
- end
28
- expect(@uploader_class.versions.size).to eq(2)
29
- expect(@uploader_class.versions).to include :large
30
- expect(@uploader_class.versions).to include :thumb
31
- expect(@uploader.large.versions).to be_empty
32
- expect(@uploader.thumb.versions.keys).to eq([:mini])
33
- expect(@uploader.thumb.mini.versions.keys).to eq([:micro])
34
- expect(@uploader.thumb.mini.micro.versions).to be_empty
35
- end
36
-
37
- it "should add an accessor which returns the version" do
38
- @uploader_class.version :thumb
39
- expect(@uploader.thumb).to be_a(@uploader_class)
40
- end
41
-
42
- it "should add it to #versions which returns the version" do
43
- @uploader_class.version :thumb
44
- expect(@uploader.versions[:thumb]).to be_a(@uploader_class)
45
- end
46
-
47
- it "should set the version name" do
48
- @uploader_class.version :thumb
49
- expect(@uploader.version_name).to eq(nil)
50
- expect(@uploader.thumb.version_name).to eq(:thumb)
51
- end
52
-
53
- it "should set the version names on the class" do
54
- @uploader_class.version :thumb
55
- expect(@uploader.class.version_names).to eq([])
56
- expect(@uploader.thumb.class.version_names).to eq([:thumb])
57
- end
58
-
59
- it "should remember mount options" do
60
- model = double('a model')
61
- @uploader_class.version :thumb
62
- @uploader = @uploader_class.new(model, :gazelle)
63
-
64
- expect(@uploader.thumb.model).to eq(model)
65
- expect(@uploader.thumb.mounted_as).to eq(:gazelle)
66
- end
67
-
68
- it "should apply any overrides given in a block" do
69
- @uploader_class.version :thumb do
70
- def store_dir
71
- public_path('monkey/apache')
72
- end
73
- end
74
- expect(@uploader.store_dir).to eq('uploads')
75
- expect(@uploader.thumb.store_dir).to eq(public_path('monkey/apache'))
76
- end
77
-
78
- it "should not initially have a value for enable processing" do
79
- thumb = (@uploader_class.version :thumb)
80
- expect(thumb.instance_variable_get('@enable_processing')).to be_nil
81
- end
82
-
83
- it "should return the enable processing value of the parent" do
84
- @uploader_class.enable_processing = false
85
- thumb = (@uploader_class.version :thumb)
86
- expect(thumb.enable_processing).to be_falsey
87
- end
88
-
89
- it "should return its own value for enable processing if set" do
90
- @uploader_class.enable_processing = false
91
- thumb = @uploader_class.version :thumb
92
- thumb.enable_processing = true
93
- expect(thumb.enable_processing).to be_truthy
94
- end
95
-
96
- it "should reopen the same class when called multiple times" do
97
- @uploader_class.version :thumb do
98
- def self.monkey
99
- "monkey"
100
- end
101
- end
102
- @uploader_class.version :thumb do
103
- def self.llama
104
- "llama"
105
- end
106
- end
107
- expect(@uploader_class.version(:thumb).monkey).to eq("monkey")
108
- expect(@uploader_class.version(:thumb).llama).to eq("llama")
109
- end
110
-
111
- it "should reopen the same instance when called multiple times" do
112
- @uploader_class.version :thumb do
113
- def store_dir
114
- public_path('monkey/apache')
115
- end
116
- end
117
- @uploader_class.version :thumb do
118
- def store_dir
119
- public_path('monkey/apache/new')
120
- end
121
- end
122
-
123
- expect(@uploader.thumb.store_dir).to eq(public_path('monkey/apache/new'))
124
- end
125
-
126
- it "should accept option :from_version" do
127
- @uploader_class.version :small_thumb, :from_version => :thumb
128
- expect(@uploader_class.version(:small_thumb).version_options[:from_version]).to eq(:thumb)
129
- end
130
-
131
- describe 'with nested versions' do
132
- before do
133
- @uploader_class.version :thumb do
134
- version :mini
135
- version :micro
136
- end
137
- end
138
-
139
- it "should add an array of version names" do
140
- expect(@uploader.class.version_names).to eq([])
141
- expect(@uploader.thumb.class.version_names).to eq([:thumb])
142
- expect(@uploader.thumb.mini.class.version_names).to eq([:thumb, :mini])
143
- expect(@uploader.thumb.micro.class.version_names).to eq([:thumb, :micro])
144
- end
145
-
146
- it "should set the version name for the instances" do
147
- expect(@uploader.version_name).to be_nil
148
- expect(@uploader.thumb.version_name).to eq(:thumb)
149
- expect(@uploader.thumb.mini.version_name).to eq(:thumb_mini)
150
- expect(@uploader.thumb.micro.version_name).to eq(:thumb_micro)
151
- end
152
-
153
- it "should set the version name for the #versions" do
154
- expect(@uploader.version_name).to be_nil
155
- expect(@uploader.versions[:thumb].version_name).to eq(:thumb)
156
- expect(@uploader.versions[:thumb].versions[:mini].version_name).to eq(:thumb_mini)
157
- expect(@uploader.versions[:thumb].versions[:micro].version_name).to eq(:thumb_micro)
158
- end
159
-
160
- it "should process nested versions" do
161
- @uploader_class.class_eval {
162
- include CarrierWave::MiniMagick
163
-
164
- version :rotated do
165
- process :rotate
166
-
167
- version :boxed do
168
- process :resize_to_fit => [200, 200]
169
- end
170
- end
171
-
172
- def rotate
173
- manipulate! do |img|
174
- img.rotate "90"
175
- img
176
- end
177
- end
178
- }
179
- @uploader.cache! File.open(file_path('portrait.jpg'))
180
-
181
- expect(@uploader).to have_dimensions(233, 337)
182
- expect(@uploader.rotated).to have_dimensions(337, 233)
183
- expect(@uploader.rotated.boxed).to have_dimensions(200, 138)
184
- end
185
- end
186
-
187
- describe 'with inheritance' do
188
-
189
- before do
190
- @uploader_class.version :thumb do
191
- def store_dir
192
- public_path('monkey/apache')
193
- end
194
- end
195
-
196
- @child_uploader_class = Class.new(@uploader_class)
197
- @child_uploader = @child_uploader_class.new
198
- end
199
-
200
- it "should override parent version" do
201
- @child_uploader_class.version :thumb do
202
- def store_dir
203
- public_path('monkey/apache/child')
204
- end
205
- end
206
-
207
- expect(@child_uploader.thumb.store_dir).to eq(public_path('monkey/apache/child'))
208
- end
209
-
210
- it "shouldn't affect parent class' version" do
211
- @child_uploader_class.version :thumb do
212
- def store_dir
213
- public_path('monkey/apache/child')
214
- end
215
- end
216
-
217
- expect(@uploader.thumb.store_dir).to eq(public_path('monkey/apache'))
218
- end
219
- end
220
- end
221
-
222
- describe 'with a version' do
223
- before do
224
- @uploader_class.version(:thumb)
225
- end
226
-
227
- describe '#cache!' do
228
-
229
- before do
230
- allow(CarrierWave).to receive(:generate_cache_id).and_return('1369894322-345-1234-2255')
231
- end
232
-
233
- it "should set store_path with versions" do
234
- expect(CarrierWave).to receive(:generate_cache_id).once
235
- @uploader.cache!(File.open(file_path('test.jpg')))
236
- expect(@uploader.store_path).to eq('uploads/test.jpg')
237
- expect(@uploader.thumb.store_path).to eq('uploads/thumb_test.jpg')
238
- expect(@uploader.thumb.store_path('kebab.png')).to eq('uploads/thumb_kebab.png')
239
- end
240
-
241
- it "should move it to the tmp dir with the filename prefixed" do
242
- expect(CarrierWave).to receive(:generate_cache_id).once
243
- @uploader.cache!(File.open(file_path('test.jpg')))
244
- expect(@uploader.current_path).to eq(public_path('uploads/tmp/1369894322-345-1234-2255/test.jpg'))
245
- expect(@uploader.thumb.current_path).to eq(public_path('uploads/tmp/1369894322-345-1234-2255/thumb_test.jpg'))
246
- expect(@uploader.file.exists?).to be_truthy
247
- expect(@uploader.thumb.file.exists?).to be_truthy
248
- end
249
-
250
- it "should cache the files based on the parent" do
251
- expect(CarrierWave).to receive(:generate_cache_id).once
252
- @uploader.cache!(File.open(file_path('bork.txt')))
253
-
254
- expect(File.read(public_path(@uploader.to_s))).to eq(File.read(public_path(@uploader.thumb.to_s)))
255
- end
256
- end
257
-
258
- describe "version with move_to_cache set" do
259
- before do
260
- FileUtils.cp(file_path('test.jpg'), file_path('test_copy.jpg'))
261
- allow(CarrierWave).to receive(:generate_cache_id).and_return('1369894322-345-1234-2255')
262
- @uploader_class.send(:define_method, :move_to_cache) do
263
- true
264
- end
265
- end
266
-
267
- after do
268
- FileUtils.mv(file_path('test_copy.jpg'), file_path('test.jpg'))
269
- end
270
-
271
- it "should copy the parent file when creating the version" do
272
- @uploader_class.version(:thumb)
273
- @uploader.cache!(File.open(file_path('test.jpg')))
274
- expect(@uploader.current_path).to eq(public_path('uploads/tmp/1369894322-345-1234-2255/test.jpg'))
275
- expect(@uploader.thumb.current_path).to eq(public_path('uploads/tmp/1369894322-345-1234-2255/thumb_test.jpg'))
276
- expect(@uploader.file.exists?).to be_truthy
277
- expect(@uploader.thumb.file.exists?).to be_truthy
278
- end
279
-
280
- it "should allow overriding move_to_cache on versions" do
281
- @uploader_class.version(:thumb) do
282
- def move_to_cache
283
- true
284
- end
285
- end
286
- @uploader.cache!(File.open(file_path('test.jpg')))
287
- expect(@uploader.current_path).to eq(public_path('uploads/tmp/1369894322-345-1234-2255/test.jpg'))
288
- expect(@uploader.thumb.current_path).to eq(public_path('uploads/tmp/1369894322-345-1234-2255/thumb_test.jpg'))
289
- expect(@uploader.file.exists?).to be_falsey
290
- expect(@uploader.thumb.file.exists?).to be_truthy
291
- end
292
- end
293
-
294
- describe '#retrieve_from_cache!' do
295
- it "should set the path to the tmp dir" do
296
- @uploader.retrieve_from_cache!('1369894322-345-1234-2255/test.jpg')
297
- expect(@uploader.current_path).to eq(public_path('uploads/tmp/1369894322-345-1234-2255/test.jpg'))
298
- expect(@uploader.thumb.current_path).to eq(public_path('uploads/tmp/1369894322-345-1234-2255/thumb_test.jpg'))
299
- end
300
-
301
- it "should set store_path with versions" do
302
- @uploader.retrieve_from_cache!('1369894322-345-1234-2255/test.jpg')
303
- expect(@uploader.store_path).to eq('uploads/test.jpg')
304
- expect(@uploader.thumb.store_path).to eq('uploads/thumb_test.jpg')
305
- expect(@uploader.thumb.store_path('kebab.png')).to eq('uploads/thumb_kebab.png')
306
- end
307
- end
308
-
309
- describe '#store!' do
310
- before do
311
- @uploader_class.storage = mock_storage('base')
312
- @uploader_class.version(:thumb).storage = mock_storage('thumb')
313
- @uploader_class.version(:preview).storage = mock_storage('preview')
314
-
315
- @file = File.open(file_path('test.jpg'))
316
-
317
- @base_stored_file = double('a stored file')
318
- allow(@base_stored_file).to receive(:path).and_return('/path/to/somewhere')
319
- allow(@base_stored_file).to receive(:url).and_return('http://www.example.com')
320
-
321
- @thumb_stored_file = double('a thumb version of a stored file')
322
- allow(@thumb_stored_file).to receive(:path).and_return('/path/to/somewhere/thumb')
323
- allow(@thumb_stored_file).to receive(:url).and_return('http://www.example.com/thumb')
324
-
325
- @preview_stored_file = double('a preview version of a stored file')
326
- allow(@preview_stored_file).to receive(:path).and_return('/path/to/somewhere/preview')
327
- allow(@preview_stored_file).to receive(:url).and_return('http://www.example.com/preview')
328
-
329
- @storage = double('a storage engine')
330
- allow(@storage).to receive(:store!).and_return(@base_stored_file)
331
-
332
- @thumb_storage = double('a storage engine for thumbnails')
333
- allow(@thumb_storage).to receive(:store!).and_return(@thumb_stored_file)
334
-
335
- @preview_storage = double('a storage engine for previews')
336
- allow(@preview_storage).to receive(:store!).and_return(@preview_stored_file)
337
-
338
- allow(@uploader_class.storage).to receive(:new).with(@uploader).and_return(@storage)
339
- allow(@uploader_class.version(:thumb).storage).to receive(:new).and_return(@thumb_storage)
340
- allow(@uploader_class.version(:preview).storage).to receive(:new).and_return(@preview_storage)
341
- end
342
-
343
- it "should set the current path for the version" do
344
- @uploader.store!(@file)
345
- expect(@uploader.current_path).to eq('/path/to/somewhere')
346
- expect(@uploader.thumb.current_path).to eq('/path/to/somewhere/thumb')
347
- end
348
-
349
- it "should set the url" do
350
- @uploader.store!(@file)
351
- expect(@uploader.url).to eq('http://www.example.com')
352
- expect(@uploader.thumb.url).to eq('http://www.example.com/thumb')
353
- end
354
-
355
- it "should, if a file is given as argument, set the store_path" do
356
- @uploader.store!(@file)
357
- expect(@uploader.store_path).to eq('uploads/test.jpg')
358
- expect(@uploader.thumb.store_path).to eq('uploads/thumb_test.jpg')
359
- expect(@uploader.thumb.store_path('kebab.png')).to eq('uploads/thumb_kebab.png')
360
- end
361
-
362
- it "should instruct the storage engine to store the file and its version" do
363
- @uploader.cache!(@file)
364
- expect(@storage).to receive(:store!).with(@uploader.file).and_return(:monkey)
365
- expect(@thumb_storage).to receive(:store!).with(@uploader.thumb.file).and_return(:gorilla)
366
- @uploader.store!
367
- end
368
-
369
- it "should process conditional versions if the condition method returns true" do
370
- @uploader_class.version(:preview).version_options[:if] = :true?
371
- expect(@uploader).to receive(:true?).at_least(:once).and_return(true)
372
- @uploader.store!(@file)
373
- expect(@uploader.thumb).to be_present
374
- expect(@uploader.preview).to be_present
375
- end
376
-
377
- it "should not process conditional versions if the condition method returns false" do
378
- @uploader_class.version(:preview).version_options[:if] = :false?
379
- expect(@uploader).to receive(:false?).at_least(:once).and_return(false)
380
- @uploader.store!(@file)
381
- expect(@uploader.thumb).to be_present
382
- expect(@uploader.preview).to be_blank
383
- end
384
-
385
- it "should process conditional version if the condition block returns true" do
386
- @uploader_class.version(:preview).version_options[:if] = lambda{|record, args| record.true?(args[:file])}
387
- expect(@uploader).to receive(:true?).at_least(:once).and_return(true)
388
- @uploader.store!(@file)
389
- expect(@uploader.thumb).to be_present
390
- expect(@uploader.preview).to be_present
391
- end
392
-
393
- it "should not process conditional versions if the condition block returns false" do
394
- @uploader_class.version(:preview).version_options[:if] = lambda{|record, args| record.false?(args[:file])}
395
- expect(@uploader).to receive(:false?).at_least(:once).and_return(false)
396
- @uploader.store!(@file)
397
- expect(@uploader.thumb).to be_present
398
- expect(@uploader.preview).to be_blank
399
- end
400
-
401
- it "should not cache file twice when store! called with a file" do
402
- @uploader_class.process :banana
403
- @uploader.thumb.class.process :banana
404
-
405
- expect(@uploader).to receive(:banana).at_least(:once).at_most(:once).and_return(true)
406
- expect(@uploader.thumb).to receive(:banana).at_least(:once).at_most(:once).and_return(true)
407
-
408
- @uploader.store!(@file)
409
- expect(@uploader.store_path).to eq('uploads/test.jpg')
410
- expect(@uploader.thumb.store_path).to eq('uploads/thumb_test.jpg')
411
- end
412
- end
413
-
414
- describe '#recreate_versions!' do
415
- before do
416
- @file = File.open(file_path('test.jpg'))
417
- end
418
-
419
- it "should overwrite all stored versions with the contents of the original file" do
420
- @uploader.store!(@file)
421
-
422
- File.open(@uploader.path, 'w') { |f| f.write "Contents changed" }
423
- expect(File.read(@uploader.thumb.path)).not_to eq("Contents changed")
424
- @uploader.recreate_versions!
425
- expect(File.read(@uploader.thumb.path)).to eq("Contents changed")
426
- end
427
-
428
- it "should recreate all versions if any are missing" do
429
- @uploader.store!(@file)
430
-
431
- expect(File.exist?(@uploader.thumb.path)).to eq(true)
432
- FileUtils.rm(@uploader.thumb.path)
433
- expect(File.exist?(@uploader.thumb.path)).to eq(false)
434
-
435
- @uploader.recreate_versions!
436
-
437
- expect(File.exist?(@uploader.thumb.path)).to eq(true)
438
- end
439
-
440
- it "should recreate only specified versions if passed as args" do
441
- @uploader_class.version(:mini)
442
- @uploader_class.version(:maxi)
443
- @uploader.store!(@file)
444
-
445
- expect(File.exist?(@uploader.thumb.path)).to eq(true)
446
- expect(File.exist?(@uploader.mini.path)).to eq(true)
447
- expect(File.exist?(@uploader.maxi.path)).to eq(true)
448
- FileUtils.rm(@uploader.thumb.path)
449
- expect(File.exist?(@uploader.thumb.path)).to eq(false)
450
- FileUtils.rm(@uploader.mini.path)
451
- expect(File.exist?(@uploader.mini.path)).to eq(false)
452
- FileUtils.rm(@uploader.maxi.path)
453
- expect(File.exist?(@uploader.maxi.path)).to eq(false)
454
-
455
- @uploader.recreate_versions!(:thumb, :maxi)
456
-
457
- expect(File.exist?(@uploader.thumb.path)).to eq(true)
458
- expect(File.exist?(@uploader.maxi.path)).to eq(true)
459
- expect(File.exist?(@uploader.mini.path)).to eq(false)
460
- end
461
-
462
- it "should not create version if proc returns false" do
463
- @uploader_class.version(:mini, :if => Proc.new { |*args| false } )
464
- @uploader.store!(@file)
465
-
466
- expect(@uploader.mini.path).to be_nil
467
-
468
- @uploader.recreate_versions!(:mini)
469
-
470
- expect(@uploader.mini.path).to be_nil
471
- end
472
-
473
- it "should not change the case of versions" do
474
- @file = File.open(file_path('Uppercase.jpg'))
475
- @uploader.store!(@file)
476
- expect(@uploader.thumb.path).to eq(public_path('uploads/thumb_Uppercase.jpg'))
477
- @uploader.recreate_versions!
478
- expect(@uploader.thumb.path).to eq(public_path('uploads/thumb_Uppercase.jpg'))
479
- end
480
- end
481
-
482
- describe '#remove!' do
483
- before do
484
- @uploader_class.storage = mock_storage('base')
485
- @uploader_class.version(:thumb).storage = mock_storage('thumb')
486
-
487
- @file = File.open(file_path('test.jpg'))
488
-
489
- @base_stored_file = double('a stored file')
490
- @thumb_stored_file = double('a thumb version of a stored file')
491
-
492
- @storage = double('a storage engine')
493
- allow(@storage).to receive(:store!).and_return(@base_stored_file)
494
-
495
- @thumb_storage = double('a storage engine for thumbnails')
496
- allow(@thumb_storage).to receive(:store!).and_return(@thumb_stored_file)
497
-
498
- allow(@uploader_class.storage).to receive(:new).with(@uploader).and_return(@storage)
499
- allow(@uploader_class.version(:thumb).storage).to receive(:new).with(@uploader.thumb).and_return(@thumb_storage)
500
-
501
- allow(@base_stored_file).to receive(:delete)
502
- allow(@thumb_stored_file).to receive(:delete)
503
-
504
- @uploader.store!(@file)
505
- end
506
-
507
- it "should reset the current path for the version" do
508
- @uploader.remove!
509
- expect(@uploader.current_path).to be_nil
510
- expect(@uploader.thumb.current_path).to be_nil
511
- end
512
-
513
- it "should reset the url" do
514
- @uploader.remove!
515
- expect(@uploader.url).to be_nil
516
- expect(@uploader.thumb.url).to be_nil
517
- end
518
-
519
- it "should delete all the files" do
520
- expect(@base_stored_file).to receive(:delete)
521
- expect(@thumb_stored_file).to receive(:delete)
522
- @uploader.remove!
523
- end
524
-
525
- end
526
-
527
- describe '#retrieve_from_store!' do
528
- before do
529
- @uploader_class.storage = mock_storage('base')
530
- @uploader_class.version(:thumb).storage = mock_storage('thumb')
531
- @uploader_class.version(:preview).storage = mock_storage('preview')
532
-
533
- @file = File.open(file_path('test.jpg'))
534
-
535
- @base_stored_file = double('a stored file')
536
- allow(@base_stored_file).to receive(:path).and_return('/path/to/somewhere')
537
- allow(@base_stored_file).to receive(:url).and_return('http://www.example.com')
538
-
539
- @thumb_stored_file = double('a thumb version of a stored file')
540
- allow(@thumb_stored_file).to receive(:path).and_return('/path/to/somewhere/thumb')
541
- allow(@thumb_stored_file).to receive(:url).and_return('http://www.example.com/thumb')
542
-
543
- @preview_stored_file = double('a preview version of a stored file')
544
- allow(@preview_stored_file).to receive(:path).and_return('/path/to/somewhere/preview')
545
- allow(@preview_stored_file).to receive(:url).and_return('http://www.example.com/preview')
546
-
547
- @storage = double('a storage engine')
548
- allow(@storage).to receive(:retrieve!).and_return(@base_stored_file)
549
-
550
- @thumb_storage = double('a storage engine for thumbnails')
551
- allow(@thumb_storage).to receive(:retrieve!).and_return(@thumb_stored_file)
552
-
553
- @preview_storage = double('a storage engine for previewnails')
554
- allow(@preview_storage).to receive(:retrieve!).and_return(@preview_stored_file)
555
-
556
- allow(@uploader_class.storage).to receive(:new).with(@uploader).and_return(@storage)
557
- allow(@uploader_class.version(:thumb).storage).to receive(:new).with(@uploader.thumb).and_return(@thumb_storage)
558
- allow(@uploader_class.version(:preview).storage).to receive(:new).with(@uploader.preview).and_return(@preview_storage)
559
- end
560
-
561
- it "should set the current path" do
562
- @uploader.retrieve_from_store!('monkey.txt')
563
- expect(@uploader.current_path).to eq('/path/to/somewhere')
564
- expect(@uploader.thumb.current_path).to eq('/path/to/somewhere/thumb')
565
- end
566
-
567
- it "should set the url" do
568
- @uploader.retrieve_from_store!('monkey.txt')
569
- expect(@uploader.url).to eq('http://www.example.com')
570
- expect(@uploader.thumb.url).to eq('http://www.example.com/thumb')
571
- end
572
-
573
- it "should pass the identifier to the storage engine" do
574
- expect(@storage).to receive(:retrieve!).with('monkey.txt').and_return(@base_stored_file)
575
- expect(@thumb_storage).to receive(:retrieve!).with('monkey.txt').and_return(@thumb_stored_file)
576
- @uploader.retrieve_from_store!('monkey.txt')
577
- expect(@uploader.file).to eq(@base_stored_file)
578
- expect(@uploader.thumb.file).to eq(@thumb_stored_file)
579
- end
580
-
581
- it "should not set the filename" do
582
- @uploader.retrieve_from_store!('monkey.txt')
583
- expect(@uploader.filename).to be_nil
584
- end
585
-
586
- it "should process conditional versions if the condition method returns true" do
587
- @uploader_class.version(:preview).version_options[:if] = :true?
588
- expect(@uploader).to receive(:true?).at_least(:once).and_return(true)
589
- @uploader.retrieve_from_store!('monkey.txt')
590
- expect(@uploader.thumb).to be_present
591
- expect(@uploader.preview).to be_present
592
- end
593
-
594
- it "should not process conditional versions if the condition method returns false" do
595
- @uploader_class.version(:preview).version_options[:if] = :false?
596
- expect(@uploader).to receive(:false?).at_least(:once).and_return(false)
597
- @uploader.retrieve_from_store!('monkey.txt')
598
- expect(@uploader.thumb).to be_present
599
- expect(@uploader.preview).to be_blank
600
- end
601
- end
602
- end
603
-
604
- describe 'with a version with option :from_version' do
605
- before do
606
- @uploader_class.class_eval do
607
- def upcase
608
- content = File.read(current_path)
609
- File.open(current_path, 'w') { |f| f.write content.upcase }
610
- end
611
- end
612
-
613
- @uploader_class.version(:thumb) do
614
- process :upcase
615
- end
616
-
617
- @uploader_class.version(:small_thumb, :from_version => :thumb)
618
- end
619
-
620
- describe '#cache!' do
621
- before do
622
- allow(CarrierWave).to receive(:generate_cache_id).and_return('1369894322-345-1234-2255')
623
- end
624
-
625
- it "should cache the files based on the version" do
626
- @uploader.cache!(File.open(file_path('bork.txt')))
627
-
628
- expect(File.read(public_path(@uploader.to_s))).not_to eq(File.read(public_path(@uploader.thumb.to_s)))
629
- expect(File.read(public_path(@uploader.thumb.to_s))).to eq(File.read(public_path(@uploader.small_thumb.to_s)))
630
- end
631
- end
632
- end
633
- end