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
82be084e
Commit
82be084e
authored
Jan 30, 2011
by
John E. Vincent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more DRY on the tests
parent
4f1941f3
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
90 additions
and
22 deletions
+90
-22
noah.rb
noah.rb
+1
-1
noahapp_configuration_spec.rb
spec/noahapp_configuration_spec.rb
+61
-6
noahapp_host_spec.rb
spec/noahapp_host_spec.rb
+13
-14
spec_helper.rb
spec/spec_helper.rb
+15
-1
No files found.
noah.rb
View file @
82be084e
...
...
@@ -295,9 +295,9 @@ class NoahApp < Sinatra::Base
data
=
JSON
.
parse
(
request
.
body
.
read
)
data
.
keys
.
sort
==
required_params
.
sort
?
(
config
.
format
=
data
[
"format"
];
config
.
body
=
data
[
"body"
])
:
(
raise
"Missing Parameters"
)
if
config
.
valid?
config
.
save
action
=
config
.
is_new?
?
"create"
:
"update"
dependency_action
=
app
.
is_new?
?
"created"
:
"updated"
config
.
save
r
=
{
"result"
=>
"success"
,
"id"
=>
"
#{
config
.
id
}
"
,
"action"
=>
action
,
"dependencies"
=>
dependency_action
,
"application"
=>
app
.
name
,
"item"
=>
config
.
name
}
r
.
to_json
else
...
...
spec/noahapp_configuration_spec.rb
View file @
82be084e
...
...
@@ -52,15 +52,70 @@ describe "Using the Configuration API", :reset_redis => false, :populate_sample_
end
describe
"PUT"
do
it
"new configuration should work"
it
"existing configuration should work"
it
"new configuration with missing format should not work"
it
"new configuration with missing body should not work"
it
"new configuration should work"
do
config_data
=
{
:format
=>
"string"
,
:body
=>
"sample_config_entry"
}.
to_json
put
'/c/newapp/newconfig'
,
config_data
,
"CONTENT_TYPE"
=>
"application/json"
last_response
.
should
be_ok
response
=
last_response
.
should
return_json
response
[
"result"
].
should
==
"success"
response
[
"action"
].
should
==
"create"
response
[
"dependencies"
].
should
==
"created"
response
[
"application"
].
should
==
"newapp"
response
[
"item"
].
should
==
"newconfig"
end
it
"existing configuration should work"
do
config_data
=
{
:format
=>
"string"
,
:body
=>
"sample_config_entry"
}.
to_json
sleep
3
put
'/c/newapp/newconfig'
,
config_data
,
"CONTENT_TYPE"
=>
"application/json"
last_response
.
should
be_ok
response
=
last_response
.
should
return_json
response
[
"result"
].
should
==
"success"
response
[
"action"
].
should
==
"update"
response
[
"dependencies"
].
should
==
"updated"
response
[
"application"
].
should
==
"newapp"
response
[
"item"
].
should
==
"newconfig"
end
it
"new configuration with missing format should not work"
do
config_data
=
{
:body
=>
"a string"
}.
to_json
put
'/c/newnewapp/someconfig'
,
config_data
,
"CONTENT_TYPE"
=>
"application/json"
last_response
.
should_not
be_ok
response
=
last_response
.
should
return_json
response
[
"result"
].
should
==
"failure"
response
[
"error_message"
].
should
==
"Missing Parameters"
end
it
"new configuration with missing body should not work"
do
config_data
=
{
:body
=>
"a string"
}.
to_json
put
'/c/newnewapp/someconfig'
,
config_data
,
"CONTENT_TYPE"
=>
"application/json"
last_response
.
should_not
be_ok
response
=
last_response
.
should
return_json
response
[
"result"
].
should
==
"failure"
response
[
"error_message"
].
should
==
"Missing Parameters"
end
end
describe
"DELETE"
do
it
"existing configuration should work"
it
"invalid configuration should not work"
before
(
:all
)
do
cparms
=
{
:name
=>
'a'
,
:format
=>
'string'
,
:body
=>
'asdf'
}
@a
=
Application
.
create
(
:name
=>
'delete_test_app'
)
@a
.
configurations
<<
Configuration
.
create
(
cparms
)
@a
.
save
@c
=
@a
.
configurations
.
first
end
it
"existing configuration should work"
do
delete
"/c/
#{
@a
.
name
}
/
#{
@c
.
name
}
"
last_response
.
should
be_ok
response
=
last_response
.
should
return_json
response
[
"result"
].
should
==
"success"
response
[
"id"
].
should
==
@c
.
id
response
[
"action"
].
should
==
"delete"
response
[
"application"
].
should
==
@a
.
name
response
[
"item"
].
should
==
@c
.
name
end
it
"invalid configuration should not work"
do
delete
"/c/
#{
@a
.
name
}
/
#{
@c
.
name
}
"
last_response
.
should
be_missing
end
end
end
...
...
spec/noahapp_host_spec.rb
View file @
82be084e
...
...
@@ -95,29 +95,28 @@ describe "Using the Host API", :reset_redis => false, :populate_sample_data => t
end
describe
"DELETE"
do
before
(
:all
)
do
@h
=
Host
.
create
(
:name
=>
'h'
,
:status
=>
'up'
)
sparms
=
{
:name
=>
's'
,
:status
=>
"up"
}
@h
.
services
<<
Service
.
create
(
sparms
.
merge
({
:host
=>
@h
}))
@h
.
save
@s
=
@h
.
services
.
first
end
it
"existing host should work"
do
h
=
Host
.
find
(
:name
=>
"localhost"
).
first
svc_size
=
h
.
services
.
size
host_data
=
{
:name
=>
"localhost"
}
delete
'/h/localhost'
,
host_data
,
"CONTENT_TYPE"
=>
"application/json"
svc_size
=
@h
.
services
.
size
delete
"/h/
#{
@h
.
name
}
"
last_response
.
should
be_ok
response
=
last_response
.
should
return_json
response
[
"result"
].
should
==
"success"
response
[
"id"
].
should
==
h
.
id
response
[
"name"
].
should
==
"localhost"
response
[
"id"
].
should
==
@
h
.
id
response
[
"name"
].
should
==
@h
.
name
response
[
"service_count"
].
should
==
svc_size
.
to_s
end
it
"invalid host should not work"
do
host_data
=
{
:name
=>
"invalid_host.asdf.com"
}
delete
'/h/invalid_host.asdf.com'
,
host_data
,
"CONTENT_TYPE"
=>
"application/json"
last_response
.
should_not
be_ok
last_response
.
status
.
should
==
404
response
=
last_response
.
should
return_json
response
[
"result"
].
should
==
"failure"
response
[
"error_message"
].
should
==
"Resource not found"
delete
"/h/
#{
@h
.
name
}
"
last_response
.
should
be_missing
end
end
...
...
spec/spec_helper.rb
View file @
82be084e
...
...
@@ -73,9 +73,23 @@ def app
NoahApp
end
RSpec
::
Matchers
.
define
:return_json
do
|
attribute
|
RSpec
::
Matchers
.
define
:return_json
do
match
do
|
last_response
|
last_response
.
headers
[
"Content-Type"
].
should
==
"application/json"
response
=
JSON
.
parse
(
last_response
.
body
)
end
failure_message_for_should
do
"Response was not valid JSON"
end
end
RSpec
::
Matchers
.
define
:be_missing
do
match
do
|
last_response
|
last_response
.
headers
[
"Content-Type"
].
should
==
"application/json"
last_response
.
status
.
should
==
404
response
=
JSON
.
parse
(
last_response
.
body
)
response
[
"result"
].
should
==
"failure"
response
[
"error_message"
].
should
==
"Resource not found"
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