vidibus-validate_uri 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/{spec/spec.opts → .rspec} +1 -1
- data/Gemfile +7 -0
- data/Gemfile.lock +86 -0
- data/Rakefile +10 -17
- data/VERSION +1 -1
- data/config/locales/en.yml +2 -1
- data/lib/vidibus/validate_uri/{instance_methods.rb → core.rb} +17 -23
- data/lib/vidibus/validate_uri/extensions/controller.rb +3 -3
- data/lib/vidibus/validate_uri/extensions.rb +1 -1
- data/lib/vidibus/validate_uri/uri_validator.rb +8 -4
- data/lib/vidibus/validate_uri.rb +2 -2
- data/lib/vidibus-validate_uri.rb +8 -1
- data/spec/spec_helper.rb +6 -6
- data/spec/vidibus/validate_uri/action_controller_spec.rb +6 -1
- data/spec/vidibus/validate_uri/{instance_methods_spec.rb → core_spec.rb} +74 -43
- data/spec/vidibus/validate_uri/uri_validator_spec.rb +32 -12
- data/vidibus-validate_uri.gemspec +11 -9
- metadata +13 -12
data/{spec/spec.opts → .rspec}
RENAMED
@@ -1,2 +1,2 @@
|
|
1
|
-
--
|
1
|
+
--colour
|
2
2
|
--format nested
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://gemcutter.org/
|
3
|
+
specs:
|
4
|
+
abstract (1.0.0)
|
5
|
+
actionmailer (3.0.0.rc2)
|
6
|
+
actionpack (= 3.0.0.rc2)
|
7
|
+
mail (~> 2.2.5)
|
8
|
+
actionpack (3.0.0.rc2)
|
9
|
+
activemodel (= 3.0.0.rc2)
|
10
|
+
activesupport (= 3.0.0.rc2)
|
11
|
+
builder (~> 2.1.2)
|
12
|
+
erubis (~> 2.6.6)
|
13
|
+
i18n (~> 0.4.1)
|
14
|
+
rack (~> 1.2.1)
|
15
|
+
rack-mount (~> 0.6.12)
|
16
|
+
rack-test (~> 0.5.4)
|
17
|
+
tzinfo (~> 0.3.23)
|
18
|
+
activemodel (3.0.0.rc2)
|
19
|
+
activesupport (= 3.0.0.rc2)
|
20
|
+
builder (~> 2.1.2)
|
21
|
+
i18n (~> 0.4.1)
|
22
|
+
activerecord (3.0.0.rc2)
|
23
|
+
activemodel (= 3.0.0.rc2)
|
24
|
+
activesupport (= 3.0.0.rc2)
|
25
|
+
arel (~> 1.0.0.rc1)
|
26
|
+
tzinfo (~> 0.3.23)
|
27
|
+
activeresource (3.0.0.rc2)
|
28
|
+
activemodel (= 3.0.0.rc2)
|
29
|
+
activesupport (= 3.0.0.rc2)
|
30
|
+
activesupport (3.0.0.rc2)
|
31
|
+
arel (1.0.0.rc1)
|
32
|
+
activesupport (>= 3.0.0.beta)
|
33
|
+
builder (2.1.2)
|
34
|
+
diff-lcs (1.1.2)
|
35
|
+
erubis (2.6.6)
|
36
|
+
abstract (>= 1.0.0)
|
37
|
+
i18n (0.4.1)
|
38
|
+
mail (2.2.5)
|
39
|
+
activesupport (>= 2.3.6)
|
40
|
+
mime-types
|
41
|
+
treetop (>= 1.4.5)
|
42
|
+
mime-types (1.16)
|
43
|
+
polyglot (0.3.1)
|
44
|
+
rack (1.2.1)
|
45
|
+
rack-mount (0.6.12)
|
46
|
+
rack (>= 1.0.0)
|
47
|
+
rack-test (0.5.4)
|
48
|
+
rack (>= 1.0)
|
49
|
+
rails (3.0.0.rc2)
|
50
|
+
actionmailer (= 3.0.0.rc2)
|
51
|
+
actionpack (= 3.0.0.rc2)
|
52
|
+
activerecord (= 3.0.0.rc2)
|
53
|
+
activeresource (= 3.0.0.rc2)
|
54
|
+
activesupport (= 3.0.0.rc2)
|
55
|
+
bundler (>= 1.0.0.rc.6)
|
56
|
+
railties (= 3.0.0.rc2)
|
57
|
+
railties (3.0.0.rc2)
|
58
|
+
actionpack (= 3.0.0.rc2)
|
59
|
+
activesupport (= 3.0.0.rc2)
|
60
|
+
rake (>= 0.8.3)
|
61
|
+
thor (~> 0.14.0)
|
62
|
+
rake (0.8.7)
|
63
|
+
relevance-rcov (0.9.2.1)
|
64
|
+
rr (1.0.0)
|
65
|
+
rspec (2.0.0.beta.20)
|
66
|
+
rspec-core (= 2.0.0.beta.20)
|
67
|
+
rspec-expectations (= 2.0.0.beta.20)
|
68
|
+
rspec-mocks (= 2.0.0.beta.20)
|
69
|
+
rspec-core (2.0.0.beta.20)
|
70
|
+
rspec-expectations (2.0.0.beta.20)
|
71
|
+
diff-lcs (>= 1.1.2)
|
72
|
+
rspec-mocks (2.0.0.beta.20)
|
73
|
+
thor (0.14.0)
|
74
|
+
treetop (1.4.8)
|
75
|
+
polyglot (>= 0.3.1)
|
76
|
+
tzinfo (0.3.23)
|
77
|
+
|
78
|
+
PLATFORMS
|
79
|
+
ruby
|
80
|
+
|
81
|
+
DEPENDENCIES
|
82
|
+
bundler (~> 1.0.0)
|
83
|
+
rails (~> 3.0.0)
|
84
|
+
relevance-rcov
|
85
|
+
rr
|
86
|
+
rspec (~> 2.0.0.beta.20)
|
data/Rakefile
CHANGED
@@ -1,5 +1,8 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "rubygems"
|
2
|
+
require "rake"
|
3
|
+
require "rake/rdoctask"
|
4
|
+
require "rspec"
|
5
|
+
require "rspec/core/rake_task"
|
3
6
|
|
4
7
|
begin
|
5
8
|
require 'jeweler'
|
@@ -11,34 +14,24 @@ begin
|
|
11
14
|
gem.homepage = "http://github.com/vidibus/vidibus-validate_uri"
|
12
15
|
gem.authors = ["Andre Pankratz"]
|
13
16
|
gem.add_development_dependency "rspec"
|
14
|
-
gem.add_dependency "rails", "
|
17
|
+
gem.add_dependency "rails", "~> 3.0.0"
|
15
18
|
end
|
16
19
|
Jeweler::GemcutterTasks.new
|
17
20
|
rescue LoadError
|
18
21
|
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
22
|
end
|
20
23
|
|
21
|
-
|
22
|
-
|
23
|
-
spec.libs << "lib" << "spec"
|
24
|
-
spec.spec_files = FileList["spec/**/*_spec.rb"]
|
25
|
-
end
|
26
|
-
|
27
|
-
Spec::Rake::SpecTask.new(:rcov) do |t|
|
28
|
-
t.spec_files = FileList["spec/vidibus/**/*_spec.rb"]
|
24
|
+
Rspec::Core::RakeTask.new(:rcov) do |t|
|
25
|
+
t.pattern = "spec/**/*_spec.rb"
|
29
26
|
t.rcov = true
|
30
27
|
t.rcov_opts = ["--exclude", "^spec,/gems/"]
|
31
28
|
end
|
32
29
|
|
33
|
-
task :spec => :check_dependencies
|
34
|
-
task :default => :spec
|
35
|
-
|
36
|
-
require "rake/rdoctask"
|
37
30
|
Rake::RDocTask.new do |rdoc|
|
38
31
|
version = File.exist?("VERSION") ? File.read("VERSION") : ""
|
39
32
|
rdoc.rdoc_dir = "rdoc"
|
40
|
-
rdoc.title = "vidibus-
|
33
|
+
rdoc.title = "vidibus-core_extensions #{version}"
|
41
34
|
rdoc.rdoc_files.include("README*")
|
42
35
|
rdoc.rdoc_files.include("lib/**/*.rb")
|
43
36
|
rdoc.options << "--charset=utf-8"
|
44
|
-
end
|
37
|
+
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/config/locales/en.yml
CHANGED
@@ -1,29 +1,27 @@
|
|
1
1
|
require "net/http"
|
2
|
+
require "uri"
|
2
3
|
|
3
4
|
module Vidibus
|
4
5
|
module ValidateUri
|
5
|
-
module
|
6
|
-
|
6
|
+
module Core
|
7
|
+
|
7
8
|
PORT_REGEXP = /(([:]\d+)?)/
|
8
|
-
DOMAIN_REGEXP = /([äüößa-z0-9\-]+\.?)*([äüößa-z0-9]{2,})\.([a-z]{2,}){1,2}/ # TODO:
|
9
|
+
DOMAIN_REGEXP = /([äüößa-z0-9\-]+\.?)*([äüößa-z0-9]{2,})\.([a-z]{2,}){1,2}/ # TODO: Add real IDN support
|
9
10
|
IP_REGEXP = /(?>(?:1?\d?\d|2[0-4]\d|25[0-5])\.){3}(?:1?\d?\d|2[0-4]\d|25[0-5])(?:\/(?:[12]?\d|3[012])|-(?>(?:1?\d?\d|2[0-4]\d|25[0-5])\.){3}(?:1?\d?\d|2[0-4]\d|25[0-5]))?/
|
10
|
-
PATH_REGEXP = /(\/[a-z0-
|
11
|
-
PARAMS_REGEXP = /\/?(\?[a-z0-
|
11
|
+
PATH_REGEXP = /(\/[a-z0-9\-_\.\,\/]*)?/
|
12
|
+
PARAMS_REGEXP = /\/?(\?[a-z0-9\-_\&=\|]*)?/
|
12
13
|
FRAGMENT_REGEXP = /(\#.*)?/
|
13
|
-
|
14
|
-
# Returns true if given
|
14
|
+
|
15
|
+
# Returns true if given URI is valid.
|
15
16
|
#
|
16
|
-
# To restrict to a certain protocol, provide :protocol option:
|
17
|
+
# To restrict URI to a certain protocol, provide :protocol option:
|
17
18
|
#
|
18
19
|
# valid_uri?(your_uri, :protocol => :rtmp)
|
19
20
|
# valid_uri?(your_uri, :protocol => [:rtsp, :rtmp])
|
20
21
|
#
|
21
|
-
# To check if the uri is accessible, provide :accessible option:
|
22
|
-
#
|
23
|
-
# valid_uri?(your_uri, :accessible => true)
|
24
|
-
#
|
25
22
|
def valid_uri?(uri, options = {})
|
26
23
|
return false if uri.blank?
|
24
|
+
|
27
25
|
if protocol = options[:protocol]
|
28
26
|
protocol = [protocol] unless p.is_a?(Array)
|
29
27
|
protocol_regexp = /#{protocol.join("|")}/
|
@@ -31,19 +29,15 @@ module Vidibus
|
|
31
29
|
protocol_regexp = /\w+/
|
32
30
|
end
|
33
31
|
regexp = /^#{protocol_regexp}:\/\/(localhost|#{DOMAIN_REGEXP}|#{IP_REGEXP})#{PORT_REGEXP}#{PATH_REGEXP}#{PARAMS_REGEXP}#{FRAGMENT_REGEXP}$/i
|
34
|
-
|
35
|
-
|
36
|
-
if options[:accessible] == true
|
37
|
-
valid = accessible_uri?(uri)
|
38
|
-
end
|
39
|
-
|
40
|
-
return valid
|
32
|
+
return !!uri.match(regexp)
|
41
33
|
end
|
42
|
-
|
43
|
-
protected
|
44
|
-
|
34
|
+
|
45
35
|
# Checks if given uri is accessible.
|
36
|
+
# The check will not be performed in test environment.
|
37
|
+
#
|
46
38
|
def accessible_uri?(uri)
|
39
|
+
return false unless valid_uri?(uri)
|
40
|
+
return true if ENV["RAILS_ENV"] == "test"
|
47
41
|
_uri = URI.parse(uri)
|
48
42
|
path = _uri.path.blank? ? "/" : _uri.path
|
49
43
|
begin
|
@@ -55,4 +49,4 @@ module Vidibus
|
|
55
49
|
end
|
56
50
|
end
|
57
51
|
end
|
58
|
-
end
|
52
|
+
end
|
@@ -2,8 +2,8 @@ module Vidibus
|
|
2
2
|
module ValidateUri
|
3
3
|
module Extensions
|
4
4
|
module Controller
|
5
|
-
include Vidibus::ValidateUri::
|
6
|
-
|
5
|
+
include Vidibus::ValidateUri::Core
|
6
|
+
|
7
7
|
def self.included(base)
|
8
8
|
base.class_eval do
|
9
9
|
helper_method :validate_uri
|
@@ -12,4 +12,4 @@ module Vidibus
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
15
|
-
end
|
15
|
+
end
|
@@ -1,13 +1,17 @@
|
|
1
1
|
module Vidibus
|
2
2
|
module ValidateUri
|
3
3
|
class UriValidator < ActiveModel::EachValidator
|
4
|
-
include Vidibus::ValidateUri::
|
5
|
-
|
4
|
+
include Vidibus::ValidateUri::Core
|
5
|
+
|
6
6
|
def validate_each(record, attribute, value)
|
7
|
-
|
7
|
+
if valid_uri?(value, options)
|
8
|
+
if options[:accessible] == true and !accessible_uri?(value)
|
9
|
+
record.errors.add(attribute, :inaccessible_uri)
|
10
|
+
end
|
11
|
+
else
|
8
12
|
record.errors.add(attribute, :invalid_uri)
|
9
13
|
end
|
10
14
|
end
|
11
15
|
end
|
12
16
|
end
|
13
|
-
end
|
17
|
+
end
|
data/lib/vidibus/validate_uri.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require "validate_uri/
|
1
|
+
require "validate_uri/core"
|
2
2
|
require "validate_uri/extensions"
|
3
3
|
require "validate_uri/uri_validator"
|
4
4
|
|
5
|
-
ActiveModel::Validations.send(:include, Vidibus::ValidateUri)
|
5
|
+
ActiveModel::Validations.send(:include, Vidibus::ValidateUri)
|
data/lib/vidibus-validate_uri.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -2,11 +2,11 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
2
2
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
3
3
|
|
4
4
|
require "rubygems"
|
5
|
-
require "
|
6
|
-
require "active_record"
|
7
|
-
require "action_controller"
|
5
|
+
require "rspec"
|
8
6
|
require "vidibus-validate_uri"
|
9
|
-
require "spec"
|
10
|
-
require "spec/autorun"
|
11
7
|
|
12
|
-
|
8
|
+
RSpec.configure do |config|
|
9
|
+
config.mock_with :rr
|
10
|
+
end
|
11
|
+
|
12
|
+
I18n.load_path += Dir[File.join('config', 'locales', '**', '*.{rb,yml}')]
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require "spec_helper"
|
2
|
+
require "action_controller"
|
2
3
|
|
3
4
|
class Controller < ActionController::Base; end
|
4
5
|
|
@@ -6,4 +7,8 @@ describe "ActionController::Base" do
|
|
6
7
|
it "should respond to #valid_uri?" do
|
7
8
|
Controller.new.should respond_to(:valid_uri?)
|
8
9
|
end
|
9
|
-
|
10
|
+
|
11
|
+
it "should respond to #accessible_uri?" do
|
12
|
+
Controller.new.should respond_to(:accessible_uri?)
|
13
|
+
end
|
14
|
+
end
|
@@ -1,10 +1,17 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
class Test
|
4
|
-
include Vidibus::ValidateUri::
|
4
|
+
include Vidibus::ValidateUri::Core
|
5
5
|
end
|
6
6
|
|
7
|
-
|
7
|
+
def in_test_environment(&block)
|
8
|
+
e = ENV["RAILS_ENV"]
|
9
|
+
ENV["RAILS_ENV"] = "test"
|
10
|
+
yield
|
11
|
+
ENV["RAILS_ENV"] = e
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "Vidibus::ValidateUri::Core" do
|
8
15
|
let(:test) { Test.new }
|
9
16
|
|
10
17
|
describe "#valid_uri?" do
|
@@ -12,172 +19,196 @@ describe "Vidibus::ValidateUri::InstanceMethods" do
|
|
12
19
|
uri = "http://mydomain.local"
|
13
20
|
test.valid_uri?(uri).should be_true
|
14
21
|
end
|
15
|
-
|
22
|
+
|
16
23
|
it "should validate http://mydomain.local/" do
|
17
24
|
uri = "http://mydomain.local/"
|
18
25
|
test.valid_uri?(uri).should be_true
|
19
26
|
end
|
20
|
-
|
27
|
+
|
21
28
|
it "should validate http://mydomain.com" do
|
22
29
|
uri = "http://mydomain.com"
|
23
30
|
test.valid_uri?(uri).should be_true
|
24
31
|
end
|
25
|
-
|
32
|
+
|
26
33
|
it "should validate http://www.mydomain.com" do
|
27
34
|
uri = "http://www.mydomain.com"
|
28
35
|
test.valid_uri?(uri).should be_true
|
29
36
|
end
|
30
|
-
|
37
|
+
|
31
38
|
it "should validate http://mydomain.com:8080" do
|
32
39
|
uri = "http://mydomain.com:8080"
|
33
40
|
test.valid_uri?(uri).should be_true
|
34
41
|
end
|
35
|
-
|
42
|
+
|
36
43
|
it "should validate http://mydomain.local/" do
|
37
44
|
uri = "http://mydomain.local/"
|
38
45
|
test.valid_uri?(uri).should be_true
|
39
46
|
end
|
40
|
-
|
47
|
+
|
41
48
|
it "should validate http://localhost" do
|
42
49
|
uri = "http://localhost"
|
43
50
|
test.valid_uri?(uri).should be_true
|
44
51
|
end
|
45
|
-
|
52
|
+
|
46
53
|
it "should validate http://localhost/" do
|
47
54
|
uri = "http://localhost/"
|
48
55
|
test.valid_uri?(uri).should be_true
|
49
56
|
end
|
50
|
-
|
57
|
+
|
51
58
|
it "should fail for http://localhosts" do
|
52
59
|
uri = "http://localhosts"
|
53
60
|
test.valid_uri?(uri).should be_false
|
54
61
|
end
|
55
|
-
|
62
|
+
|
56
63
|
it "should validate http://localhost:3000" do
|
57
64
|
uri = "http://localhost:3000"
|
58
65
|
test.valid_uri?(uri).should be_true
|
59
66
|
end
|
60
|
-
|
67
|
+
|
61
68
|
it "should validate http://localhost:3000/" do
|
62
69
|
uri = "http://localhost:3000/"
|
63
70
|
test.valid_uri?(uri).should be_true
|
64
71
|
end
|
65
|
-
|
72
|
+
|
66
73
|
it "should validate http://84.191.143.127" do
|
67
74
|
uri = "http://84.191.199.127"
|
68
75
|
test.valid_uri?(uri).should be_true
|
69
76
|
end
|
70
|
-
|
77
|
+
|
71
78
|
it "should validate http://84.191.143.127/" do
|
72
79
|
uri = "http://84.191.199.127/"
|
73
80
|
test.valid_uri?(uri).should be_true
|
74
81
|
end
|
75
|
-
|
82
|
+
|
76
83
|
it "should validate http://84.191.143.127:80" do
|
77
84
|
uri = "http://84.191.199.127:80"
|
78
85
|
test.valid_uri?(uri).should be_true
|
79
86
|
end
|
80
|
-
|
87
|
+
|
81
88
|
it "should fail for http://84.2a.143.127" do
|
82
89
|
uri = "http://84.2a.143.127"
|
83
90
|
test.valid_uri?(uri).should be_false
|
84
91
|
end
|
85
|
-
|
92
|
+
|
86
93
|
it "should validate https://some.weird.sub.1.mydomain.com:10000" do
|
87
94
|
uri = "https://some.weird.sub.1.mydomain.com:10000"
|
88
95
|
test.valid_uri?(uri).should be_true
|
89
96
|
end
|
90
|
-
|
97
|
+
|
91
98
|
it "should validate http://mydomain.local?some=params" do
|
92
99
|
uri = "http://mydomain.local?some=params"
|
93
100
|
test.valid_uri?(uri).should be_true
|
94
101
|
end
|
95
|
-
|
102
|
+
|
96
103
|
it "should validate http://mydomain.local/?some=params" do
|
97
104
|
uri = "http://mydomain.local/?some=params"
|
98
105
|
test.valid_uri?(uri).should be_true
|
99
106
|
end
|
100
|
-
|
107
|
+
|
101
108
|
it "should validate http://mydomain.local/hello/world" do
|
102
109
|
uri = "http://mydomain.local/hello/world"
|
103
110
|
test.valid_uri?(uri).should be_true
|
104
111
|
end
|
105
|
-
|
112
|
+
|
106
113
|
it "should fail for http://mydomain.local/hel lo/world" do
|
107
114
|
uri = "http://mydomain.local/hel lo/world"
|
108
115
|
test.valid_uri?(uri).should be_false
|
109
116
|
end
|
110
|
-
|
117
|
+
|
111
118
|
it "should validate http://mydomain.local/hello/world/" do
|
112
119
|
uri = "http://mydomain.local/hello/world/"
|
113
120
|
test.valid_uri?(uri).should be_true
|
114
121
|
end
|
115
|
-
|
122
|
+
|
116
123
|
it "should validate http://mydomain.local/hello/world.html" do
|
117
124
|
uri = "http://mydomain.local/hello/world.html"
|
118
125
|
test.valid_uri?(uri).should be_true
|
119
126
|
end
|
120
|
-
|
127
|
+
|
121
128
|
it "should validate http://mydomain.local/hello/world.html#doit" do
|
122
129
|
uri = "http://mydomain.local/hello/world.html#doit"
|
123
130
|
test.valid_uri?(uri).should be_true
|
124
131
|
end
|
125
|
-
|
132
|
+
|
126
133
|
it "should validate http://mydomain.local/hello/world?some=params" do
|
127
134
|
uri = "http://mydomain.local/hello/world?some=params"
|
128
135
|
test.valid_uri?(uri).should be_true
|
129
136
|
end
|
130
|
-
|
137
|
+
|
131
138
|
it "should validate http://mydomain.local/hello/world/?some=params" do
|
132
139
|
uri = "http://mydomain.local/hello/world/?some=params"
|
133
140
|
test.valid_uri?(uri).should be_true
|
134
141
|
end
|
135
|
-
|
142
|
+
|
136
143
|
it "should validate http://mydomain.local?some=params&another=one" do
|
137
144
|
uri = "http://mydomain.local?some=params&another=one"
|
138
145
|
test.valid_uri?(uri).should be_true
|
139
146
|
end
|
140
|
-
|
147
|
+
|
141
148
|
it "should validate http://mydomain.local?some=params&another=one#withFragment" do
|
142
149
|
uri = "http://mydomain.local?some=params&another=one#withFragment"
|
143
150
|
test.valid_uri?(uri).should be_true
|
144
151
|
end
|
145
|
-
|
152
|
+
|
146
153
|
it "should validate https://mydomain.local" do
|
147
154
|
uri = "https://mydomain.local"
|
148
155
|
test.valid_uri?(uri).should be_true
|
149
156
|
end
|
150
|
-
|
157
|
+
|
151
158
|
it "should validate https://mydomain.local with protocol => :https" do
|
152
159
|
uri = "https://mydomain.local"
|
153
160
|
test.valid_uri?(uri, :protocol => :https).should be_true
|
154
161
|
end
|
155
|
-
|
162
|
+
|
156
163
|
it "should validate https://mydomain.local with protocol => [:http, :https]" do
|
157
164
|
uri = "https://mydomain.local"
|
158
165
|
test.valid_uri?(uri, :protocol => [:http, :https]).should be_true
|
159
166
|
end
|
160
|
-
|
167
|
+
|
161
168
|
it "should fail for https://mydomain.local with protocol => :http" do
|
162
169
|
uri = "https://mydomain.local"
|
163
170
|
test.valid_uri?(uri, :protocol => :http).should be_false
|
164
171
|
end
|
165
|
-
|
172
|
+
|
166
173
|
it "should fail for https://mydomain.local with protocol => [:http, :rtmp]" do
|
167
174
|
uri = "https://mydomain.local"
|
168
175
|
test.valid_uri?(uri, :protocol => [:http, :rtmp]).should be_false
|
169
176
|
end
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
177
|
+
|
178
|
+
it "should validate rtmp://mydomain.local/video/13os/pi1x/1391/sxj9/go.flv?10|12|33 with protocol => [:rtmp, :rtsp]" do
|
179
|
+
uri = "rtmp://mydomain.local/video/13os/pi1x/1391/sxj9/go.flv?10|12|33"
|
180
|
+
test.valid_uri?(uri, :protocol => [:rtmp, :rtsp]).should be_true
|
181
|
+
end
|
182
|
+
|
183
|
+
it "should validate http://www.ali.baba.döner.de" do
|
184
|
+
uri = "http://www.ali.baba.döner.de"
|
185
|
+
test.valid_uri?(uri).should be_true
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
describe "#accessible_uri?" do
|
190
|
+
it "should validate http://www.vidibus.org" do
|
191
|
+
uri = "http://www.vidibus.org"
|
192
|
+
test.accessible_uri?(uri).should be_true
|
193
|
+
end
|
194
|
+
|
195
|
+
it "should fail for http://www.vidibus.zzz" do
|
196
|
+
uri = "http://www.vidibus.zzz"
|
197
|
+
test.accessible_uri?(uri).should be_false
|
198
|
+
end
|
199
|
+
|
200
|
+
it "should not perform accessibility check of syntactically invalid URIs" do
|
201
|
+
uri = "http://invalid"
|
202
|
+
dont_allow(URI).parse
|
203
|
+
test.accessible_uri?(uri).should be_false
|
204
|
+
end
|
205
|
+
|
206
|
+
it "should not perform accessibility check in test environment" do
|
207
|
+
in_test_environment do
|
178
208
|
uri = "http://www.vidibus.zzz"
|
179
|
-
|
209
|
+
dont_allow(URI).parse
|
210
|
+
test.accessible_uri?(uri).should be_true
|
180
211
|
end
|
181
212
|
end
|
182
213
|
end
|
183
|
-
end
|
214
|
+
end
|
@@ -2,33 +2,53 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
class Model
|
4
4
|
include ActiveModel::Validations
|
5
|
-
attr_accessor :uri
|
5
|
+
attr_accessor :uri
|
6
6
|
validates :uri, :uri => true
|
7
|
-
|
7
|
+
end
|
8
|
+
|
9
|
+
class SecureModel < Model
|
10
|
+
validates :uri, :uri => { :protocol => "https" }
|
11
|
+
end
|
12
|
+
|
13
|
+
class AccessibleModel < Model
|
14
|
+
validates :uri, :uri => { :accessible => true }
|
8
15
|
end
|
9
16
|
|
10
17
|
describe "Vidibus::ValidateUri::UriValidator" do
|
11
18
|
let(:model) { Model.new }
|
12
|
-
|
19
|
+
let(:secure_model) { SecureModel.new }
|
20
|
+
let(:acessible_model) { AccessibleModel.new }
|
21
|
+
|
13
22
|
it "should be available as URI validator" do
|
14
23
|
Model.validators_on(:uri).first.should be_a_kind_of(Vidibus::ValidateUri::UriValidator)
|
15
24
|
end
|
16
|
-
|
25
|
+
|
17
26
|
it "should add an error to model if URI is blank" do
|
18
27
|
model.uri = nil
|
19
28
|
model.should be_invalid
|
20
|
-
model.errors[:uri].should eql(["is
|
29
|
+
model.errors[:uri].should eql(["is invalid"])
|
21
30
|
end
|
22
|
-
|
31
|
+
|
23
32
|
it "should add an error to model if URI is invalid" do
|
24
33
|
model.uri = "http://localhosts"
|
25
34
|
model.should be_invalid
|
26
|
-
model.errors[:uri].should eql(["is
|
35
|
+
model.errors[:uri].should eql(["is invalid"])
|
27
36
|
end
|
28
|
-
|
29
|
-
it "should
|
30
|
-
model.
|
31
|
-
model.should
|
32
|
-
|
37
|
+
|
38
|
+
it "should add no error to model if URI is valid" do
|
39
|
+
model.uri = "http://vidibus.org"
|
40
|
+
model.should be_valid
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should add an error if uri does not match provided protocols" do
|
44
|
+
secure_model.uri = "http://www.vidibus.org"
|
45
|
+
secure_model.should be_invalid
|
46
|
+
secure_model.errors[:uri].should have(1).error
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should add an error to model if URI is inaccessible" do
|
50
|
+
acessible_model.uri = "http://vidibus.zzz"
|
51
|
+
acessible_model.should be_invalid
|
52
|
+
acessible_model.errors[:uri].should eql(["is inaccessible"])
|
33
53
|
end
|
34
54
|
end
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{vidibus-validate_uri}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Andre Pankratz"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-09-23}
|
13
13
|
s.description = %q{It provides validation of URIs (URLs) to ActiveModel records and ActionControllers in Rails 3.}
|
14
14
|
s.email = %q{andre@vidibus.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -19,6 +19,9 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.files = [
|
20
20
|
".document",
|
21
21
|
".gitignore",
|
22
|
+
".rspec",
|
23
|
+
"Gemfile",
|
24
|
+
"Gemfile.lock",
|
22
25
|
"LICENSE",
|
23
26
|
"README.rdoc",
|
24
27
|
"Rakefile",
|
@@ -26,14 +29,13 @@ Gem::Specification.new do |s|
|
|
26
29
|
"config/locales/en.yml",
|
27
30
|
"lib/vidibus-validate_uri.rb",
|
28
31
|
"lib/vidibus/validate_uri.rb",
|
32
|
+
"lib/vidibus/validate_uri/core.rb",
|
29
33
|
"lib/vidibus/validate_uri/extensions.rb",
|
30
34
|
"lib/vidibus/validate_uri/extensions/controller.rb",
|
31
|
-
"lib/vidibus/validate_uri/instance_methods.rb",
|
32
35
|
"lib/vidibus/validate_uri/uri_validator.rb",
|
33
|
-
"spec/spec.opts",
|
34
36
|
"spec/spec_helper.rb",
|
35
37
|
"spec/vidibus/validate_uri/action_controller_spec.rb",
|
36
|
-
"spec/vidibus/validate_uri/
|
38
|
+
"spec/vidibus/validate_uri/core_spec.rb",
|
37
39
|
"spec/vidibus/validate_uri/uri_validator_spec.rb",
|
38
40
|
"vidibus-validate_uri.gemspec"
|
39
41
|
]
|
@@ -45,7 +47,7 @@ Gem::Specification.new do |s|
|
|
45
47
|
s.test_files = [
|
46
48
|
"spec/spec_helper.rb",
|
47
49
|
"spec/vidibus/validate_uri/action_controller_spec.rb",
|
48
|
-
"spec/vidibus/validate_uri/
|
50
|
+
"spec/vidibus/validate_uri/core_spec.rb",
|
49
51
|
"spec/vidibus/validate_uri/uri_validator_spec.rb"
|
50
52
|
]
|
51
53
|
|
@@ -55,14 +57,14 @@ Gem::Specification.new do |s|
|
|
55
57
|
|
56
58
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
57
59
|
s.add_development_dependency(%q<rspec>, [">= 0"])
|
58
|
-
s.add_runtime_dependency(%q<rails>, ["
|
60
|
+
s.add_runtime_dependency(%q<rails>, ["~> 3.0.0"])
|
59
61
|
else
|
60
62
|
s.add_dependency(%q<rspec>, [">= 0"])
|
61
|
-
s.add_dependency(%q<rails>, ["
|
63
|
+
s.add_dependency(%q<rails>, ["~> 3.0.0"])
|
62
64
|
end
|
63
65
|
else
|
64
66
|
s.add_dependency(%q<rspec>, [">= 0"])
|
65
|
-
s.add_dependency(%q<rails>, ["
|
67
|
+
s.add_dependency(%q<rails>, ["~> 3.0.0"])
|
66
68
|
end
|
67
69
|
end
|
68
70
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vidibus-validate_uri
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Andre Pankratz
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-09-23 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -38,15 +38,14 @@ dependencies:
|
|
38
38
|
requirement: &id002 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
|
-
- -
|
41
|
+
- - ~>
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
hash:
|
43
|
+
hash: 7
|
44
44
|
segments:
|
45
45
|
- 3
|
46
46
|
- 0
|
47
47
|
- 0
|
48
|
-
|
49
|
-
version: 3.0.0.rc
|
48
|
+
version: 3.0.0
|
50
49
|
type: :runtime
|
51
50
|
version_requirements: *id002
|
52
51
|
description: It provides validation of URIs (URLs) to ActiveModel records and ActionControllers in Rails 3.
|
@@ -61,6 +60,9 @@ extra_rdoc_files:
|
|
61
60
|
files:
|
62
61
|
- .document
|
63
62
|
- .gitignore
|
63
|
+
- .rspec
|
64
|
+
- Gemfile
|
65
|
+
- Gemfile.lock
|
64
66
|
- LICENSE
|
65
67
|
- README.rdoc
|
66
68
|
- Rakefile
|
@@ -68,14 +70,13 @@ files:
|
|
68
70
|
- config/locales/en.yml
|
69
71
|
- lib/vidibus-validate_uri.rb
|
70
72
|
- lib/vidibus/validate_uri.rb
|
73
|
+
- lib/vidibus/validate_uri/core.rb
|
71
74
|
- lib/vidibus/validate_uri/extensions.rb
|
72
75
|
- lib/vidibus/validate_uri/extensions/controller.rb
|
73
|
-
- lib/vidibus/validate_uri/instance_methods.rb
|
74
76
|
- lib/vidibus/validate_uri/uri_validator.rb
|
75
|
-
- spec/spec.opts
|
76
77
|
- spec/spec_helper.rb
|
77
78
|
- spec/vidibus/validate_uri/action_controller_spec.rb
|
78
|
-
- spec/vidibus/validate_uri/
|
79
|
+
- spec/vidibus/validate_uri/core_spec.rb
|
79
80
|
- spec/vidibus/validate_uri/uri_validator_spec.rb
|
80
81
|
- vidibus-validate_uri.gemspec
|
81
82
|
has_rdoc: true
|
@@ -115,5 +116,5 @@ summary: Provides an URI validator for Rails 3.
|
|
115
116
|
test_files:
|
116
117
|
- spec/spec_helper.rb
|
117
118
|
- spec/vidibus/validate_uri/action_controller_spec.rb
|
118
|
-
- spec/vidibus/validate_uri/
|
119
|
+
- spec/vidibus/validate_uri/core_spec.rb
|
119
120
|
- spec/vidibus/validate_uri/uri_validator_spec.rb
|