validates_as_email_address 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -1,5 +1,9 @@
1
1
  == master
2
2
 
3
+ == 0.2.1 / 2008-01-11
4
+
5
+ * Ensure correct encoding for regular expressions to be compatible with Ruby 1.9+
6
+
3
7
  == 0.2.0 / 2008-12-14
4
8
 
5
9
  * Remove the PluginAWeek namespace
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ require 'rake/contrib/sshpublisher'
5
5
 
6
6
  spec = Gem::Specification.new do |s|
7
7
  s.name = 'validates_as_email_address'
8
- s.version = '0.2.0'
8
+ s.version = '0.2.1'
9
9
  s.platform = Gem::Platform::RUBY
10
10
  s.summary = 'Adds support for validating the format/length of email addresses'
11
11
 
@@ -14,25 +14,35 @@ module ValidatesAsEmailAddress
14
14
  # limits, i.e. between 3 and 320 characters in length.
15
15
  #
16
16
  # Configuration options for length:
17
- # * +minimum+ - The minimum size of the attribute
18
- # * +maximum+ - The maximum size of the attribute
19
- # * +is+ - The exact size of the attribute
20
- # * +within+ - A range specifying the minimum and maximum size of the attribute
21
- # * +in+ - A synonym(or alias) for :within
22
- # * +too_long+ - The error message if the attribute goes over the maximum (default is: "is too long (maximum is %d characters)")
23
- # * +too_short+ - The error message if the attribute goes under the minimum (default is: "is too short (minimum is %d characters)")
24
- # * +wrong_length+ - The error message if using the :is method and the attribute is the wrong size (default is: "is the wrong length (should be %d characters)")
17
+ # * <tt>:minimum</tt> - The minimum size of the attribute
18
+ # * <tt>:maximum</tt> - The maximum size of the attribute
19
+ # * <tt>:is</tt> - The exact size of the attribute
20
+ # * <tt>:within</tt> - A range specifying the minimum and maximum size of the
21
+ # attribute
22
+ # * <tt>:in</tt> - A synonym (or alias) for <tt>:within</tt>
23
+ # * <tt>:too_long</tt> - The error message if the attribute goes over the
24
+ # maximum (default is: "is too long (maximum is %d characters)")
25
+ # * <tt>:too_short</tt> - The error message if the attribute goes under the
26
+ # minimum (default is: "is too short (minimum is %d characters)")
27
+ # * <tt>:wrong_length</tt> - The error message if using the <tt>:is</tt>
28
+ # method and the attribute is the wrong size (default is:
29
+ # "is the wrong length (should be %d characters)")
25
30
  #
26
31
  # Configuration options for format:
27
- # * +wrong_format+ - A custom error message (default is: "is an invalid email address")
32
+ # * <tt>:wrong_format</tt> - A custom error message (default is:
33
+ # "is an invalid email address")
28
34
  #
29
35
  # Miscellaneous configuration options:
30
- # * +allow_nil+ - Attribute may be nil; skip validation.
31
- # * +on+ - Specifies when this validation is active (default is :save, other options :create, :update)
32
- # * +if+ - Specifies a method, proc or string to call to determine if the validation should
33
- # occur (e.g. :if => :allow_validation, or :if => lambda { |user| user.signup_step > 2 }). The
34
- # method, proc or string should return or evaluate to a true or false value.
35
- # * +strict+ - Specifies if the domain part of the email should be compliant to RFC 1035 (default is true). If set to false domains such as '-online.com', '[127.0.0.1]' become valid.
36
+ # * <tt>:allow_nil</tt> - Attribute may be nil; skip validation.
37
+ # * <tt>:on</tt> - Specifies when this validation is active (default is
38
+ # :save, other options :create, :update)
39
+ # * <tt>:if</tt> - Specifies a method, proc or string to call to determine if
40
+ # the validation should occur (e.g. :if => :allow_validation, or
41
+ # :if => lambda { |user| user.signup_step > 2 }). The method, proc or
42
+ # string should return or evaluate to a true or false value.
43
+ # * <tt>:strict</tt> - Specifies if the domain part of the email should be
44
+ # compliant to RFC 1035 (default is true). If set to false domains such as
45
+ # '-online.com', '[127.0.0.1]' become valid.
36
46
  def validates_as_email_address(*attr_names)
37
47
  configuration = attr_names.last.is_a?(Hash) ? attr_names.pop : {}
38
48
  configuration.reverse_merge!(
@@ -4,8 +4,8 @@ module ValidatesAsEmailAddress
4
4
  # Matches domain according to the RFC 1035 standard, with the exception
5
5
  # that domains can start with a letter *or* digit
6
6
  Domain = begin
7
- digit = "[\\d]"
8
- letter = "[\\x61-\\x7a\\x41-\\x5a]"
7
+ digit = '[\\d]'
8
+ letter = '[\\x61-\\x7a\\x41-\\x5a]'
9
9
  let_dig = "(?:#{letter}|#{digit})"
10
10
  let_dig_hyp = "(?:#{let_dig}|[\\x2d])"
11
11
  label = "#{let_dig}(?:#{let_dig_hyp}*#{let_dig})?"
@@ -20,6 +20,7 @@ module ValidatesAsEmailAddress
20
20
  local_part = RFC822::LocalPart.source
21
21
  domain = Domain.source
22
22
  addr_spec = "(#{local_part})\\x40(#{domain})"
23
+ addr_spec.force_encoding('binary') if addr_spec.respond_to?(:force_encoding)
23
24
 
24
25
  /\A#{addr_spec}\z/
25
26
  end
@@ -14,11 +14,13 @@ module ValidatesAsEmailAddress
14
14
  # Local part
15
15
  word = "(?:#{atom}|#{quoted_string})"
16
16
  local_part = "#{word}(?:\\x2e#{word})*"
17
+ local_part.force_encoding('binary') if local_part.respond_to?(:force_encoding)
17
18
 
18
19
  # Domain
19
20
  domain_ref = atom
20
21
  sub_domain = "(?:#{domain_ref}|#{domain_literal})"
21
22
  domain = "#{sub_domain}(?:\\x2e#{sub_domain})*"
23
+ domain.force_encoding('binary') if domain.respond_to?(:force_encoding)
22
24
 
23
25
  [/#{local_part}/, /#{domain}/]
24
26
  end
@@ -28,6 +30,7 @@ module ValidatesAsEmailAddress
28
30
  local_part = LocalPart.source
29
31
  domain = Domain.source
30
32
  addr_spec = "(#{local_part})\\x40(#{domain})"
33
+ addr_spec.force_encoding('binary') if addr_spec.respond_to?(:force_encoding)
31
34
 
32
35
  /\A#{addr_spec}\z/
33
36
  end
@@ -186,28 +186,28 @@ class ValidatesAsEmailAddressTest < Test::Unit::TestCase
186
186
  end
187
187
 
188
188
  def test_should_validate_if_if_is_true
189
- User.validates_as_email_address :email, :if => lambda {true}
189
+ User.validates_as_email_address :email, :if => lambda {|user| true}
190
190
 
191
191
  user = new_user(:email => 'a')
192
192
  assert !user.valid?
193
193
  end
194
194
 
195
195
  def test_should_not_validate_if_if_is_false
196
- User.validates_as_email_address :email, :if => lambda {false}
196
+ User.validates_as_email_address :email, :if => lambda {|user| false}
197
197
 
198
198
  user = new_user(:email => 'a')
199
199
  assert user.valid?
200
200
  end
201
201
 
202
202
  def test_should_validate_if_unless_is_false
203
- User.validates_as_email_address :email, :unless => lambda {false}
203
+ User.validates_as_email_address :email, :unless => lambda {|user| false}
204
204
 
205
205
  user = new_user(:email => 'a')
206
206
  assert !user.valid?
207
207
  end
208
208
 
209
209
  def test_should_not_validate_if_unless_is_true
210
- User.validates_as_email_address :email, :unless => lambda {true}
210
+ User.validates_as_email_address :email, :unless => lambda {|user| true}
211
211
 
212
212
  user = new_user(:email => 'a')
213
213
  assert user.valid?
@@ -237,4 +237,12 @@ class ValidatesAsEmailAddressUnrestrictedTest < Test::Unit::TestCase
237
237
  assert user.valid?, "#{address} should be legal."
238
238
  end
239
239
  end
240
+
241
+ def teardown
242
+ User.class_eval do
243
+ @validate_callbacks = ActiveSupport::Callbacks::CallbackChain.new
244
+ @validate_on_create_callbacks = ActiveSupport::Callbacks::CallbackChain.new
245
+ @validate_on_update_callbacks = ActiveSupport::Callbacks::CallbackChain.new
246
+ end
247
+ end
240
248
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validates_as_email_address
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Pfeifer
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-14 00:00:00 -05:00
12
+ date: 2009-01-11 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15