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
293c86ff
Commit
293c86ff
authored
Apr 11, 2011
by
John E. Vincent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
converting applications json to hashes
parent
709e6bf3
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
26 additions
and
24 deletions
+26
-24
application_routes.rb
lib/noah/application_routes.rb
+3
-11
applications.rb
lib/noah/models/applications.rb
+10
-4
configurations.rb
lib/noah/models/configurations.rb
+1
-0
application_spec.rb
spec/application_spec.rb
+2
-2
noahapp_application_spec.rb
spec/noahapp_application_spec.rb
+10
-7
No files found.
lib/noah/application_routes.rb
View file @
293c86ff
...
...
@@ -65,23 +65,15 @@ class Noah::App
if
app
.
nil?
halt
404
else
# configs are no longer tied to apps. remove the cascade delete
# configurations = []
# Noah::Configuration.find(:application_id => app.id).sort.each {|x| configurations << x; x.delete} if app.configurations.size > 0
app
.
delete
# r = {"result" => "success", "action" => "delete", "id" => "#{app.id}", "name" => "#{appname}", "configurations" => "#{configurations.size}"}
r
=
{
"result"
=>
"success"
,
"action"
=>
"delete"
,
"id"
=>
"
#{
app
.
id
}
"
,
"name"
=>
"
#{
appname
}
"
}
r
.
to_json
end
end
get
'/applications/?'
do
apps
=
[]
Noah
::
Application
.
all
.
sort
.
each
{
|
a
|
apps
<<
a
.
to_hash
}
if
apps
.
empty?
halt
404
else
apps
.
to_json
end
apps
=
Noah
::
Applications
.
all
(
halt
404
)
if
apps
.
size
==
0
apps
.
to_json
end
end
lib/noah/models/applications.rb
View file @
293c86ff
...
...
@@ -2,6 +2,7 @@ require File.join(File.dirname(__FILE__), 'configurations')
module
Noah
class
Application
<
Model
include
Taggable
include
Linkable
attribute
:name
set
:configurations
,
Configuration
...
...
@@ -14,9 +15,11 @@ module Noah
end
def
to_hash
arr
=
[]
self
.
configurations
.
sort
.
each
{
|
c
|
arr
<<
c
.
to_hash
}
if
self
.
configurations
.
size
!=
0
super
.
merge
(
:name
=>
name
,
:configurations
=>
arr
,
:created_at
=>
created_at
,
:updated_at
=>
updated_at
)
cfg_hash
=
Hash
.
new
configurations
.
sort
.
each
do
|
cfg
|
cfg_hash
[
"
#{
cfg
.
name
}
"
]
=
{
:format
=>
cfg
.
to_hash
[
:format
],
:body
=>
cfg
.
to_hash
[
:body
]}
end
super
.
merge
(
:name
=>
name
,
:created_at
=>
created_at
,
:updated_at
=>
updated_at
,
:configurations
=>
cfg_hash
)
end
class
<<
self
...
...
@@ -37,7 +40,10 @@ module Noah
class
Applications
def
self
.
all
(
options
=
{})
options
.
empty?
?
Application
.
all
.
sort
:
Application
.
find
(
options
).
sort
app_hash
=
Hash
.
new
options
.
empty?
?
apps
=
Application
.
all
.
sort
:
apps
=
Application
.
find
(
options
).
sort
apps
.
each
{
|
x
|
app_hash
[
"
#{
x
.
name
}
"
]
=
x
.
to_hash
.
reject
{
|
k
,
v
|
k
==
:name
}
}
app_hash
end
end
end
lib/noah/models/configurations.rb
View file @
293c86ff
...
...
@@ -2,6 +2,7 @@ require File.join(File.dirname(__FILE__), 'applications')
module
Noah
class
Configuration
<
Model
include
Taggable
include
Linkable
attribute
:name
attribute
:format
attribute
:body
...
...
spec/application_spec.rb
View file @
293c86ff
...
...
@@ -61,8 +61,8 @@ describe "Using the Application Model", :reset_redis => true do
b
=
Noah
::
Application
.
create
(
@appdata2
)
c
=
Noah
::
Applications
.
all
c
.
size
.
should
==
2
c
.
member?
(
a
).
should
==
true
c
.
member?
(
b
).
should
==
true
c
.
has_key?
(
a
.
name
).
should
==
true
c
.
has_key?
(
b
.
name
).
should
==
true
end
end
...
...
spec/noahapp_application_spec.rb
View file @
293c86ff
...
...
@@ -14,20 +14,23 @@ describe "Using the Application API", :reset_redis => false do
get
'/applications'
last_response
.
should
be_ok
response
=
last_response
.
should
return_json
response
.
is_a?
(
Array
).
should
==
true
response
.
is_a?
(
Hash
).
should
==
true
end
it
"named application should work"
do
get
'/applications/rspec_sample_app'
last_response
.
should
be_ok
response
=
last_response
.
should
return_json
response
[
"id"
].
should
==
@a
.
id
response
[
"name"
].
should
==
@a
.
name
c
=
response
[
"configurations"
].
first
c
[
"id"
].
should
==
@c
.
id
c
[
"name"
].
should
==
@c
.
name
c
[
"body"
].
should
==
@c
.
body
c
[
"format"
].
should
==
@c
.
format
response
[
"id"
].
should
==
@a
.
id
.
to_s
response
[
"name"
].
should
==
@a
.
name
response
.
has_key?
(
"configurations"
).
should
==
true
c
=
response
[
"configurations"
]
c
.
has_key?
(
@c
.
name
).
should
==
true
p
@c
p
c
c
[
"
#{
@c
.
name
}
"
][
"format"
].
should
==
"
#{
@c
.
format
}
"
c
[
"
#{
@c
.
name
}
"
][
"body"
].
should
==
"
#{
@c
.
body
}
"
end
it
"named configuration for application should work"
do
get
"/applications/
#{
@a
.
name
}
/
#{
@c
.
name
}
"
...
...
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