simplificator-arext 0.2.9 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Simplificator GmbH
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.
@@ -50,4 +50,4 @@ in your ActiveRecord class:
50
50
 
51
51
 
52
52
 
53
- Copyright (c) 2008 [simplificator gmbh], released under the MIT license
53
+ Copyright (c) 2008 - now [simplificator gmbh]
data/Rakefile ADDED
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "arext"
8
+ gem.summary = %Q{Adds new validations to AR}
9
+ gem.email = "info@simplificator.com"
10
+ gem.homepage = "http://github.com/simplificator/arext"
11
+ gem.authors = ["simplificator"]
12
+ gem.files.exclude '**/*.sqlite3', '*.sqlite3'
13
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
14
+ end
15
+ rescue LoadError
16
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
17
+ end
18
+
19
+ require 'rake/testtask'
20
+ Rake::TestTask.new(:test) do |test|
21
+ test.libs << 'lib' << 'test'
22
+ test.pattern = 'test/**/*_test.rb'
23
+ test.verbose = true
24
+ end
25
+
26
+ begin
27
+ require 'rcov/rcovtask'
28
+ Rcov::RcovTask.new do |test|
29
+ test.libs << 'test'
30
+ test.pattern = 'test/**/*_test.rb'
31
+ test.verbose = true
32
+ end
33
+ rescue LoadError
34
+ task :rcov do
35
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
36
+ end
37
+ end
38
+
39
+
40
+ task :default => :test
41
+
42
+ require 'rake/rdoctask'
43
+ Rake::RDocTask.new do |rdoc|
44
+ if File.exist?('VERSION.yml')
45
+ config = YAML.load(File.read('VERSION.yml'))
46
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
47
+ else
48
+ version = ""
49
+ end
50
+
51
+ rdoc.rdoc_dir = 'rdoc'
52
+ rdoc.title = "arext #{version}"
53
+ rdoc.rdoc_files.include('README*')
54
+ rdoc.rdoc_files.include('lib/**/*.rb')
55
+ end
56
+
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :major: 0
3
+ :minor: 3
4
+ :patch: 0
data/test/foo.rb ADDED
@@ -0,0 +1,3 @@
1
+ class Foo < ActiveRecord::Base
2
+
3
+ end
@@ -0,0 +1,39 @@
1
+ require 'rubygems'
2
+ require 'active_record'
3
+ require 'test/unit'
4
+
5
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'arext')
6
+
7
+
8
+ ActiveRecord::Base.establish_connection(
9
+ :adapter => 'sqlite3',
10
+ :database => 'test.sqlite3',
11
+ :timeout => 5000
12
+ )
13
+
14
+ begin
15
+ ActiveRecord::Base.connection.drop_table(:foos)
16
+ rescue
17
+ # no such table
18
+ end
19
+
20
+ ActiveRecord::Base.connection.create_table(:foos) do |table|
21
+ table.string(:not_null_string_with_limit, :null => false, :limit => 10)
22
+ table.string(:string_with_limit, :null => true, :limit => 20)
23
+ table.string(:null_string_without_limit, :null => true)
24
+ table.boolean(:null_boolean)
25
+ table.boolean(:not_null_boolean, :null => false)
26
+ table.integer(:null_integer, :null => true)
27
+ table.integer(:not_null_integer, :null => false)
28
+ table.float(:null_float, :null => true)
29
+ table.float(:not_null_float, :null => false)
30
+
31
+ table.string(:url)
32
+ table.string(:host)
33
+ table.string(:email)
34
+ end
35
+
36
+ ActiveRecord::Base.logger = Logger.new(STDOUT)
37
+ ActiveRecord::Base.logger.level = Logger::DEBUG # change to DEBUG if you want to see something :-)
38
+
39
+ require File.join(File.dirname(__FILE__), 'foo')
@@ -0,0 +1,99 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
+
3
+ class ValidatesConstraintsTest < Test::Unit::TestCase
4
+
5
+ def test_not_null_string_with_limit
6
+ Foo.send(:validates_constraints, :not_null_string_with_limit)
7
+ assert(valid_foo())
8
+ assert((not valid_foo(:not_null_string_with_limit => 'x' * 11).valid?))
9
+ assert(valid_foo(:not_null_string_with_limit => '').valid?)
10
+ assert(valid_foo(:not_null_string_with_limit => 'x' * 10).valid?)
11
+ end
12
+ def test_string_with_limit
13
+ Foo.send(:validates_constraints, :string_with_limit)
14
+ assert(valid_foo())
15
+ assert((not valid_foo(:string_with_limit => 'x' * 21).valid?))
16
+ assert(valid_foo(:string_with_limit => '').valid?)
17
+ assert(valid_foo(:string_with_limit => 'x' * 10).valid?)
18
+
19
+ end
20
+
21
+ def test_null_string_withouth_limit
22
+ Foo.send(:validates_constraints, :null_string_without_limit)
23
+ assert(valid_foo.valid?)
24
+ assert(valid_foo(:null_string_without_limit => '').valid?)
25
+ assert(valid_foo(:null_string_without_limit => 'x' * 5).valid?)
26
+ assert(valid_foo(:null_string_without_limit => 'x' * 255).valid?)
27
+ # sqllite still adds a limit for string columns (255 chars)
28
+ assert((not valid_foo(:null_string_without_limit => 'x' * 256).valid?))
29
+ end
30
+
31
+ def test_null_boolean
32
+ Foo.send(:validates_constraints, :null_boolean)
33
+ assert(valid_foo.valid?)
34
+ assert(valid_foo(:null_boolean => true).valid?)
35
+ assert(valid_foo(:null_boolean => false).valid?)
36
+ end
37
+
38
+ def test_not_null_boolean
39
+ Foo.send(:validates_constraints, :not_null_boolean)
40
+ assert(valid_foo.valid?)
41
+ assert(valid_foo(:not_null_boolean => true).valid?)
42
+ assert(valid_foo(:not_null_boolean => false).valid?)
43
+ assert((not valid_foo(:not_null_boolean => nil).valid?))
44
+ end
45
+
46
+ def test_null_integer
47
+ Foo.send(:validates_constraints, :null_integer)
48
+ assert(valid_foo.valid?)
49
+ assert(valid_foo(:null_integer => nil).valid?)
50
+ assert(valid_foo(:null_integer => 1).valid?)
51
+ assert(valid_foo(:null_integer => 0).valid?)
52
+ assert(valid_foo(:null_integer => -1).valid?)
53
+ end
54
+
55
+ def test_not_null_integer
56
+ Foo.send(:validates_constraints, :not_null_integer)
57
+ assert(valid_foo.valid?)
58
+ assert((not valid_foo(:not_null_integer => nil).valid?))
59
+ assert(valid_foo(:not_null_integer => 1).valid?)
60
+ assert(valid_foo(:not_null_integer => 0).valid?)
61
+ assert(valid_foo(:not_null_integer => -1).valid?)
62
+ end
63
+
64
+ def test_null_float
65
+ Foo.send(:validates_constraints, :null_float)
66
+ assert(valid_foo.valid?)
67
+ assert(valid_foo(:null_float => nil).valid?)
68
+ assert(valid_foo(:null_float => 1.0).valid?)
69
+ assert(valid_foo(:null_float => 0.0).valid?)
70
+ assert(valid_foo(:null_float => -1.0).valid?)
71
+ end
72
+
73
+ def test_not_null_float
74
+ Foo.send(:validates_constraints, :not_null_float)
75
+ assert(valid_foo.valid?)
76
+ assert((not valid_foo(:not_null_float => nil).valid?))
77
+ assert(valid_foo(:not_null_float => 1.0).valid?)
78
+ assert(valid_foo(:not_null_float => 0.0).valid?)
79
+ assert(valid_foo(:not_null_float => -1.0).valid?)
80
+ end
81
+ private
82
+
83
+ def valid_foo(options = {})
84
+ valid = {
85
+ :null_string_without_limit => '',
86
+ :not_null_string_with_limit => '',
87
+ :string_with_limit => '',
88
+ :null_boolean => nil,
89
+ :not_null_boolean => false,
90
+ :null_integer => nil,
91
+ :not_null_integer => 123,
92
+ :null_float => nil,
93
+ :not_null_float => 123.0
94
+ }
95
+ Foo.new(valid.merge(options))
96
+
97
+ end
98
+
99
+ end
@@ -0,0 +1,33 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
+
3
+ class ValidatesEmailTest < Test::Unit::TestCase
4
+ VALID_ADDRESSES = ['vorname.nachmane@gmail.com', 'vorname.nachname@gmail.ch', 'name@gmail.com',
5
+ 'vorname-nachname@test-ch.net', 'vorname_nachname@gmail.org', 'name@gmail.name',
6
+ 'joesmith.nospamplease@nospam.example.com', 'test77@t-online.ch'
7
+ ]
8
+
9
+ INVALID_ADDRESSES = ['vorname.gmail.com', 'vorname%nachmane@gmail.com', 'test@gmail.1',
10
+ 'vorname', 'vorname.nachname', '', 'vorname,nachmane@schweiz.ch'
11
+ ]
12
+
13
+ def setup()
14
+ Foo.send(:validates_email, :email)
15
+ end
16
+
17
+ def test_valid_email_formats
18
+
19
+ VALID_ADDRESSES.each do |email|
20
+ foo = Foo.new(:email => email)
21
+ foo.valid?
22
+ assert(foo.errors[:email].blank?, "eMail-Address '#{email}' is supposed to be valid")
23
+ end
24
+ end
25
+
26
+ def test_invalid_email_formats
27
+ INVALID_ADDRESSES.each do |email|
28
+ foo = Foo.new(:email => email)
29
+ foo.valid?
30
+ assert(foo.errors[:email], "eMail-Address '#{email}' is supposed to be invalid")
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,27 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
+
3
+ class ValidatesHostTest < Test::Unit::TestCase
4
+ VALID_HOSTS = ['simplificator.com', 'www.hallo.com', 'hallo-velo.ch', 'www.hallo-velo.ch',
5
+ '1.1.1.1', '255.255.255.255']
6
+ INVALID_HOSTS = ['', '.2.3.4', 'http://www.google.ch', '10.10.10.10:3000', 'google', '10.10.10.10.']
7
+
8
+ def setup()
9
+ Foo.send(:validates_host, :host)
10
+ end
11
+ def test_valid_host_formats
12
+
13
+ VALID_HOSTS.each do |host|
14
+ foo = Foo.new(:host => host)
15
+ foo.valid?
16
+ assert(foo.errors[:host].blank?, "Host '#{host}' is supposed to be valid")
17
+ end
18
+ end
19
+
20
+ def test_invalid_host_formats
21
+ INVALID_HOSTS.each do |host|
22
+ foo = Foo.new(:host => host)
23
+ foo.valid?
24
+ assert(foo.errors[:host], "Host '#{host}' is supposed to be invalid")
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,34 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
+
3
+ class ValidatesUrlTest < Test::Unit::TestCase
4
+ VALID_URLS = ['http://simplificator.com', 'http://www.simplificator.com', 'https://www.simplificator.com',
5
+ 'https://simplificator.com', 'https://simplificator.com:3333', 'http://10.10.10.10',
6
+ 'https://10.10.10.10:1234', 'http://255.255.255.255:1212/test', 'http://a-b.com']
7
+ INVALID_URLS = ['http.//www.uptimehq.com', 'https.//google.com', 'http://simplificator.c', 'www.google.com']
8
+
9
+
10
+ def setup()
11
+ Foo.send(:validates_url, :url)
12
+ end
13
+
14
+ def test_setup()
15
+ assert Foo.columns_hash['url'], "ActiveRecord should provide an url accessor"
16
+ end
17
+
18
+ def test_valid_url_formats
19
+
20
+ VALID_URLS.each do |url|
21
+ foo = Foo.new(:url => url)
22
+ foo.valid?
23
+ assert(foo.errors[:url].blank?, "URL '#{url}' is supposed to be valid: #{foo.errors[:url]}")
24
+ end
25
+ end
26
+
27
+ def test_invalid_url_formats
28
+ INVALID_URLS.each do |url|
29
+ foo = Foo.new(:url => url)
30
+ foo.valid?
31
+ assert(foo.errors[:url], "URL '#{url}' is supposed to be invalid")
32
+ end
33
+ end
34
+ end
metadata CHANGED
@@ -1,36 +1,45 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simplificator-arext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
- - Simplificator GmbH
7
+ - simplificator
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-10-09 00:00:00 -07:00
12
+ date: 2009-05-28 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
- description: Adds some new validations to AR.
16
+ description:
17
17
  email: info@simplificator.com
18
18
  executables: []
19
19
 
20
20
  extensions: []
21
21
 
22
- extra_rdoc_files: []
23
-
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.rdoc
24
25
  files:
25
- - init.rb
26
+ - LICENSE
27
+ - README.rdoc
28
+ - Rakefile
29
+ - VERSION.yml
26
30
  - lib/arext.rb
27
31
  - lib/arext/validations.rb
28
- - README
29
- has_rdoc: false
30
- homepage: http://simplificator.com/en/lab
32
+ - test/foo.rb
33
+ - test/test_helper.rb
34
+ - test/unit/validates_constraints_test.rb
35
+ - test/unit/validates_email_test.rb
36
+ - test/unit/validates_host_test.rb
37
+ - test/unit/validates_url_test.rb
38
+ has_rdoc: true
39
+ homepage: http://github.com/simplificator/arext
31
40
  post_install_message:
32
- rdoc_options: []
33
-
41
+ rdoc_options:
42
+ - --charset=UTF-8
34
43
  require_paths:
35
44
  - lib
36
45
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -50,7 +59,12 @@ requirements: []
50
59
  rubyforge_project:
51
60
  rubygems_version: 1.2.0
52
61
  signing_key:
53
- specification_version: 2
54
- summary: provieds some extensions to ActiveRecord
55
- test_files: []
56
-
62
+ specification_version: 3
63
+ summary: Adds new validations to AR
64
+ test_files:
65
+ - test/foo.rb
66
+ - test/test_helper.rb
67
+ - test/unit/validates_constraints_test.rb
68
+ - test/unit/validates_email_test.rb
69
+ - test/unit/validates_host_test.rb
70
+ - test/unit/validates_url_test.rb
data/init.rb DELETED
@@ -1,4 +0,0 @@
1
- require File.join(File.dirname(__FILE__), 'lib', 'arext')
2
-
3
-
4
-