validates_as_uri 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
4
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in gem-unico.gemspec
4
+ gemspec
@@ -0,0 +1,23 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ validates_as_uri (0.1.1)
5
+ activemodel (>= 3.0.0)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ activemodel (3.0.1)
11
+ activesupport (= 3.0.1)
12
+ builder (~> 2.1.2)
13
+ i18n (~> 0.4.1)
14
+ activesupport (3.0.1)
15
+ builder (2.1.2)
16
+ i18n (0.4.1)
17
+
18
+ PLATFORMS
19
+ ruby
20
+
21
+ DEPENDENCIES
22
+ activemodel (>= 3.0.0)
23
+ validates_as_uri!
@@ -4,15 +4,15 @@ URI validation for ActiveModel
4
4
 
5
5
  h2. Installation
6
6
 
7
- You can install as gem:
7
+ gem install validates_as_uri
8
8
 
9
- <pre>gem "validates_as_uri"</pre>
9
+ h2. Usage
10
10
 
11
- Or as plugin:
11
+ Gemfile:
12
12
 
13
- <pre>$ rails plugin install git://github.com/sobrinho/validates_as_uri.git</pre>
13
+ <pre>gem 'validate_as_uri'</pre>
14
14
 
15
- h2. Usage
15
+ Model:
16
16
 
17
17
  <pre>class Repository < ActiveRecord::Base
18
18
  validates :url, :uri => { :protocols => %w(git svn) }
data/Rakefile CHANGED
@@ -1,24 +1,14 @@
1
+ require 'bundler'
2
+ require 'rake'
1
3
  require 'rake/testtask'
2
4
 
3
- desc 'Default: run unit tests.'
4
- task :default => :test
5
+ task :default => [:test]
5
6
 
6
- desc 'Test the validates_as_uri plugin.'
7
- Rake::TestTask.new(:test) do |t|
7
+ Rake::TestTask.new("test") { |t|
8
8
  t.libs << 'test'
9
9
  t.pattern = 'test/**/*_test.rb'
10
- end
10
+ t.verbose = true
11
+ t.warning = true
12
+ }
11
13
 
12
- begin
13
- require 'jeweler'
14
- Jeweler::Tasks.new do |gemspec|
15
- gemspec.name = "validates_as_uri"
16
- gemspec.summary = "URI validation for ActiveModel"
17
- gemspec.email = "gabriel.sobrinho@gmail.com"
18
- gemspec.homepage = "http://github.com/sobrinho/validates_as_uri"
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
14
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,4 @@
1
+ en:
2
+ errors:
3
+ messages:
4
+ invalid_uri: "must be a valid uri"
@@ -1 +1,3 @@
1
1
  require 'validates_as_uri/uri_validator'
2
+ require 'validates_as_uri/version'
3
+ require 'validates_as_uri/engine' if defined?(Rails)
@@ -0,0 +1,4 @@
1
+ module ValidateAsUri
2
+ class Engine < Rails::Engine
3
+ end
4
+ end
@@ -1,9 +1,9 @@
1
1
  class UriValidator < ActiveModel::EachValidator
2
2
  def validate_each(record, attribute, value)
3
- options[:protocols] ||= %w(http https)
3
+ protocols = options[:protocols] || %w(http https)
4
4
 
