validates_as_mail 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2010 Gabriel Sobrinho
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
@@ -0,0 +1,23 @@
1
+ h1. ValidatesAsMail
2
+
3
+ This gem is based on *gbdev* works in "http://github.com/gbdev/validates_as_email":http://github.com/gbdev/validates_as_email
4
+
5
+ h2. Installation
6
+
7
+ You can install as gem:
8
+
9
+ <pre>gem "validates_as_mail"</pre>
10
+
11
+ Or as plugin:
12
+
13
+ <pre>$ rails plugin install git://github.com/sobrinho/validates_as_mail.git</pre>
14
+
15
+ h2. Usage
16
+
17
+ <pre>class Person < ActiveRecord::Base
18
+ validates :email, :mail => true
19
+ end</pre>
20
+
21
+ h2. License
22
+
23
+ Copyright (c) 2010 Gabriel Sobrinho, released under the MIT license
@@ -0,0 +1,24 @@
1
+ require 'rake/testtask'
2
+
3
+ desc 'Default: run unit tests.'
4
+ task :default => :test
5
+
6
+ desc 'Test the validates_as_mail plugin.'
7
+ Rake::TestTask.new(:test) do |t|
8
+ t.libs << 'test'
9
+ t.pattern = 'test/**/*_test.rb'
10
+ end
11
+
12
+ begin
13
+ require 'jeweler'
14
+ Jeweler::Tasks.new do |gemspec|
15
+ gemspec.name = "validates_as_mail"
16
+ gemspec.summary = "Mail validation for ActiveModel"
17
+ gemspec.email = "gabriel.sobrinho@gmail.com"
18
+ gemspec.homepage = "http://github.com/sobrinho/validates_as_mail"
19
+ gemspec.authors = ["Gabriel Sobrinho"]
20
+ end
21
+ Jeweler::GemcutterTasks.new
22
+ rescue LoadError
23
+ puts "Jeweler not available. Install it with: gem install jeweler"
24
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'validates_as_mail'
@@ -0,0 +1 @@
1
+ require 'validates_as_mail/mail_validator'
@@ -0,0 +1,7 @@
1
+ class MailValidator < ActiveModel::EachValidator
2
+ def validate_each(record, attribute, value)
3
+ if value !~ /^([\w\.!#\$%\-+.]+@[A-Za-z0-9\-]+(\.[A-Za-z0-9\-]+)+)$/
4
+ record.errors.add(attribute, options[:message])
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,17 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'active_support'
4
+ require 'active_record'
5
+ require 'validates_as_mail/mail_validator'
6
+
7
+ # create a temporary database
8
+ ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => ':memory:'
9
+
10
+ silence_stream(STDOUT) do
11
+ ActiveRecord::Schema.define do
12
+ create_table :people do |t|
13
+ t.string :name
14
+ t.string :email
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,25 @@
1
+ require 'test_helper'
2
+
3
+ class ValidatesAsMailTest < ActiveSupport::TestCase
4
+ class Person < ActiveRecord::Base
5
+ validates :email, :mail => true
6
+ end
7
+
8
+ test "blank values" do
9
+ assert_equal false, Person.new(:email => '').valid?
10
+ assert_equal false, Person.new(:email => false).valid?
11
+ assert_equal false, Person.new(:email => nil).valid?
12
+ end
13
+
14
+ test "illegal addresses" do
15
+ ['Max@Job 3:14', 'Job@Book of Job', "J. P. 's-Gravezande, a.k.a. The Hacker!@example.com"].each do |mail|
16
+ assert_equal false, Person.new(:email => mail).valid?
17
+ end
18
+ end
19
+
20
+ test "legal addresses" do
21
+ ['test@example.com', 'test@example.co.uk', 'someone@123.com'].each do |mail|
22
+ assert Person.new(:email => mail).valid?
23
+ end
24
+ end
25
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: validates_as_mail
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Gabriel Sobrinho
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-02-28 00:00:00 -03:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description:
22
+ email: gabriel.sobrinho@gmail.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - README.textile
29
+ files:
30
+ - MIT-LICENSE
31
+ - README.textile
32
+ - Rakefile
33
+ - VERSION
34
+ - init.rb
35
+ - lib/validates_as_mail.rb
36
+ - lib/validates_as_mail/mail_validator.rb
37
+ - test/test_helper.rb
38
+ - test/validates_as_mail_test.rb
39
+ has_rdoc: true
40
+ homepage: http://github.com/sobrinho/validates_as_mail
41
+ licenses: []
42
+
43
+ post_install_message:
44
+ rdoc_options:
45
+ - --charset=UTF-8
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ segments:
53
+ - 0
54
+ version: "0"
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ requirements: []
63
+
64
+ rubyforge_project:
65
+ rubygems_version: 1.3.6
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: Mail validation for ActiveModel
69
+ test_files:
70
+ - test/test_helper.rb
71
+ - test/validates_as_mail_test.rb