Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
Noah
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Noah
Commits
bad01f0d
Commit
bad01f0d
authored
Jan 31, 2011
by
John E. Vincent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
quick cleanup of test structure
parent
9fc817d8
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
733 additions
and
709 deletions
+733
-709
index.html
doc/coverage/index.html
+38
-38
lib-helpers_rb.html
doc/coverage/lib-helpers_rb.html
+6
-6
lib-models_rb.html
doc/coverage/lib-models_rb.html
+280
-274
noah_rb.html
doc/coverage/noah_rb.html
+210
-204
host_spec.rb
spec/host_spec.rb
+103
-99
service_spec.rb
spec/service_spec.rb
+96
-88
No files found.
doc/coverage/index.html
View file @
bad01f0d
...
...
@@ -48,46 +48,30 @@
<tfoot>
<tr>
<td
class=
"left_align"
>
TOTAL
</td>
<td
class=
'right_align'
><tt>
61
0
</tt></td>
<td
class=
'right_align'
><tt>
5
18
</tt></td>
<td
class=
"left_align"
><div
class=
"percent_graph_legend"
><tt
class=
''
>
55.25
%
</tt></div>
<td
class=
'right_align'
><tt>
61
2
</tt></td>
<td
class=
'right_align'
><tt>
5
21
</tt></td>
<td
class=
"left_align"
><div
class=
"percent_graph_legend"
><tt
class=
''
>
83.33
%
</tt></div>
<div
class=
"percent_graph"
>
<div
class=
"covered"
style=
"width:
55
px"
></div>
<div
class=
"uncovered"
style=
"width:
45
px"
></div>
<div
class=
"covered"
style=
"width:
83
px"
></div>
<div
class=
"uncovered"
style=
"width:
17
px"
></div>
</div></td>
<td
class=
"left_align"
><div
class=
"percent_graph_legend"
><tt
class=
'coverage_total'
>
50.58
%
</tt></div>
<td
class=
"left_align"
><div
class=
"percent_graph_legend"
><tt
class=
'coverage_total'
>
81.96
%
</tt></div>
<div
class=
"percent_graph"
>
<div
class=
"covered"
style=
"width:
51
px"
></div>
<div
class=
"uncovered"
style=
"width:
49
px"
></div>
<div
class=
"covered"
style=
"width:
82
px"
></div>
<div
class=
"uncovered"
style=
"width:
18
px"
></div>
</div></td>
</tr>
</tfoot>
<tbody>
<tr
class=
"all_files all_coverage 50 60 70 80 90 100 even"
>
<td
class=
"left_align"
><a
href=
"noah_rb.html"
>
noah.rb
</a></td>
<td
class=
'right_align'
><tt>
325
</tt></td>
<td
class=
'right_align'
><tt>
283
</tt></td>
<td
class=
"left_align"
><div
class=
"percent_graph_legend"
><tt
class=
''
>
48.31%
</tt></div>
<div
class=
"percent_graph"
>
<div
class=
"covered"
style=
"width:48px"
></div>
<div
class=
"uncovered"
style=
"width:52px"
></div>
</div></td>
<td
class=
"left_align"
><div
class=
"percent_graph_legend"
><tt
class=
''
>
42.40%
</tt></div>
<div
class=
"percent_graph"
>
<div
class=
"covered"
style=
"width:42px"
></div>
<div
class=
"uncovered"
style=
"width:58px"
></div>
</div></td>
</tr>
<tr
class=
"all_files all_coverage 60 70 80 90 100 lib odd"
>
<tr
class=
"all_files all_coverage 60 70 80 90 100 lib even"
>
<td
class=
"left_align"
><a
href=
"lib-helpers_rb.html"
>
lib/helpers.rb
</a></td>
<td
class=
'right_align'
><tt>
55
</tt></td>
<td
class=
'right_align'
><tt>
45
</tt></td>
<td
class=
"left_align"
><div
class=
"percent_graph_legend"
><tt
class=
''
>
5
4.55
%
</tt></div>
<td
class=
"left_align"
><div
class=
"percent_graph_legend"
><tt
class=
''
>
5
6.36
%
</tt></div>
<div
class=
"percent_graph"
>
<div
class=
"covered"
style=
"width:5
5
px"
></div>
<div
class=
"uncovered"
style=
"width:4
5
px"
></div>
<div
class=
"covered"
style=
"width:5
6
px"
></div>
<div
class=
"uncovered"
style=
"width:4
4
px"
></div>
</div></td>
<td
class=
"left_align"
><div
class=
"percent_graph_legend"
><tt
class=
''
>
57.78%
</tt></div>
<div
class=
"percent_graph"
>
...
...
@@ -96,19 +80,35 @@
</div></td>
</tr>
<tr
class=
"all_files all_coverage 70 80 90 100 lib even"
>
<tr
class=
"all_files all_coverage 90 100 odd"
>
<td
class=
"left_align"
><a
href=
"noah_rb.html"
>
noah.rb
</a></td>
<td
class=
'right_align'
><tt>
326
</tt></td>
<td
class=
'right_align'
><tt>
285
</tt></td>
<td
class=
"left_align"
><div
class=
"percent_graph_legend"
><tt
class=
''
>
82.52%
</tt></div>
<div
class=
"percent_graph"
>
<div
class=
"covered"
style=
"width:83px"
></div>
<div
class=
"uncovered"
style=
"width:17px"
></div>
</div></td>
<td
class=
"left_align"
><div
class=
"percent_graph_legend"
><tt
class=
''
>
81.05%
</tt></div>
<div
class=
"percent_graph"
>
<div
class=
"covered"
style=
"width:81px"
></div>
<div
class=
"uncovered"
style=
"width:19px"
></div>
</div></td>
</tr>
<tr
class=
"all_files all_coverage 90 100 lib even"
>
<td
class=
"left_align"
><a
href=
"lib-models_rb.html"
>
lib/models.rb
</a></td>
<td
class=
'right_align'
><tt>
23
0
</tt></td>
<td
class=
'right_align'
><tt>
19
0
</tt></td>
<td
class=
"left_align"
><div
class=
"percent_graph_legend"
><tt
class=
''
>
65.22
%
</tt></div>
<td
class=
'right_align'
><tt>
23
1
</tt></td>
<td
class=
'right_align'
><tt>
19
1
</tt></td>
<td
class=
"left_align"
><div
class=
"percent_graph_legend"
><tt
class=
''
>
90.91
%
</tt></div>
<div
class=
"percent_graph"
>
<div
class=
"covered"
style=
"width:
65
px"
></div>
<div
class=
"uncovered"
style=
"width:
35
px"
></div>
<div
class=
"covered"
style=
"width:
91
px"
></div>
<div
class=
"uncovered"
style=
"width:
9
px"
></div>
</div></td>
<td
class=
"left_align"
><div
class=
"percent_graph_legend"
><tt
class=
''
>
61.05
%
</tt></div>
<td
class=
"left_align"
><div
class=
"percent_graph_legend"
><tt
class=
''
>
89.01
%
</tt></div>
<div
class=
"percent_graph"
>
<div
class=
"covered"
style=
"width:
61
px"
></div>
<div
class=
"uncovered"
style=
"width:
39
px"
></div>
<div
class=
"covered"
style=
"width:
89
px"
></div>
<div
class=
"uncovered"
style=
"width:
11
px"
></div>
</div></td>
</tr>
...
...
@@ -116,7 +116,7 @@
</table>
</div>
<p>
Generated on 2011-01-
27 21:32:1
2 -0500 with
<a
href=
"http://github.com/relevance/rcov"
>
rcov 0.9.8
</a></p>
<p>
Generated on 2011-01-
31 05:03:3
2 -0500 with
<a
href=
"http://github.com/relevance/rcov"
>
rcov 0.9.8
</a></p>
<script
type=
"text/javascript"
>
$
(
document
).
ready
(
function
(){
$
(
"
#report_table
"
).
tablesorter
({
widgets
:
[
'
zebra
'
],
textExtraction
:
'
complex
'
});});
...
...
doc/coverage/lib-helpers_rb.html
View file @
bad01f0d
...
...
@@ -30,10 +30,10 @@
<td
class=
"left_align"
><a
href=
"lib-helpers_rb.html"
>
lib/helpers.rb
</a></td>
<td
class=
'right_align'
><tt>
55
</tt></td>
<td
class=
'right_align'
><tt>
45
</tt></td>
<td
class=
"left_align"
><div
class=
"percent_graph_legend"
><tt
class=
''
>
5
4.55
%
</tt></div>
<td
class=
"left_align"
><div
class=
"percent_graph_legend"
><tt
class=
''
>
5
6.36
%
</tt></div>
<div
class=
"percent_graph"
>
<div
class=
"covered"
style=
"width:5
5
px"
></div>
<div
class=
"uncovered"
style=
"width:4
5
px"
></div>
<div
class=
"covered"
style=
"width:5
6
px"
></div>
<div
class=
"uncovered"
style=
"width:4
4
px"
></div>
</div></td>
<td
class=
"left_align"
><div
class=
"percent_graph_legend"
><tt
class=
''
>
57.78%
</tt></div>
<div
class=
"percent_graph"
>
...
...
@@ -158,13 +158,13 @@
<tr
class=
"
inferr
ed"
>
<tr
class=
"
mark
ed"
>
<td><pre><a
name=
"line18"
>
18
</a>
end
</pre></td>
</tr>
<tr
class=
"
uncover
ed"
>
<tr
class=
"
mark
ed"
>
<td><pre><a
name=
"line19"
>
19
</a>
</pre></td>
</tr>
...
...
@@ -387,7 +387,7 @@
</tbody>
</table>
<p>
Generated on 2011-01-
27 21:32:1
2 -0500 with
<a
href=
"http://github.com/relevance/rcov"
>
rcov 0.9.8
</a></p>
<p>
Generated on 2011-01-
31 05:03:3
2 -0500 with
<a
href=
"http://github.com/relevance/rcov"
>
rcov 0.9.8
</a></p>
</body>
</html>
doc/coverage/lib-models_rb.html
View file @
bad01f0d
This diff is collapsed.
Click to expand it.
doc/coverage/noah_rb.html
View file @
bad01f0d
This diff is collapsed.
Click to expand it.
spec/host_spec.rb
View file @
bad01f0d
require
File
.
expand_path
(
File
.
dirname
(
__FILE__
)
+
'/spec_helper'
)
describe
"
Noah
Host Model"
,
:reset_redis
=>
true
do
describe
"
Using the
Host Model"
,
:reset_redis
=>
true
do
it
"should create a new Host with no services"
do
hostname
=
"host1.domain.com"
hoststatus
=
"up"
host
=
Host
.
create
(
:name
=>
hostname
,
:status
=>
hoststatus
)
host
.
valid?
.
should
==
true
host
.
save
host
.
name
.
should
==
hostname
host
.
status
.
should
==
hoststatus
host
.
services
.
size
.
should
==
0
end
describe
"should"
do
it
"create a new Host with no services"
do
hostname
=
"host1.domain.com"
hoststatus
=
"up"
host
=
Host
.
create
(
:name
=>
hostname
,
:status
=>
hoststatus
)
host
.
valid?
.
should
==
true
host
.
save
host
.
name
.
should
==
hostname
host
.
status
.
should
==
hoststatus
host
.
services
.
size
.
should
==
0
end
it
"should
create a new Host with services"
do
hostname
=
"host2.domain.com"
hoststatus
=
"down"
servicename
=
'myservice'
servicestatus
=
'pending'
host
=
Host
.
create
(
:name
=>
hostname
,
:status
=>
hoststatus
)
host
.
valid?
.
should
==
true
host
.
save
host
.
services
<<
Service
.
create
(
:name
=>
servicename
,
:status
=>
servicestatus
,
:host
=>
host
)
host
.
name
.
should
==
hostname
host
.
status
.
should
==
hoststatus
host
.
services
.
size
.
should
==
1
host
.
services
[
1
].
valid?
.
should
==
true
host
.
services
[
1
].
name
.
should
==
servicename
host
.
services
[
1
].
status
.
should
==
servicestatus
host
.
services
[
1
].
host_id
.
should
==
host
.
id
end
it
"
create a new Host with services"
do
hostname
=
"host2.domain.com"
hoststatus
=
"down"
servicename
=
'myservice'
servicestatus
=
'pending'
host
=
Host
.
create
(
:name
=>
hostname
,
:status
=>
hoststatus
)
host
.
valid?
.
should
==
true
host
.
save
host
.
services
<<
Service
.
create
(
:name
=>
servicename
,
:status
=>
servicestatus
,
:host
=>
host
)
host
.
name
.
should
==
hostname
host
.
status
.
should
==
hoststatus
host
.
services
.
size
.
should
==
1
host
.
services
[
1
].
valid?
.
should
==
true
host
.
services
[
1
].
name
.
should
==
servicename
host
.
services
[
1
].
status
.
should
==
servicestatus
host
.
services
[
1
].
host_id
.
should
==
host
.
id
end
it
"should
create a Host via find_or_create"
do
hostname
=
"host3.domain.com"
hoststatus
=
"up"
host
=
Host
.
find_or_create
(
:name
=>
hostname
,
:status
=>
hoststatus
)
host
.
valid?
.
should
==
true
host
.
save
host
.
is_new?
.
should
==
true
end
it
"
create a Host via find_or_create"
do
hostname
=
"host3.domain.com"
hoststatus
=
"up"
host
=
Host
.
find_or_create
(
:name
=>
hostname
,
:status
=>
hoststatus
)
host
.
valid?
.
should
==
true
host
.
save
host
.
is_new?
.
should
==
true
end
it
"should
update a Host via find_or_create"
do
hostname
=
"host3.domain.com"
hoststatus
=
"pending"
newstatus
=
"down"
host
=
Host
.
find_or_create
(
:name
=>
hostname
,
:status
=>
hoststatus
)
host
.
valid?
.
should
==
true
host
.
save
host
.
is_new?
.
should
==
true
sleep
1
host1
=
Host
.
find_or_create
(
:name
=>
hostname
,
:status
=>
newstatus
)
host1
.
save
host1
.
is_new?
.
should
==
false
end
it
"
update a Host via find_or_create"
do
hostname
=
"host3.domain.com"
hoststatus
=
"pending"
newstatus
=
"down"
host
=
Host
.
find_or_create
(
:name
=>
hostname
,
:status
=>
hoststatus
)
host
.
valid?
.
should
==
true
host
.
save
host
.
is_new?
.
should
==
true
sleep
1
host1
=
Host
.
find_or_create
(
:name
=>
hostname
,
:status
=>
newstatus
)
host1
.
save
host1
.
is_new?
.
should
==
false
end
it
"should
delete a Host"
do
hostname
=
"host3.domain.com"
hoststatus
=
"pending"
host
=
Host
.
create
(
:name
=>
hostname
,
:status
=>
hoststatus
)
host
.
save
host
.
delete
Host
.
find
(
:name
=>
hostname
).
empty?
.
should
==
true
end
it
"
delete a Host"
do
hostname
=
"host3.domain.com"
hoststatus
=
"pending"
host
=
Host
.
create
(
:name
=>
hostname
,
:status
=>
hoststatus
)
host
.
save
host
.
delete
Host
.
find
(
:name
=>
hostname
).
empty?
.
should
==
true
end
it
"should not create a new Host with missing status"
do
hostname
=
"host3.domain.com"
host
=
Host
.
create
(
:name
=>
hostname
)
host
.
valid?
.
should
==
false
host
.
errors
.
should
==
[[
:status
,
:not_present
],
[
:status
,
:not_member
]]
it
"should return all Hosts"
do
hostname1
=
"host1.domain.com"
status1
=
"up"
hostname2
=
"host2.domain.com"
status2
=
"down"
host1
=
Host
.
create
(
:name
=>
hostname1
,
:status
=>
status1
)
host2
=
Host
.
create
(
:name
=>
hostname2
,
:status
=>
status2
)
host1
.
save
host2
.
save
Hosts
.
all
.
class
.
should
==
Array
Hosts
.
all
.
size
.
should
==
2
Hosts
.
all
.
first
.
name
.
should
==
hostname1
Hosts
.
all
.
first
.
status
.
should
==
status1
Hosts
.
all
.
last
.
name
.
should
==
hostname2
Hosts
.
all
.
last
.
status
.
should
==
status2
end
end
it
"should not create a new Host with missing hostname"
do
status
=
"up"
host
=
Host
.
create
(
:status
=>
status
)
host
.
valid?
.
should
==
false
host
.
errors
.
should
==
[[
:name
,
:not_present
]]
end
describe
"should not"
do
it
"create a new Host with missing status"
do
hostname
=
"host3.domain.com"
host
=
Host
.
create
(
:name
=>
hostname
)
host
.
valid?
.
should
==
false
host
.
errors
.
should
==
[[
:status
,
:not_present
],
[
:status
,
:not_member
]]
end
it
"should not create a new Host with an invalid status"
do
hostname
=
"host3.domain.com"
status
=
"online"
host
=
Host
.
create
(
:name
=>
hostname
,
:status
=>
status
)
host
.
valid?
.
should
==
false
host
.
errors
.
should
==
[[
:status
,
:not_member
]]
end
it
"create a new Host with missing hostname"
do
status
=
"up"
host
=
Host
.
create
(
:status
=>
status
)
host
.
valid?
.
should
==
false
host
.
errors
.
should
==
[[
:name
,
:not_present
]]
end
it
"should not create a duplicate Host"
do
hostname
=
"host1.domain.com"
status
=
"up"
host1
=
Host
.
create
(
:name
=>
hostname
,
:status
=>
status
)
host1
.
save
host2
=
Host
.
create
(
:name
=>
hostname
,
:status
=>
status
)
host2
.
valid?
.
should
==
false
host2
.
errors
.
should
==
[[
:name
,
:not_unique
]]
end
it
"create a new Host with an invalid status"
do
hostname
=
"host3.domain.com"
status
=
"online"
host
=
Host
.
create
(
:name
=>
hostname
,
:status
=>
status
)
host
.
valid?
.
should
==
false
host
.
errors
.
should
==
[[
:status
,
:not_member
]]
end
it
"should return all Hosts"
do
hostname1
=
"host1.domain.com"
status1
=
"up"
hostname2
=
"host2.domain.com"
status2
=
"down"
host1
=
Host
.
create
(
:name
=>
hostname1
,
:status
=>
status1
)
host2
=
Host
.
create
(
:name
=>
hostname2
,
:status
=>
status2
)
host1
.
save
host2
.
save
Hosts
.
all
.
class
.
should
==
Array
Hosts
.
all
.
size
.
should
==
2
Hosts
.
all
.
first
.
name
.
should
==
hostname1
Hosts
.
all
.
first
.
status
.
should
==
status1
Hosts
.
all
.
last
.
name
.
should
==
hostname2
Hosts
.
all
.
last
.
status
.
should
==
status2
it
"create a duplicate Host"
do
hostname
=
"host1.domain.com"
status
=
"up"
host1
=
Host
.
create
(
:name
=>
hostname
,
:status
=>
status
)
host1
.
save
host2
=
Host
.
create
(
:name
=>
hostname
,
:status
=>
status
)
host2
.
valid?
.
should
==
false
host2
.
errors
.
should
==
[[
:name
,
:not_unique
]]
end
end
end
spec/service_spec.rb
View file @
bad01f0d
require
File
.
expand_path
(
File
.
dirname
(
__FILE__
)
+
'/spec_helper'
)
describe
"Noah Service Model"
,
:reset_redis
=>
true
do
describe
"should"
do
it
"should
create a new Service"
do
servicename
=
"myservice"
servicestatus
=
"up"
hostname
=
"mytesthost1"
hoststatus
=
"up"
host
=
Host
.
create
(
:name
=>
hostname
,
:status
=>
hoststatus
)
host
.
save
service
=
Service
.
create
(
:name
=>
servicename
,
:status
=>
servicestatus
,
:host
=>
host
)
service
.
valid?
.
should
==
true
service
.
save
service
.
name
.
should
==
servicename
service
.
status
.
should
==
servicestatus
service
.
host_id
.
should
==
host
.
id
host
.
services
[
1
].
name
.
should
==
servicename
end
it
"
create a new Service"
do
servicename
=
"myservice"
servicestatus
=
"up"
hostname
=
"mytesthost1"
hoststatus
=
"up"
host
=
Host
.
create
(
:name
=>
hostname
,
:status
=>
hoststatus
)
host
.
save
service
=
Service
.
create
(
:name
=>
servicename
,
:status
=>
servicestatus
,
:host
=>
host
)
service
.
valid?
.
should
==
true
service
.
save
service
.
name
.
should
==
servicename
service
.
status
.
should
==
servicestatus
service
.
host_id
.
should
==
host
.
id
host
.
services
[
1
].
name
.
should
==
servicename
end
it
"should not create a new Service when missing a Host
"
do
servicename
=
"myservice1"
servicestatus
=
"up"
service
=
Service
.
create
(
:name
=>
servicename
,
:status
=>
servicestatus
)
service
.
valid?
.
should
==
fals
e
service
.
errors
.
should
==
[[
:host_id
,
:not_present
]]
end
it
"create a new Service with find_or_create
"
do
host
=
Host
.
create
(
:name
=>
"h1"
,
:status
=>
"up"
)
host
.
save
service
=
Service
.
find_or_create
(
:name
=>
"s1"
,
:status
=>
"up"
,
:host
=>
host
)
service
.
sav
e
service
.
is_new?
.
should
==
true
end
it
"should not create a new Service when missing a name"
do
host
=
Host
.
create
(
:name
=>
"host1.domain.com"
,
:status
=>
"up"
)
host
.
save
service
=
Service
.
create
(
:status
=>
"up"
,
:host
=>
host
)
service
.
valid?
.
should
==
false
service
.
errors
.
should
==
[[
:name
,
:not_present
]]
end
it
"update an existing Service with find_or_create"
do
host
=
Host
.
create
(
:name
=>
"h2"
,
:status
=>
"up"
)
host
.
save
service
=
Service
.
find_or_create
(
:name
=>
"s2"
,
:status
=>
"up"
,
:host
=>
host
)
service
.
save
sleep
1
service2
=
Service
.
find_or_create
(
:name
=>
"s2"
,
:status
=>
"up"
,
:host
=>
host
)
service2
.
save
service2
.
is_new?
.
should
==
false
end
it
"should not create a new Service when missing a status"
do
host
=
Host
.
create
(
:name
=>
"host1.domain.com"
,
:status
=>
"up"
)
host
.
save
service
=
Service
.
create
(
:name
=>
'foo'
,
:host
=>
host
)
service
.
valid?
.
should
==
false
service
.
errors
.
should
==
[[
:status
,
:not_present
],
[
:status
,
:not_member
]]
end
it
"delete a Service"
do
h
=
Host
.
create
(
:name
=>
"h1"
,
:status
=>
"up"
)
h
.
save
s
=
Service
.
create
(
:name
=>
"s1"
,
:status
=>
"up"
,
:host
=>
h
)
s
.
save
s
=
Service
.
find
(
:name
=>
"s1"
).
first
s
.
delete
s
=
Service
.
find
(
:name
=>
"s1"
).
first
s
.
should
==
nil
end
it
"should not create a new Service with an invalid status"
do
host
=
Host
.
create
(
:name
=>
"host1.domain.com"
,
:status
=>
"up"
)
host
.
save
service
=
Service
.
create
(
:name
=>
"myservice"
,
:status
=>
"invalid_status"
,
:host
=>
host
)
service
.
valid?
.
should
==
false
service
.
errors
.
should
==
[[
:status
,
:not_member
]]
end
it
"find multiple Services"
do
h
=
Host
.
create
(
:name
=>
"h1"
,
:status
=>
"up"
)
if
h
.
valid?
h
.
services
<<
Service
.
create
(
:name
=>
"s1"
,
:status
=>
"up"
,
:host
=>
h
)
h
.
services
<<
Service
.
create
(
:name
=>
"s2"
,
:status
=>
"up"
,
:host
=>
h
)
h
.
save
end
Services
.
all
.
size
.
should
==
2
Services
.
all
.
first
.
name
.
should
==
"s1"
Services
.
all
.
last
.
name
.
should
==
"s2"
end
it
"should not create a duplicate Service"
do
host
=
Host
.
create
(
:name
=>
"host1.domain.com"
,
:status
=>
"up"
)
host
.
save
s
=
Service
.
create
(
:name
=>
"myservice"
,
:status
=>
"up"
,
:host
=>
host
)
s
.
save
s1
=
Service
.
create
(
:name
=>
"myservice"
,
:status
=>
"up"
,
:host
=>
host
)
s1
.
valid?
.
should
==
false
s1
.
errors
.
should
==
[[[
:name
,
:host_id
],
:not_unique
]]
end
it
"should create a new Service with find_or_create"
do
host
=
Host
.
create
(
:name
=>
"h1"
,
:status
=>
"up"
)
host
.
save
service
=
Service
.
find_or_create
(
:name
=>
"s1"
,
:status
=>
"up"
,
:host
=>
host
)
service
.
save
service
.
is_new?
.
should
==
true
end
describe
"should not"
do
it
"should update an existing Service with find_or_create"
do
host
=
Host
.
create
(
:name
=>
"h2"
,
:status
=>
"up"
)
host
.
save
service
=
Service
.
find_or_create
(
:name
=>
"s2"
,
:status
=>
"up"
,
:host
=>
host
)
service
.
save
sleep
1
service2
=
Service
.
find_or_create
(
:name
=>
"s2"
,
:status
=>
"up"
,
:host
=>
host
)
service2
.
save
service2
.
is_new?
.
should
==
false
end
it
"create a new Service when missing a Host"
do
servicename
=
"myservice1"
servicestatus
=
"up"
service
=
Service
.
create
(
:name
=>
servicename
,
:status
=>
servicestatus
)
service
.
valid?
.
should
==
false
service
.
errors
.
should
==
[[
:host_id
,
:not_present
]]
end
it
"should delete a Service"
do
h
=
Host
.
create
(
:name
=>
"h1"
,
:status
=>
"up"
)
h
.
save
s
=
Service
.
create
(
:name
=>
"s1"
,
:status
=>
"up"
,
:host
=>
h
)
s
.
save
s
=
Service
.
find
(
:name
=>
"s1"
).
first
s
.
delete
s
=
Service
.
find
(
:name
=>
"s1"
).
first
s
.
should
==
nil
end
it
"create a new Service when missing a name"
do
host
=
Host
.
create
(
:name
=>
"host1.domain.com"
,
:status
=>
"up"
)
host
.
save
service
=
Service
.
create
(
:status
=>
"up"
,
:host
=>
host
)
service
.
valid?
.
should
==
false
service
.
errors
.
should
==
[[
:name
,
:not_present
]]
end
it
"should find multiple Services"
do
h
=
Host
.
create
(
:name
=>
"h1"
,
:status
=>
"up"
)
if
h
.
valid?
h
.
services
<<
Service
.
create
(
:name
=>
"s1"
,
:status
=>
"up"
,
:host
=>
h
)
h
.
services
<<
Service
.
create
(
:name
=>
"s2"
,
:status
=>
"up"
,
:host
=>
h
)
h
.
save
it
"create a new Service when missing a status"
do
host
=
Host
.
create
(
:name
=>
"host1.domain.com"
,
:status
=>
"up"
)
host
.
save
service
=
Service
.
create
(
:name
=>
'foo'
,
:host
=>
host
)
service
.
valid?
.
should
==
false
service
.
errors
.
should
==
[[
:status
,
:not_present
],
[
:status
,
:not_member
]]
end
it
"create a new Service with an invalid status"
do
host
=
Host
.
create
(
:name
=>
"host1.domain.com"
,
:status
=>
"up"
)
host
.
save
service
=
Service
.
create
(
:name
=>
"myservice"
,
:status
=>
"invalid_status"
,
:host
=>
host
)
service
.
valid?
.
should
==
false
service
.
errors
.
should
==
[[
:status
,
:not_member
]]
end
Services
.
all
.
size
.
should
==
2
Services
.
all
.
first
.
name
.
should
==
"s1"
Services
.
all
.
last
.
name
.
should
==
"s2"
end
it
"create a duplicate Service"
do
host
=
Host
.
create
(
:name
=>
"host1.domain.com"
,
:status
=>
"up"
)
host
.
save
s
=
Service
.
create
(
:name
=>
"myservice"
,
:status
=>
"up"
,
:host
=>
host
)
s
.
save
s1
=
Service
.
create
(
:name
=>
"myservice"
,
:status
=>
"up"
,
:host
=>
host
)
s1
.
valid?
.
should
==
false
s1
.
errors
.
should
==
[[[
:name
,
:host_id
],
:not_unique
]]
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment