rails_uploads 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +4 -4
- data/app/controllers/rails_uploads/presets_controller.rb +8 -3
- data/config/routes.rb +1 -1
- data/lib/rails_uploads/engine.rb +1 -1
- data/lib/rails_uploads/types/file.rb +20 -16
- data/lib/rails_uploads/types/image.rb +2 -6
- data/lib/rails_uploads/validators/attachment_content_type_validator.rb +3 -3
- data/lib/rails_uploads/validators/attachment_presence_validator.rb +4 -4
- data/lib/rails_uploads/validators/attachment_size_validator.rb +2 -2
- data/lib/rails_uploads/validators/base.rb +0 -5
- data/lib/rails_uploads/version.rb +1 -1
- data/test/dummy/app/models/file_upload.rb +1 -1
- data/test/dummy/app/models/image_upload.rb +1 -1
- data/test/dummy/app/models/validation_upload.rb +2 -2
- data/test/dummy/log/test.log +3258 -0
- data/test/dummy/public/uploads/files/default.txt +1 -0
- data/test/dummy/public/uploads/files/file.txt +1 -0
- data/test/dummy/public/uploads/images/original/default.jpg +0 -0
- data/test/dummy/public/uploads/images/original/image.jpg +0 -0
- data/test/file_string_test.rb +6 -5
- data/test/file_upload_test.rb +5 -5
- data/test/{controller_test.rb → generate_test.rb} +3 -3
- data/test/image_presets_test.rb +4 -4
- data/test/image_string_test.rb +10 -10
- data/test/image_upload_test.rb +4 -4
- data/test/rails_uploads_test.rb +1 -1
- data/test/records_test.rb +10 -10
- data/test/validators_test.rb +4 -4
- metadata +12 -4
@@ -0,0 +1 @@
|
|
1
|
+
1234567890
|
@@ -0,0 +1 @@
|
|
1
|
+
1234567890
|
Binary file
|
Binary file
|
data/test/file_string_test.rb
CHANGED
@@ -4,7 +4,7 @@ class FileStringTest < ActiveSupport::TestCase
|
|
4
4
|
|
5
5
|
setup :create_file
|
6
6
|
|
7
|
-
test
|
7
|
+
test "methods should work properly" do
|
8
8
|
|
9
9
|
# Basic tests
|
10
10
|
|
@@ -12,13 +12,13 @@ class FileStringTest < ActiveSupport::TestCase
|
|
12
12
|
assert_equal 11, @file.size
|
13
13
|
assert_equal '.txt', @file.extname
|
14
14
|
assert_equal ::File.join('', 'uploads', 'files', @file.filename), @file.path
|
15
|
-
assert_equal Rails.root.join('
|
15
|
+
assert_equal Rails.root.join('tmp', 'uploads', 'files', @file.filename).to_s, @file.realpath
|
16
16
|
|
17
17
|
# Delete tests
|
18
18
|
|
19
|
-
uploads_path = Rails.root.join('
|
19
|
+
uploads_path = Rails.root.join('tmp', 'uploads', 'files', @file.filename).to_s
|
20
20
|
@file.delete
|
21
|
-
assert
|
21
|
+
assert !::File.exists?(uploads_path)
|
22
22
|
assert !@file.exists?
|
23
23
|
|
24
24
|
end
|
@@ -26,8 +26,9 @@ class FileStringTest < ActiveSupport::TestCase
|
|
26
26
|
protected
|
27
27
|
|
28
28
|
def create_file
|
29
|
+
FileUtils.mkdir_p Rails.root.join('tmp', 'uploads', 'files')
|
29
30
|
filename = 'file.txt'
|
30
|
-
FileUtils.cp ::File.join(ActiveSupport::TestCase.fixture_path, filename), Rails.root.join('
|
31
|
+
FileUtils.cp ::File.join(ActiveSupport::TestCase.fixture_path, filename), Rails.root.join('tmp', 'uploads', 'files', filename)
|
31
32
|
@file = RailsUploads::Types::File.new(filename)
|
32
33
|
end
|
33
34
|
|
data/test/file_upload_test.rb
CHANGED
@@ -5,14 +5,14 @@ class FileUploadTest < ActiveSupport::TestCase
|
|
5
5
|
|
6
6
|
setup :create_file
|
7
7
|
|
8
|
-
test
|
8
|
+
test "methods should work properly" do
|
9
9
|
|
10
10
|
# Basic tests
|
11
11
|
|
12
12
|
assert @file.exists?
|
13
13
|
assert_equal 58841, @file.size
|
14
14
|
assert_equal '.jpg', @file.extname
|
15
|
-
assert_equal File.join('', 'uploads', 'files', @file.filename), @file.path
|
15
|
+
assert_equal ::File.join('', 'uploads', 'files', @file.filename), @file.path
|
16
16
|
|
17
17
|
# Delete test
|
18
18
|
|
@@ -22,12 +22,12 @@ class FileUploadTest < ActiveSupport::TestCase
|
|
22
22
|
# Store and delete tests
|
23
23
|
|
24
24
|
@file.store
|
25
|
-
uploads_path = Rails.root.join('
|
26
|
-
assert File.exists?(uploads_path)
|
25
|
+
uploads_path = Rails.root.join('tmp', 'uploads', 'files', @file.filename).to_s
|
26
|
+
assert ::File.exists?(uploads_path)
|
27
27
|
assert_equal uploads_path, @file.realpath
|
28
28
|
|
29
29
|
@file.delete
|
30
|
-
assert
|
30
|
+
assert !::File.exists?(uploads_path)
|
31
31
|
assert !@file.exists?
|
32
32
|
|
33
33
|
end
|
@@ -1,18 +1,18 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class GenerateTest < ActionDispatch::IntegrationTest
|
4
4
|
include ActionDispatch::TestProcess
|
5
5
|
|
6
6
|
setup :create_image
|
7
7
|
|
8
|
-
test
|
8
|
+
test "should generate preset" do
|
9
9
|
::File.delete @image.realpath(:small)
|
10
10
|
path = ::File.join('', 'uploads', 'images', 'small', @image.filename)
|
11
11
|
|
12
12
|
get path
|
13
13
|
assert_redirected_to path
|
14
14
|
|
15
|
-
realpath = Rails.root.join('
|
15
|
+
realpath = Rails.root.join('tmp', 'uploads', 'images', 'small', @image.filename)
|
16
16
|
assert ::File.exists?(realpath)
|
17
17
|
@image.delete
|
18
18
|
end
|
data/test/image_presets_test.rb
CHANGED
@@ -5,7 +5,7 @@ class ImagePresetsTest < ActiveSupport::TestCase
|
|
5
5
|
|
6
6
|
setup :create_image
|
7
7
|
|
8
|
-
test
|
8
|
+
test "should save/destory main image and thumbs" do
|
9
9
|
|
10
10
|
#assert_equal 58841, @record.image.size
|
11
11
|
#assert_equal 89314, @record.image.size(:big)
|
@@ -17,9 +17,9 @@ class ImagePresetsTest < ActiveSupport::TestCase
|
|
17
17
|
|
18
18
|
@record.destroy
|
19
19
|
|
20
|
-
assert
|
21
|
-
assert
|
22
|
-
assert
|
20
|
+
assert !::File.exists?(original)
|
21
|
+
assert !::File.exists?(big)
|
22
|
+
assert !::File.exists?(small)
|
23
23
|
|
24
24
|
end
|
25
25
|
|
data/test/image_string_test.rb
CHANGED
@@ -4,7 +4,7 @@ class ImageStringTest < ActiveSupport::TestCase
|
|
4
4
|
|
5
5
|
setup :create_image
|
6
6
|
|
7
|
-
test
|
7
|
+
test "should destory main image and thumbs" do
|
8
8
|
|
9
9
|
original = @image.realpath
|
10
10
|
big = @image.realpath(:big)
|
@@ -12,23 +12,23 @@ class ImageStringTest < ActiveSupport::TestCase
|
|
12
12
|
|
13
13
|
@image.delete
|
14
14
|
|
15
|
-
assert
|
16
|
-
assert
|
17
|
-
assert
|
15
|
+
assert !::File.exists?(original)
|
16
|
+
assert !::File.exists?(big)
|
17
|
+
assert !::File.exists?(small)
|
18
18
|
|
19
19
|
end
|
20
20
|
|
21
21
|
protected
|
22
22
|
|
23
23
|
def create_image
|
24
|
-
FileUtils.mkdir_p Rails.root.join('
|
25
|
-
FileUtils.mkdir_p Rails.root.join('
|
26
|
-
FileUtils.mkdir_p Rails.root.join('
|
24
|
+
FileUtils.mkdir_p Rails.root.join('tmp', 'uploads', 'images', 'original')
|
25
|
+
FileUtils.mkdir_p Rails.root.join('tmp', 'uploads', 'images', 'big')
|
26
|
+
FileUtils.mkdir_p Rails.root.join('tmp', 'uploads', 'images', 'small')
|
27
27
|
filename = 'image.jpg'
|
28
28
|
fixture = ::File.join(ActiveSupport::TestCase.fixture_path, filename)
|
29
|
-
FileUtils.cp fixture, Rails.root.join('
|
30
|
-
FileUtils.cp fixture, Rails.root.join('
|
31
|
-
FileUtils.cp fixture, Rails.root.join('
|
29
|
+
FileUtils.cp fixture, Rails.root.join('tmp', 'uploads', 'images', 'original', filename)
|
30
|
+
FileUtils.cp fixture, Rails.root.join('tmp', 'uploads', 'images', 'big', filename)
|
31
|
+
FileUtils.cp fixture, Rails.root.join('tmp', 'uploads', 'images', 'small', filename)
|
32
32
|
@options = { :presets => [:small, :big] }
|
33
33
|
@image = RailsUploads::Types::Image.new(filename, @options)
|
34
34
|
end
|
data/test/image_upload_test.rb
CHANGED
@@ -5,7 +5,7 @@ class ImageUploadTest < ActiveSupport::TestCase
|
|
5
5
|
|
6
6
|
setup :create_image
|
7
7
|
|
8
|
-
test
|
8
|
+
test "should save/destory main image and thumbs" do
|
9
9
|
|
10
10
|
#assert_equal 58841, @image.size
|
11
11
|
#assert_equal 89314, @image.size(:big)
|
@@ -17,9 +17,9 @@ class ImageUploadTest < ActiveSupport::TestCase
|
|
17
17
|
|
18
18
|
@image.delete
|
19
19
|
|
20
|
-
assert
|
21
|
-
assert
|
22
|
-
assert
|
20
|
+
assert !::File.exists?(original)
|
21
|
+
assert !::File.exists?(big)
|
22
|
+
assert !::File.exists?(small)
|
23
23
|
|
24
24
|
end
|
25
25
|
|
data/test/rails_uploads_test.rb
CHANGED
data/test/records_test.rb
CHANGED
@@ -2,7 +2,7 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class RecordsTest < ActiveSupport::TestCase
|
4
4
|
|
5
|
-
test
|
5
|
+
test "should save/update/destroy from the database and save/destroy the file" do
|
6
6
|
|
7
7
|
# Save
|
8
8
|
|
@@ -13,7 +13,7 @@ class RecordsTest < ActiveSupport::TestCase
|
|
13
13
|
assert_equal image_filename, FileUpload.first.file.filename
|
14
14
|
|
15
15
|
image_upload_path = record.file.realpath
|
16
|
-
assert File.exists?(image_upload_path)
|
16
|
+
assert ::File.exists?(image_upload_path)
|
17
17
|
|
18
18
|
# Update
|
19
19
|
|
@@ -25,30 +25,30 @@ class RecordsTest < ActiveSupport::TestCase
|
|
25
25
|
assert_equal doc_filename, FileUpload.first.file.filename
|
26
26
|
|
27
27
|
doc_upload_path = record.file.realpath
|
28
|
-
assert
|
29
|
-
assert File.exists?(doc_upload_path)
|
28
|
+
assert !::File.exists?(image_upload_path)
|
29
|
+
assert ::File.exists?(doc_upload_path)
|
30
30
|
|
31
31
|
# Destroy
|
32
32
|
|
33
33
|
record.destroy
|
34
34
|
assert !FileUpload.first
|
35
|
-
assert
|
35
|
+
assert !::File.exists?(doc_upload_path)
|
36
36
|
|
37
37
|
end
|
38
38
|
|
39
|
-
test
|
39
|
+
test "should take default file/image and shouldn't store/delete it" do
|
40
40
|
|
41
41
|
# File
|
42
42
|
|
43
43
|
record = FileUpload.create
|
44
|
-
assert_equal ::File.join('', '
|
44
|
+
assert_equal ::File.join('', 'uploads', 'files', 'default.txt'), record.file.path
|
45
45
|
|
46
46
|
# Image
|
47
47
|
|
48
48
|
record = ImageUpload.create
|
49
|
-
assert_equal ::File.join('', '
|
50
|
-
assert_equal ::File.join('', '
|
51
|
-
assert_equal ::File.join('', '
|
49
|
+
assert_equal ::File.join('', 'uploads', 'images', 'original', 'default.jpg'), record.image.path
|
50
|
+
assert_equal ::File.join('', 'uploads', 'images', 'small', 'default.jpg'), record.image.path(:small)
|
51
|
+
assert_equal ::File.join('', 'uploads', 'images', 'big', 'default.jpg'), record.image.path(:big)
|
52
52
|
|
53
53
|
end
|
54
54
|
|
data/test/validators_test.rb
CHANGED
@@ -5,7 +5,7 @@ class ValidatorsTest < ActiveSupport::TestCase
|
|
5
5
|
|
6
6
|
setup :create_record
|
7
7
|
|
8
|
-
test
|
8
|
+
test "should check if file is present" do
|
9
9
|
|
10
10
|
assert !@record.valid?
|
11
11
|
assert_equal [I18n.t('errors.messages.attachment_presence')], @record.errors[:file_presence]
|
@@ -16,7 +16,7 @@ class ValidatorsTest < ActiveSupport::TestCase
|
|
16
16
|
|
17
17
|
end
|
18
18
|
|
19
|
-
test
|
19
|
+
test "should check the file content type" do
|
20
20
|
|
21
21
|
@record.image_content_type = fixture_file_upload(::File.join('', 'file.txt'), 'text/plain')
|
22
22
|
assert !@record.valid?
|
@@ -28,7 +28,7 @@ class ValidatorsTest < ActiveSupport::TestCase
|
|
28
28
|
|
29
29
|
end
|
30
30
|
|
31
|
-
test
|
31
|
+
test "should check the file size" do
|
32
32
|
|
33
33
|
@record.file_size = fixture_file_upload(::File.join('', 'file_big.txt'), 'text/plain')
|
34
34
|
assert !@record.valid?
|
@@ -56,7 +56,7 @@ class ValidatorsTest < ActiveSupport::TestCase
|
|
56
56
|
|
57
57
|
end
|
58
58
|
|
59
|
-
test
|
59
|
+
test "should check all the validations together" do
|
60
60
|
|
61
61
|
@record.file_all = fixture_file_upload(::File.join('', 'file.txt'), 'text/plain')
|
62
62
|
assert !@record.valid?
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_uploads
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-05-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -69,7 +69,6 @@ files:
|
|
69
69
|
- MIT-LICENSE
|
70
70
|
- Rakefile
|
71
71
|
- README.rdoc
|
72
|
-
- test/controller_test.rb
|
73
72
|
- test/dummy/app/assets/images/image.jpg
|
74
73
|
- test/dummy/app/assets/javascripts/application.js
|
75
74
|
- test/dummy/app/assets/stylesheets/application.css
|
@@ -107,6 +106,10 @@ files:
|
|
107
106
|
- test/dummy/public/422.html
|
108
107
|
- test/dummy/public/500.html
|
109
108
|
- test/dummy/public/favicon.ico
|
109
|
+
- test/dummy/public/uploads/files/default.txt
|
110
|
+
- test/dummy/public/uploads/files/file.txt
|
111
|
+
- test/dummy/public/uploads/images/original/default.jpg
|
112
|
+
- test/dummy/public/uploads/images/original/image.jpg
|
110
113
|
- test/dummy/Rakefile
|
111
114
|
- test/dummy/README.rdoc
|
112
115
|
- test/dummy/script/rails
|
@@ -124,6 +127,7 @@ files:
|
|
124
127
|
- test/fixtures/image.jpg
|
125
128
|
- test/fixtures/image_big.jpg
|
126
129
|
- test/fixtures/image_empty.jpg
|
130
|
+
- test/generate_test.rb
|
127
131
|
- test/image_presets_test.rb
|
128
132
|
- test/image_string_test.rb
|
129
133
|
- test/image_upload_test.rb
|
@@ -156,7 +160,6 @@ signing_key:
|
|
156
160
|
specification_version: 3
|
157
161
|
summary: Toolkit for Rails Uploads.
|
158
162
|
test_files:
|
159
|
-
- test/controller_test.rb
|
160
163
|
- test/dummy/app/assets/images/image.jpg
|
161
164
|
- test/dummy/app/assets/javascripts/application.js
|
162
165
|
- test/dummy/app/assets/stylesheets/application.css
|
@@ -194,6 +197,10 @@ test_files:
|
|
194
197
|
- test/dummy/public/422.html
|
195
198
|
- test/dummy/public/500.html
|
196
199
|
- test/dummy/public/favicon.ico
|
200
|
+
- test/dummy/public/uploads/files/default.txt
|
201
|
+
- test/dummy/public/uploads/files/file.txt
|
202
|
+
- test/dummy/public/uploads/images/original/default.jpg
|
203
|
+
- test/dummy/public/uploads/images/original/image.jpg
|
197
204
|
- test/dummy/Rakefile
|
198
205
|
- test/dummy/README.rdoc
|
199
206
|
- test/dummy/script/rails
|
@@ -211,6 +218,7 @@ test_files:
|
|
211
218
|
- test/fixtures/image.jpg
|
212
219
|
- test/fixtures/image_big.jpg
|
213
220
|
- test/fixtures/image_empty.jpg
|
221
|
+
- test/generate_test.rb
|
214
222
|
- test/image_presets_test.rb
|
215
223
|
- test/image_string_test.rb
|
216
224
|
- test/image_upload_test.rb
|