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
5b7c9c25
Commit
5b7c9c25
authored
Mar 10, 2011
by
John E. Vincent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix specs and such on 1.8.7
parent
4386dac7
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
66 additions
and
37 deletions
+66
-37
application_routes.rb
lib/noah/application_routes.rb
+1
-1
configuration_routes.rb
lib/noah/configuration_routes.rb
+1
-1
ephemeral_routes.rb
lib/noah/ephemeral_routes.rb
+1
-1
helpers.rb
lib/noah/helpers.rb
+25
-0
host_routes.rb
lib/noah/host_routes.rb
+1
-1
service_routes.rb
lib/noah/service_routes.rb
+1
-1
configuration_spec.rb
spec/configuration_spec.rb
+7
-10
ephemeral_spec.rb
spec/ephemeral_spec.rb
+20
-13
noahapp_configuration_spec.rb
spec/noahapp_configuration_spec.rb
+2
-2
noahapp_host_spec.rb
spec/noahapp_host_spec.rb
+1
-1
noahapp_service_spec.rb
spec/noahapp_service_spec.rb
+1
-1
watcher_spec.rb
spec/watcher_spec.rb
+5
-5
No files found.
lib/noah/application_routes.rb
View file @
5b7c9c25
...
...
@@ -41,7 +41,7 @@ class Noah::App
r
=
{
"result"
=>
"success"
,
"id"
=>
app
.
id
,
"action"
=>
action
,
"name"
=>
app
.
name
}
r
.
to_json
else
raise
"
#{
app
.
errors
}
"
raise
"
#{
format_errors
(
app
)
}
"
end
end
...
...
lib/noah/configuration_routes.rb
View file @
5b7c9c25
...
...
@@ -59,7 +59,7 @@ class Noah::App
r
=
{
"result"
=>
"success"
,
"id"
=>
"
#{
config
.
id
}
"
,
"action"
=>
action
,
"dependencies"
=>
dependency_action
,
"application"
=>
app
.
name
,
"item"
=>
config
.
name
}
r
.
to_json
else
raise
"
#{
config
.
errors
}
"
raise
"
#{
format_errors
(
config
)
}
"
end
end
...
...
lib/noah/ephemeral_routes.rb
View file @
5b7c9c25
...
...
@@ -24,7 +24,7 @@ class Noah::App
raise
(
"Data too large"
)
if
request
.
body
.
size
>
512
d
=
Base64
.
encode64
(
request
.
body
.
read
)
||
nil
e
=
Noah
::
Ephemeral
.
new
(
:path
=>
params
[
:splat
][
0
],
:data
=>
d
)
e
.
valid?
?
(
e
.
save
;
e
.
to_json
)
:
(
raise
"
#{
e
.
errors
}
"
)
e
.
valid?
?
(
e
.
save
;
e
.
to_json
)
:
(
raise
"
#{
format_errors
(
e
)
}
"
)
end
delete
'/e/*'
do
...
...
lib/noah/helpers.rb
View file @
5b7c9c25
module
Noah
module
SinatraHelpers
def
format_errors
(
model
)
error_messages
=
model
.
errors
.
present
do
|
e
|
# Missing attributes
e
.
on
[
:name
,
:not_present
],
"Name attribute missing"
e
.
on
[
:status
,
:not_present
],
"Status attribute missing"
e
.
on
[
:format
,
:not_present
],
"Format attribute missing"
e
.
on
[
:body
,
:not_present
],
"Body attribute missing"
e
.
on
[
:application_id
,
:not_present
],
"Application attribute missing"
e
.
on
[
:path
,
:not_present
],
"Path attribute missing"
e
.
on
[
:pattern
,
:not_present
],
"Pattern attribute missing"
e
.
on
[
:endpoint
,
:not_present
],
"Endpoint attribute missing"
# Invalid option
e
.
on
[
:status
,
:not_member
],
"Status must be up, down or pending"
# Duplicate keys
e
.
on
[[
:name
,
:application_id
],
:not_unique
],
"Record already exists"
e
.
on
[[
:name
,
:host_id
],
:not_unique
],
"Record already exists"
e
.
on
[[
:endpoint
,
:pattern
],
:not_unique
],
"Record already exists"
e
.
on
[
:path
,
:not_unique
],
"Record already exists"
# Custom exceptions
e
.
on
[
:pattern
,
:already_provided
],
"Pattern is already provided"
e
.
on
[
:pattern
,
:replaces_existing
],
"Pattern would overwrite existing"
end
error_messages
.
first
end
def
host
(
opts
=
{})
Noah
::
Host
.
find
(
opts
).
first
...
...
lib/noah/host_routes.rb
View file @
5b7c9c25
...
...
@@ -49,7 +49,7 @@ class Noah::App
r
=
{
"result"
=>
"success"
,
"id"
=>
"
#{
host
.
id
}
"
,
"status"
=>
"
#{
host
.
status
}
"
,
"name"
=>
"
#{
host
.
name
}
"
,
"new_record"
=>
host
.
is_new?
}
r
.
to_json
else
raise
"
#{
host
.
errors
}
"
raise
"
#{
format_errors
(
host
)
}
"
end
end
...
...
lib/noah/service_routes.rb
View file @
5b7c9c25
...
...
@@ -50,7 +50,7 @@ class Noah::App
r
=
{
"action"
=>
action
,
"result"
=>
"success"
,
"id"
=>
service
.
id
,
"host"
=>
h
.
name
,
"name"
=>
service
.
name
}
r
.
to_json
else
raise
"
#{
service
.
errors
}
"
raise
"
#{
format_errors
(
service
)
}
"
end
else
raise
"Missing Parameters"
...
...
spec/configuration_spec.rb
View file @
5b7c9c25
require
File
.
expand_path
(
File
.
dirname
(
__FILE__
)
+
'/spec_helper'
)
describe
"Using the Configuration Model"
,
:reset_redis
=>
true
do
before
(
:all
)
do
app
=
Noah
::
Application
.
create
(
:name
=>
"my_application"
)
app
.
save
@appconf_string
=
{
:name
=>
"mystringconf"
,
:format
=>
"string"
,
:body
=>
"some_var"
,
:application_id
=>
app
.
id
}
@appconf_json
=
{
:name
=>
"myjsonconf"
,
:format
=>
"json"
,
:body
=>
@appconf_string
.
to_json
,
:application_id
=>
app
.
id
}
@appconf_missing_name
=
@appconf_string
.
reject
{
|
x
|
x
==
:name
}
@appconf_missing_format
=
@appconf_string
.
reject
{
|
x
|
x
==
:format
}
@appconf_missing_body
=
@appconf_string
.
reject
{
|
x
|
x
==
:body
}
@appconf_missing_application
=
@appconf_string
.
reject
{
|
x
|
x
==
:application_id
}
end
before
(
:each
)
do
Ohm
.
redis
.
flushdb
app
=
Noah
::
Application
.
create
:name
=>
"my_application"
@appconf_string
=
{
:name
=>
"mystringconf"
,
:format
=>
"string"
,
:body
=>
"some_var"
,
:application_id
=>
app
.
id
}
@appconf_json
=
{
:name
=>
"myjsonconf"
,
:format
=>
"json"
,
:body
=>
@appconf_string
.
to_json
,
:application_id
=>
app
.
id
}
@appconf_missing_name
=
@appconf_string
.
reject
{
|
k
,
v
|
k
==
:name
}
@appconf_missing_format
=
@appconf_string
.
reject
{
|
k
,
v
|
k
==
:format
}
@appconf_missing_body
=
@appconf_string
.
reject
{
|
k
,
v
|
k
==
:body
}
@appconf_missing_application
=
@appconf_string
.
reject
{
|
k
,
v
|
k
==
:application_id
}
end
after
(
:each
)
do
Ohm
.
redis
.
flushdb
...
...
spec/ephemeral_spec.rb
View file @
5b7c9c25
...
...
@@ -3,8 +3,8 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe
"Using the Ephemeral Model"
,
:reset_redis
=>
true
do
before
(
:all
)
do
@edata
=
{
:path
=>
"/foo/bar/baz"
,
:data
=>
"some_value"
}
@emissing_path
=
@edata
.
reject
{
|
x
|
x
==
:path
}
@emissing_data
=
@edata
.
reject
{
|
x
|
x
==
:data
}
@emissing_path
=
@edata
.
reject
{
|
k
,
v
|
k
==
:path
}
@emissing_data
=
@edata
.
reject
{
|
k
,
v
|
k
==
:data
}
@good_ephemeral
=
Noah
::
Ephemeral
.
new
(
@edata
)
@missing_path
=
Noah
::
Ephemeral
.
new
(
@emissing_path
)
@missing_data
=
Noah
::
Ephemeral
.
new
(
@emissing_data
)
...
...
@@ -28,15 +28,15 @@ describe "Using the Ephemeral Model", :reset_redis => true do
b
=
Noah
::
Ephemeral
[
@missing_data
.
id
]
b
.
should
==
@missing_data
end
#
it "update an existing Noah::Ephemeral" do
# @good_ephemeral.save
#
Noah::Ephemeral.all.size.should == 1
# c = Noah::Ephemeral[@good_ephemeral.id]
# c.data = "updated_data"
# c.save
# sleep(2)
#
c.is_new?.should == false
#
end
it
"update an existing Noah::Ephemeral"
do
e
=
Noah
::
Ephemeral
.
create
:path
=>
"/is/new/test"
Noah
::
Ephemeral
.
all
.
size
.
should
==
1
sleep
(
2
)
c
=
Noah
::
Ephemeral
[
e
.
id
]
c
.
data
=
"updated_data"
c
.
save
c
.
is_new?
.
should
==
false
end
it
"delete an existing Noah::Ephemeral"
do
@good_ephemeral
.
save
@good_ephemeral
.
delete
...
...
@@ -45,8 +45,15 @@ describe "Using the Ephemeral Model", :reset_redis => true do
end
describe
"should not"
do
it
"create a new Noah::Ephemeral with missing path"
do
@missing_path
.
valid?
.
should
==
false
@missing_path
.
errors
.
should
==
[[
:path
,
:not_present
]]
e
=
Noah
::
Ephemeral
.
create
e
.
valid?
.
should
==
false
e
.
errors
.
should
==
[[
:path
,
:not_present
]]
end
it
"create a duplicate Noah::Ephemeral"
do
e
=
Noah
::
Ephemeral
.
create
:path
=>
"/random/path"
f
=
Noah
::
Ephemeral
.
create
:path
=>
"/random/path"
f
.
valid?
.
should
==
false
f
.
errors
.
should
==
[[
:path
,
:not_unique
]]
end
end
end
spec/noahapp_configuration_spec.rb
View file @
5b7c9c25
...
...
@@ -34,8 +34,8 @@ describe "Using the Configuration API", :reset_redis => false, :populate_sample_
response
=
YAML
.
load
(
last_response
.
body
)
response
.
is_a?
(
Hash
).
should
==
true
response
.
keys
.
should
==
[
"development"
]
response
[
"development"
].
keys
.
s
hould
==
[
"database"
,
"adapter"
,
"username"
,
"password
"
]
response
[
"development"
].
values
.
s
hould
==
[
"development_database"
,
"mysql"
,
"dev_user"
,
"dev_password
"
]
response
[
"development"
].
keys
.
s
ort
.
should
==
[
"adapter"
,
"database"
,
"password"
,
"username
"
]
response
[
"development"
].
values
.
s
ort
.
should
==
[
"dev_password"
,
"dev_user"
,
"development_database"
,
"mysql
"
]
end
it
"invalid application should not work"
do
get
'/c/badapp'
...
...
spec/noahapp_host_spec.rb
View file @
5b7c9c25
...
...
@@ -82,7 +82,7 @@ describe "Using the Host API", :reset_redis => false, :populate_sample_data => t
response
=
last_response
.
should
return_json
response
[
"result"
].
should
==
"failure"
response
[
"error_message"
].
should
==
"
[[:status, :not_member]]
"
response
[
"error_message"
].
should
==
"
Status must be up, down or pending
"
end
end
...
...
spec/noahapp_service_spec.rb
View file @
5b7c9c25
...
...
@@ -68,7 +68,7 @@ describe "Using the Service API", :reset_redis => false, :populate_sample_data =
put
"/s/foobar"
,
{
:name
=>
"foobar"
,
:status
=>
"fsck"
,
:host
=>
@h
.
name
}.
to_json
,
"CONTENT_TYPE"
=>
"application/json"
last_response
.
should_not
be_ok
response
=
last_response
.
should
return_json
response
[
"error_message"
].
should
==
"
[[:status, :not_member]]
"
response
[
"error_message"
].
should
==
"
Status must be up, down or pending
"
end
it
"new service with missing name should not work"
do
put
"/s/foobar"
,
{
:status
=>
"fsck"
,
:host
=>
@h
.
name
}.
to_json
,
"CONTENT_TYPE"
=>
"application/json"
...
...
spec/watcher_spec.rb
View file @
5b7c9c25
...
...
@@ -32,30 +32,30 @@ describe "Using the Watcher Model", :reset_redis => true do
it
"create a new Noah::Watcher with missing endpoint"
do
a
=
Noah
::
Watcher
.
create
(
:pattern
=>
"/foo/bar"
)
a
.
valid?
.
should
==
false
a
.
errors
.
to_s
.
should
==
"[[:endpoint, :not_present]]"
a
.
errors
.
should
==
[[
:endpoint
,
:not_present
]]
end
it
"create a new Noah::Watcher with missing pattern"
do
a
=
Noah
::
Watcher
.
create
(
:endpoint
=>
"http://localhost/webhook"
)
a
.
valid?
.
should
==
false
a
.
errors
.
to_s
.
should
==
"[[:pattern, :not_present]]"
a
.
errors
.
should
==
[[
:pattern
,
:not_present
]]
end
it
"create a new Noah::Watcher with subset pattern"
do
a
=
Noah
::
Watcher
.
create
(
:endpoint
=>
"http://localhost.domain.com/webhook"
,
:pattern
=>
"//noah/"
)
b
=
Noah
::
Watcher
.
create
(
:endpoint
=>
"http://localhost.domain.com/webhook"
,
:pattern
=>
"//noah/foobar"
)
b
.
valid?
.
should
==
false
b
.
errors
.
to_s
.
should
==
"[[:pattern, :already_provided]]"
b
.
errors
.
should
==
[[
:pattern
,
:already_provided
]]
end
it
"create a new Noah::Watcher with superset pattern"
do
a
=
Noah
::
Watcher
.
create
(
:endpoint
=>
"http://localhost.domain.com/webhook"
,
:pattern
=>
"//noah/foobar"
)
b
=
Noah
::
Watcher
.
create
(
:endpoint
=>
"http://localhost.domain.com/webhook"
,
:pattern
=>
"//noah"
)
b
.
valid?
.
should
==
false
b
.
errors
.
to_s
.
should
==
"[[:pattern, :replaces_existing]]"
b
.
errors
.
should
==
[[
:pattern
,
:replaces_existing
]]
end
it
"create a duplicate Noah::Watcher"
do
a
=
Noah
::
Watcher
.
create
(
:endpoint
=>
"http://localhost.domain.com/webhook"
,
:pattern
=>
"//noah/foobar"
)
b
=
Noah
::
Watcher
.
create
(
:endpoint
=>
"http://localhost.domain.com/webhook"
,
:pattern
=>
"//noah/foobar"
)
b
.
valid?
.
should
==
false
b
.
errors
.
to_s
.
should
==
"[[[:endpoint, :pattern], :not_unique]]"
b
.
errors
.
should
==
[[[
:endpoint
,
:pattern
],
:not_unique
]]
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