image_validators 1.0.0
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/.gitignore +17 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +52 -0
- data/Rakefile +5 -0
- data/image_validators.gemspec +30 -0
- data/lib/image_validators/dimensions_validator.rb +58 -0
- data/lib/image_validators/version.rb +3 -0
- data/lib/image_validators.rb +6 -0
- data/spec/dimensions_validator_spec.rb +285 -0
- data/spec/fixtures/images/bad_wolf_619x619.png +0 -0
- data/spec/fixtures/images/bad_wolf_619x620.png +0 -0
- data/spec/fixtures/images/bad_wolf_620x619.png +0 -0
- data/spec/fixtures/images/bad_wolf_620x620.png +0 -0
- data/spec/spec_helper.rb +14 -0
- data/tasks/rspec.rake +3 -0
- metadata +204 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Estevan Vedovelli
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# Image Validators
|
2
|
+
|
3
|
+
[](http://badge.fury.io/rb/image_validators)
|
4
|
+
[](https://travis-ci.org/evedovelli/image_validators)
|
5
|
+
[](https://codeclimate.com/github/evedovelli/image_validators)
|
6
|
+
|
7
|
+
|
8
|
+
A set of validators for image files.
|
9
|
+
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
gem 'image_validators'
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install image_validators
|
24
|
+
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
In your model you have a image file attribute attached by using [Paperclip](https://github.com/thoughtbot/paperclip):
|
29
|
+
|
30
|
+
class User < ActiveRecord::Base
|
31
|
+
has_attached_file :photo, :styles => {:medium => "620x620>", :thumb => "200x200#"}
|
32
|
+
|
33
|
+
### Validation of image dimensions
|
34
|
+
|
35
|
+
To validate the width and height of the image are greater or equal than 620x620, add to your model:
|
36
|
+
|
37
|
+
validates :image, :dimensions => {:greater_than_or_equal_to => {width: 620, height: 620}}
|
38
|
+
|
39
|
+
You can validate your image dimensions whith these operations: `:less_than`, `:less_than_or_equal_to`, `:greater_than`, `:greater_than_or_equal_to`, or `:equal_to`.
|
40
|
+
|
41
|
+
Optionally you can also specify an error message:
|
42
|
+
|
43
|
+
validates :image, :dimensions => {:equal_to => {width: 620}, :message => "Invalid image dimensions"}
|
44
|
+
|
45
|
+
|
46
|
+
## Contributing
|
47
|
+
|
48
|
+
1. Fork it
|
49
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
50
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
51
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
52
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'image_validators/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "image_validators"
|
8
|
+
spec.version = ImageValidators::VERSION
|
9
|
+
spec.authors = ["Estevan Vedovelli"]
|
10
|
+
spec.email = ["evedovelli@gmail.com"]
|
11
|
+
spec.description = %q{A set of validators for image files. Currently it includes validators for image dimensions. See details in http://github.com/evedovelli/image_validators}
|
12
|
+
spec.summary = %q{A set of validators for image files}
|
13
|
+
spec.homepage = "http://github.com/evedovelli/image_validators"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^spec/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "activemodel"
|
22
|
+
spec.add_dependency "i18n"
|
23
|
+
spec.add_dependency "paperclip", "~> 3.4.1"
|
24
|
+
|
25
|
+
spec.add_development_dependency "activerecord", ">= 3.0.0"
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
27
|
+
spec.add_development_dependency "rake"
|
28
|
+
spec.add_development_dependency "rspec"
|
29
|
+
spec.add_development_dependency "mocha"
|
30
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require "image_validators/version"
|
2
|
+
|
3
|
+
class DimensionsValidator < ActiveModel::EachValidator
|
4
|
+
AVAILABLE_CHECKS = [:less_than, :less_than_or_equal_to, :greater_than, :greater_than_or_equal_to, :equal_to]
|
5
|
+
|
6
|
+
def meet_constraints(operation, image_dimension, threshold)
|
7
|
+
return true unless threshold
|
8
|
+
|
9
|
+
case operation
|
10
|
+
when :less_than
|
11
|
+
return image_dimension < threshold
|
12
|
+
when :less_than_or_equal_to
|
13
|
+
return image_dimension <= threshold
|
14
|
+
when :greater_than
|
15
|
+
return image_dimension > threshold
|
16
|
+
when :greater_than_or_equal_to
|
17
|
+
return image_dimension >= threshold
|
18
|
+
when :equal_to
|
19
|
+
return image_dimension == threshold
|
20
|
+
else
|
21
|
+
raise ArgumentError, "You must pass either :less_than, :less_than_or_equal_to, :greater_than, :greater_than_or_equal_to, or :equal_to to the validator"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def validate_each(record, attribute, value)
|
26
|
+
if record.send("#{attribute}?".to_sym) and value.queued_for_write[:original]
|
27
|
+
dimensions = Paperclip::Geometry.from_file(value.queued_for_write[:original].path)
|
28
|
+
|
29
|
+
options.slice(*AVAILABLE_CHECKS).each do |operation, params|
|
30
|
+
width = params[:width]
|
31
|
+
height = params[:height]
|
32
|
+
|
33
|
+
# Width
|
34
|
+
if (not meet_constraints(operation, dimensions.width.to_i, width))
|
35
|
+
record.errors[attribute] <<
|
36
|
+
(options[:message] || I18n.t('image_validators.errors.' + operation.to_s + '.width',
|
37
|
+
default: "width must be " + operation.to_s.humanize.downcase + " %{width}px",
|
38
|
+
width: width))
|
39
|
+
end
|
40
|
+
|
41
|
+
# Height
|
42
|
+
if (not meet_constraints(operation, dimensions.height.to_i, height))
|
43
|
+
record.errors[attribute] <<
|
44
|
+
(options[:message] || I18n.t('image_validators.errors.' + operation.to_s + '.height',
|
45
|
+
default: "height must be " + operation.to_s.humanize.downcase + " %{height}px",
|
46
|
+
height: width))
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def check_validity!
|
54
|
+
unless (AVAILABLE_CHECKS).any? { |argument| options.has_key?(argument) }
|
55
|
+
raise ArgumentError, "You must pass either :less_than, :less_than_or_equal_to, :greater_than, :greater_than_or_equal_to, or :equal_to to the validator"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,285 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class TestModel
|
4
|
+
include ActiveModel::Validations
|
5
|
+
def initialize(attributes = {})
|
6
|
+
@attributes = attributes
|
7
|
+
end
|
8
|
+
def read_attribute_for_validation(key)
|
9
|
+
@attributes[key]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class Photo1 < TestModel
|
14
|
+
validates :picture, :dimensions => {:greater_than_or_equal_to => {width: 620, height: 620}}
|
15
|
+
end
|
16
|
+
class Photo2 < TestModel
|
17
|
+
validates :picture, :dimensions => {:greater_than_or_equal_to => {width: 620}}
|
18
|
+
end
|
19
|
+
class Photo3 < TestModel
|
20
|
+
validates :picture, :dimensions => {:greater_than_or_equal_to => {height: 620}}
|
21
|
+
end
|
22
|
+
class Photo4 < TestModel
|
23
|
+
validates :picture, :dimensions => {:greater_than_or_equal_to => {width: 619, height: 619}}
|
24
|
+
end
|
25
|
+
class Photo5 < TestModel
|
26
|
+
validates :picture, :dimensions => {:less_than => {width: 619, height: 619}}
|
27
|
+
end
|
28
|
+
class Photo6 < TestModel
|
29
|
+
validates :picture, :dimensions => {:less_than => {width: 620}}
|
30
|
+
end
|
31
|
+
class Photo7 < TestModel
|
32
|
+
validates :picture, :dimensions => {:less_than => {height: 620}}
|
33
|
+
end
|
34
|
+
class Photo8 < TestModel
|
35
|
+
validates :picture, :dimensions => {:less_than => {width: 620, height: 620}}
|
36
|
+
end
|
37
|
+
class Photo9 < TestModel
|
38
|
+
validates :picture, :dimensions => {:less_than_or_equal_to => {width: 619, height: 619}}
|
39
|
+
end
|
40
|
+
class Photo10 < TestModel
|
41
|
+
validates :picture, :dimensions => {:less_than_or_equal_to => {width: 619}}
|
42
|
+
end
|
43
|
+
class Photo11 < TestModel
|
44
|
+
validates :picture, :dimensions => {:less_than_or_equal_to => {height: 619}}
|
45
|
+
end
|
46
|
+
class Photo12 < TestModel
|
47
|
+
validates :picture, :dimensions => {:less_than_or_equal_to => {width: 620, height: 620}}
|
48
|
+
end
|
49
|
+
class Photo13 < TestModel
|
50
|
+
validates :picture, :dimensions => {:greater_than => {width: 620, height: 620}}
|
51
|
+
end
|
52
|
+
class Photo14 < TestModel
|
53
|
+
validates :picture, :dimensions => {:greater_than => {width: 619}}
|
54
|
+
end
|
55
|
+
class Photo15 < TestModel
|
56
|
+
validates :picture, :dimensions => {:greater_than => {height: 619}}
|
57
|
+
end
|
58
|
+
class Photo16 < TestModel
|
59
|
+
validates :picture, :dimensions => {:greater_than => {width: 619, height: 619}}
|
60
|
+
end
|
61
|
+
class Photo17 < TestModel
|
62
|
+
validates :picture, :dimensions => {:equal_to => {width: 619, height: 619}}
|
63
|
+
end
|
64
|
+
class Photo18 < TestModel
|
65
|
+
validates :picture, :dimensions => {:equal_to => {width: 619}}
|
66
|
+
end
|
67
|
+
class Photo19 < TestModel
|
68
|
+
validates :picture, :dimensions => {:equal_to => {height: 620}}
|
69
|
+
end
|
70
|
+
class Photo20 < TestModel
|
71
|
+
validates :picture, :dimensions => {:equal_to => {width: 620, height: 620}}
|
72
|
+
end
|
73
|
+
class Photo21 < TestModel
|
74
|
+
validates :picture, :dimensions => {:equal_to => {width: 620, height: 620}, :message => "Invalid image dimensions"}
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
describe DimensionsValidator do
|
79
|
+
def stubs_image_file(width, height)
|
80
|
+
file = mock()
|
81
|
+
path = mock()
|
82
|
+
path.stubs(:path).returns(ROOT + "spec/fixtures/images/bad_wolf_#{width}x#{height}.png")
|
83
|
+
file.stubs(:queued_for_write).returns({:original => path})
|
84
|
+
return file
|
85
|
+
end
|
86
|
+
|
87
|
+
describe 'validation of dimensions' do
|
88
|
+
describe 'with greater_than_or_equal_to' do
|
89
|
+
it 'should fails for images with both width and height less than thresholds' do
|
90
|
+
file = stubs_image_file(619, 619)
|
91
|
+
photo = Photo1.new({:picture => file})
|
92
|
+
photo.stubs(:picture?).returns(true)
|
93
|
+
expect(photo).not_to be_valid
|
94
|
+
end
|
95
|
+
it 'should fails for images with width less than thresholds' do
|
96
|
+
file = stubs_image_file(619, 620)
|
97
|
+
photo = Photo2.new({:picture => file})
|
98
|
+
photo.stubs(:picture?).returns(true)
|
99
|
+
expect(photo).not_to be_valid
|
100
|
+
end
|
101
|
+
it 'should fails for images with height less than thresholds' do
|
102
|
+
file = stubs_image_file(620, 619)
|
103
|
+
photo = Photo3.new({:picture => file})
|
104
|
+
photo.stubs(:picture?).returns(true)
|
105
|
+
expect(photo).not_to be_valid
|
106
|
+
end
|
107
|
+
it 'should not fail for images with both width and height equal to the thresholds' do
|
108
|
+
file = stubs_image_file(620, 620)
|
109
|
+
photo = Photo1.new({:picture => file})
|
110
|
+
photo.stubs(:picture?).returns(true)
|
111
|
+
expect(photo).to be_valid
|
112
|
+
end
|
113
|
+
it 'should not fail for images with both width and height greater than thresholds' do
|
114
|
+
file = stubs_image_file(620, 620)
|
115
|
+
photo = Photo4.new({:picture => file})
|
116
|
+
photo.stubs(:picture?).returns(true)
|
117
|
+
expect(photo).to be_valid
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe 'with less_than' do
|
122
|
+
it 'should fails for images with both width and height equal to the thresholds' do
|
123
|
+
file = stubs_image_file(619, 619)
|
124
|
+
photo = Photo5.new({:picture => file})
|
125
|
+
photo.stubs(:picture?).returns(true)
|
126
|
+
expect(photo).not_to be_valid
|
127
|
+
end
|
128
|
+
it 'should fails for images with both width and height greater to the thresholds' do
|
129
|
+
file = stubs_image_file(620, 620)
|
130
|
+
photo = Photo5.new({:picture => file})
|
131
|
+
photo.stubs(:picture?).returns(true)
|
132
|
+
expect(photo).not_to be_valid
|
133
|
+
end
|
134
|
+
it 'should fails for images with width equal to the thresholds' do
|
135
|
+
file = stubs_image_file(620, 619)
|
136
|
+
photo = Photo6.new({:picture => file})
|
137
|
+
photo.stubs(:picture?).returns(true)
|
138
|
+
expect(photo).not_to be_valid
|
139
|
+
end
|
140
|
+
it 'should fails for images with height equal to the thresholds' do
|
141
|
+
file = stubs_image_file(619, 620)
|
142
|
+
photo = Photo7.new({:picture => file})
|
143
|
+
photo.stubs(:picture?).returns(true)
|
144
|
+
expect(photo).not_to be_valid
|
145
|
+
end
|
146
|
+
it 'should not fail for images with both width and height less than thresholds' do
|
147
|
+
file = stubs_image_file(619, 619)
|
148
|
+
photo = Photo8.new({:picture => file})
|
149
|
+
photo.stubs(:picture?).returns(true)
|
150
|
+
expect(photo).to be_valid
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
describe 'with less_than_or_equal_to' do
|
155
|
+
it 'should fails for images with both width and height greater than thresholds' do
|
156
|
+
file = stubs_image_file(620, 620)
|
157
|
+
photo = Photo9.new({:picture => file})
|
158
|
+
photo.stubs(:picture?).returns(true)
|
159
|
+
expect(photo).not_to be_valid
|
160
|
+
end
|
161
|
+
it 'should fails for images with width greater than thresholds' do
|
162
|
+
file = stubs_image_file(620, 619)
|
163
|
+
photo = Photo10.new({:picture => file})
|
164
|
+
photo.stubs(:picture?).returns(true)
|
165
|
+
expect(photo).not_to be_valid
|
166
|
+
end
|
167
|
+
it 'should fails for images with height greater than thresholds' do
|
168
|
+
file = stubs_image_file(619, 620)
|
169
|
+
photo = Photo11.new({:picture => file})
|
170
|
+
photo.stubs(:picture?).returns(true)
|
171
|
+
expect(photo).not_to be_valid
|
172
|
+
end
|
173
|
+
it 'should not fail for images with both width and height less than thresholds' do
|
174
|
+
file = stubs_image_file(619, 619)
|
175
|
+
photo = Photo12.new({:picture => file})
|
176
|
+
photo.stubs(:picture?).returns(true)
|
177
|
+
expect(photo).to be_valid
|
178
|
+
end
|
179
|
+
it 'should not fail for images with both width and height equal to the thresholds' do
|
180
|
+
file = stubs_image_file(620, 620)
|
181
|
+
photo = Photo12.new({:picture => file})
|
182
|
+
photo.stubs(:picture?).returns(true)
|
183
|
+
expect(photo).to be_valid
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
describe 'with greater_than' do
|
188
|
+
it 'should fails for images with both width and height equal to the thresholds' do
|
189
|
+
file = stubs_image_file(620, 620)
|
190
|
+
photo = Photo13.new({:picture => file})
|
191
|
+
photo.stubs(:picture?).returns(true)
|
192
|
+
expect(photo).not_to be_valid
|
193
|
+
end
|
194
|
+
it 'should fails for images with both width and height less than thresholds' do
|
195
|
+
file = stubs_image_file(619, 619)
|
196
|
+
photo = Photo13.new({:picture => file})
|
197
|
+
photo.stubs(:picture?).returns(true)
|
198
|
+
expect(photo).not_to be_valid
|
199
|
+
end
|
200
|
+
it 'should fails for images with width equal to the thresholds' do
|
201
|
+
file = stubs_image_file(619, 620)
|
202
|
+
photo = Photo14.new({:picture => file})
|
203
|
+
photo.stubs(:picture?).returns(true)
|
204
|
+
expect(photo).not_to be_valid
|
205
|
+
end
|
206
|
+
it 'should fails for images with height equal to the thresholds' do
|
207
|
+
file = stubs_image_file(620, 619)
|
208
|
+
photo = Photo15.new({:picture => file})
|
209
|
+
photo.stubs(:picture?).returns(true)
|
210
|
+
expect(photo).not_to be_valid
|
211
|
+
end
|
212
|
+
it 'should not fail for images with both width and height greater than thresholds' do
|
213
|
+
file = stubs_image_file(620, 620)
|
214
|
+
photo = Photo16.new({:picture => file})
|
215
|
+
photo.stubs(:picture?).returns(true)
|
216
|
+
expect(photo).to be_valid
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
describe 'with equal_to' do
|
221
|
+
it 'should fails for images with both width and height greater than thresholds' do
|
222
|
+
file = stubs_image_file(620, 620)
|
223
|
+
photo = Photo17.new({:picture => file})
|
224
|
+
photo.stubs(:picture?).returns(true)
|
225
|
+
expect(photo).not_to be_valid
|
226
|
+
end
|
227
|
+
it 'should fails for images with both width and height less than thresholds' do
|
228
|
+
file = stubs_image_file(619, 619)
|
229
|
+
photo = Photo20.new({:picture => file})
|
230
|
+
photo.stubs(:picture?).returns(true)
|
231
|
+
expect(photo).not_to be_valid
|
232
|
+
end
|
233
|
+
it 'should fails for images with width greater than thresholds' do
|
234
|
+
file = stubs_image_file(620, 619)
|
235
|
+
photo = Photo18.new({:picture => file})
|
236
|
+
photo.stubs(:picture?).returns(true)
|
237
|
+
expect(photo).not_to be_valid
|
238
|
+
end
|
239
|
+
it 'should fails for images with height less than thresholds' do
|
240
|
+
file = stubs_image_file(620, 619)
|
241
|
+
photo = Photo19.new({:picture => file})
|
242
|
+
photo.stubs(:picture?).returns(true)
|
243
|
+
expect(photo).not_to be_valid
|
244
|
+
end
|
245
|
+
it 'should not fail for images with both width and height equal to the thresholds' do
|
246
|
+
file = stubs_image_file(620, 620)
|
247
|
+
photo = Photo20.new({:picture => file})
|
248
|
+
photo.stubs(:picture?).returns(true)
|
249
|
+
expect(photo).to be_valid
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
describe 'error messages' do
|
255
|
+
it 'should be default when the message is not defined' do
|
256
|
+
file = stubs_image_file(619, 619)
|
257
|
+
photo = Photo20.new({:picture => file})
|
258
|
+
photo.stubs(:picture?).returns(true)
|
259
|
+
photo.valid?
|
260
|
+
expect(photo.errors.messages).to match({:picture=>["width must be equal to 620px", "height must be equal to 620px"]})
|
261
|
+
end
|
262
|
+
it 'should be the provided message when it is defined' do
|
263
|
+
file = stubs_image_file(619, 619)
|
264
|
+
photo = Photo21.new({:picture => file})
|
265
|
+
photo.stubs(:picture?).returns(true)
|
266
|
+
photo.valid?
|
267
|
+
expect(photo.errors.messages).to match({:picture=>["Invalid image dimensions", "Invalid image dimensions"]})
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
describe 'invalid operations' do
|
272
|
+
it 'should raise ArgumentError' do
|
273
|
+
expect {
|
274
|
+
class PhotoError < TestModel
|
275
|
+
validates :picture, :dimensions => {:different_from => {width: 620, height: 620}}
|
276
|
+
end
|
277
|
+
}.to raise_error
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
end
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'active_model'
|
2
|
+
require 'active_record'
|
3
|
+
require 'image_validators'
|
4
|
+
require 'image_validators/dimensions_validator'
|
5
|
+
require 'paperclip'
|
6
|
+
require 'mocha/api'
|
7
|
+
|
8
|
+
ROOT = Pathname(File.expand_path(File.join(File.dirname(__FILE__), '..')))
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.mock_with :mocha
|
12
|
+
Paperclip.options[:log] = false
|
13
|
+
end
|
14
|
+
|
data/tasks/rspec.rake
ADDED
metadata
ADDED
@@ -0,0 +1,204 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: image_validators
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Estevan Vedovelli
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-03-06 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activemodel
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: i18n
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: paperclip
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 3.4.1
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.4.1
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: activerecord
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 3.0.0
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 3.0.0
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: bundler
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '1.3'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '1.3'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: rake
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: rspec
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: mocha
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
type: :development
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
description: A set of validators for image files. Currently it includes validators
|
143
|
+
for image dimensions. See details in http://github.com/evedovelli/image_validators
|
144
|
+
email:
|
145
|
+
- evedovelli@gmail.com
|
146
|
+
executables: []
|
147
|
+
extensions: []
|
148
|
+
extra_rdoc_files: []
|
149
|
+
files:
|
150
|
+
- .gitignore
|
151
|
+
- .rspec
|
152
|
+
- Gemfile
|
153
|
+
- LICENSE.txt
|
154
|
+
- README.md
|
155
|
+
- Rakefile
|
156
|
+
- image_validators.gemspec
|
157
|
+
- lib/image_validators.rb
|
158
|
+
- lib/image_validators/dimensions_validator.rb
|
159
|
+
- lib/image_validators/version.rb
|
160
|
+
- spec/dimensions_validator_spec.rb
|
161
|
+
- spec/fixtures/images/bad_wolf_619x619.png
|
162
|
+
- spec/fixtures/images/bad_wolf_619x620.png
|
163
|
+
- spec/fixtures/images/bad_wolf_620x619.png
|
164
|
+
- spec/fixtures/images/bad_wolf_620x620.png
|
165
|
+
- spec/spec_helper.rb
|
166
|
+
- tasks/rspec.rake
|
167
|
+
homepage: http://github.com/evedovelli/image_validators
|
168
|
+
licenses:
|
169
|
+
- MIT
|
170
|
+
post_install_message:
|
171
|
+
rdoc_options: []
|
172
|
+
require_paths:
|
173
|
+
- lib
|
174
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
175
|
+
none: false
|
176
|
+
requirements:
|
177
|
+
- - ! '>='
|
178
|
+
- !ruby/object:Gem::Version
|
179
|
+
version: '0'
|
180
|
+
segments:
|
181
|
+
- 0
|
182
|
+
hash: -283621393
|
183
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
184
|
+
none: false
|
185
|
+
requirements:
|
186
|
+
- - ! '>='
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
version: '0'
|
189
|
+
segments:
|
190
|
+
- 0
|
191
|
+
hash: -283621393
|
192
|
+
requirements: []
|
193
|
+
rubyforge_project:
|
194
|
+
rubygems_version: 1.8.24
|
195
|
+
signing_key:
|
196
|
+
specification_version: 3
|
197
|
+
summary: A set of validators for image files
|
198
|
+
test_files:
|
199
|
+
- spec/dimensions_validator_spec.rb
|
200
|
+
- spec/fixtures/images/bad_wolf_619x619.png
|
201
|
+
- spec/fixtures/images/bad_wolf_619x620.png
|
202
|
+
- spec/fixtures/images/bad_wolf_620x619.png
|
203
|
+
- spec/fixtures/images/bad_wolf_620x620.png
|
204
|
+
- spec/spec_helper.rb
|