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
get '/applications/:appname/?' do |appname|
app = Noah::Application.find(:name => appname).first
if app.nil?
halt 404
else
app.to_json
end
(halt 404) if app.nil?
app.to_json
end
put '/applications/:appname/tag' do |appname|
......@@ -63,13 +60,10 @@ class Noah::App
delete '/applications/:appname/?' do |appname|
app = Noah::Application.find(:name => appname).first
if app.nil?
halt 404
else
app.delete
r = {"result" => "success", "action" => "delete", "id" => "#{app.id}", "name" => "#{appname}"}
r.to_json
end
(halt 404) if app.nil?
app.delete
r = {"result" => "success", "action" => "delete", "id" => "#{app.id}", "name" => "#{appname}"}
r.to_json
end
get '/applications/?' do
......
......@@ -29,13 +29,9 @@ class Noah::App
end
get '/configurations/?' do
configs = []
Noah::Configuration.all.sort.each {|c| configs << c.to_hash}
if configs.empty?
halt 404
else
configs.to_json
end
configs = Noah::Configurations.all.to_hash
(halt 404) if configs.size == 0
configs.to_json
end
put '/configurations/:configname/link' do |configname|
......
......@@ -19,7 +19,7 @@ module Noah
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)
{name => {:id => id, :created_at => created_at, :updated_at => updated_at, :configurations => cfg_hash}}
end
class << self
......
......@@ -41,7 +41,10 @@ module Noah
class Configurations
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
......@@ -50,9 +50,10 @@ describe "Using the Configuration Model", :reset_redis => true do
a = Noah::Configuration.find_or_create(@appconf_string)
b = Noah::Configuration.find_or_create(@appconf_json)
c = Noah::Configurations.all
c.class.to_s.should == 'Hash'
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
......
......@@ -20,12 +20,11 @@ describe "Using the Application API", :reset_redis => false do
get '/applications/rspec_sample_app'
last_response.should be_ok
response = last_response.should return_json
response["name"].should == @a.name
response["id"].should == @a.id.to_s
response["name"].should == @a.name
response.has_key?("configurations").should == true
c = response["configurations"]
response.has_key?(@a.name).should == true
response[@a.name].class.to_s.should == 'Hash'
response[@a.name]["id"].should == @a.id.to_s
response[@a.name].has_key?("configurations").should == true
c = response[@a.name]["configurations"]
c.has_key?(@c.name).should == true
c["#{@c.name}"]["format"].should == "#{@c.format}"
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