5
- if value !~ %r{^(#{Array(options[:protocols]).join('|')})://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$}
6
- record.errors.add(attribute, options[:message])
5
+ if value !~ %r{^(#{Array.wrap(protocols).join('|')})://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$}
6
+ record.errors.add(attribute, options[:message] || :invalid_uri)
7
7
  end
8
8
  end
9
9
  end
@@ -0,0 +1,7 @@
1
+ module ValidatesAsUri
2
+ MAJOR = 0
3
+ MINOR = 1
4
+ TINY = 1
5
+
6
+ VERSION = [MAJOR, MINOR, TINY].join('.')
7
+ end
@@ -1,17 +1,15 @@
1
1
  require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'active_model'
2
4
  require 'test/unit'
3
- require 'active_support'
4
- require 'active_record'
5
- require 'validates_as_uri/uri_validator'
5
+ require 'validates_as_uri'
6
6
 
7
- # create a temporary database
8
- ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => ':memory:'
7
+ class Repository < Struct.new(:url)
8
+ include ActiveModel::Validations
9
+ validates :url, :uri => { :protocols => %w(git svn) }
10
+ end
9
11
 
10
- silence_stream(STDOUT) do
11
- ActiveRecord::Schema.define do
12
- create_table :repositories do |t|
13
- t.string :url
14
- t.string :homepage
15
- end
16
- end
12
+ class Site < Struct.new(:url)
13
+ include ActiveModel::Validations
14
+ validates :url, :uri => true
17
15
  end
@@ -0,0 +1,27 @@
1
+ require 'test_helper'
2
+
3
+ class UriValidatorTest < Test::Unit::TestCase
4
+ def test_valid_protocols
5
+ assert Repository.new('git://github.com/sobrinho/validates_as_uri.git').valid?
6
+ assert Repository.new('svn://svnhub.com/sobrinho/validates_as_uri').valid?
7
+ assert Site.new('http://github.com/').valid?
8
+ assert Site.new('https://github.com/').valid?
9
+ end
10
+
11
+ def test_invalid_protocols
12
+ assert Repository.new('http://github.com/').invalid?
13
+ assert Repository.new('https://github.com/').invalid?
14
+ assert Site.new('git://github.com/sobrinho/validates_as_uri.git').invalid?
15
+ assert Site.new('svn://svnhub.com/sobrinho/validates_as_uri').invalid?
16
+ end
17
+
18
+ def test_ip
19
+ assert Repository.new('git://10.0.0.1/sobrinho/validates_as_uri.git').valid?
20
+ assert Site.new('http://10.0.0.1/').valid?
21
+ end
22
+
23
+ def test_port
24
+ assert Site.new('https://github.com:3000/').valid?
25
+ assert Site.new('https://10.0.0.1:3000/').valid?
26
+ end
27
+ end
@@ -0,0 +1,18 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "validates_as_uri/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "validates_as_uri"
7
+ s.version = ValidatesAsUri::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Gabriel Sobrinho"]
10
+ s.email = ["gabriel.sobrinho@gmail.com"]
11
+ s.homepage = "http://github.com/sobrinho/validates_as_uri"
12
+ s.summary = %q{URI validation for ActiveModel}
13
+ s.files = `git ls-files`.split("\n")
14
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
+ s.require_paths = ["lib"]
17
+ s.add_dependency %q<activemodel>, [">= 3.0.0"]
18
+ end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validates_as_uri
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 25
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 1
8
- - 0
9
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
10
11
  platform: ruby
11
12
  authors:
12
13
  - Gabriel Sobrinho
@@ -14,58 +15,83 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-02-28 00:00:00 -03:00
18
+ date: 2010-10-30 00:00:00 -02:00
18
19
  default_executable:
19
- dependencies: []
20
-
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: activemodel
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 7
30
+ segments:
31
+ - 3
32
+ - 0
33
+ - 0
34
+ version: 3.0.0
35
+ type: :runtime
36
+ version_requirements: *id001
21
37
  description:
22
- email: gabriel.sobrinho@gmail.com
38
+ email:
39
+ - gabriel.sobrinho@gmail.com
23
40
  executables: []
24
41
 
25
42
  extensions: []
26
43
 
27
- extra_rdoc_files:
28
- - README.textile
44
+ extra_rdoc_files: []
45
+
29
46
  files:
47
+ - .gitignore
48
+ - Gemfile
49
+ - Gemfile.lock
30
50
  - MIT-LICENSE
31
51
  - README.textile
32
52
  - Rakefile
33
- - VERSION
34
- - init.rb
53
+ - config/locales/validates_as_uri.yml
35
54
  - lib/validates_as_uri.rb
55
+ - lib/validates_as_uri/engine.rb
36
56
  - lib/validates_as_uri/uri_validator.rb
57
+ - lib/validates_as_uri/version.rb
37
58
  - test/test_helper.rb
38
- - test/validates_as_uri_test.rb
59
+ - test/uri_validator_test.rb
60
+ - validates_as_uri.gemspec
39
61
  has_rdoc: true
40
62
  homepage: http://github.com/sobrinho/validates_as_uri
41
63
  licenses: []
42
64
 
43
65
  post_install_message:
44
- rdoc_options:
45
- - --charset=UTF-8
66
+ rdoc_options: []
67
+
46
68
  require_paths:
47
69
  - lib
48
70
  required_ruby_version: !ruby/object:Gem::Requirement
71
+ none: false
49
72
  requirements:
50
73
  - - ">="
51
74
  - !ruby/object:Gem::Version
75
+ hash: 3
52
76
  segments:
53
77
  - 0
54
78
  version: "0"
55
79
  required_rubygems_version: !ruby/object:Gem::Requirement
80
+ none: false
56
81
  requirements:
57
82
  - - ">="
58
83
  - !ruby/object:Gem::Version
84
+ hash: 3
59
85
  segments:
60
86
  - 0
61
87
  version: "0"
62
88
  requirements: []
63
89
 
64
90
  rubyforge_project:
65
- rubygems_version: 1.3.6
91
+ rubygems_version: 1.3.7
66
92
  signing_key:
67
93
  specification_version: 3
68
94
  summary: URI validation for ActiveModel
69
95
  test_files:
70
96
  - test/test_helper.rb
71
- - test/validates_as_uri_test.rb
97
+ - test/uri_validator_test.rb
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.1.0
data/init.rb DELETED
@@ -1 +0,0 @@
1
- require 'validates_as_uri'
@@ -1,32 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ValidatesUriCpfTest < ActiveSupport::TestCase
4
- class Repository < ActiveRecord::Base
5
- validates :url, :uri => { :protocols => %w(git svn) }
6
- validates :homepage, :uri => true
7
- end
8
-
9
- test "blank values" do
10
- assert_equal false, Repository.new(:url => '', :homepage => '').valid?
11
- assert_equal false, Repository.new(:url => false, :homepage => false).valid?
12
- assert_equal false, Repository.new(:url => nil, :homepage => nil).valid?
13
- end
14
-
15
- test "valid protocols" do
16
- assert Repository.new(:url => 'git://github.com/sobrinho/validates_as_uri.git',
17
- :homepage => 'http://github.com/sobrinho/validates_as_uri').valid?
18
-
19
- assert Repository.new(:url => 'svn://repository.com/sobrinho/validates_as_uri',
20
- :homepage => 'http://github.com/sobrinho/validates_as_uri').valid?
21
- end
22
-
23
- test "invalid protocols" do
24
- assert_equal false, Repository.new(:url => 'http://github.com/sobrinho/validates_as_uri.git',
25
- :homepage => 'http://github.com/sobrinho/validates_as_uri').valid?
26
- end
27
-
28
- test "ip and port" do
29
- assert Repository.new(:url => 'git://127.0.0.1/sobrinho/validates_as_uri.git',
30
- :homepage => 'https://127.0.0.1:3000/sobrinho/validates_as_uri').valid?
31
- end
32
- end