zerigo_dns 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/zerigo_dns.rb CHANGED
@@ -43,8 +43,8 @@ module Zerigo
43
43
 
44
44
 
45
45
  class Zone < Base
46
- # Find or Create Zone
47
- def self.find_or_create(domain)
46
+ # Find by domain
47
+ def self.find_by_domain(domain)
48
48
  zones = find(:all)
49
49
  zone = nil
50
50
  zones.each do |z|
@@ -53,7 +53,13 @@ module Zerigo
53
53
  break;
54
54
  end
55
55
  end
56
-
56
+ zone
57
+ end
58
+
59
+
60
+ # Find or Create Zone
61
+ def self.find_or_create(domain)
62
+ zone = find_by_domain(domain)
57
63
  unless zone
58
64
  zone = create(:domain=> domain, :ns_type=>'pri_sec')
59
65
  end
@@ -64,8 +70,8 @@ module Zerigo
64
70
 
65
71
  class Host < Base
66
72
 
67
- # Update or Create Host for a zone
68
- def self.update_or_create(zone, hostname, type, data)
73
+ # Find by host name
74
+ def self.find_by_hostname(zone, hostname)
69
75
  hosts = find(:all)
70
76
  host = nil
71
77
  hosts.each do |h|
@@ -73,22 +79,27 @@ module Zerigo
73
79
  host = h
74
80
  break;
75
81
  end
76
- end
77
-
82
+ end
83
+ host
84
+ end
85
+
86
+ # Update or Create Host for a zone
87
+ def self.update_or_create(zone, hostname, type, ttl, data)
88
+ host = find_by_hostname(zone, hostname)
78
89
  if host
79
90
  # update
80
- host.host_type = type
81
- host.data = data
82
- host.ttl = 86400
91
+ host.host_type = type
92
+ host.data = data
93
+ host.ttl = ttl
83
94
  host.save
84
95
  else
85
96
  # creatae
86
97
  host = create(
87
- :zone_id => zone,
88
- :hostname => hostname,
89
- :host_type => type,
90
- :data => data,
91
- :ttl=>86400
98
+ :zone_id => zone,
99
+ :hostname => hostname,
100
+ :host_type => type,
101
+ :data => data,
102
+ :ttl => ttl
92
103
  )
93
104
  end
94
105
  host
@@ -6,7 +6,7 @@ describe "Zerigo::DNS::Host.update_or_create" do
6
6
  Zerigo::DNS::Host.stub!(:find).and_return([])
7
7
  Zerigo::DNS::Host.stub!(:create).and_return(:success => true)
8
8
 
9
- Zerigo::DNS::Host.update_or_create(1, 'www', 'A', '10.10.10.10')[:success].should be_true
9
+ Zerigo::DNS::Host.update_or_create(1, 'www', 'A', '10.10.10.10', 86400)[:success].should be_true
10
10
  end
11
11
 
12
12
  it 'should update host' do
@@ -20,8 +20,13 @@ describe "Zerigo::DNS::Host.update_or_create" do
20
20
  Zerigo::DNS::Host.stub!(:find).and_return([jackhq])
21
21
  Zerigo::DNS::Host.stub!(:create).and_return(:success => false)
22
22
 
23
- Zerigo::DNS::Host.update_or_create(1, 'www', 'A', '10.10.10.10').hostname == 'www'
23
+ Zerigo::DNS::Host.update_or_create(1, 'www', 'A', '10.10.10.10', 86499).hostname == 'www'
24
+ end
25
+
26
+ it 'should find by zone and host' do
27
+ jackhq = mock('Zerigo::DNS::Host')
28
+ jackhq.stub!(:hostname).and_return('www')
29
+ Zerigo::DNS::Host.stub!(:find).and_return([jackhq])
30
+ Zerigo::DNS::Host.find_by_hostname(1, 'www').hostname == 'www'
24
31
  end
25
-
26
-
27
32
  end
@@ -18,6 +18,15 @@ describe "Zerigo::DNS::Zone.find_or_create" do
18
18
 
19
19
  Zerigo::DNS::Zone.find_or_create('example.com').domain == 'example.com'
20
20
  end
21
+
22
+ it 'should find zone by domain' do
23
+ jackhq = mock('Zerigo::DNS::Zone')
24
+ jackhq.stub!(:domain).and_return('example.com')
25
+
26
+ Zerigo::DNS::Zone.stub!(:find).and_return([jackhq])
27
+
28
+ Zerigo::DNS::Zone.find_by_domain('example.com').domain == 'example.com'
29
+ end
21
30
 
22
31
 
23
32
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zerigo_dns
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Wilson