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
898db489
Commit
898db489
authored
Aug 06, 2011
by
John E. Vincent
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'issue-7'
parents
897b5e3b
f899b568
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
55 additions
and
4 deletions
+55
-4
configurations.rb
lib/noah/models/configurations.rb
+7
-2
configurations.rb
lib/noah/routes/configurations.rb
+8
-2
configuration_spec.rb
spec/configuration_spec.rb
+11
-0
noahapp_configuration_spec.rb
spec/noahapp_configuration_spec.rb
+29
-0
No files found.
lib/noah/models/configurations.rb
View file @
898db489
...
...
@@ -62,10 +62,15 @@ module Noah
end
class
Configurations
def
self
.
all
(
options
=
{})
def
self
.
all
(
options
=
{},
short
=
false
)
short_keys
=
[
:format
,
:created_at
,
:updated_at
]
config_hash
=
Hash
.
new
options
.
empty?
?
configs
=
Configuration
.
all
.
sort
:
configs
=
Configuration
.
find
(
options
).
sort
if
short
==
false
configs
.
each
{
|
x
|
config_hash
[
"
#{
x
.
name
}
"
]
=
x
.
to_hash
.
reject
{
|
k
,
v
|
k
==
:name
}
}
else
configs
.
each
{
|
x
|
config_hash
[
"
#{
x
.
name
}
"
]
=
x
.
to_hash
.
select
{
|
k
,
v
|
k
if
short_keys
.
include?
(
k
)}
}
end
config_hash
end
end
...
...
lib/noah/routes/configurations.rb
View file @
898db489
...
...
@@ -14,15 +14,21 @@ class Noah::App
c
=
Noah
::
Configuration
.
find
(
:name
=>
configname
).
first
(
halt
404
)
if
c
.
nil?
content_type
content_type_mapping
[
c
.
format
.
to_sym
]
if
content_type_mapping
[
c
.
format
.
to_sym
]
#response.headers['Content-Disposition'] = "attachment; filename=#{configname}"
c
.
body
end
# GET all configurations
get
'/configurations/?'
do
configs
=
Noah
::
Configurations
.
all
.
to_hash
params
[
:short
]
||=
false
configs
=
Noah
::
Configurations
.
all
({},
params
[
:short
])
(
halt
404
)
if
configs
.
size
==
0
configs
.
each
do
|
config
,
values
|
u
=
request
.
url
.
gsub
(
/(\/\?short=true|\?short=true)/
,
'/'
+
config
)
values
.
merge!
({
:location
=>
u
})
if
params
[
:short
]
end
configs
.
to_json
end
# Add configuration object to a custom link hierarchy
put
'/configurations/:configname/link'
do
|
configname
|
required_params
=
[
"link_name"
]
...
...
spec/configuration_spec.rb
View file @
898db489
...
...
@@ -68,6 +68,17 @@ describe "Using the Configuration Model", :reset_redis => true do
c
.
has_key?
(
a
.
name
).
should
==
true
c
.
has_key?
(
b
.
name
).
should
==
true
end
it
"return all Configurations in short form"
do
a
=
Noah
::
Configuration
.
find_or_create
(
@appconf_string
)
b
=
Noah
::
Configuration
.
find_or_create
(
@appconf_json
)
c
=
Noah
::
Configurations
.
all
({},
true
)
c
.
class
.
to_s
.
should
==
'Hash'
c
.
size
.
should
==
2
c
.
has_key?
(
a
.
name
).
should
==
true
c
.
has_key?
(
b
.
name
).
should
==
true
c
.
each
{
|
k
,
v
|
v
.
keys
.
map
{
|
k
|
k
.
to_s
}.
sort
.
should
==
[
'created_at'
,
'format'
,
'updated_at'
]}
end
end
describe
"should not"
do
...
...
spec/noahapp_configuration_spec.rb
View file @
898db489
...
...
@@ -41,6 +41,35 @@ describe "Using the Configuration API", :reset_redis => true, :populate_sample_d
end
end
end
it
"all configurations in short form with no trailing slash"
do
get
'/configurations?short=true'
last_response
.
should
be_ok
response
=
last_response
.
should
return_json
response
.
keys
.
size
.
should
==
3
%w[redis_url json_config yaml_config]
.
each
do
|
c
|
response
.
keys
.
member?
(
c
).
should
==
true
%w[format location created_at updated_at]
.
each
do
|
ck
|
response
[
c
].
keys
.
member?
(
ck
).
should
==
true
end
end
response
.
each
{
|
k
,
v
|
v
[
'location'
].
should
=~
/^http:\/\/.*\/configurations\/
#{
k
}
/
}
end
it
"all configurations in short form with trailing slash"
do
get
'/configurations/?short=true'
last_response
.
should
be_ok
response
=
last_response
.
should
return_json
response
.
keys
.
size
.
should
==
3
%w[redis_url json_config yaml_config]
.
each
do
|
c
|
response
.
keys
.
member?
(
c
).
should
==
true
%w[format location created_at updated_at]
.
each
do
|
ck
|
response
[
c
].
keys
.
member?
(
ck
).
should
==
true
end
end
response
.
each
{
|
k
,
v
|
v
[
'location'
].
should
=~
/^http:\/\/.*\/configurations\/
#{
k
}
/
}
end
it
"named configuration should work as JSON"
do
header
"Accept"
,
"application/json"
get
'/configurations/redis_url'
...
...
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