noah 0.4 → 0.6.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/Rakefile +2 -69
  2. data/lib/noah/agent.rb +1 -0
  3. data/lib/noah/agents/base_agent.rb +4 -2
  4. data/lib/noah/agents/http_agent.rb +1 -1
  5. data/lib/noah/agents/https_agent.rb +6 -0
  6. data/lib/noah/app.rb +8 -6
  7. data/lib/noah/exceptions.rb +0 -0
  8. data/lib/noah/linkable.rb +21 -0
  9. data/lib/noah/models/applications.rb +19 -9
  10. data/lib/noah/models/configurations.rb +32 -13
  11. data/lib/noah/models/ephemerals.rb +7 -6
  12. data/lib/noah/models/hosts.rb +11 -5
  13. data/lib/noah/models/link.rb +70 -29
  14. data/lib/noah/models/services.rb +11 -2
  15. data/lib/noah/models/tags.rb +86 -5
  16. data/lib/noah/models/watchers.rb +0 -1
  17. data/lib/noah/models.rb +14 -25
  18. data/lib/noah/{application_routes.rb → routes/applications.rb} +31 -27
  19. data/lib/noah/routes/configurations.rb +77 -0
  20. data/lib/noah/{ephemeral_routes.rb → routes/ephemerals.rb} +5 -5
  21. data/lib/noah/{host_routes.rb → routes/hosts.rb} +16 -1
  22. data/lib/noah/routes/links.rb +16 -0
  23. data/lib/noah/{service_routes.rb → routes/services.rb} +28 -12
  24. data/lib/noah/routes/tags.rb +15 -0
  25. data/lib/noah/{watcher_routes.rb → routes/watchers.rb} +0 -0
  26. data/lib/noah/taggable.rb +30 -0
  27. data/lib/noah/version.rb +1 -1
  28. data/lib/noah.rb +1 -0
  29. data/noah.gemspec +5 -4
  30. data/spec/application_spec.rb +3 -3
  31. data/spec/configuration_spec.rb +19 -12
  32. data/spec/host_spec.rb +5 -5
  33. data/spec/noahapp_application_spec.rb +11 -13
  34. data/spec/noahapp_configuration_spec.rb +63 -40
  35. data/spec/noahapp_ephemeral_spec.rb +15 -15
  36. data/spec/noahapp_host_spec.rb +4 -6
  37. data/spec/noahapp_service_spec.rb +8 -7
  38. data/spec/service_spec.rb +2 -2
  39. data/spec/spec_helper.rb +5 -5
  40. data/spec/support/sample_data.rb +87 -0
  41. data/spec/tag_spec.rb +78 -0
  42. data/views/index.haml +7 -1
  43. metadata +23 -16
  44. data/lib/noah/configuration_routes.rb +0 -81
  45. data/lib/noah/models/link_member.rb +0 -18
data/lib/noah/models.rb CHANGED
@@ -10,8 +10,7 @@ module Noah
10
10
  model.send :include, Ohm::Callbacks
11
11
  model.send :include, Ohm::ExtraValidations
12
12
 
13
- model.send :attribute, :tags
14
- model.send :index, :tag
13
+ model.send :attribute, :metadata
15
14
 
16
15
  # removing this as it's simply redundant
17
16
  # model.after :save, :notify_via_redis_save
@@ -33,30 +32,24 @@ module Noah
33
32
  self.created_at == self.updated_at
34
33
  end
35
34
 
36
- def tag(tags = self.tags)
37
- tags.to_s.split(/\s*,\s*/).uniq
38
- end
39
-
40
35
  def link!(path)
41
36
  base_pattern = "#{self.patternize_me}"
42
37
  path.nil? ? (raise ArgumentError, "Must provide a path") : p=path
43
38
 
44
39
  begin
45
- l = Link.new :path => p, :source => base_pattern
46
- l.valid? ? l.save : (raise "#{l.errors}")
47
- l.name
40
+ l = Link.find_or_create :path => p
41
+ l.nodes = self
48
42
  rescue Exception => e
