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
fbbff2db
Commit
fbbff2db
authored
Apr 11, 2011
by
John E. Vincent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
finishing tags. writing specs for ruby tag API
parent
3110020f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
0 deletions
+61
-0
tags.rb
lib/noah/models/tags.rb
+2
-0
tag_spec.rb
spec/tag_spec.rb
+59
-0
No files found.
lib/noah/models/tags.rb
View file @
fbbff2db
...
...
@@ -2,6 +2,7 @@ module Noah
class
Tag
<
Model
attribute
:name
attribute
:members
index
:members
index
:name
def
validate
...
...
@@ -12,6 +13,7 @@ module Noah
def
members
=
(
member
)
self
.
key
[
:members
].
sadd
(
member
.
key
)
member
.
tag!
self
.
name
unless
member
.
tags
.
member?
(
self
)
end
def
members
...
...
spec/tag_spec.rb
0 → 100644
View file @
fbbff2db
require
File
.
expand_path
(
File
.
dirname
(
__FILE__
)
+
'/spec_helper'
)
describe
"Using the Tag Model"
,
:reset_redis
=>
true
do
before
(
:each
)
do
Ohm
.
redis
.
flushdb
@tags1
=
[
"production"
,
"databases"
,
"in-service"
]
@tags2
=
"out-of-service"
@host
=
Noah
::
Host
.
create
(
:name
=>
'tagged_host'
,
:status
=>
'up'
)
@service
=
Noah
::
Service
.
create
(
:name
=>
'tagged_service'
,
:status
=>
'down'
,
:host_id
=>
@host
.
id
)
@application
=
Noah
::
Application
.
create
(
:name
=>
'tagged_application'
)
@configuration
=
Noah
::
Configuration
.
create
(
:name
=>
'tagged_configuration'
)
@ephemeral
=
Noah
::
Ephemeral
.
create
(
:path
=>
'/tagged/ephemeral'
)
end
after
(
:each
)
do
Ohm
.
redis
.
flushdb
end
describe
"should"
do
it
"create a new Noah::Tag"
do
t
=
Noah
::
Tag
.
new
(
:name
=>
'some_tag'
)
t
.
valid?
.
should
==
true
t
.
save
t
.
is_new?
.
should
==
true
b
=
Noah
::
Tag
.
find
(
:name
=>
'some_tag'
).
first
b
.
should
==
t
end
it
"create a new Noah::Tag and add a member"
do
t
=
Noah
::
Tag
.
create
(
:name
=>
'some_tag'
)
t
.
members
=
@host
@host
.
tags
.
member?
(
t
).
should
==
true
t
.
members
[
:hosts
].
size
.
should
==
1
t
.
members
[
:hosts
].
member?
(
@host
.
name
).
should
==
true
end
it
"tag! an existing object with a single tag"
do
@host
.
tag!
@tags2
t
=
Noah
::
Tag
.
find
(
:name
=>
@tags2
).
first
@host
.
tags
.
member?
(
t
).
should
==
true
t
.
members
[
:hosts
].
size
.
should
==
1
t
.
members
[
:hosts
].
member?
(
@host
.
name
).
should
==
true
end
it
"tag! an existing object with an array of tags"
do
@host
.
tag!
@tags1
@tags1
.
each
do
|
tag
|
t
=
Noah
::
Tag
.
find
(
:name
=>
tag
).
first
@host
.
tags
.
member?
(
t
).
should
==
true
t
.
members
[
:hosts
].
size
.
should
==
1
t
.
members
[
:hosts
].
member?
(
@host
.
name
).
should
==
true
end
Noah
::
Tag
.
all
.
size
.
should
==
3
end
end
describe
"should not"
do
it
"should not create a new Noah::Tag without a name"
do
a
=
Noah
::
Tag
.
create
a
.
valid?
.
should
==
false
a
.
errors
.
should
==
[[
:name
,
:not_present
]]
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