misc_validators 0.2 → 0.3
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/README.rdoc +9 -8
- data/Rakefile +7 -11
- data/init.rb +0 -1
- data/lib/misc_validators.rb +2 -0
- data/uninstall.rb +1 -0
- metadata +2 -4
- data/test/misc_validators_test.rb +0 -38
- data/test/unit/validates_email_test.rb +0 -25
- data/test/unit/validates_url_test.rb +0 -27
data/README.rdoc
CHANGED
@@ -4,13 +4,13 @@ A compilation of simple validators we need in most rails apps (AR based).
|
|
4
4
|
|
5
5
|
== Examples
|
6
6
|
|
7
|
-
Validation of an email address:
|
7
|
+
Validation of an email address :
|
8
8
|
|
9
9
|
class MyModel < ActiveRecord::Base
|
10
10
|
validates_email :my_email_field
|
11
11
|
end
|
12
12
|
|
13
|
-
Validation of an URL:
|
13
|
+
Validation of an URL :
|
14
14
|
|
15
15
|
class MyModel < ActiveRecord::Base
|
16
16
|
validates_url :my_url_field
|
@@ -18,17 +18,18 @@ Validation of an URL:
|
|
18
18
|
|
19
19
|
== Installation
|
20
20
|
|
21
|
-
As a gem:
|
21
|
+
As a gem from Gemcutter :
|
22
22
|
|
23
|
-
sudo
|
24
|
-
sudo gem install aurels-misc_validators
|
23
|
+
sudo gem install misc_validators
|
25
24
|
|
26
|
-
As a plugin
|
25
|
+
As a plugin :
|
27
26
|
|
28
27
|
script/plugin install git://github.com/aurels/misc_validators.git
|
29
28
|
|
30
|
-
|
29
|
+
== Tests
|
31
30
|
|
32
|
-
|
31
|
+
If you wanna run the tests :
|
32
|
+
|
33
|
+
rake spec
|
33
34
|
|
34
35
|
Copyright (c) 2009 Aurélien Malisart, released under the MIT license
|
data/Rakefile
CHANGED
@@ -1,15 +1,11 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'rake'
|
3
|
-
require 'rake/
|
4
|
-
require 'rake/rdoctask'
|
3
|
+
require 'spec/rake/spectask'
|
5
4
|
|
6
|
-
desc
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
Rake::TestTask.new(:test) do |t|
|
11
|
-
t.libs << 'lib'
|
12
|
-
t.libs << 'test'
|
13
|
-
t.pattern = 'test/**/*_test.rb'
|
14
|
-
t.verbose = true
|
5
|
+
desc "Run specs"
|
6
|
+
Spec::Rake::SpecTask.new do |t|
|
7
|
+
t.spec_files = Rake::FileList["spec/**/*_spec.rb"]
|
8
|
+
t.spec_opts = ["-c"]
|
15
9
|
end
|
10
|
+
|
11
|
+
task :default => :spec
|
data/init.rb
CHANGED
data/lib/misc_validators.rb
CHANGED
data/uninstall.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Uninstall hook code here
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: misc_validators
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: "0.
|
4
|
+
version: "0.3"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "Aur\xC3\xA9lien Malisart"
|
@@ -23,14 +23,12 @@ extra_rdoc_files:
|
|
23
23
|
- README.rdoc
|
24
24
|
files:
|
25
25
|
- lib/misc_validators.rb
|
26
|
-
- test/misc_validators_test.rb
|
27
|
-
- test/unit/validates_email_test.rb
|
28
|
-
- test/unit/validates_url_test.rb
|
29
26
|
- LICENSE
|
30
27
|
- README.rdoc
|
31
28
|
- Rakefile
|
32
29
|
- install.rb
|
33
30
|
- init.rb
|
31
|
+
- uninstall.rb
|
34
32
|
has_rdoc: true
|
35
33
|
homepage: http://github.com/aurels/misc_validators
|
36
34
|
licenses: []
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'test/unit'
|
3
|
-
require 'active_support'
|
4
|
-
require 'active_support/test_case'
|
5
|
-
require 'activerecord'
|
6
|
-
require 'init'
|
7
|
-
|
8
|
-
# ActiveRecord setup ===========================================================
|
9
|
-
|
10
|
-
ActiveRecord::Base.establish_connection({
|
11
|
-
:adapter => 'sqlite3',
|
12
|
-
:dbfile => 'test.db'
|
13
|
-
})
|
14
|
-
|
15
|
-
ActiveRecord::Schema.define do
|
16
|
-
create_table "users", :force => true do |t|
|
17
|
-
t.column "email", :string
|
18
|
-
end
|
19
|
-
|
20
|
-
create_table "bookmarks", :force => true do |t|
|
21
|
-
t.column "url", :string
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
# Utils models =================================================================
|
26
|
-
|
27
|
-
class User < ActiveRecord::Base
|
28
|
-
validates_email :email
|
29
|
-
end
|
30
|
-
|
31
|
-
class Bookmark < ActiveRecord::Base
|
32
|
-
validates_url :url
|
33
|
-
end
|
34
|
-
|
35
|
-
# Units tests ==================================================================
|
36
|
-
|
37
|
-
require 'unit/validates_email_test'
|
38
|
-
require 'unit/validates_url_test'
|
@@ -1,25 +0,0 @@
|
|
1
|
-
class MiscValidatorsValidatesEmailTest < ActiveSupport::TestCase
|
2
|
-
def test_truth
|
3
|
-
assert true
|
4
|
-
end
|
5
|
-
|
6
|
-
def test_good_email
|
7
|
-
assert User.new(:email => "dude.lastname@yahoo.cz").valid?
|
8
|
-
assert User.new(:email => "dude@gmail.com").valid?
|
9
|
-
assert User.new(:email => "dude@gmail.co.uk").valid?
|
10
|
-
assert User.new(:email => "Francois.Stephany@gmail.com").valid?
|
11
|
-
assert User.new(:email => "Francois.Stephay@gmail.co.uk").valid?
|
12
|
-
assert User.new(:email => "dude-blip@gmail.com").valid?
|
13
|
-
assert User.new(:email => "dude_blop@gmail.com").valid?
|
14
|
-
assert User.new(:email => "dude789@gmail.com").valid?
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_wrong_email
|
18
|
-
assert !User.new(:email => "thisisnotanemail").valid?
|
19
|
-
assert !User.new(:email => "@thisisnotanemail").valid?
|
20
|
-
assert !User.new(:email => "thisisnotanemail@").valid?
|
21
|
-
assert !User.new(:email => "thisisnotanemail@gmail").valid?
|
22
|
-
assert !User.new(:email => "thisisnotanemail@hotmail@gmail.com").valid?
|
23
|
-
assert !User.new(:email => "this.is.not.anemail").valid?
|
24
|
-
end
|
25
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
class MiscValidatorsValidatesUrlTest < ActiveSupport::TestCase
|
2
|
-
def test_truth
|
3
|
-
assert true
|
4
|
-
end
|
5
|
-
|
6
|
-
def test_good_url
|
7
|
-
assert Bookmark.new(:url => "http://www.google.com").valid?
|
8
|
-
assert Bookmark.new(:url => "http://google.com").valid?
|
9
|
-
assert Bookmark.new(:url => "https://www.google.com").valid?
|
10
|
-
assert Bookmark.new(:url => "http://www.google.com/test").valid?
|
11
|
-
assert Bookmark.new(:url => "http://www.google.com/test-blop").valid?
|
12
|
-
assert Bookmark.new(:url => "http://www.google.com/~aurels").valid?
|
13
|
-
assert Bookmark.new(:url => "http://localhost").valid?
|
14
|
-
assert Bookmark.new(:url => "http://www.google.com:890/").valid?
|
15
|
-
assert Bookmark.new(:url => "http://www.google.com:80").valid?
|
16
|
-
assert Bookmark.new(:url => "http://www.google.com/blop:8080").valid?
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_wrong_url
|
20
|
-
assert !Bookmark.new(:url => "www.google.com").valid?
|
21
|
-
assert !Bookmark.new(:url => "google").valid?
|
22
|
-
assert !Bookmark.new(:url => "ftp://www.google.com").valid?
|
23
|
-
assert !Bookmark.new(:url => "ftp://www.google.com").valid?
|
24
|
-
assert !Bookmark.new(:url => "http://www.google.com:").valid?
|
25
|
-
assert !Bookmark.new(:url => "http://www.goo:gle.com").valid?
|
26
|
-
end
|
27
|
-
end
|