thorsson_carrierwave 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. data/Generators +4 -0
  2. data/History.txt +125 -0
  3. data/Manifest.txt +111 -0
  4. data/README.rdoc +528 -0
  5. data/Rakefile +39 -0
  6. data/cucumber.yml +2 -0
  7. data/features/caching.feature +28 -0
  8. data/features/download.feature +20 -0
  9. data/features/file_storage.feature +37 -0
  10. data/features/file_storage_overridden_filename.feature +38 -0
  11. data/features/file_storage_overridden_store_dir.feature +38 -0
  12. data/features/file_storage_reversing_processor.feature +43 -0
  13. data/features/fixtures/bork.txt +1 -0
  14. data/features/fixtures/monkey.txt +1 -0
  15. data/features/grid_fs_storage.feature +32 -0
  16. data/features/mount_activerecord.feature +46 -0
  17. data/features/mount_datamapper.feature +46 -0
  18. data/features/step_definitions/activerecord_steps.rb +22 -0
  19. data/features/step_definitions/caching_steps.rb +14 -0
  20. data/features/step_definitions/datamapper_steps.rb +29 -0
  21. data/features/step_definitions/download_steps.rb +4 -0
  22. data/features/step_definitions/file_steps.rb +53 -0
  23. data/features/step_definitions/general_steps.rb +85 -0
  24. data/features/step_definitions/mount_steps.rb +19 -0
  25. data/features/step_definitions/store_steps.rb +18 -0
  26. data/features/support/activerecord.rb +30 -0
  27. data/features/support/datamapper.rb +7 -0
  28. data/features/support/env.rb +22 -0
  29. data/features/versions_basics.feature +50 -0
  30. data/features/versions_nested_versions.feature +70 -0
  31. data/features/versions_overridden_filename.feature +51 -0
  32. data/features/versions_overriden_store_dir.feature +41 -0
  33. data/lib/carrierwave/compatibility/paperclip.rb +95 -0
  34. data/lib/carrierwave/core_ext/blank.rb +46 -0
  35. data/lib/carrierwave/core_ext/inheritable_attributes.rb +104 -0
  36. data/lib/carrierwave/core_ext/module_setup.rb +51 -0
  37. data/lib/carrierwave/mount.rb +359 -0
  38. data/lib/carrierwave/orm/activerecord.rb +73 -0
  39. data/lib/carrierwave/orm/datamapper.rb +27 -0
  40. data/lib/carrierwave/orm/mongoid.rb +23 -0
  41. data/lib/carrierwave/orm/mongomapper.rb +27 -0
  42. data/lib/carrierwave/orm/sequel.rb +45 -0
  43. data/lib/carrierwave/processing/image_science.rb +101 -0
  44. data/lib/carrierwave/processing/mini_magick.rb +265 -0
  45. data/lib/carrierwave/processing/rmagick.rb +282 -0
  46. data/lib/carrierwave/sanitized_file.rb +273 -0
  47. data/lib/carrierwave/storage/abstract.rb +30 -0
  48. data/lib/carrierwave/storage/cloud_files.rb +169 -0
  49. data/lib/carrierwave/storage/file.rb +48 -0
  50. data/lib/carrierwave/storage/grid_fs.rb +97 -0
  51. data/lib/carrierwave/storage/right_s3.rb +167 -0
  52. data/lib/carrierwave/storage/s3.rb +199 -0
  53. data/lib/carrierwave/test/matchers.rb +128 -0
  54. data/lib/carrierwave/uploader/cache.rb +145 -0
  55. data/lib/carrierwave/uploader/callbacks.rb +42 -0
  56. data/lib/carrierwave/uploader/configuration.rb +130 -0
  57. data/lib/carrierwave/uploader/default_url.rb +19 -0
  58. data/lib/carrierwave/uploader/download.rb +59 -0
  59. data/lib/carrierwave/uploader/extension_whitelist.rb +37 -0
  60. data/lib/carrierwave/uploader/mountable.rb +39 -0
  61. data/lib/carrierwave/uploader/processing.rb +83 -0
  62. data/lib/carrierwave/uploader/proxy.rb +62 -0
  63. data/lib/carrierwave/uploader/remove.rb +22 -0
  64. data/lib/carrierwave/uploader/store.rb +89 -0
  65. data/lib/carrierwave/uploader/url.rb +33 -0
  66. data/lib/carrierwave/uploader/versions.rb +146 -0
  67. data/lib/carrierwave/uploader.rb +44 -0
  68. data/lib/carrierwave.rb +99 -0
  69. data/merb_generators/uploader_generator.rb +22 -0
  70. data/rails_generators/uploader/USAGE +2 -0
  71. data/rails_generators/uploader/templates/uploader.rb +47 -0
  72. data/rails_generators/uploader/uploader_generator.rb +21 -0
  73. data/script/console +10 -0
  74. data/script/destroy +14 -0
  75. data/script/generate +14 -0
  76. data/spec/compatibility/paperclip_spec.rb +52 -0
  77. data/spec/fixtures/bork.txt +1 -0
  78. data/spec/fixtures/landscape.jpg +0 -0
  79. data/spec/fixtures/portrait.jpg +0 -0
  80. data/spec/fixtures/test.jpeg +1 -0
  81. data/spec/fixtures/test.jpg +1 -0
  82. data/spec/mount_spec.rb +538 -0
  83. data/spec/orm/activerecord_spec.rb +271 -0
  84. data/spec/orm/datamapper_spec.rb +168 -0
  85. data/spec/orm/mongoid_spec.rb +202 -0
  86. data/spec/orm/mongomapper_spec.rb +202 -0
  87. data/spec/orm/sequel_spec.rb +183 -0
  88. data/spec/processing/image_science_spec.rb +56 -0
  89. data/spec/processing/mini_magick_spec.rb +76 -0
  90. data/spec/processing/rmagick_spec.rb +75 -0
  91. data/spec/sanitized_file_spec.rb +623 -0
  92. data/spec/spec_helper.rb +92 -0
  93. data/spec/storage/grid_fs_spec.rb +83 -0
  94. data/spec/storage/right_s3_spec.rb +83 -0
  95. data/spec/storage/s3_spec.rb +95 -0
  96. data/spec/uploader/cache_spec.rb +209 -0
  97. data/spec/uploader/configuration_spec.rb +105 -0
  98. data/spec/uploader/default_url_spec.rb +85 -0
  99. data/spec/uploader/download_spec.rb +75 -0
  100. data/spec/uploader/extension_whitelist_spec.rb +44 -0
  101. data/spec/uploader/mountable_spec.rb +33 -0
  102. data/spec/uploader/paths_spec.rb +22 -0
  103. data/spec/uploader/processing_spec.rb +73 -0
  104. data/spec/uploader/proxy_spec.rb +54 -0
  105. data/spec/uploader/remove_spec.rb +70 -0
  106. data/spec/uploader/store_spec.rb +264 -0
  107. data/spec/uploader/url_spec.rb +102 -0
  108. data/spec/uploader/versions_spec.rb +298 -0
  109. metadata +436 -0