49
43
  e.message
50
44
  end
51
45
  end
52
46
 
53
- def watch!(opts={:endpoint => nil, :pattern => nil})
47
+ def watch!(opts={:endpoint => nil})
54
48
  base_pattern = "#{self.patternize_me}"
55
49
  opts[:endpoint].nil? ? (raise ArgumentError, "Need an endpoint") : endpoint=opts[:endpoint]
56
- opts[:pattern].nil? ? pattern=base_pattern : pattern=opts[:pattern]
57
50
 
58
51
  begin
59
- w = Watcher.new :pattern => pattern, :endpoint => endpoint
52
+ w = Watcher.new :pattern => base_pattern, :endpoint => endpoint
60
53
  w.valid? ? w.save : (raise "#{w.errors}")
61
54
  w.name
62
55
  rescue Exception => e
@@ -65,17 +58,18 @@ module Noah
65
58
  end
66
59
 
67
60
  protected
68
- def patternize_me
61
+ def patternize_me(opts = {:namespace => nil})
62
+ opts[:namespace].nil? ? namespace="//noah/#{self.class_to_lower}s" : namespace="//noah/#{opts[:namespace]}/#{self.class_to_lower}s"
69
63
  name.match(/^\//) ? n = name.gsub(/^\//, '') : n = name
70
- "//noah/#{self.class_to_lower}s/#{n}"
64
+ "#{namespace}/#{n}"
71
65
  end
72
66
 
73
67
  def stash_name
74
68
  @deleted_name = self.name
75
69
  end
76
70
 
77
- def class_to_lower
78
- self.class.to_s.gsub(/(.*)::(\w)/,'\2').downcase
71
+ def class_to_lower(class_name = self.class.to_s)
72
+ class_name.gsub(/(.*)::(\w)/,'\2').downcase
79
73
  end
80
74
 
81
75
  def dbnum
@@ -85,15 +79,6 @@ module Noah
85
79
  o[:db].nil? ? "#{o[:url].split('/').last}" : "#{o[:db]}"
86
80
  end
87
81
 
88
- def before_update
89
- return if new?
90
- tag(read_remote(:tags)).map(&Tag).each {|t| t.decr :total}
91
- end
92
-
93
- def after_save
94
- tag.map(&Tag).each {|t| t.incr :total }
95
- end
96
-
97
82
  ["create", "update", "delete"].each do |meth|
98
83
  class_eval do
99
84
  define_method("notify_via_redis_#{meth}".to_sym) do
@@ -126,7 +111,11 @@ module Noah
126
111
 
127
112
  end
128
113
 
114
+ require File.join(File.dirname(__FILE__), 'linkable')
115
+ require File.join(File.dirname(__FILE__), 'models','link')
116
+ require File.join(File.dirname(__FILE__), 'taggable')
129
117
  require File.join(File.dirname(__FILE__), 'models','tags')
118
+ require File.join(File.dirname(__FILE__), 'models','link')
130
119
  require File.join(File.dirname(__FILE__), 'models','hosts')
131
120
  require File.join(File.dirname(__FILE__), 'models','services')
132
121
  require File.join(File.dirname(__FILE__), 'models','applications')
@@ -2,21 +2,23 @@ class Noah::App
2
2
  # Application URIs
3
3
  get '/applications/:appname/:config/?' do |appname, config|
4
4
  app = Noah::Application.find(:name => appname).first
5
- if app.nil?
6
- halt 404
7
- else
8
- c = Noah::Configuration.find(:name => config, :application_id => app.id).first
9
- c.to_json
10
- end
5
+ (halt 404) if app.nil?
6
+ c = app.configurations.find(:name => config).first
7
+ c.to_json
11
8
  end
12
9
 
13
10
  get '/applications/:appname/?' do |appname|
14
11
  app = Noah::Application.find(:name => appname).first
15
- if app.nil?
16
- halt 404
17
- else
18
- app.to_json
19
- end
12
+ (halt 404) if app.nil?
13
+ app.to_json
14
+ end
15
+
16
+ put '/applications/:appname/tag' do |appname|
17
+ required_params = ["tags"]
18
+ data = JSON.parse(request.body.read)
19
+ (data.keys.sort == required_params.sort) ? (a=Noah::Application.find(:name=>appname).first) : (raise "Missing Parameters")
20
+ a.nil? ? (halt 404) : (a.tag!(data['tags']))
21
+ a.to_json
20
22
  end
21
23
 
22
24
  put '/applications/:appname/watch' do |appname|
@@ -27,6 +29,14 @@ class Noah::App
27
29
  w.to_json
28
30
  end
29
31
 
32
+ put '/applications/:appname/link' do |appname|
33
+ required_params = ["link_name"]
34
+ data = JSON.parse(request.body.read)
35
+ (data.keys.sort == required_params.sort) ? (a = Noah::Application.find(:name => appname).first) : (raise "Missing Parameters")
36
+ a.nil? ? (halt 404) : (a.link! data["link_name"])
37
+ a.to_json
38
+ end
39
+
30
40
  put '/applications/:appname/?' do |appname|
31
41
  required_params = ["name"]
32
42
  data = JSON.parse(request.body.read)
@@ -47,24 +57,18 @@ class Noah::App
47
57
 
48
58
  delete '/applications/:appname/?' do |appname|
49
59
  app = Noah::Application.find(:name => appname).first
50
- if app.nil?
51
- halt 404
52
- else
53
- configurations = []
54
- Noah::Configuration.find(:application_id => app.id).sort.each {|x| configurations << x; x.delete} if app.configurations.size > 0
55
- app.delete
56
- r = {"result" => "success", "action" => "delete", "id" => "#{app.id}", "name" => "#{appname}", "configurations" => "#{configurations.size}"}
57
- r.to_json
58
- end
60
+ (halt 404) if app.nil?
61
+ app.delete
62
+ r = {"result" => "success", "action" => "delete", "id" => "#{app.id}", "name" => "#{appname}"}
63
+ r.to_json
64
+ end
65
+
66
+ delete '/applications/:appname/configurations/:configname/?' do |appname, configname|
59
67
  end
60
68
 
61
69
  get '/applications/?' do
62
- apps = []
63
- Noah::Application.all.sort.each {|a| apps << a.to_hash}
64
- if apps.empty?
65
- halt 404
66
- else
67
- apps.to_json
68
- end
70
+ apps = Noah::Applications.all
71
+ (halt 404) if apps.size == 0
72
+ apps.to_json
69
73
  end
70
74
  end
@@ -0,0 +1,77 @@
1
+ class Noah::App
2
+ content_type_mapping = {
3
+ :yaml => "text/x-yaml",
4
+ :json => "application/json",
5
+ :xml => "text/xml",
6
+ :string => "text/plain"
7
+ }
8
+ # GET the raw data of a configuration object
9
+ get '/configurations/:configname/data/?' do |configname|
10
+ c = Noah::Configuration.find(:name => configname).first
11
+ (halt 404) if c.nil?
12
+ content_type content_type_mapping[c.format.to_sym] if content_type_mapping[c.format.to_sym]
13
+ response.headers['Content-Disposition'] = "attachment; filename=#{configname}"
14
+ c.body
15
+ end
16
+ # GET the JSON representation of a configuration object
17
+ get '/configurations/:configname/?' do |configname|
18
+ c = Noah::Configuration.find(:name => configname).first
19
+ (halt 404) if c.nil?
20
+ c.to_json
21
+ end
22
+ # GET all configurations
23
+ get '/configurations/?' do
24
+ configs = Noah::Configurations.all.to_hash
25
+ (halt 404) if configs.size == 0
26
+ configs.to_json
27
+ end
28
+ # Add configuration object to a custom link hierarchy
29
+ put '/configurations/:configname/link' do |configname|
30
+ required_params = ["link_name"]
31
+ data = JSON.parse(request.body.read)
32
+ (data.keys.sort == required_params.sort) ? (a = Noah::Configuration.find(:name => configname).first) : (raise "Missing Parameters")
33
+ a.nil? ? (halt 404) : (a.link! data["link_name"])
34
+ a.to_json
35
+ end
36
+ # Add a tag to a configuration object
37
+ put '/configurations/:configname/tag' do |configname|
38
+ required_params = ["tags"]
39
+ data = JSON.parse(request.body.read)
40
+ (data.keys.sort == required_params.sort) ? (c=Noah::Configuration.find(:name=>configname).first) : (raise "Missing Parameters")
41
+ c.nil? ? (halt 404) : (c.tag!(data['tags']))
42
+ c.to_json
43
+
44
+ end
45
+ # Add a watch to a configuration object
46
+ put '/configurations/:configname/watch' do |configname|
47
+ required_params = ["endpoint"]
48
+ data = JSON.parse(request.body.read)
49
+ (data.keys.sort == required_params.sort) ? (c = Noah::Configuration.find(:name => configname).first) : (raise "Missing Parameters")
50
+ c.nil? ? (halt 404) : (w = c.watch!(:endpoint => data['endpoint']))
51
+ w.to_json
52
+ end
53
+ # Attach a configuration object to an application object
54
+ put '/configurations/:configname/?' do |configname|
55
+ required_params = ["format", "body"]
56
+ data = JSON.parse(request.body.read)
57
+ data.keys.sort == required_params.sort ? config=Noah::Configuration.find_or_create(:name => configname) : (raise "Missing Parameters")
58
+ config.body = data["body"]
59
+ config.format = data["format"]
60
+ if config.valid?
61
+ config.save
62
+ action = config.is_new? ? "create" : "update"
63
+ r = {"result" => "success","id" => "#{config.id}", "action" => action, "item" => config.name}
64
+ r.to_json
65
+ else
66
+ raise "#{format_errors(config)}"
67
+ end
68
+ end
69
+
70
+ delete '/configurations/:configname/?' do |configname|
71
+ cfg = Noah::Configuration.find(:name => configname).first
72
+ (halt 404) if cfg.nil?
73
+ cfg.delete
74
+ r = {"result" => "success", "id" => cfg.id, "action" => "delete", "affected_applications" => cfg.affected_applications, "item" => cfg.name}
75
+ r.to_json
76
+ end
77
+ end
@@ -1,16 +1,16 @@
1
1
  class Noah::App
2
- get '/e/?' do
2
+ get '/ephemerals/?' do
3
3
  halt 404
4
4
  end
5
5
 
6
- get '/e/*' do
6
+ get '/ephemerals/*' do
7
7
  params["splat"].size == 0 ? (halt 404) : (e=Noah::Ephemeral.find(:path => "/#{params["splat"][0]}").first)
8
8
  (halt 404) if e.nil?
9
9
  content_type "application/octet-stream"
10
10
  e.data.nil? ? "" : "#{e.data}"
11
11
  end
12
12
 
13
- put '/e/*/watch' do
13
+ put '/ephemerals/*/watch' do
14
14
  required_params = ["endpoint"]
15
15
  data = JSON.parse(request.body.read)
16
16
  (data.keys.sort == required_params.sort) ? (e = Noah::Watcher.find(:path => params[:splat][0]).first) : (raise "Missing Parameters")
@@ -18,7 +18,7 @@ class Noah::App
18
18
  w.to_json
19
19
  end
20
20
 
21
- put '/e/*' do
21
+ put '/ephemerals/*' do
22
22
  raise("Data too large") if request.body.size > 512
23
23
  d = request.body.read || nil
24
24
  opts = {:path => "/#{params[:splat][0]}", :data => d}
@@ -32,7 +32,7 @@ class Noah::App
32
32
  end
33
33
  end
34
34
 
35
- delete '/e/*' do
35
+ delete '/ephemerals/*' do
36
36
  p = params[:splat][0]
37
37
  e = Noah::Ephemeral.find(:path => "/"+p).first
38
38
  if e
@@ -25,7 +25,6 @@ class Noah::App
25
25
 
26
26
  # GET all {Hosts}
27
27
  get '/hosts/?' do
28
- hosts.map {|h| h.to_hash}
29
28
  if hosts.size == 0
30
29
  halt 404
31
30
  else
@@ -33,6 +32,14 @@ class Noah::App
33
32
  end
34
33
  end
35
34
 
35
+ put '/hosts/:hostname/tag' do |hostname|
36
+ required_params = ["tags"]
37
+ data = JSON.parse(request.body.read)
38
+ (data.keys.sort == required_params.sort) ? (a=Noah::Host.find(:name=>hostname).first) : (raise "Missing Parameters")
39
+ a.nil? ? (halt 404) : (a.tag!(data['tags']))
40
+ a.to_json
41
+ end
42
+
36
43
  put '/hosts/:hostname/watch' do |hostname|
37
44
  required_params = ["endpoint"]
38
45
  data = JSON.parse(request.body.read)
@@ -41,6 +48,14 @@ class Noah::App
41
48
  w.to_json
42
49
  end
43
50
 
51
+ put '/hosts/:hostname/link' do |hostname|
52
+ required_params = ["link_name"]
53
+ data = JSON.parse(request.body.read)
54
+ (data.keys.sort == required_params.sort) ? (a = Noah::Host.find(:name => hostname).first) : (raise "Missing Parameters")
55
+ a.nil? ? (halt 404) : (a.link! data["link_name"])
56
+ a.to_json
57
+ end
58
+
44
59
  put '/hosts/:hostname/?' do |hostname|
45
60
  required_params = ["name", "status"]
46
61
  data = JSON.parse(request.body.read)
@@ -0,0 +1,16 @@
1
+ class Noah::App
2
+
3
+ get '/:link_name/:model_name/?' do |path, model|
4
+ link_name = Noah::Link.find(:path => "/"+path).first
5
+ (halt 404) if link_name.nil?
6
+ (halt 404) if link_name.to_hash.has_key?(model.to_sym) == false
7
+ link_name.to_hash[model.to_sym].to_json
8
+ end
9
+
10
+ get '/:link_name/?' do |path|
11
+ link_name = Noah::Link.find(:path => "/"+path).first
12
+ (halt 404) if link_name.nil?
13
+ link_name.to_json
14
+ end
15
+
16
+ end
@@ -13,21 +13,37 @@ class Noah::App
13
13
 
14
14
  get '/services/:servicename/?' do |servicename|
15
15
  s = services(:name => servicename)
16
- s.map {|x| x.to_hash}
17
- if s.empty?
18
- halt 404
19
- else
20
- s.to_json
21
- end
16
+ (halt 404) if s.size == 0
17
+ s.to_json
22
18
  end
23
19
 
24
20
  get '/services/?' do
25
- if services.empty?
26
- halt 404
27
- else
28
- services.map {|s| s.to_hash}
29
- services.to_json
30
- end
21
+ (halt 404) if services.size == 0
22
+ services.to_json
23
+ end
24
+
25
+ put '/services/:servicename/link' do |appname|
26
+ required_params = ["link_name"]
27
+ data = JSON.parse(request.body.read)
28
+ (data.keys.sort == required_params.sort) ? (a = Noah::Service.find(:name => servicename).first) : (raise "Missing Parameters")
29
+ a.nil? ? (halt 404) : (a.link! data["link_name"])
30
+ a.to_json
31
+ end
32
+
33
+ put '/services/:servicename/:hostname/link' do |servicename, hostname|
34
+ required_params = ["link_name"]
35
+ data = JSON.parse(request.body.read)
36
+ (data.keys.sort == required_params.sort) ? (a=host_service(hostname, servicename)) : (raise "Missing Parameters")
37
+ a.nil? ? (halt 404) : (a.link! data["link_name"])
38
+ a.to_json
39
+ end
40
+
41
+ put '/services/:servicename/:hostname/tag' do |servicename, hostname|
42
+ required_params = ["tags"]
43
+ data = JSON.parse(request.body.read)
44
+ (data.keys.sort == required_params.sort) ? (a=host_service(hostname, servicename)) : (raise "Missing Parameters")
45
+ a.nil? ? (halt 404) : (a.tag!(data['tags']))
46
+ a.to_json
31
47
  end
32
48
 
33
49
  put '/services/:servicename/watch' do |servicename|
@@ -0,0 +1,15 @@
1
+ class Noah::App
2
+
3
+ get '/tags/:tagname/?' do |tagname|
4
+ tags = Noah::Tags.all(:name => tagname).to_hash
5
+ (halt 404) if tags.size == 0
6
+ tags.to_json
7
+ end
8
+
9
+ get '/tags/?' do
10
+ tags = Noah::Tags.all.to_hash
11
+ (halt 404) if tags.size == 0
12
+ tags.to_json
13
+ end
14
+
15
+ end
File without changes
@@ -0,0 +1,30 @@
1
+ module Noah::Taggable
2
+ def self.included(model)
3
+ model.send :set, :tags, ::Noah::Tag
4
+ model.send :index, :tags
5
+ end
6
+
7
+ def tag!(tag_name)
8
+ case tag_name.class.to_s
9
+ when "Array"
10
+ tag_name.each do |t|
11
+ my_tag = ::Noah::Tag.find_or_create(:name => t)
12
+ tags << my_tag
13
+ my_tag.members = self
14
+ end
15
+ else
16
+ my_tag = ::Noah::Tag.find_or_create(:name => tag_name)
17
+ tags << my_tag
18
+ my_tag.members = self
19
+ end
20
+ end
21
+
22
+ def untag!(tag_name)
23
+ end
24
+
25
+ def to_hash
26
+ tag_arr = Array.new
27
+ self.tags.sort.each {|t| tag_arr << t.name} if self.tags.size != 0
28
+ super.merge(:tags => tag_arr)
29
+ end
30
+ end
data/lib/noah/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Noah
2
- VERSION = "0.4"
2
+ VERSION = "0.6"
3
3
  end
data/lib/noah.rb CHANGED
@@ -17,6 +17,7 @@ require 'yaml'
17
17
  require 'sinatra/base'
18
18
 
19
19
  require File.join(File.dirname(__FILE__), 'noah', 'log')
20
+ require File.join(File.dirname(__FILE__), 'noah', 'exceptions')
20
21
  require File.join(File.dirname(__FILE__), 'noah', 'custom_watcher')
21
22
  require File.join(File.dirname(__FILE__), 'noah','validations')
22
23
  require File.join(File.dirname(__FILE__), 'noah','models')
data/noah.gemspec CHANGED
@@ -4,7 +4,8 @@ require "noah/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "noah"
7
- s.version = Noah::VERSION
7
+ s.version = "#{Noah::VERSION}.pre"
8
+ s.post_install_message = %q{This release has backwards incompatible changes to the API. Please watch http://goo.gl/jYqp2 for details}
8
9
  s.platform = Gem::Platform::RUBY
9
10
  #s.platform = "jruby"
10
11
  s.authors = ["John E. Vincent"]
@@ -22,11 +23,11 @@ Gem::Specification.new do |s|
22
23
 
23
24
  s.add_dependency("eventmachine", ["1.0.0.beta.3"])
24
25
  s.add_dependency("em-http-request", ["1.0.0.beta.3"])
25
- s.add_dependency("redis", ["= 2.1.1"])
26
+ s.add_dependency("redis", ["= 2.2.0"])
26
27
  s.add_dependency("nest", ["= 1.1.0"])
27
- s.add_dependency("rack", ["= 1.2.1"])
28
+ s.add_dependency("rack", ["= 1.2.2"])
28
29
  s.add_dependency("tilt", ["= 1.2.2"])
29
- s.add_dependency("sinatra", ["= 1.2.0"])
30
+ s.add_dependency("sinatra", ["= 1.2.3"])
30
31
  s.add_dependency("ohm", ["= 0.1.3"])
31
32
  s.add_dependency("ohm-contrib", ["= 0.1.1"])
32
33
  s.add_dependency("haml", ["= 3.0.25"])
@@ -23,7 +23,7 @@ describe "Using the Application Model", :reset_redis => true do
23
23
  end
24
24
  it "create a new Noah::Application with Configurations" do
25
25
  a = Noah::Application.create(@appdata1)
26
- a.configurations << Noah::Configuration.create(@appconf_string.merge({:application => a}))
26
+ a.configurations << Noah::Configuration.create(@appconf_string)
27
27
  a.valid?.should == true
28
28
  a.is_new?.should == true
29
29
  a.save
@@ -61,8 +61,8 @@ describe "Using the Application Model", :reset_redis => true do
61
61
  b = Noah::Application.create(@appdata2)
62
62
  c = Noah::Applications.all
63
63
  c.size.should == 2
64
- c.member?(a).should == true
65
- c.member?(b).should == true
64
+ c.keys.member?(a.name).should == true
65
+ c.keys.member?(b.name).should == true
66
66
  end
67
67
  end
68
68
 
@@ -3,13 +3,11 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
3
  describe "Using the Configuration Model", :reset_redis => true do
4
4
  before(:each) do
5
5
  Ohm.redis.flushdb
6
- app = Noah::Application.create :name => "my_application"
7
- @appconf_string = {:name => "mystringconf", :format => "string", :body => "some_var", :application_id => app.id}
8
- @appconf_json = {:name => "myjsonconf", :format => "json", :body => @appconf_string.to_json, :application_id => app.id}
6
+ @appconf_string = {:name => "mystringconf", :format => "string", :body => "some_var"}
7
+ @appconf_json = {:name => "myjsonconf", :format => "json", :body => @appconf_string.to_json}
9
8
  @appconf_missing_name = @appconf_string.reject {|k, v| k == :name}
10
9
  @appconf_missing_format = @appconf_string.reject {|k, v| k == :format}
11
10
  @appconf_missing_body = @appconf_string.reject {|k, v| k == :body}
12
- @appconf_missing_application = @appconf_string.reject {|k, v| k == :application_id}
13
11
  end
14
12
  after(:each) do
15
13
  Ohm.redis.flushdb
@@ -48,13 +46,27 @@ describe "Using the Configuration Model", :reset_redis => true do
48
46
  c = Noah::Configuration.find(@appconf_string).first
49
47
  c.nil?.should == true
50
48
  end
49
+ it "delete from Application when deleting Configuration" do
50
+ # We have to test this because we override delete in Configuration
51
+ a = Noah::Configuration.find_or_create(@appconf_string)
52
+ b = Noah::Configuration.find(@appconf_string).first
53
+ c = Noah::Application.create(:name => "somerandomapp1234")
54
+ c.configurations << a
55
+ b.should == a
56
+ a.delete
57
+ d = Noah::Configuration.find(@appconf_string).first
58
+ d.nil?.should == true
59
+ a.affected_applications.member?(c.name).should == true
60
+ c.configurations.size.should == 0
61
+ end
51
62
  it "return all Configurations" do
52
63
  a = Noah::Configuration.find_or_create(@appconf_string)
53
64
  b = Noah::Configuration.find_or_create(@appconf_json)
54
65
  c = Noah::Configurations.all
66
+ c.class.to_s.should == 'Hash'
55
67
  c.size.should == 2
56
- c.member?(a).should == true
57
- c.member?(b).should == true
68
+ c.has_key?(a.name).should == true
69
+ c.has_key?(b.name).should == true
58
70
  end
59
71
  end
60
72
 
@@ -74,15 +86,10 @@ describe "Using the Configuration Model", :reset_redis => true do
74
86
  a.valid?.should == false
75
87
  a.errors.should == [[:body, :not_present]]
76
88
  end
77
- it "create a new Confguration without an application" do
78
- a = Noah::Configuration.create(@appconf_missing_application)
79
- a.valid?.should == false
80
- a.errors.should == [[:application_id, :not_present]]
81
- end
82
89
  it "create a duplicate Configuration" do
83
90
  a = Noah::Configuration.create(@appconf_string)
84
91
  b = Noah::Configuration.create(@appconf_string)
85
- b.errors.should == [[[:name, :application_id], :not_unique]]
92
+ b.errors.should == [[:name, :not_unique]]
86
93
  end
87
94
  end
88
95
 
data/spec/host_spec.rb CHANGED
@@ -73,12 +73,12 @@ describe "Using the Host Model", :reset_redis => true do
73
73
  host2 = Noah::Host.create(:name => hostname2, :status => status2)
74
74
  host1.save
75
75
  host2.save
76
- Noah::Hosts.all.class.should == Array
76
+ Noah::Hosts.all.class.should == Hash
77
77
  Noah::Hosts.all.size.should == 2
78
- Noah::Hosts.all.first.name.should == hostname1
79
- Noah::Hosts.all.first.status.should == status1
80
- Noah::Hosts.all.last.name.should == hostname2
81
- Noah::Hosts.all.last.status.should == status2
78
+ Noah::Hosts.all.has_key?(hostname1).should == true
79
+ Noah::Hosts.all[hostname1][:status].should == status1
80
+ Noah::Hosts.all.has_key?(hostname2).should == true
81
+ Noah::Hosts.all[hostname2][:status].should == status2
82
82
  end
83
83
  end
84
84
 
@@ -3,9 +3,9 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
3
  describe "Using the Application API", :reset_redis => false do
4
4
  before(:all) do
5
5
  @a = Noah::Application.create(:name => 'rspec_sample_app')
6
- @a.configurations << Noah::Configuration.create(:name => 'rspec_config', :format => 'string', :body => 'rspec is great', :application => @a)
6
+ @c = Noah::Configuration.create(:name => 'rspec_config', :format => 'string', :body => 'rspec is great')
7
+ @a.configurations << @c
7
8
  @a.save
8
- @c = @a.configurations.first
9
9
  end
10
10
  describe "calling" do
11
11
 
@@ -14,20 +14,20 @@ describe "Using the Application API", :reset_redis => false do
14
14
  get '/applications'
15
15
  last_response.should be_ok
16
16
  response = last_response.should return_json
17
- response.is_a?(Array).should == true
17
+ response.is_a?(Hash).should == true
18
18
  end
19
19
  it "named application should work" do
20
20
  get '/applications/rspec_sample_app'
21
21
  last_response.should be_ok
22
22
  response = last_response.should return_json
23
-
24
- response["id"].should == @a.id
25
- response["name"].should == @a.name
26
- c = response["configurations"].first
27
- c["id"].should == @c.id
28
- c["name"].should == @c.name
29
- c["body"].should == @c.body
30
- c["format"].should == @c.format
23
+ response.has_key?(@a.name).should == true
24
+ response[@a.name].class.to_s.should == 'Hash'
25
+ response[@a.name]["id"].should == @a.id.to_s
26
+ response[@a.name].has_key?("configurations").should == true
27
+ c = response[@a.name]["configurations"]
28
+ c.has_key?(@c.name).should == true
29
+ c["#{@c.name}"]["format"].should == "#{@c.format}"
30
+ c["#{@c.name}"]["body"].should == "#{@c.body}"
31
31
  end
32
32
  it "named configuration for application should work" do
33
33
  get "/applications/#{@a.name}/#{@c.name}"
@@ -38,7 +38,6 @@ describe "Using the Application API", :reset_redis => false do
38
38
  response["name"].should == @c.name
39
39
  response["format"].should == @c.format
40
40
  response["body"].should == @c.body
41
- response["application"].should == @a.name
42
41
  end
43
42
  it "invalid application should not work" do
44
43
  get "/applications/should_not_exist"
@@ -96,7 +95,6 @@ describe "Using the Application API", :reset_redis => false do
96
95
  response["action"].should == "delete"
97
96
  response["id"].nil?.should == false
98
97
  response["name"].should == @appdata[:name]
99
- response["configurations"].should == "0"
100
98
  end
101
99
  it "invalid application should not work" do
102
100
  delete "/applications/should_not_work"