validates_as_email_address 0.1.0 → 0.1.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,10 @@
1
1
  == master
2
2
 
3
+ == 0.1.1 / 2008-10-25
4
+
5
+ * Fix major performance hit on long domains when in strict mode
6
+ * Fix single-character/digit domains not being allowed in strict mode
7
+
3
8
  == 0.1.0 / 2008-09-07
4
9
 
5
10
  * Allow all options to be passed to format/length validations so that future options can be defined without changing this plugin
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.1.0'
8
+ s.version = '0.1.1'
9
9
  s.platform = Gem::Platform::RUBY
10
10
  s.summary = 'Adds support for validating the format/length of email addresses'
11
11
 
@@ -2,13 +2,14 @@ module PluginAWeek #:nodoc:
2
2
  module ValidatesAsEmailAddress
3
3
  # The standard describing the format of domains
4
4
  module RFC1035
5
- # Matches domain according to the RFC 1035 standard
5
+ # Matches domain according to the RFC 1035 standard, with the exception
6
+ # that domains can start with a letter *or* digit
6
7
  Domain = begin
7
8
  digit = "[\\d]"
8
9
  letter = "[\\x61-\\x7a\\x41-\\x5a]"
9
10
  let_dig = "(?:#{letter}|#{digit})"
10
- ldh_str = "(?:#{let_dig}|[\\x2d])+"
11
- label = "#{let_dig}(?:(?:#{ldh_str})*#{let_dig})"
11
+ let_dig_hyp = "(?:#{let_dig}|[\\x2d])"
12
+ label = "#{let_dig}(?:#{let_dig_hyp}*#{let_dig})?"
12
13
  subdomain = "(?:#{label}\\.)*#{label}"
13
14
  domain = "(?:#{subdomain}|\\x20)"
14
15
 
data/test/factory.rb CHANGED
@@ -13,12 +13,16 @@ module Factory
13
13
  def valid_attributes_for(model, attributes = {})
14
14
  name = model.to_s.underscore
15
15
  send("#{name}_attributes", attributes)
16
+ attributes.stringify_keys!
16
17
  attributes
17
18
  end
18
19
 
19
20
  # Build an unsaved record
20
21
  def new_record(model, *args)
21
- model.new(valid_attributes_for(model, *args))
22
+ attributes = valid_attributes_for(model, *args)
23
+ record = model.new(attributes)
24
+ attributes.each {|attr, value| record.send("#{attr}=", value) if model.accessible_attributes && !model.accessible_attributes.include?(attr) || model.protected_attributes && model.protected_attributes.include?(attr)}
25
+ record
22
26
  end
23
27
 
24
28
  # Build and save/reload a record
data/test/test_helper.rb CHANGED
@@ -8,6 +8,6 @@ ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate")
8
8
 
9
9
  # Mixin the factory helper
10
10
  require File.expand_path("#{File.dirname(__FILE__)}/factory")
11
- class Test::Unit::TestCase #:nodoc:
11
+ Test::Unit::TestCase.class_eval do
12
12
  include Factory
13
13
  end
@@ -9,10 +9,16 @@ class ValidatesAsEmailAddressByDefaultTest < Test::Unit::TestCase
9
9
  user = new_user(:email => 'a@')
10
10
  assert !user.valid?
11
11
  assert_equal 2, Array(user.errors.on(:email)).size
12
+
13
+ user.email = 'a@a'
14
+ assert user.valid?
12
15
  end
13
16
 
14
17
  def test_should_not_allow_email_addresses_longer_than_320_characters
15
- user = new_user(:email => 'a@' + 'a' * 315 + '.com')
18
+ user = new_user(:email => 'a@' + 'a' * 318)
19
+ assert user.valid?
20
+
21
+ user.email += 'a'
16
22
  assert !user.valid?
17
23
  assert_equal 1, Array(user.errors.on(:email)).size
18
24
  end
@@ -45,8 +51,8 @@ class ValidatesAsEmailAddressByDefaultTest < Test::Unit::TestCase
45
51
  def test_should_not_allow_illegal_rfc1035_formats
46
52
  [
47
53
  'test@[127.0.0.1]',
48
- 'test@-domain_not_starting_with_letter.com',
49
- 'test@domain_not_ending_with_alphanum-.com'
54
+ 'test@-domain-not-starting-with-letter.com',
55
+ 'test@domain-not-ending-with-alphanum-.com'
50
56
  ].each do |address|
51
57
  user = new_user(:email => address)
52
58
  assert !user.valid?, "#{address} should be illegal."
@@ -66,34 +72,34 @@ class ValidatesAsEmailAddressTest < Test::Unit::TestCase
66
72
  def test_should_allow_minimum_length
67
73
  User.validates_as_email_address :email, :minimum => 8
68
74
 
69
- user = new_user(:email => 'a@aa.com')
75
+ user = new_user(:email => 'a@' + 'a' * 6)
70
76
  assert user.valid?
71
77
 
72
- user = new_user(:email => 'a@a.com')
78
+ user.email.chop!
73
79
  assert !user.valid?
74
80
  end
75
81
 
76
82
  def test_should_not_check_maximum_length_if_minimum_length_defined
