Commit f11cdec6 authored by John E. Vincent's avatar John E. Vincent

customizing hash for configurations

parent 7a10fa79
...@@ -12,11 +12,8 @@ class Noah::App ...@@ -12,11 +12,8 @@ class Noah::App
get '/applications/:appname/?' do |appname| get '/applications/:appname/?' do |appname|
app = Noah::Application.find(:name => appname).first app = Noah::Application.find(:name => appname).first
if app.nil? (halt 404) if app.nil?
halt 404 app.to_json
else
app.to_json
end
end end
put '/applications/:appname/tag' do |appname| put '/applications/:appname/tag' do |appname|
...@@ -63,13 +60,10 @@ class Noah::App ...@@ -63,13 +60,10 @@ class Noah::App
delete '/applications/:appname/?' do |appname| delete '/applications/:appname/?' do |appname|
app = Noah::Application.find(:name => appname).first app = Noah::Application.find(:name => appname).first
if app.nil? (halt 404) if app.nil?
halt 404 app.delete
else r = {"result" => "success", "action" => "delete", "id" => "#{app.id}", "name" => "#{appname}"}
app.delete r.to_json
r = {"result" => "success", "action" => "delete", "id" => "#{app.id}", "name" => "#{appname}"}
r.to_json
end
end end
get '/applications/?' do get '/applications/?' do
......
...@@ -29,13 +29,9 @@ class Noah::App ...@@ -29,13 +29,9 @@ class Noah::App
end end
get '/configurations/?' do get '/configurations/?' do
configs = [] configs = Noah::Configurations.all.to_hash
Noah::Configuration.all.sort.each {|c| configs << c.to_hash} (halt 404) if configs.size == 0
if configs.empty? configs.to_json
halt 404
else
configs.to_json
end
end end
put '/configurations/:configname/link' do |configname| put '/configurations/:configname/link' do |configname|
......
...@@ -19,7 +19,7 @@ module Noah ...@@ -19,7 +19,7 @@ module Noah
configurations.sort.each do |cfg| configurations.sort.each do |cfg|
cfg_hash["#{cfg.name}"] = {:format => cfg.to_hash[:format], :body => cfg.to_hash[:body]} cfg_hash["#{cfg.name}"] = {:format => cfg.to_hash[:format], :body => cfg.to_hash[:body]}
end end
super.merge(:name => name, :created_at => created_at, :updated_at => updated_at, :configurations => cfg_hash) {name => {:id => id, :created_at => created_at, :updated_at => updated_at, :configurations => cfg_hash}}
end end
class << self class << self
......
...@@ -41,7 +41,10 @@ module Noah ...@@ -41,7 +41,10 @@ module Noah
class Configurations class Configurations
def self.all(options = {}) def self.all(options = {})
options.empty? ? Configuration.all.sort : Configuration.find(options).sort config_hash = Hash.new
options.empty? ? configs=Configuration.all.sort : configs=Configuration.find(options).sort
configs.each {|x| config_hash["#{x.name}"] = x.to_hash.reject {|k,v| k == :name} }
config_hash
end end
end end
end end
...@@ -50,9 +50,10 @@ describe "Using the Configuration Model", :reset_redis => true do ...@@ -50,9 +50,10 @@ describe "Using the Configuration Model", :reset_redis => true do
a = Noah::Configuration.find_or_create(@appconf_string) a = Noah::Configuration.find_or_create(@appconf_string)
b = Noah::Configuration.find_or_create(@appconf_json) b = Noah::Configuration.find_or_create(@appconf_json)
c = Noah::Configurations.all c = Noah::Configurations.all
c.class.to_s.should == 'Hash'
c.size.should == 2 c.size.should == 2
c.member?(a).should == true c.has_key?(a.name).should == true
c.member?(b).should == true c.has_key?(b.name).should == true
end end
end end
......
...@@ -20,12 +20,11 @@ describe "Using the Application API", :reset_redis => false do ...@@ -20,12 +20,11 @@ describe "Using the Application API", :reset_redis => false do
get '/applications/rspec_sample_app' get '/applications/rspec_sample_app'
last_response.should be_ok last_response.should be_ok
response = last_response.should return_json response = last_response.should return_json
response.has_key?(@a.name).should == true
response["name"].should == @a.name response[@a.name].class.to_s.should == 'Hash'
response["id"].should == @a.id.to_s response[@a.name]["id"].should == @a.id.to_s
response["name"].should == @a.name response[@a.name].has_key?("configurations").should == true
response.has_key?("configurations").should == true c = response[@a.name]["configurations"]
c = response["configurations"]
c.has_key?(@c.name).should == true c.has_key?(@c.name).should == true
c["#{@c.name}"]["format"].should == "#{@c.format}" c["#{@c.name}"]["format"].should == "#{@c.format}"
c["#{@c.name}"]["body"].should == "#{@c.body}" c["#{@c.name}"]["body"].should == "#{@c.body}"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment