extra_validators 1.0

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 ADDED
@@ -0,0 +1,32 @@
1
+ == ExtraValidators
2
+
3
+ A compilation of simple validators we need in most Rails apps.
4
+ This gem plugin only works with Rails 3 / ActiveModel.
5
+
6
+ == Examples
7
+
8
+ Validation of an email address :
9
+
10
+ class MyModel < ActiveRecord::Base
11
+ validates :my_email_field, :email => true
12
+ end
13
+
14
+ Validation of an URL :
15
+
16
+ class MyModel < ActiveRecord::Base
17
+ validates :my_url_field, :url => true
18
+ end
19
+
20
+ == Installation
21
+
22
+ As a gem in your app's Gemfile :
23
+
24
+ gem 'extra_validators'
25
+
26
+ == Tests
27
+
28
+ If you wanna run the tests :
29
+
30
+ rake spec
31
+
32
+ Copyright (c) 2010 Aurélien Malisart, released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'spec/rake/spectask'
4
+
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"]
9
+ end
10
+
11
+ task :default => :spec
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'more_validators'
@@ -0,0 +1,2 @@
1
+ require 'extra_validators/email_validator'
2
+ require 'extra_validators/url_validator'
@@ -0,0 +1,47 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe User do
4
+ it "should be valid if email attribute is well-formatted" do
5
+ User.new(:email => "dude.lastname@yahoo.cz").should be_valid
6
+ User.new(:email => "dude@gmail.com").should be_valid
7
+ User.new(:email => "dude@gmail.co.uk").should be_valid
8
+ User.new(:email => "Francois.Stephany@gmail.com").should be_valid
9
+ User.new(:email => "Francois.Stephay@gmail.co.uk").should be_valid
10
+ User.new(:email => "dude-blip@gmail.com").should be_valid
11
+ User.new(:email => "dude_blop@gmail.com").should be_valid
12
+ User.new(:email => "dude789@gmail.com").should be_valid
13
+ end
14
+
15
+ it "should not be valid if email attribute is not well-formatted" do
16
+ User.new(:email => "thisisnotanemail").should_not be_valid
17
+ User.new(:email => "@thisisnotanemail").should_not be_valid
18
+ User.new(:email => "thisisnotanemail@").should_not be_valid
19
+ User.new(:email => "thisisnotanemail@gmail").should_not be_valid
20
+ User.new(:email => "thisisnotanemail@hotmail@gmail.com").should_not be_valid
21
+ User.new(:email => "this.is.not.anemail").should_not be_valid
22
+ end
23
+ end
24
+
25
+ describe Bookmark do
26
+ it "should be valid if url attribute is well-formatted" do
27
+ Bookmark.new(:url => "http://www.google.com").should be_valid
28
+ Bookmark.new(:url => "http://google.com").should be_valid
29
+ Bookmark.new(:url => "https://www.google.com").should be_valid
30
+ Bookmark.new(:url => "http://www.google.com/test").should be_valid
31
+ Bookmark.new(:url => "http://www.google.com/test-blop").should be_valid
32
+ Bookmark.new(:url => "http://www.google.com/~aurels").should be_valid
33
+ Bookmark.new(:url => "http://localhost").should be_valid
34
+ Bookmark.new(:url => "http://www.google.com:890/").should be_valid
35
+ Bookmark.new(:url => "http://www.google.com:80").should be_valid
36
+ Bookmark.new(:url => "http://www.google.com/blop:8080").should be_valid
37
+ end
38
+
39
+ it "should not be valid if url attribute is not well-formatted" do
40
+ Bookmark.new(:url => "www.google.com").should_not be_valid
41
+ Bookmark.new(:url => "google").should_not be_valid
42
+ Bookmark.new(:url => "ftp://www.google.com").should_not be_valid
43
+ Bookmark.new(:url => "ftp://www.google.com").should_not be_valid
44
+ Bookmark.new(:url => "http://www.google.com:").should_not be_valid
45
+ Bookmark.new(:url => "http://www.goo:gle.com").should_not be_valid
46
+ end
47
+ end
@@ -0,0 +1,30 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+ require 'active_model'
4
+
5
+ require File.dirname(__FILE__) + '/../lib/extra_validators.rb'
6
+
7
+ # Utils models =================================================================
8
+
9
+ class BaseTestModel
10
+ include ActiveModel::Serialization
11
+ include ActiveModel::Validations
12
+
13
+ attr_accessor :attributes
14
+
15
+ def initialize(attributes = {})
16
+ @attributes = attributes
17
+ end
18
+
19
+ def read_attribute_for_validation(key)
20
+ @attributes[key]
21
+ end
22
+ end
23
+
24
+ class User < BaseTestModel
25
+ validates :email, :email => true
26
+ end
27
+
28
+ class Bookmark < BaseTestModel
29
+ validates :url, :url => true
30
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: extra_validators
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ version: "1.0"
9
+ platform: ruby
10
+ authors:
11
+ - "Aur\xC3\xA9lien Malisart"
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+
16
+ date: 2010-05-15 00:00:00 +02:00
17
+ default_executable:
18
+ dependencies: []
19
+
20
+ description: A collection of misc usefull validators for ActiveModel
21
+ email: aurelien.malisart@gmail.com
22
+ executables: []
23
+
24
+ extensions: []
25
+
26
+ extra_rdoc_files:
27
+ - README.rdoc
28
+ files:
29
+ - lib/extra_validators.rb
30
+ - spec/extra_validators/validations_spec.rb
31
+ - spec/spec_helper.rb
32
+ - README.rdoc
33
+ - Rakefile
34
+ - init.rb
35
+ has_rdoc: true
36
+ homepage: http://github.com/aurels/extra_validators
37
+ licenses: []
38
+
39
+ post_install_message:
40
+ rdoc_options: []
41
+
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ segments:
49
+ - 0
50
+ version: "0"
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 1
57
+ - 2
58
+ version: "1.2"
59
+ requirements: []
60
+
61
+ rubyforge_project:
62
+ rubygems_version: 1.3.6
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: A collection of misc usefull validators for ActiveModel
66
+ test_files: []
67
+