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
140f5211
Commit
140f5211
authored
Mar 19, 2011
by
John E. Vincent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reserving paths in epehemerals
parent
41913163
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
54 additions
and
4 deletions
+54
-4
noah.rb
lib/noah.rb
+1
-1
helpers.rb
lib/noah/helpers.rb
+1
-0
ephemerals.rb
lib/noah/models/ephemerals.rb
+2
-0
watchers.rb
lib/noah/models/watchers.rb
+1
-3
validations.rb
lib/noah/validations.rb
+1
-0
ephemeral_validations.rb
lib/noah/validations/ephemeral_validations.rb
+20
-0
ephemeral_spec.rb
spec/ephemeral_spec.rb
+13
-0
noahapp_ephemeral_spec.rb
spec/noahapp_ephemeral_spec.rb
+15
-0
No files found.
lib/noah.rb
View file @
140f5211
module
Noah
PROTECTED_PATHS
=
%w[applications configurations hosts services watches]
PROTECTED_PATHS
=
%w[applications configurations hosts services watches
ark noah
]
end
begin
require
'yajl'
...
...
lib/noah/helpers.rb
View file @
140f5211
...
...
@@ -22,6 +22,7 @@ module Noah
# Custom exceptions
e
.
on
[
:pattern
,
:already_provided
],
"Pattern is already provided"
e
.
on
[
:pattern
,
:replaces_existing
],
"Pattern would overwrite existing"
e
.
on
[
:path
,
:reserved_path
],
"Path is reserved"
end
error_messages
.
first
end
...
...
lib/noah/models/ephemerals.rb
View file @
140f5211
module
Noah
class
Ephemeral
<
Model
include
EphemeralValidations
attribute
:path
attribute
:data
...
...
@@ -11,6 +12,7 @@ module Noah
super
assert_present
:path
assert_unique
:path
assert_not_reserved
end
def
name
...
...
lib/noah/models/watchers.rb
View file @
140f5211
require
'digest/sha1'
module
Noah
class
Watcher
<
Model
#NYI
# Don't trust anything in here yet
# I'm still trying a few things
class
Watcher
<
Model
include
WatcherValidations
attribute
:pattern
...
...
lib/noah/validations.rb
View file @
140f5211
require
File
.
join
(
File
.
dirname
(
__FILE__
),
'validations'
,
'watcher_validations'
)
require
File
.
join
(
File
.
dirname
(
__FILE__
),
'validations'
,
'ephemeral_validations'
)
lib/noah/validations/ephemeral_validations.rb
0 → 100644
View file @
140f5211
module
Noah
module
EphemeralValidations
def
assert_not_reserved
(
error
=
[
:path
,
:reserved_path
])
# This is to work around how Ohm evaluates validations
# Allows assert_present :path to override
return
if
self
.
path
.
nil?
# This is the real test
self
.
instance_of?
(
Noah
::
Ephemeral
)
?
(
assert
valid_path?
,
error
)
:
(
assert
false
,
"Validation not applicable"
)
end
private
def
valid_path?
PROTECTED_PATHS
.
member?
(
self
.
path
.
split
(
"/"
)[
1
])
?
(
return
false
)
:
(
return
true
)
rescue
ArgumentError
return
false
end
end
end
spec/ephemeral_spec.rb
View file @
140f5211
...
...
@@ -42,6 +42,12 @@ describe "Using the Ephemeral Model", :reset_redis => true do
@good_ephemeral
.
delete
Noah
::
Ephemeral
[
@good_ephemeral
.
id
].
should
==
nil
end
it
"should allow reserved keywords as subpaths"
do
Noah
::
PROTECTED_PATHS
.
each
do
|
path
|
e
=
Noah
::
Ephemeral
.
new
:path
=>
"/this/should/be/
#{
path
}
"
e
.
valid?
.
should
==
true
end
end
end
describe
"should not"
do
it
"create a new Noah::Ephemeral with missing path"
do
...
...
@@ -55,5 +61,12 @@ describe "Using the Ephemeral Model", :reset_redis => true do
f
.
valid?
.
should
==
false
f
.
errors
.
should
==
[[
:path
,
:not_unique
]]
end
it
"allow a reserved keyword as a path"
do
Noah
::
PROTECTED_PATHS
.
each
do
|
path
|
e
=
Noah
::
Ephemeral
.
new
:path
=>
"/
#{
path
}
"
e
.
valid?
.
should
==
false
e
.
errors
.
should
==
[[
:path
,
:reserved_path
]]
end
end
end
end
spec/noahapp_ephemeral_spec.rb
View file @
140f5211
...
...
@@ -87,6 +87,21 @@ describe "Using the Ephemeral API", :reset_redis => true do
last_response
.
should
be_ok
last_response
.
body
.
should
==
'a new value'
end
it
"ephemeral with reserved word in subpath should work"
do
Noah
::
PROTECTED_PATHS
.
each
do
|
path
|
put
"/e/a/valid/path/with/
#{
path
}
"
last_response
.
should
be_ok
end
end
it
"ephemeral with reserved word as path should not work"
do
Noah
::
PROTECTED_PATHS
.
each
do
|
path
|
put
"/e/
#{
path
}
/other/stuff"
last_response
.
should_not
be_ok
response
=
last_response
.
should
return_json
response
[
'error_message'
].
should
==
'Path is reserved'
response
[
'result'
].
should
==
'failure'
end
end
end
describe
"DELETE"
do
...
...
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