data/Rakefile ADDED
@@ -0,0 +1,39 @@
1
+ require 'rubygems'
2
+ gem 'hoe', '>= 2.1.0'
3
+ require 'hoe'
4
+ require 'fileutils'
5
+ $:.unshift File.join(File.dirname(__FILE__), 'lib')
6
+ require 'carrierwave'
7
+
8
+ Hoe.plugin :newgem
9
+ # Hoe.plugin :website
10
+ Hoe.plugin :cucumberfeatures
11
+
12
+ $hoe = Hoe.spec 'carrierwave' do
13
+ self.developer 'Jonas Nicklas', 'jonas.nicklas@gmail.com'
14
+ self.rubyforge_name = self.name
15
+ self.readme_file = 'README.rdoc'
16
+ self.version = CarrierWave::VERSION
17
+ self.extra_dev_deps << ['newgem', '>=1.5.2']
18
+ self.extra_dev_deps << ['rspec', '>=1.2.8']
19
+ self.extra_dev_deps << ['cucumber', '>=0.3.96']
20
+ self.extra_dev_deps << ['activerecord', '>=2.3.3']
21
+ self.extra_dev_deps << ['sqlite3-ruby', '>=1.2.5']
22
+ self.extra_dev_deps << ['dm-core', '>=0.9.11']
23
+ self.extra_dev_deps << ['data_objects', '>=0.9.12']
24
+ self.extra_dev_deps << ['do_sqlite3', '>=0.9.11']
25
+ self.extra_dev_deps << ['sequel', '>=3.2.0']
26
+ self.extra_dev_deps << ['rmagick', '>=2.10.0']
27
+ self.extra_dev_deps << ['mini_magick', '>=1.2.5']
28
+ self.extra_dev_deps << ['mongo_mapper', '>=0.6.8']
29
+ self.extra_dev_deps << ['mongoid', '>=0.10.4']
30
+ self.extra_dev_deps << ['aws-s3', '>=0.6.2']
31
+ self.extra_dev_deps << ['timecop', '>=0.3.4']
32
+ self.extra_dev_deps << ['json', '>=1.1.9']
33
+ self.extra_rdoc_files << 'README.rdoc'
34
+ end
35
+
36
+ require 'newgem/tasks'
37
+ Dir['tasks/**/*.rake'].each { |t| load t }
38
+
39
+ task :default => [:spec, :features]
data/cucumber.yml ADDED
@@ -0,0 +1,2 @@
1
+ default: --format pretty --no-source
2
+ html: --format html --out features.html
@@ -0,0 +1,28 @@
1
+ Feature: uploader with file storage
2
+ In order to be able to temporarily store files to disk
3
+ As a developer using CarrierWave
4
+ I want to cache files
5
+
6
+ Scenario: cache a file
7
+ Given an uploader class that uses the 'file' storage
8
+ And an instance of that class
9
+ When I cache the file 'fixtures/bork.txt'
10
+ Then there should be a file called 'bork.txt' somewhere in a subdirectory of 'public/uploads/tmp'
11
+ And the file called 'bork.txt' in a subdirectory of 'public/uploads/tmp' should be identical to the file at 'fixtures/bork.txt'
12
+
13
+ Scenario: cache two files in succession
14
+ Given an uploader class that uses the 'file' storage
15
+ And an instance of that class
16
+ When I cache the file 'fixtures/bork.txt'
17
+ Then there should be a file called 'bork.txt' somewhere in a subdirectory of 'public/uploads/tmp'
18
+ And the file called 'bork.txt' in a subdirectory of 'public/uploads/tmp' should be identical to the file at 'fixtures/bork.txt'
19
+ When I cache the file 'fixtures/monkey.txt'
20
+ Then there should be a file called 'monkey.txt' somewhere in a subdirectory of 'public/uploads/tmp'
21
+ And the file called 'monkey.txt' in a subdirectory of 'public/uploads/tmp' should be identical to the file at 'fixtures/monkey.txt'
22
+
23
+ Scenario: retrieving a file from cache
24
+ Given an uploader class that uses the 'file' storage
25
+ And an instance of that class
26
+ And the file 'fixtures/bork.txt' is cached file at 'public/uploads/tmp/20090212-2343-8336-0348/bork.txt'
27
+ When I retrieve the cache name '20090212-2343-8336-0348/bork.txt' from the cache
28
+ Then the uploader should have 'public/uploads/tmp/20090212-2343-8336-0348/bork.txt' as its current path
@@ -0,0 +1,20 @@
1
+ Feature: downloading files
2
+ In order to allow users to upload remote files
3
+ As a developer using CarrierWave
4
+ I want to download files to the filesystem via HTTP
5
+
6
+ Background:
7
+ Given an uploader class that uses the 'file' storage
8
+ And an instance of that class
9
+
10
+ Scenario: download a file
11
+ When I download the file 'http://s3.amazonaws.com/Monkey/testfile.txt'
12
+ Then there should be a file called 'testfile.txt' somewhere in a subdirectory of 'public/uploads/tmp'
13
+ And the file called 'testfile.txt' in a subdirectory of 'public/uploads/tmp' should contain 'S3 Remote File'
14
+
15
+ Scenario: downloading a file then storing
16
+ When I download the file 'http://s3.amazonaws.com/Monkey/testfile.txt'
17
+ And I store the file
18
+ Then there should be a file at 'public/uploads/testfile.txt'
19
+ And the file at 'public/uploads/testfile.txt' should contain 'S3 Remote File'
20
+
@@ -0,0 +1,37 @@
1
+ Feature: uploader with file storage
2
+ In order to be awesome
3
+ As a developer using CarrierWave
4
+ I want to upload files to the filesystem
5
+
6
+ Background:
7
+ Given an uploader class that uses the 'file' storage
8
+ And an instance of that class
9
+
10
+ Scenario: store a file
11
+ When I store the file 'fixtures/bork.txt'
12
+ Then there should be a file at 'public/uploads/bork.txt'
13
+ And the file at 'public/uploads/bork.txt' should be identical to the file at 'fixtures/bork.txt'
14
+
15
+ Scenario: store two files in succession
16
+ When I store the file 'fixtures/bork.txt'
17
+ Then there should be a file at 'public/uploads/bork.txt'
18
+ And the file at 'public/uploads/bork.txt' should be identical to the file at 'fixtures/bork.txt'
19
+ When I store the file 'fixtures/monkey.txt'
20
+ Then there should be a file at 'public/uploads/monkey.txt'
21
+ And the file at 'public/uploads/monkey.txt' should be identical to the file at 'fixtures/monkey.txt'
22
+
23
+ Scenario: cache a file and then store it
24
+ When I cache the file 'fixtures/bork.txt'
25
+ Then there should be a file called 'bork.txt' somewhere in a subdirectory of 'public/uploads/tmp'
26
+ And the file called 'bork.txt' in a subdirectory of 'public/uploads/tmp' should be identical to the file at 'fixtures/bork.txt'
27
+ And there should not be a file at 'public/uploads/bork.txt'
28
+ When I store the file
29
+ Then there should be a file at 'public/uploads/bork.txt'
30
+ And the file at 'public/uploads/bork.txt' should be identical to the file at 'fixtures/bork.txt'
31
+
32
+ Scenario: retrieving a file from cache then storing
33
+ Given the file 'fixtures/bork.txt' is cached file at 'public/uploads/tmp/20090212-2343-8336-0348/bork.txt'
34
+ When I retrieve the cache name '20090212-2343-8336-0348/bork.txt' from the cache
35
+ And I store the file
36
+ Then there should be a file at 'public/uploads/bork.txt'
37
+ And the file at 'public/uploads/bork.txt' should be identical to the file at 'fixtures/bork.txt'
@@ -0,0 +1,38 @@
1
+ Feature: uploader with file storage and overriden filename
2
+ In order to be awesome
3
+ As a developer using CarrierWave
4
+ I want to upload files to the filesystem with an overriden filename
5
+
6
+ Background:
7
+ Given an uploader class that uses the 'file' storage
8
+ And that the uploader reverses the filename
9
+ And an instance of that class
10
+
11
+ Scenario: store a file
12
+ When I store the file 'fixtures/bork.txt'
13
+ Then there should be a file at 'public/uploads/txt.krob'
14
+ And the file at 'public/uploads/txt.krob' should be identical to the file at 'fixtures/bork.txt'
15
+
16
+ Scenario: store two files in succession
17
+ When I store the file 'fixtures/bork.txt'
18
+ Then there should be a file at 'public/uploads/txt.krob'
19
+ And the file at 'public/uploads/txt.krob' should be identical to the file at 'fixtures/bork.txt'
20
+ When I store the file 'fixtures/monkey.txt'
21
+ Then there should be a file at 'public/uploads/txt.yeknom'
22
+ And the file at 'public/uploads/txt.yeknom' should be identical to the file at 'fixtures/monkey.txt'
23
+
24
+ Scenario: cache a file and then store it
25
+ When I cache the file 'fixtures/bork.txt'
26
+ Then there should be a file called 'bork.txt' somewhere in a subdirectory of 'public/uploads/tmp'
27
+ And the file called 'bork.txt' in a subdirectory of 'public/uploads/tmp' should be identical to the file at 'fixtures/bork.txt'
28
+ And there should not be a file at 'public/uploads/txt.krob'
29
+ When I store the file
30
+ Then there should be a file at 'public/uploads/txt.krob'
31
+ And the file at 'public/uploads/txt.krob' should be identical to the file at 'fixtures/bork.txt'
32
+
33
+ Scenario: retrieving a file from cache then storing
34
+ Given the file 'fixtures/bork.txt' is cached file at 'public/uploads/tmp/20090212-2343-8336-0348/bork.txt'
35
+ When I retrieve the cache name '20090212-2343-8336-0348/bork.txt' from the cache
36
+ And I store the file
37
+ Then there should be a file at 'public/uploads/txt.krob'
38
+ And the file at 'public/uploads/txt.krob' should be identical to the file at 'fixtures/bork.txt'
@@ -0,0 +1,38 @@
1
+ Feature: uploader with file storage and overridden store dir
2
+ In order to be awesome
3
+ As a developer using CarrierWave
4
+ I want to upload files to the filesystem
5
+
6
+ Background:
7
+ Given an uploader class that uses the 'file' storage
8
+ And that the uploader has the store_dir overridden to 'public/monkey/llama'
9
+ And an instance of that class
10
+
11
+ Scenario: store a file
12
+ When I store the file 'fixtures/bork.txt'
13
+ Then there should be a file at 'public/monkey/llama/bork.txt'
14
+ And the file at 'public/monkey/llama/bork.txt' should be identical to the file at 'fixtures/bork.txt'
15
+
16
+ Scenario: store two files in succession
17
+ When I store the file 'fixtures/bork.txt'
18
+ Then there should be a file at 'public/monkey/llama/bork.txt'
19
+ And the file at 'public/monkey/llama/bork.txt' should be identical to the file at 'fixtures/bork.txt'
20
+ When I store the file 'fixtures/monkey.txt'
21
+ Then there should be a file at 'public/monkey/llama/monkey.txt'
22
+ And the file at 'public/monkey/llama/monkey.txt' should be identical to the file at 'fixtures/monkey.txt'
23
+
24
+ Scenario: cache a file and then store it
25
+ When I cache the file 'fixtures/bork.txt'
26
+ Then there should be a file called 'bork.txt' somewhere in a subdirectory of 'public/uploads/tmp'
27
+ And the file called 'bork.txt' in a subdirectory of 'public/uploads/tmp' should be identical to the file at 'fixtures/bork.txt'
28
+ And there should not be a file at 'public/monkey/llama/bork.txt'
29
+ When I store the file
30
+ Then there should be a file at 'public/monkey/llama/bork.txt'
31
+ And the file at 'public/monkey/llama/bork.txt' should be identical to the file at 'fixtures/bork.txt'
32
+
33
+ Scenario: retrieving a file from cache then storing
34
+ Given the file 'fixtures/bork.txt' is cached file at 'public/uploads/tmp/20090212-2343-8336-0348/bork.txt'
35
+ When I retrieve the cache name '20090212-2343-8336-0348/bork.txt' from the cache
36
+ And I store the file
37
+ Then there should be a file at 'public/monkey/llama/bork.txt'
38
+ And the file at 'public/monkey/llama/bork.txt' should be identical to the file at 'fixtures/bork.txt'
@@ -0,0 +1,43 @@
1
+ Feature: uploader with file storage and a processor that reverses the file
2
+ In order to be awesome
3
+ As a developer using CarrierWave
4
+ I want to upload files to the filesystem
5
+
6
+ Background:
7
+ Given an uploader class that uses the 'file' storage
8
+ And an instance of that class
9
+ And the class has a method called 'reverse' that reverses the contents of a file
10
+ And the class will process 'reverse'
11
+
12
+ Scenario: store a file
13
+ When I store the file 'fixtures/bork.txt'
14
+ Then there should be a file at 'public/uploads/bork.txt'
15
+ And the file at 'public/uploads/bork.txt' should not be identical to the file at 'fixtures/bork.txt'
16
+ And the file at 'public/uploads/bork.txt' should be the reverse of the file at 'fixtures/bork.txt'
17
+
18
+ Scenario: store two files in succession
19
+ When I store the file 'fixtures/bork.txt'
20
+ Then there should be a file at 'public/uploads/bork.txt'
21
+ And the file at 'public/uploads/bork.txt' should not be identical to the file at 'fixtures/bork.txt'
22
+ And the file at 'public/uploads/bork.txt' should be the reverse of the file at 'fixtures/bork.txt'
23
+ When I store the file 'fixtures/monkey.txt'
24
+ Then there should be a file at 'public/uploads/monkey.txt'
25
+ And the file at 'public/uploads/monkey.txt' should not be identical to the file at 'fixtures/monkey.txt'
26
+ And the file at 'public/uploads/monkey.txt' should be the reverse of the file at 'fixtures/monkey.txt'
27
+
28
+ Scenario: cache a file and then store it
29
+ When I cache the file 'fixtures/bork.txt'
30
+ Then there should be a file called 'bork.txt' somewhere in a subdirectory of 'public/uploads/tmp'
31
+ And the file called 'bork.txt' in a subdirectory of 'public/uploads/tmp' should not be identical to the file at 'fixtures/bork.txt'
32
+ And there should not be a file at 'public/uploads/bork.txt'
33
+ When I store the file
34
+ Then there should be a file at 'public/uploads/bork.txt'
35
+ And the file at 'public/uploads/bork.txt' should not be identical to the file at 'fixtures/bork.txt'
36
+ And the file at 'public/uploads/bork.txt' should be the reverse of the file at 'fixtures/bork.txt'
37
+
38
+ Scenario: retrieving a file from cache then storing
39
+ Given the file 'fixtures/bork.txt' is cached file at 'public/uploads/tmp/20090212-2343-8336-0348/bork.txt'
40
+ When I retrieve the cache name '20090212-2343-8336-0348/bork.txt' from the cache
41
+ And I store the file
42
+ Then there should be a file at 'public/uploads/bork.txt'
43
+ And the file at 'public/uploads/bork.txt' should be identical to the file at 'fixtures/bork.txt'
@@ -0,0 +1 @@
1
+ this is a file
@@ -0,0 +1 @@
1
+ this is another file
@@ -0,0 +1,32 @@
1
+ Feature: uploader with file storage
2
+ In order to be awesome
3
+ As a developer using CarrierWave
4
+ I want to upload files to the filesystem
5
+
6
+ Background:
7
+ Given an uploader class that uses the 'grid_fs' storage
8
+ And an instance of that class
9
+
10
+ Scenario: store a file
11
+ When I store the file 'fixtures/bork.txt'
12
+ Then the contents of the file should be 'this is a file'
13
+
14
+ Scenario: store two files in succession
15
+ When I store the file 'fixtures/bork.txt'
16
+ Then the contents of the file should be 'this is a file'
17
+ When I store the file 'fixtures/monkey.txt'
18
+ Then the contents of the file should be 'this is another file'
19
+
20
+ Scenario: cache a file and then store it
21
+ When I cache the file 'fixtures/bork.txt'
22
+ Then there should be a file called 'bork.txt' somewhere in a subdirectory of 'public/uploads/tmp'
23
+ And the file called 'bork.txt' in a subdirectory of 'public/uploads/tmp' should be identical to the file at 'fixtures/bork.txt'
24
+ And there should not be a file at 'public/uploads/bork.txt'
25
+ When I store the file
26
+ Then the contents of the file should be 'this is a file'
27
+
28
+ Scenario: retrieving a file from cache then storing
29
+ Given the file 'fixtures/bork.txt' is cached file at 'public/uploads/tmp/20090212-2343-8336-0348/bork.txt'
30
+ When I retrieve the cache name '20090212-2343-8336-0348/bork.txt' from the cache
31
+ And I store the file
32
+ Then the contents of the file should be 'this is a file'
@@ -0,0 +1,46 @@
1
+ Feature: Mount an Uploader on ActiveRecord class
2
+ In order to easily attach files to a form
3
+ As a web developer using CarrierWave
4
+ I want to mount an uploader on an ActiveRecord class
5
+
6
+ Background:
7
+ Given an uploader class that uses the 'file' storage
8
+ And an activerecord class that uses the 'users' table
9
+ And the uploader class is mounted on the 'avatar' column
10
+ And an instance of the activerecord class
11
+
12
+ Scenario: assign a file
13
+ When I assign the file 'fixtures/bork.txt' to the 'avatar' column
14
+ Then there should be a file called 'bork.txt' somewhere in a subdirectory of 'public/uploads/tmp'
15
+ And the file called 'bork.txt' in a subdirectory of 'public/uploads/tmp' should be identical to the file at 'fixtures/bork.txt'
16
+
17
+ Scenario: assign a file and save the record
18
+ When I assign the file 'fixtures/bork.txt' to the 'avatar' column
19
+ And I save the active record
20
+ Then there should be a file at 'public/uploads/bork.txt'
21
+ And the file at 'public/uploads/bork.txt' should be identical to the file at 'fixtures/bork.txt'
22
+ And the url for the column 'avatar' should be '/uploads/bork.txt'
23
+
24
+ Scenario: assign a file and retrieve it from cache
25
+ When I assign the file 'fixtures/bork.txt' to the 'avatar' column
26
+ And I retrieve the file later from the cache name for the column 'avatar'
27
+ And I save the active record
28
+ Then there should be a file at 'public/uploads/bork.txt'
29
+ And the file at 'public/uploads/bork.txt' should be identical to the file at 'fixtures/bork.txt'
30
+ And the url for the column 'avatar' should be '/uploads/bork.txt'
31
+
32
+ Scenario: store a file and retrieve it later
33
+ When I assign the file 'fixtures/bork.txt' to the 'avatar' column
34
+ And I retrieve the file later from the cache name for the column 'avatar'
35
+ And I save the active record
36
+ Then there should be a file at 'public/uploads/bork.txt'
37
+ When I reload the active record
38
+ Then the url for the column 'avatar' should be '/uploads/bork.txt'
39
+
40
+ Scenario: store a file and delete the record
41
+ When I assign the file 'fixtures/bork.txt' to the 'avatar' column
42
+ And I retrieve the file later from the cache name for the column 'avatar'
43
+ And I save the active record
44
+ Then there should be a file at 'public/uploads/bork.txt'
45
+ When I delete the active record
46
+ Then there should not be a file at 'public/uploads/bork.txt'
@@ -0,0 +1,46 @@
1
+ Feature: Mount an Uploader on ActiveRecord class
2
+ In order to easily attach files to a form
3
+ As a web developer using CarrierWave
4
+ I want to mount an uploader on an ActiveRecord class
5
+
6
+ Background:
7
+ Given an uploader class that uses the 'file' storage
8
+ And a datamapper class that has a 'avatar' column
9
+ And the uploader class is mounted on the 'avatar' column
10
+ And an instance of the datamapper class
11
+
12
+ Scenario: assign a file
13
+ When I assign the file 'fixtures/bork.txt' to the 'avatar' column
14
+ Then there should be a file called 'bork.txt' somewhere in a subdirectory of 'public/uploads/tmp'
15
+ And the file called 'bork.txt' in a subdirectory of 'public/uploads/tmp' should be identical to the file at 'fixtures/bork.txt'
16
+
17
+ Scenario: assign a file and save the record
18
+ When I assign the file 'fixtures/bork.txt' to the 'avatar' column
19
+ And I save the datamapper record
20
+ Then there should be a file at 'public/uploads/bork.txt'
21
+ And the file at 'public/uploads/bork.txt' should be identical to the file at 'fixtures/bork.txt'
22
+ And the url for the column 'avatar' should be '/uploads/bork.txt'
23
+
24
+ Scenario: assign a file and retrieve it from cache
25
+ When I assign the file 'fixtures/bork.txt' to the 'avatar' column
26
+ And I retrieve the file later from the cache name for the column 'avatar'
27
+ And I save the datamapper record
28
+ Then there should be a file at 'public/uploads/bork.txt'
29
+ And the file at 'public/uploads/bork.txt' should be identical to the file at 'fixtures/bork.txt'
30
+ And the url for the column 'avatar' should be '/uploads/bork.txt'
31
+
32
+ # Scenario: store a file and retrieve it later
33
+ # When I assign the file 'fixtures/bork.txt' to the 'avatar' column
34
+ # And I retrieve the file later from the cache name for the column 'avatar'
35
+ # And I save the datamapper record
36
+ # Then there should be a file at 'public/uploads/bork.txt'
37
+ # When I reload the datamapper record
38
+ # Then the url for the column 'avatar' should be '/uploads/bork.txt'
39
+ #
40
+ # Scenario: store a file and delete the record
41
+ # When I assign the file 'fixtures/bork.txt' to the 'avatar' column
42
+ # And I retrieve the file later from the cache name for the column 'avatar'
43
+ # And I save the datamapper record
44
+ # Then there should be a file at 'public/uploads/bork.txt'
45
+ # When I delete the datamapper record
46
+ # Then there should not be a file at 'public/uploads/bork.txt'
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+
3
+ Given /^an activerecord class that uses the '([^\']*)' table$/ do |name|
4
+ @mountee_klass = Class.new(ActiveRecord::Base)
5
+ @mountee_klass.table_name = name
6
+ end
7
+
8
+ Given /^an instance of the activerecord class$/ do
9
+ @instance = @mountee_klass.new
10
+ end
11
+
12
+ When /^I save the active record$/ do
13
+ @instance.save!
14
+ end
15
+
16
+ When /^I reload the active record$/ do
17
+ @instance = @instance.class.find(@instance.id)
18
+ end
19
+
20
+ When /^I delete the active record$/ do
21
+ @instance.destroy
22
+ end
@@ -0,0 +1,14 @@
1
+ # encoding: utf-8
2
+
3
+ Given /^the file '(.*?)' is cached file at '(.*?)'$/ do |file, cached|
4
+ FileUtils.mkdir_p(File.dirname(file_path(cached)))
5
+ FileUtils.cp(file_path(file), file_path(cached))
6
+ end
7
+
8
+ When /^I cache the file '(.*?)'$/ do |file|
9
+ @uploader.cache!(File.open(file_path(file)))
10
+ end
11
+
12
+ When /^I retrieve the cache name '(.*?)' from the cache$/ do |name|
13
+ @uploader.retrieve_from_cache!(name)
14
+ end
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+
3
+ Given /^a datamapper class that has a '([^\']*)' column$/ do |column|
4
+ @mountee_klass = Class.new do
5
+ include DataMapper::Resource
6
+
7
+ storage_names[:default] = 'users'
8
+
9
+ property :id, Integer, :key => true
10
+ property column.to_sym, String
11
+ end
12
+ @mountee_klass.auto_migrate!
13
+ end
14
+
15
+ Given /^an instance of the datamapper class$/ do
16
+ @instance = @mountee_klass.new
17
+ end
18
+
19
+ When /^I save the datamapper record$/ do
20
+ @instance.save
21
+ end
22
+
23
+ When /^I reload the datamapper record$/ do
24
+ @instance = @instance.class.first(:id => @instance.key)
25
+ end
26
+
27
+ When /^I delete the datamapper record$/ do
28
+ @instance.destroy
29
+ end