validates_host 0.2.0 → 1.2.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.
- checksums.yaml +7 -0
- data/.gitignore +5 -4
- data/.rubocop.yml +53 -0
- data/.ruby-gemset +1 -0
- data/.travis.yml +31 -0
- data/Gemfile +3 -1
- data/README.md +24 -3
- data/Rakefile +9 -4
- data/gemfiles/Gemfile.rails3 +6 -0
- data/gemfiles/Gemfile.rails4 +5 -0
- data/gemfiles/Gemfile.rails5 +5 -0
- data/lib/validates_host.rb +16 -5
- data/lib/validates_host/domain_name.rb +15 -0
- data/lib/validates_host/domain_name_validator.rb +3 -19
- data/lib/validates_host/host_name.rb +15 -0
- data/lib/validates_host/host_name_validator.rb +3 -19
- data/lib/validates_host/ip.rb +17 -0
- data/lib/validates_host/ip_validator.rb +3 -19
- data/lib/validates_host/{shoulda-matchers/domain_name_matcher.rb → require_a_valid_domain_name_matcher.rb} +9 -11
- data/lib/validates_host/{shoulda-matchers/host_name_matcher.rb → require_a_valid_host_name_matcher.rb} +9 -11
- data/lib/validates_host/{shoulda-matchers/ip_matcher.rb → require_a_valid_ip_matcher.rb} +9 -11
- data/lib/validates_host/require_a_valid_subnet_matcher.rb +35 -0
- data/lib/validates_host/subnet.rb +15 -0
- data/lib/validates_host/subnet_validator.rb +7 -0
- data/lib/validates_host/version.rb +3 -1
- data/spec/fake_app/server.rb +19 -5
- data/spec/fake_app/subnet.rb +11 -0
- data/spec/shoulda/matchers/active_model/require_a_valid_domain_name_matcher_spec.rb +23 -0
- data/spec/shoulda/matchers/active_model/require_a_valid_host_name_matcher_spec.rb +23 -0
- data/spec/shoulda/matchers/active_model/require_a_valid_ip_matcher_spec.rb +23 -0
- data/spec/shoulda/matchers/active_model/require_a_valid_subnet_matcher_spec.rb +23 -0
- data/spec/spec_helper.rb +11 -7
- data/spec/validates_host/domain_name_validator_spec.rb +41 -0
- data/spec/validates_host/host_name_validator_spec.rb +41 -0
- data/spec/validates_host/ip_validator_spec.rb +56 -0
- data/spec/validates_host/subnet_validator_spec.rb +41 -0
- data/validates_host.gemspec +22 -19
- metadata +89 -88
- data/lib/validates_host/remarkable.rb +0 -3
- data/lib/validates_host/remarkable/domain_name_matcher.rb +0 -29
- data/lib/validates_host/remarkable/host_name_matcher.rb +0 -29
- data/lib/validates_host/remarkable/ip_matcher.rb +0 -29
- data/lib/validates_host/shoulda-matchers.rb +0 -3
- data/spec/fake_app/db/migrations/create_servers.rb +0 -13
- data/spec/validates_host.rb/domain_name_validator_spec.rb +0 -40
- data/spec/validates_host.rb/host_name_validator_spec.rb +0 -40
- data/spec/validates_host.rb/ip_validator_spec.rb +0 -40
- data/spec/validates_host.rb/remarkable/domain_name_matcher_spec.rb +0 -20
- data/spec/validates_host.rb/remarkable/host_name_matcher_spec.rb +0 -20
- data/spec/validates_host.rb/remarkable/ip_matcher_spec.rb +0 -20
- data/spec/validates_host.rb/shoulda-matchers/domain_name_matcher_spec.rb +0 -20
- data/spec/validates_host.rb/shoulda-matchers/host_name_matcher_spec.rb +0 -20
- data/spec/validates_host.rb/shoulda-matchers/ip_matcher_spec.rb +0 -20
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe HostNameValidator do
|
4
|
-
context "when host_name is invalid" do
|
5
|
-
before :each do
|
6
|
-
@server = Server.new(:host_name => "http://")
|
7
|
-
I18n.stub(:t).with(:"activerecord.errors.models.server.attributes.host_name.invalid",
|
8
|
-
:default => :"activerecord.errors.messages.invalid").and_return("is invalid")
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should set object as invalid" do
|
12
|
-
@server.valid?.should be_false
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should set an error" do
|
16
|
-
@server.valid?
|
17
|
-
@server.errors[:host_name].should == ['is invalid']
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
context "when host_name is valid" do
|
22
|
-
before :each do
|
23
|
-
@server = Server.new(:host_name => "bd01")
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should set object as valid" do
|
27
|
-
@server.valid?.should be_true
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should not set an error on attribute" do
|
31
|
-
@server.valid?
|
32
|
-
@server.errors[:host_name].should be_blank
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should be valid with a nil value" do
|
37
|
-
@server = Server.new(:host_name => nil)
|
38
|
-
@server.valid?.should be_true
|
39
|
-
end
|
40
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe IpValidator do
|
4
|
-
context "when ip is invalid" do
|
5
|
-
before :each do
|
6
|
-
@server = Server.new(:ip => "127.0.0")
|
7
|
-
I18n.stub(:t).with(:"activerecord.errors.models.server.attributes.ip.invalid",
|
8
|
-
:default => :"activerecord.errors.messages.invalid").and_return("is invalid")
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should set object as invalid" do
|
12
|
-
@server.valid?.should be_false
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should set an error" do
|
16
|
-
@server.valid?
|
17
|
-
@server.errors[:ip].should == ['is invalid']
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
context "when ip is valid" do
|
22
|
-
before :each do
|
23
|
-
@server = Server.new(:ip => "10.10.10.1")
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should set object as valid" do
|
27
|
-
@server.valid?.should be_true
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should not set an error on attribute" do
|
31
|
-
@server.valid?
|
32
|
-
@server.errors[:ip].should be_blank
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should be valid with a nil value" do
|
37
|
-
@server = Server.new(:ip => nil)
|
38
|
-
@server.valid?.should be_true
|
39
|
-
end
|
40
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'remarkable/active_model'
|
3
|
-
|
4
|
-
describe Remarkable::ActiveModel::Matchers::DomainNameMatcher do
|
5
|
-
before :each do
|
6
|
-
@server = Server.new
|
7
|
-
end
|
8
|
-
|
9
|
-
it "should accept on domain_name" do
|
10
|
-
@server.should require_a_valid_domain_name(:domain_name)
|
11
|
-
end
|
12
|
-
|
13
|
-
it "should accept without a specified attribute" do
|
14
|
-
@server.should require_a_valid_domain_name
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should reject on host_name" do
|
18
|
-
@server.should_not require_a_valid_domain_name(:host_name)
|
19
|
-
end
|
20
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'remarkable/active_model'
|
3
|
-
|
4
|
-
describe Remarkable::ActiveModel::Matchers::HostNameMatcher do
|
5
|
-
before :each do
|
6
|
-
@server = Server.new
|
7
|
-
end
|
8
|
-
|
9
|
-
it "should accept on host_name" do
|
10
|
-
@server.should require_a_valid_host_name(:host_name)
|
11
|
-
end
|
12
|
-
|
13
|
-
it "should accept without a specified attribute" do
|
14
|
-
@server.should require_a_valid_domain_name
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should reject on domain_name" do
|
18
|
-
@server.should_not require_a_valid_host_name(:domain_name)
|
19
|
-
end
|
20
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'remarkable/active_model'
|
3
|
-
|
4
|
-
describe Remarkable::ActiveModel::Matchers::IpMatcher do
|
5
|
-
before :each do
|
6
|
-
@server = Server.new
|
7
|
-
end
|
8
|
-
|
9
|
-
it "should accept on ip" do
|
10
|
-
@server.should require_a_valid_ip(:ip)
|
11
|
-
end
|
12
|
-
|
13
|
-
it "should accept without a specified attribute" do
|
14
|
-
@server.should require_a_valid_ip
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should reject on domain_name" do
|
18
|
-
@server.should_not require_a_valid_ip(:domain_name)
|
19
|
-
end
|
20
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'shoulda-matchers'
|
3
|
-
|
4
|
-
describe Shoulda::Matchers::ActiveModel::DomainNameMatcher do
|
5
|
-
before :each do
|
6
|
-
@server = Server.new
|
7
|
-
end
|
8
|
-
|
9
|
-
it "should accept on domain_name" do
|
10
|
-
@server.should require_a_valid_domain_name(:domain_name)
|
11
|
-
end
|
12
|
-
|
13
|
-
it "should accept without a specified attribute" do
|
14
|
-
@server.should require_a_valid_domain_name
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should reject on host_name" do
|
18
|
-
@server.should_not require_a_valid_domain_name(:host_name)
|
19
|
-
end
|
20
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'shoulda-matchers'
|
3
|
-
|
4
|
-
describe Shoulda::Matchers::ActiveModel::HostNameMatcher do
|
5
|
-
before :each do
|
6
|
-
@server = Server.new
|
7
|
-
end
|
8
|
-
|
9
|
-
it "should accept on host_name" do
|
10
|
-
@server.should require_a_valid_host_name(:host_name)
|
11
|
-
end
|
12
|
-
|
13
|
-
it "should accept without a specified attribute" do
|
14
|
-
@server.should require_a_valid_host_name
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should reject on domain_name" do
|
18
|
-
@server.should_not require_a_valid_host_name(:domain_name)
|
19
|
-
end
|
20
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'shoulda-matchers'
|
3
|
-
|
4
|
-
describe Shoulda::Matchers::ActiveModel::IpMatcher do
|
5
|
-
before :each do
|
6
|
-
@server = Server.new
|
7
|
-
end
|
8
|
-
|
9
|
-
it "should accept on ip" do
|
10
|
-
@server.should require_a_valid_ip(:ip)
|
11
|
-
end
|
12
|
-
|
13
|
-
it "should accept without a specified attribute" do
|
14
|
-
@server.should require_a_valid_ip
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should reject on domain_name" do
|
18
|
-
@server.should_not require_a_valid_ip(:domain_name)
|
19
|
-
end
|
20
|
-
end
|