77
83
  User.validates_as_email_address :email, :minimum => 10
78
84
 
79
- user = new_user(:email => 'a@' + 'a' * 315 + '.com')
85
+ user = new_user(:email => 'a@' + 'a' * 319)
80
86
  assert user.valid?
81
87
  end
82
88
 
83
89
  def test_should_allow_maximum_length
84
90
  User.validates_as_email_address :email, :maximum => 8
85
91
 
86
- user = new_user(:email => 'a@aa.com')
92
+ user = new_user(:email => 'a@' + 'a' * 6)
87
93
  assert user.valid?
88
94
 
89
- user = new_user(:email => 'a@aaa.com')
95
+ user.email += 'a'
90
96
  assert !user.valid?
91
97
  end
92
98
 
93
99
  def test_should_not_check_minimum_length_if_maximum_length_defined
94
100
  User.validates_as_email_address :email, :maximum => 8
95
101
 
96
- user = new_user(:email => 'a@a')
102
+ user = new_user(:email => 'a@')
97
103
  assert !user.valid?
98
104
  assert_equal 1, Array(user.errors.on(:email)).size
99
105
  end
@@ -101,52 +107,52 @@ class ValidatesAsEmailAddressTest < Test::Unit::TestCase
101
107
  def test_should_allow_exact_length
102
108
  User.validates_as_email_address :email, :is => 8
103
109
 
104
- user = new_user(:email => 'a@aa.com')
110
+ user = new_user(:email => 'a@' + 'a' * 6)
105
111
  assert user.valid?
106
112
 
107
- user = new_user(:email => 'a@a.com')
113
+ user.email.chop!
108
114
  assert !user.valid?
109
115
 
110
- user = new_user(:email => 'a@aaa.com')
116
+ user.email += 'aa'
111
117
  assert !user.valid?
112
118
  end
113
119
 
114
120
  def test_should_allow_within_range
115
- User.validates_as_email_address :email, :within => 8..10
121
+ User.validates_as_email_address :email, :within => 8..9
116
122
 
117
- user = new_user(:email => 'a@a.com')
123
+ user = new_user(:email => 'a@' + 'a' * 5)
118
124
  assert !user.valid?
119
125
 
120
- user = new_user(:email => 'a@aa.com')
126
+ user.email += 'a'
121
127
  assert user.valid?
122
128
 
123
- user = new_user(:email => 'a@aaaa.com')
129
+ user.email += 'a'
124
130
  assert user.valid?
125
131
 
126
- user = new_user(:email => 'a@aaaaa.com')
132
+ user.email += 'a'
127
133
  assert !user.valid?
128
134
  end
129
135
 
130
136
  def test_should_allow_in_range
131
- User.validates_as_email_address :email, :in => 8..10
137
+ User.validates_as_email_address :email, :in => 8..9
132
138
 
133
- user = new_user(:email => 'a@a.com')
139
+ user = new_user(:email => 'a@' + 'a' * 5)
134
140
  assert !user.valid?
135
141
 
136
- user = new_user(:email => 'a@aa.com')
142
+ user.email += 'a'
137
143
  assert user.valid?
138
144
 
139
- user = new_user(:email => 'a@aaaa.com')
145
+ user.email += 'a'
140
146
  assert user.valid?
141
147
 
142
- user = new_user(:email => 'a@aaaaa.com')
148
+ user.email += 'a'
143
149
  assert !user.valid?
144
150
  end
145
151
 
146
152
  def test_should_allow_too_long_message
147
153
  User.validates_as_email_address :email, :too_long => 'custom'
148
154
 
149
- user = new_user(:email => 'a@' + 'a' * 315 + '.com')
155
+ user = new_user(:email => 'a@' + 'a' * 319)
150
156
  user.valid?
151
157
 
152
158
  assert_equal 'custom', Array(user.errors.on(:email)).last
@@ -171,9 +177,9 @@ class ValidatesAsEmailAddressTest < Test::Unit::TestCase
171
177
  end
172
178
 
173
179
  def test_should_allow_wrong_format_message
174
- User.validates_as_email_address :email, :is => 8, :wrong_format => 'custom'
180
+ User.validates_as_email_address :email, :wrong_format => 'custom'
175
181
 
176
- user = new_user(:email => 'a@a')
182
+ user = new_user(:email => 'a@!')
177
183
  user.valid?
178
184
 
179
185
  assert_equal 'custom', Array(user.errors.on(:email)).first
@@ -224,8 +230,8 @@ class ValidatesAsEmailAddressUnrestrictedTest < Test::Unit::TestCase
224
230
  def test_should_allow_illegal_rfc1035_formats
225
231
  [
226
232
  'test@[127.0.0.1]',
227
- 'test@-domain_not_starting_with_letter.com',
228
- 'test@domain_not_ending_with_alphanum-.com'
233
+ 'test@-domain-not-starting-with-letter.com',
234
+ 'test@domain-not-ending-with-alphanum-.com'
229
235
  ].each do |address|
230
236
  user = new_user(:email => address)
231
237
  assert user.valid?, "#{address} should be legal."
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.1.0
4
+ version: 0.1.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-09-12 00:00:00 -04:00
12
+ date: 2008-10-26 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15