aspecta 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # aspecta
2
2
 
3
- ``aspect`` is small add-on for the awesome
3
+ ``aspecta`` is small add-on for the awesome
4
4
  [carrierwave](http://github.com/jnicklas/carrierwave) gem. ``aspecta``
5
5
  adds image dimensions validator to your ActiveRecords models.
6
6
 
@@ -17,7 +17,8 @@ Gem::Specification.new do |s|
17
17
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
18
  s.require_paths = ["lib"]
19
19
 
20
- s.add_development_dependency "activemodel"
21
- s.add_development_dependency "carrierwave"
20
+ s.add_development_dependency "activemodel", ">=3.0.0"
21
+ s.add_development_dependency "activerecord", ">=3.0.0"
22
+ s.add_development_dependency "carrierwave", "~>0.5.0"
22
23
  s.add_dependency "fastimage"
23
24
  end
@@ -33,15 +33,19 @@ class DimensionsValidator < ActiveModel::EachValidator
33
33
 
34
34
  dimensions = FastImage.size value.path
35
35
 
36
- DIMENSIONS.each_with_index do |dimension, index|
37
- next if options[dimension].nil?
36
+ if dimensions.nil?
37
+ record.errors.add(attribute, :invalid)
38
+ else
39
+ DIMENSIONS.each_with_index do |dimension, index|
40
+ next if options[dimension].nil?
38
41
 
39
- options[dimension].each do |measure, size|
40
- unless dimensions[index].send(ATTRIBUTES[measure], size)
41
- record.errors.add(attribute,
42
+ options[dimension].each do |measure, size|
43
+ unless dimensions[index].send(ATTRIBUTES[measure], size)
44
+ record.errors.add(attribute,
42
45
  MESSAGES[dimension][measure],
43
46
  :size => size
44
47
  )
48
+ end
45
49
  end
46
50
  end
47
51
  end
@@ -1,3 +1,3 @@
1
1
  module Aspecta
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -9,7 +9,7 @@ class AspectaTest < Test::Unit::TestCase
9
9
  # ===========
10
10
 
11
11
  def fixture(file)
12
- File.open(File.dirname(__FILE__) + "/fixtures/#{file}.png")
12
+ File.open(File.dirname(__FILE__) + "/fixtures/#{file}")
13
13
  end
14
14
 
15
15
  # ===========
@@ -24,7 +24,7 @@ class AspectaTest < Test::Unit::TestCase
24
24
 
25
25
  def test_requires_width_or_height_option
26
26
  user = UserWithInvalidValidation.new
27
- user.avatar = fixture "200x200"
27
+ user.avatar = fixture "200x200.png"
28
28
 
29
29
  exception = assert_raise ArgumentError do
30
30
  user.valid?
@@ -36,7 +36,7 @@ class AspectaTest < Test::Unit::TestCase
36
36
 
37
37
  def test_requires_minimum_or_maximum_for_height_option
38
38
  user = UserWithInvalidValitionHeightOptions.new
39
- user.avatar = fixture "200x200"
39
+ user.avatar = fixture "200x200.png"
40
40
 
41
41
  exception = assert_raise ArgumentError do
42
42
  user.valid?
@@ -48,7 +48,7 @@ class AspectaTest < Test::Unit::TestCase
48
48
 
49
49
  def test_requires_minimum_or_maximum_for_width_option
50
50
  user = UserWithInvalidValitionWidthOptions.new
51
- user.avatar = fixture "200x200"
51
+ user.avatar = fixture "200x200.png"
52
52
 
53
53
  exception = assert_raise ArgumentError do
54
54
  user.valid?
@@ -65,14 +65,14 @@ class AspectaTest < Test::Unit::TestCase
65
65
  def test_valid_minimum_width
66
66
  user = UserMinimumWidth200.new
67
67
 
68
- user.avatar = fixture "200x200"
68
+ user.avatar = fixture "200x200.png"
69
69
  assert user.valid?
70
70
  end
71
71
 
72
72
  def test_invalid_minimum_width
73
73
  user = UserMinimumWidth200.new
74
74
 
75
- user.avatar = fixture "199x199"
75
+ user.avatar = fixture "199x199.png"
76
76
  assert ! user.valid?
77
77
  assert user.errors[:avatar].
78
78
  include?("image is too narrow, minimum is 200 pixels")
@@ -85,14 +85,14 @@ class AspectaTest < Test::Unit::TestCase
85
85
  def test_valid_minimum_height
86
86
  user = UserMinimumHeight200.new
87
87
 
88
- user.avatar = fixture "200x200"
88
+ user.avatar = fixture "200x200.png"
89
89
  assert user.valid?
90
90
  end
91
91
 
92
92
  def test_invalid_minimum_height
93
93
  user = UserMinimumHeight200.new
94
94
 
95
- user.avatar = fixture "199x199"
95
+ user.avatar = fixture "199x199.png"
96
96
  assert ! user.valid?
97
97
  assert user.errors[:avatar].
98
98
  include?("image is too short, minimum is 200 pixels")
@@ -105,14 +105,14 @@ class AspectaTest < Test::Unit::TestCase
105
105
  def test_valid_maximum_width
106
106
  user = UserMaximumWidth200.new
107
107
 
108
- user.avatar = fixture "200x200"
108
+ user.avatar = fixture "200x200.png"
109
109
  assert user.valid?
110
110
  end
111
111
 
112
112
  def test_invalid_maximum_width
113
113
  user = UserMaximumWidth200.new
114
114
 
115
- user.avatar = fixture "201x201"
115
+ user.avatar = fixture "201x201.png"
116
116
  assert ! user.valid?
117
117
  assert user.errors[:avatar].
118
118
  include?("image is too wide, maximum is 200 pixels")
@@ -125,16 +125,28 @@ class AspectaTest < Test::Unit::TestCase
125
125
  def test_valid_maximum_height
126
126
  user = UserMaximumHeight200.new
127
127
 
128
- user.avatar = fixture "200x200"
128
+ user.avatar = fixture "200x200.png"
129
129
  assert user.valid?
130
130
  end
131
131
 
132
132
  def test_invalid_maximum_height
133
133
  user = UserMaximumHeight200.new
134
134
 
135
- user.avatar = fixture "201x201"
135
+ user.avatar = fixture "201x201.png"
136
136
  assert ! user.valid?
137
137
  assert user.errors[:avatar].
138
138
  include?("image is too tall, maximum is 200 pixels")
139
139
  end
140
+
141
+ # =====================
142
+ # = invalid file type =
143
+ # =====================
144
+
145
+ def test_valid_maximum_height
146
+ user = UserMinimumDimensions100.new
147
+
148
+ user.avatar = fixture "200x200.tiff"
149
+ assert !user.valid?
150
+ assert user.errors[:avatar].include?("is invalid")
151
+ end
140
152
  end
@@ -47,4 +47,11 @@ class UserMaximumHeight200 < User
47
47
  validates :avatar, :dimensions => {
48
48
  :height => { :maximum => 200 }
49
49
  }
50
+ end
51
+
52
+ class UserMinimumDimensions100 < User
53
+ validates :avatar, :dimensions => {
54
+ :height => { :minimum => 100 },
55
+ :width => { :maximum => 100 }
56
+ }
50
57
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aspecta
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,33 +9,44 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-23 00:00:00.000000000Z
12
+ date: 2012-02-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
16
- requirement: &2243656820 !ruby/object:Gem::Requirement
16
+ requirement: &70285277553340 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: '0'
21
+ version: 3.0.0
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2243656820
24
+ version_requirements: *70285277553340
25
25
  - !ruby/object:Gem::Dependency
26
- name: carrierwave
27
- requirement: &2243656400 !ruby/object:Gem::Requirement
26
+ name: activerecord
27
+ requirement: &70285277552420 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
31
31
  - !ruby/object:Gem::Version
32
- version: '0'
32
+ version: 3.0.0
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70285277552420
36
+ - !ruby/object:Gem::Dependency
37
+ name: carrierwave
38
+ requirement: &70285277551460 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 0.5.0
33
44
  type: :development
34
45
  prerelease: false
35
- version_requirements: *2243656400
46
+ version_requirements: *70285277551460
36
47
  - !ruby/object:Gem::Dependency
37
48
  name: fastimage
38
- requirement: &2243655980 !ruby/object:Gem::Requirement
49
+ requirement: &70285277550820 !ruby/object:Gem::Requirement
39
50
  none: false
40
51
  requirements:
41
52
  - - ! '>='
@@ -43,7 +54,7 @@ dependencies:
43
54
  version: '0'
44
55
  type: :runtime
45
56
  prerelease: false
46
- version_requirements: *2243655980
57
+ version_requirements: *70285277550820
47
58
  description: image dimensions ActiveRecord validator for carrierwave gem
48
59
  email:
49
60
  - filip@tepper.pl
@@ -58,9 +69,10 @@ files:
58
69
  - aspecta.gemspec
59
70
  - lib/aspecta.rb
60
71
  - lib/aspecta/version.rb
61
- - test/aspect_test.rb
72
+ - test/aspecta_test.rb
62
73
  - test/fixtures/199x199.png
63
74
  - test/fixtures/200x200.png
75
+ - test/fixtures/200x200.tiff
64
76
  - test/fixtures/201x201.png
65
77
  - test/lib/avatar_uploader.rb
66
78
  - test/lib/user.rb
@@ -86,14 +98,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
98
  version: '0'
87
99
  requirements: []
88
100
  rubyforge_project:
89
- rubygems_version: 1.8.6
101
+ rubygems_version: 1.8.10
90
102
  signing_key:
91
103
  specification_version: 3
92
104
  summary: image dimensions ActiveRecord validator for carrierwave gem
93
105
  test_files:
94
- - test/aspect_test.rb
106
+ - test/aspecta_test.rb
95
107
  - test/fixtures/199x199.png
96
108
  - test/fixtures/200x200.png
109
+ - test/fixtures/200x200.tiff
97
110
  - test/fixtures/201x201.png
98
111
  - test/lib/avatar_uploader.rb
99
112
  - test/lib/user.rb