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
38e3fc14
Commit
38e3fc14
authored
May 11, 2011
by
John E. Vincent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adding link spec. fixed bug in link path
parent
64203806
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
89 additions
and
0 deletions
+89
-0
link.rb
lib/noah/models/link.rb
+1
-0
link_spec.rb
spec/link_spec.rb
+88
-0
No files found.
lib/noah/models/link.rb
View file @
38e3fc14
...
...
@@ -30,6 +30,7 @@ module Noah
def
validate
super
assert_present
:path
assert_unique
:path
end
def
to_hash
...
...
spec/link_spec.rb
0 → 100644
View file @
38e3fc14
require
File
.
expand_path
(
File
.
dirname
(
__FILE__
)
+
'/spec_helper'
)
describe
"Using the Link Model"
,
:reset_redis
=>
true
do
before
(
:each
)
do
Ohm
.
redis
.
flushdb
@link
=
"/myorg"
@host
=
Noah
::
Host
.
create
(
:name
=>
'linked_host'
,
:status
=>
'up'
)
@service
=
Noah
::
Service
.
create
(
:name
=>
'linked_service'
,
:status
=>
'down'
,
:host_id
=>
@host
.
id
)
@application
=
Noah
::
Application
.
create
(
:name
=>
"linked_application"
)
@configuration
=
Noah
::
Configuration
.
create
(
:name
=>
"linked_configuration"
,
:format
=>
"string"
,
:body
=>
"some_string"
)
@ephemeral
=
Noah
::
Ephemeral
.
create
(
:path
=>
"/linked/ephemeral"
)
end
after
(
:each
)
do
Ohm
.
redis
.
flushdb
end
describe
"should"
do
it
"create a new Noah::Link"
do
l
=
Noah
::
Link
.
new
(
:path
=>
@link
)
l
.
valid?
.
should
==
true
l
.
save
l
.
is_new?
.
should
==
true
xl
=
Noah
::
Link
.
find
(
:path
=>
@link
).
first
xl
.
should
==
l
end
it
"create a new Noah::Link and add a single member"
do
l
=
Noah
::
Link
.
create
(
:path
=>
@link
)
l
.
nodes
=
@host
@host
.
links
.
member?
(
l
).
should
==
true
@host
.
links
.
size
.
should
==
1
l
.
nodes
.
size
.
should
==
1
l
.
nodes
.
member?
(
@host
.
key
).
should
==
true
end
it
"create a new Noah::Link and add multiple members"
do
l
=
Noah
::
Link
.
create
(
:path
=>
@link
)
l
.
nodes
=
[
@host
,
@service
,
@application
,
@configuration
,
@ephemeral
]
l
.
nodes
.
size
.
should
==
5
[
@host
,
@service
,
@application
,
@configuration
,
@ephemeral
].
each
do
|
node
|
l
.
nodes
.
member?
(
node
.
key
).
should
==
true
node
.
links
.
member?
(
l
).
should
==
true
node
.
links
.
size
.
should
==
1
end
end
it
"link! an existing object to a single link"
do
@host
.
link!
(
@link
)
l
=
Noah
::
Link
.
find
(
:path
=>
@link
).
first
@host
.
links
.
member?
(
l
).
should
==
true
@host
.
links
.
size
.
should
==
1
l
.
nodes
.
member?
(
@host
.
key
).
should
==
true
l
.
nodes
.
size
.
should
==
1
end
it
"return a hash of all nodes"
do
l
=
Noah
::
Link
.
create
(
:path
=>
@link
)
l
.
nodes
=
[
@host
,
@service
,
@application
,
@configuration
,
@ephemeral
]
h
=
l
.
to_hash
h
[
:id
].
should
==
l
.
id
h
[
:name
].
should
==
l
.
name
h
[
:updated_at
].
should
==
l
.
updated_at
h
[
:created_at
].
should
==
l
.
created_at
h
[
:hosts
].
has_key?
(
@host
.
name
).
should
==
true
h
[
:hosts
][
@host
.
name
].
keys
.
sort
.
should
==
[
:id
,
:status
,
:tags
,
:services
].
sort
h
[
:services
].
has_key?
(
@service
.
name
).
should
==
true
h
[
:services
][
@service
.
name
][
@host
.
name
].
keys
.
sort
.
should
==
[
:id
,
:status
,
:tags
].
sort
h
[
:applications
].
has_key?
(
@application
.
name
).
should
==
true
h
[
:applications
][
@application
.
name
].
keys
.
sort
.
should
==
[
:id
,
:tags
,
:configurations
].
sort
h
[
:configurations
].
has_key?
(
@configuration
.
name
).
should
==
true
h
[
:configurations
][
@configuration
.
name
].
keys
.
sort
.
should
==
[
:id
,
:tags
,
:format
,
:body
].
sort
h
[
:ephemerals
].
has_key?
(
@ephemeral
.
name
).
should
==
true
h
[
:ephemerals
][
@ephemeral
.
name
].
keys
.
sort
.
should
==
[
:id
,
:tags
,
:path
,
:data
].
sort
end
end
describe
"should not"
do
it
"create a new Noah::Link without a path"
do
l
=
Noah
::
Link
.
create
l
.
valid?
.
should
==
false
l
.
errors
.
should
==
[[
:path
,
:not_present
]]
end
it
"create a link with a duplicate name"
do
l
=
Noah
::
Link
.
create
(
:path
=>
@link
)
ln
=
Noah
::
Link
.
create
(
:path
=>
@link
)
ln
.
valid?
.
should
==
false
ln
.
errors
.
should
==
[[
:path
,
: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