attachs 4.0.0.2 → 4.0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/attachs.rb +2 -0
- data/lib/attachs/attachment.rb +5 -340
- data/lib/attachs/attachment/attributes.rb +118 -0
- data/lib/attachs/attachment/processing.rb +242 -0
- data/lib/attachs/collection.rb +1 -1
- data/lib/attachs/extensions/active_record/validations/attachment_content_type_validator.rb +5 -7
- data/lib/attachs/extensions/active_record/validations/attachment_presence_validator.rb +5 -6
- data/lib/attachs/extensions/active_record/validations/attachment_size_validator.rb +4 -5
- data/lib/attachs/extensions/active_record/validations/attachment_validator.rb +11 -3
- data/lib/attachs/locales/en.yml +1 -1
- data/lib/attachs/locales/es.yml +1 -1
- data/lib/attachs/version.rb +1 -1
- data/lib/generators/attachs/upload/templates/model.rb +4 -3
- data/test/dummy/app/models/upload.rb +5 -4
- data/test/dummy/log/test.log +4699 -0
- data/test/{validator_test.rb → validation_test.rb} +44 -28
- metadata +6 -4
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class ValidationTest < ActiveSupport::TestCase
|
4
4
|
include StorageHelper
|
5
5
|
|
6
6
|
teardown do
|
@@ -14,6 +14,22 @@ class ValidatorTest < ActiveSupport::TestCase
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
+
test 'presence' do
|
18
|
+
Product.class_eval do
|
19
|
+
validates :pictures, attachment_presence: true
|
20
|
+
validates :brief, attachment_presence: true
|
21
|
+
end
|
22
|
+
|
23
|
+
product = Product.new
|
24
|
+
assert_not product.valid?
|
25
|
+
assert product.errors[:pictures].empty?
|
26
|
+
assert product.errors.added?(:brief, :blank)
|
27
|
+
assert product.brief.errors.added?(:value, :blank)
|
28
|
+
|
29
|
+
product = Product.new(pictures: [image], brief: file)
|
30
|
+
assert product.valid?
|
31
|
+
end
|
32
|
+
|
17
33
|
test 'content type with' do
|
18
34
|
Product.class_eval do
|
19
35
|
validates :pictures, attachment_content_type: { with: /\Aimage/ }
|
@@ -23,10 +39,10 @@ class ValidatorTest < ActiveSupport::TestCase
|
|
23
39
|
product = Product.new(pictures: [file, image], brief: image)
|
24
40
|
assert_not product.valid?
|
25
41
|
assert product.errors.added?(:pictures, :invalid)
|
26
|
-
assert product.pictures.first.errors.added?(:
|
42
|
+
assert product.pictures.first.errors.added?(:value, :not_allowed)
|
27
43
|
assert product.pictures.second.valid?
|
28
|
-
assert product.errors.added?(:brief, :
|
29
|
-
assert product.brief.errors.added?(:
|
44
|
+
assert product.errors.added?(:brief, :not_allowed)
|
45
|
+
assert product.brief.errors.added?(:value, :not_allowed)
|
30
46
|
|
31
47
|
product = Product.new(pictures: [image], brief: file)
|
32
48
|
assert product.valid?
|
@@ -41,10 +57,10 @@ class ValidatorTest < ActiveSupport::TestCase
|
|
41
57
|
product = Product.new(pictures: [file, image], brief: image)
|
42
58
|
assert_not product.valid?
|
43
59
|
assert product.errors.added?(:pictures, :invalid)
|
44
|
-
assert product.pictures.first.errors.added?(:
|
60
|
+
assert product.pictures.first.errors.added?(:value, :can_only_be, list: 'image/jpeg')
|
45
61
|
assert product.pictures.second.valid?
|
46
|
-
assert product.errors.added?(:brief, :
|
47
|
-
assert product.brief.errors.added?(:
|
62
|
+
assert product.errors.added?(:brief, :can_only_be, list: 'text/plain')
|
63
|
+
assert product.brief.errors.added?(:value, :can_only_be, list: 'text/plain')
|
48
64
|
|
49
65
|
product = Product.new(pictures: [image], brief: file)
|
50
66
|
assert product.valid?
|
@@ -60,10 +76,10 @@ class ValidatorTest < ActiveSupport::TestCase
|
|
60
76
|
product = Product.new(pictures: [file, image], brief: image)
|
61
77
|
assert_not product.valid?
|
62
78
|
assert product.errors.added?(:pictures, :invalid)
|
63
|
-
assert product.pictures.first.errors.added?(:
|
79
|
+
assert product.pictures.first.errors.added?(:value, :can_only_be, list: 'image/jpeg')
|
64
80
|
assert product.pictures.second.valid?
|
65
|
-
assert product.errors.added?(:brief, :
|
66
|
-
assert product.brief.errors.added?(:
|
81
|
+
assert product.errors.added?(:brief, :can_only_be, list: 'text/plain')
|
82
|
+
assert product.brief.errors.added?(:value, :can_only_be, list: 'text/plain')
|
67
83
|
|
68
84
|
product = Product.new(pictures: [image], brief: file)
|
69
85
|
assert product.valid?
|
@@ -78,18 +94,18 @@ class ValidatorTest < ActiveSupport::TestCase
|
|
78
94
|
product = Product.new(pictures: [big_image, image], brief: big_file)
|
79
95
|
assert_not product.valid?
|
80
96
|
assert product.errors.added?(:pictures, :invalid)
|
81
|
-
assert product.pictures.first.errors.added?(:
|
97
|
+
assert product.pictures.first.errors.added?(:value, :less_than_or_equal_to, count: humanize_size(250.kilobytes))
|
82
98
|
assert product.pictures.second.valid?
|
83
|
-
assert product.errors.added?(:brief, :
|
84
|
-
assert product.brief.errors.added?(:
|
99
|
+
assert product.errors.added?(:brief, :less_than_or_equal_to, count: humanize_size(500.bytes))
|
100
|
+
assert product.brief.errors.added?(:value, :less_than_or_equal_to, count: humanize_size(500.bytes))
|
85
101
|
|
86
102
|
product = Product.new(pictures: [small_image, image], brief: small_file)
|
87
103
|
assert_not product.valid?
|
88
104
|
assert product.errors.added?(:pictures, :invalid)
|
89
|
-
assert product.pictures.first.errors.added?(:
|
105
|
+
assert product.pictures.first.errors.added?(:value, :greater_than_or_equal_to, count: humanize_size(15.kilobytes))
|
90
106
|
assert product.pictures.second.valid?
|
91
|
-
assert product.errors.added?(:brief, :
|
92
|
-
assert product.brief.errors.added?(:
|
107
|
+
assert product.errors.added?(:brief, :greater_than_or_equal_to, count: humanize_size(14.bytes))
|
108
|
+
assert product.brief.errors.added?(:value, :greater_than_or_equal_to, count: humanize_size(14.bytes))
|
93
109
|
|
94
110
|
product = Product.new(pictures: [image], brief: file)
|
95
111
|
assert product.valid?
|
@@ -104,18 +120,18 @@ class ValidatorTest < ActiveSupport::TestCase
|
|
104
120
|
product = Product.new(pictures: [big_image, image], brief: big_file)
|
105
121
|
assert_not product.valid?
|
106
122
|
assert product.errors.added?(:pictures, :invalid)
|
107
|
-
assert product.pictures.first.errors.added?(:
|
123
|
+
assert product.pictures.first.errors.added?(:value, :less_than_or_equal_to, count: humanize_size(250.kilobytes))
|
108
124
|
assert product.pictures.second.valid?
|
109
|
-
assert product.errors.added?(:brief, :
|
110
|
-
assert product.brief.errors.added?(:
|
125
|
+
assert product.errors.added?(:brief, :less_than_or_equal_to, count: humanize_size(500.bytes))
|
126
|
+
assert product.brief.errors.added?(:value, :less_than_or_equal_to, count: humanize_size(500.bytes))
|
111
127
|
|
112
128
|
product = Product.new(pictures: [small_image, image], brief: small_file)
|
113
129
|
assert_not product.valid?
|
114
130
|
assert product.errors.added?(:pictures, :invalid)
|
115
|
-
assert product.pictures.first.errors.added?(:
|
131
|
+
assert product.pictures.first.errors.added?(:value, :greater_than_or_equal_to, count: humanize_size(15.kilobytes))
|
116
132
|
assert product.pictures.second.valid?
|
117
|
-
assert product.errors.added?(:brief, :
|
118
|
-
assert product.brief.errors.added?(:
|
133
|
+
assert product.errors.added?(:brief, :greater_than_or_equal_to, count: humanize_size(14.bytes))
|
134
|
+
assert product.brief.errors.added?(:value, :greater_than_or_equal_to, count: humanize_size(14.bytes))
|
119
135
|
|
120
136
|
product = Product.new(pictures: [image], brief: file)
|
121
137
|
assert product.valid?
|
@@ -130,10 +146,10 @@ class ValidatorTest < ActiveSupport::TestCase
|
|
130
146
|
product = Product.new(pictures: [big_image, image], brief: big_file)
|
131
147
|
assert_not product.valid?
|
132
148
|
assert product.errors.added?(:pictures, :invalid)
|
133
|
-
assert product.pictures.first.errors.added?(:
|
149
|
+
assert product.pictures.first.errors.added?(:value, :less_than, count: humanize_size(250.kilobytes))
|
134
150
|
assert product.pictures.second.valid?
|
135
|
-
assert product.errors.added?(:brief, :
|
136
|
-
assert product.brief.errors.added?(:
|
151
|
+
assert product.errors.added?(:brief, :less_than, count: humanize_size(500.bytes))
|
152
|
+
assert product.brief.errors.added?(:value, :less_than, count: humanize_size(500.bytes))
|
137
153
|
|
138
154
|
product = Product.new(pictures: [image], brief: file)
|
139
155
|
assert product.valid?
|
@@ -148,10 +164,10 @@ class ValidatorTest < ActiveSupport::TestCase
|
|
148
164
|
product = Product.new(pictures: [small_image, image], brief: small_file)
|
149
165
|
assert_not product.valid?
|
150
166
|
assert product.errors.added?(:pictures, :invalid)
|
151
|
-
assert product.pictures.first.errors.added?(:
|
167
|
+
assert product.pictures.first.errors.added?(:value, :greater_than, count: humanize_size(15.kilobytes))
|
152
168
|
assert product.pictures.second.valid?
|
153
|
-
assert product.errors.added?(:brief, :
|
154
|
-
assert product.brief.errors.added?(:
|
169
|
+
assert product.errors.added?(:brief, :greater_than, count: humanize_size(14.bytes))
|
170
|
+
assert product.brief.errors.added?(:value, :greater_than, count: humanize_size(14.bytes))
|
155
171
|
|
156
172
|
product = Product.new(pictures: [image], brief: file)
|
157
173
|
assert product.valid?
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: attachs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.0.
|
4
|
+
version: 4.0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mmontossi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -84,6 +84,8 @@ files:
|
|
84
84
|
- Rakefile
|
85
85
|
- lib/attachs.rb
|
86
86
|
- lib/attachs/attachment.rb
|
87
|
+
- lib/attachs/attachment/attributes.rb
|
88
|
+
- lib/attachs/attachment/processing.rb
|
87
89
|
- lib/attachs/builder.rb
|
88
90
|
- lib/attachs/collection.rb
|
89
91
|
- lib/attachs/concern.rb
|
@@ -171,7 +173,7 @@ files:
|
|
171
173
|
- test/task_test.rb
|
172
174
|
- test/test_helper.rb
|
173
175
|
- test/upload_test.rb
|
174
|
-
- test/
|
176
|
+
- test/validation_test.rb
|
175
177
|
homepage: https://github.com/mmontossi/attachs
|
176
178
|
licenses:
|
177
179
|
- MIT
|
@@ -257,4 +259,4 @@ test_files:
|
|
257
259
|
- test/task_test.rb
|
258
260
|
- test/test_helper.rb
|
259
261
|
- test/upload_test.rb
|
260
|
-
- test/
|
262
|
+
- test/validation_test.rb
|