Permalink
Browse files

JSON payload now { 'links' => [...], 'processes/errors/...' => [...] }

  • Loading branch information...
1 parent 437aa3d commit 54ed8b20b5c71f56bcf3bb56cd0cec254d6c3004 @jmettraux committed Oct 20, 2009
@@ -63,7 +63,7 @@ def link (href, rel)
{ 'href' => href, 'rel' => rel }
end
- def to_hash (content)
+ def to_hash (resource_name, content)
# TODO : site prefix ?
@@ -77,7 +77,7 @@ def to_hash (content)
link(request.fullpath, 'self')
]
- h['content'] = content if content
+ h[resource_name] = content if content
h
end
@@ -33,7 +33,7 @@ class Ruote::Http::App
def render_process_history_json (records)
- h = to_hash(records.collect { |r| r.to_h })
+ h = to_hash('history', records.collect { |r| r.to_h })
h['links'] << link("/process/#{params[:wfid]}", rel('#process'))
@@ -47,7 +47,7 @@ def render_process_history_html (records)
def render_history_json (records)
- to_hash(records.collect { |r| r.to_h }).to_json
+ to_hash('history', records.collect { |r| r.to_h }).to_json
end
def render_history_html (records)
@@ -57,7 +57,7 @@ def render_history_html (records)
def render_history_range_json (range)
- h = to_hash(nil)
+ h = to_hash('history_range', nil)
h['links'] << link(
"/history/#{range.first.strftime('%F')}", rel('#history_last'))
@@ -31,7 +31,7 @@ class Ruote::Http::App
def render_index_json (o)
- to_hash(nil).to_json
+ to_hash('index', nil).to_json
end
def render_index_html (o)
@@ -31,7 +31,7 @@ class Ruote::Http::App
def render_message_json (msg)
- to_hash(msg).to_json
+ to_hash('message', msg).to_json
end
def render_message_html (msg)
@@ -32,7 +32,7 @@ class Ruote::Http::App
def render_processes_json (processes)
- to_hash(processes.collect { |ps| ps.to_h }).to_json
+ to_hash('processes', processes.collect { |ps| ps.to_h }).to_json
end
def render_processes_html (processes)
@@ -42,7 +42,7 @@ def render_processes_html (processes)
def render_process_json (process)
- h = to_hash(process.to_h)
+ h = to_hash('process', process.to_h)
h['links'] << link("/history/#{params[:wfid]}", rel('#process_history'))
View
@@ -17,7 +17,7 @@ def test_history_empty
assert last_response.ok?
assert_equal 5, last_response.json_body['links'].size
- assert_equal [], last_response.json_body['content']
+ assert_equal [], last_response.json_body['history']
end
def test_history_range
@@ -39,7 +39,7 @@ def test_history_range
l['rel'] == 'http://ruote.rubyforge.org/rel.html#history_last'
}.first['href'])
- assert_equal nil, last_response.json_body['content']
+ assert_equal nil, last_response.json_body['history_range']
end
def test_process_history_missing
@@ -56,7 +56,7 @@ def test_process_history_missing
l['rel'] == 'http://ruote.rubyforge.org/rel.html#history'
}.first['href'])
- assert_equal [], last_response.json_body['content']
+ assert_equal [], last_response.json_body['history']
end
def test_process_history
@@ -77,7 +77,7 @@ def test_process_history
assert_equal(
"RuntimeError unknown expression 'nada'",
- last_response.json_body['content'].last['message'])
+ last_response.json_body['history'].last['message'])
end
def test_history
@@ -87,7 +87,7 @@ def test_history
get '/history'
assert last_response.ok?
- assert_equal 2, last_response.json_body['content'].size
+ assert_equal 2, last_response.json_body['history'].size
end
def test_history_date
@@ -97,12 +97,12 @@ def test_history_date
get "/history/#{Time.now.strftime('%F')}"
assert last_response.ok?
- assert_equal 2, last_response.json_body['content'].size
+ assert_equal 2, last_response.json_body['history'].size
get "/history/#{(Time.now + 60 * 60 * 25).strftime('%F')}"
assert last_response.ok?
- assert_equal 0, last_response.json_body['content'].size
+ assert_equal 0, last_response.json_body['history'].size
end
end
View
@@ -20,7 +20,7 @@ def test_processes_empty
h = last_response.json_body
assert_equal 2, h.size
- assert_equal [], h['content']
+ assert_equal [], h['processes']
assert_equal 5, h['links'].size
@@ -36,7 +36,7 @@ def test_processes_slash
get '/processes/'
assert last_response.ok?
- assert_equal [], last_response.json_body['content']
+ assert_equal [], last_response.json_body['processes']
end
def test_processes
@@ -50,8 +50,8 @@ def test_processes
h = last_response.json_body
#p h
- assert_equal 1, h['content'].size
- assert_equal wfid, h['content'].first['wfid']
+ assert_equal 1, h['processes'].size
+ assert_equal wfid, h['processes'].first['wfid']
end
def test_process
@@ -74,7 +74,7 @@ def test_process
"/history/#{wfid}",
h['links'].select { |h| h['rel'].match(/#process_history$/) }.first['href'])
- assert_equal Hash, h['content'].class
+ assert_equal Hash, h['process'].class
end
def test_launch_process
@@ -89,7 +89,7 @@ def test_launch_process
{ 'CONTENT_TYPE' => 'application/json;charset=utf-8' })
assert_match /^\/processes\/.+$/, last_response.headers['Location']
- assert_match /^process .+ launched\.$/, last_response.json_body['content']
+ assert_match /^process .+ launched\.$/, last_response.json_body['message']
sleep 0.400
@@ -107,7 +107,7 @@ def test_cancel_process
assert_equal(
"process #{wfid} cancelled.",
- last_response.json_body['content'])
+ last_response.json_body['message'])
sleep 0.400

0 comments on commit 54ed8b2

Please sign in to comment.