noah 0.4-jruby → 0.6.pre-jruby

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.rb +1 -0
  3. data/lib/noah/agent.rb +1 -0
  4. data/lib/noah/agents/base_agent.rb +4 -2
  5. data/lib/noah/agents/http_agent.rb +1 -1
  6. data/lib/noah/agents/https_agent.rb +6 -0
  7. data/lib/noah/app.rb +8 -6
  8. data/lib/noah/exceptions.rb +0 -0
  9. data/lib/noah/linkable.rb +21 -0
  10. data/lib/noah/models.rb +14 -25
  11. data/lib/noah/models/applications.rb +19 -9
  12. data/lib/noah/models/configurations.rb +32 -13
  13. data/lib/noah/models/ephemerals.rb +7 -6
  14. data/lib/noah/models/hosts.rb +11 -5
  15. data/lib/noah/models/link.rb +70 -29
  16. data/lib/noah/models/services.rb +11 -2
  17. data/lib/noah/models/tags.rb +86 -5
  18. data/lib/noah/models/watchers.rb +0 -1
  19. data/lib/noah/{application_routes.rb → routes/applications.rb} +31 -27
  20. data/lib/noah/routes/configurations.rb +77 -0
  21. data/lib/noah/{ephemeral_routes.rb → routes/ephemerals.rb} +5 -5
  22. data/lib/noah/{host_routes.rb → routes/hosts.rb} +16 -1
  23. data/lib/noah/routes/links.rb +16 -0
  24. data/lib/noah/{service_routes.rb → routes/services.rb} +28 -12
  25. data/lib/noah/routes/tags.rb +15 -0
  26. data/lib/noah/{watcher_routes.rb → routes/watchers.rb} +0 -0
  27. data/lib/noah/taggable.rb +30 -0
  28. data/lib/noah/version.rb +1 -1
  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 +335 -311
  44. data/lib/noah/configuration_routes.rb +0 -81
  45. data/lib/noah/models/link_member.rb +0 -18
@@ -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/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"
@@ -1,34 +1,61 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
- describe "Using the Configuration API", :reset_redis => false, :populate_sample_data => true do
3
+ SAMPLE_YAML = <<EOY
4
+ development:
5
+ database: development_database
6
+ adapter: mysql
7
+ username: dev_user
8
+ password: dev_password
9
+ EOY
10
+
11
+ SAMPLE_JSON = <<EOJ
12
+ {
13
+ "id":"hostname",
14
+ "data":"localhost"
15
+ }
16
+ EOJ
17
+
18
+ describe "Using the Configuration API", :reset_redis => true, :populate_sample_data => false do
4
19
  describe "calling" do
20
+ before(:each) do
21
+ Ohm.redis.flushdb
22
+ @redis_config = Noah::Configuration.create(:name => 'redis_url', :format => 'string', :body => 'redis://127.0.0.1:6379/0')
23
+ @json_config = Noah::Configuration.create(:name => 'json_config', :format => 'json', :body => SAMPLE_JSON)
24
+ @yaml_config = Noah::Configuration.create(:name => 'yaml_config', :format => 'yaml', :body => SAMPLE_YAML)
25
+ @sample_application = Noah::Application.create(:name => 'rspec_application')
26
+ end
27
+ after(:each) do
28
+ Ohm.redis.flushdb
29
+ end
5
30
 
6
31
  describe "GET" do
7
32
  it "all configurations should work" do
8
33
  get '/configurations'
9
34
  last_response.should be_ok
10
- last_response.should return_json
11
- end
12
- it "named application should work" do
13
- get '/configurations/noah'
14
- last_response.should be_ok
15
35
  response = last_response.should return_json
16
-
17
- response.is_a?(Array).should == true
18
- response.first["name"].should == "redis"
19
- response.first["format"].should == "string"
20
- response.first["body"].should == "redis://127.0.0.1:6379/0"
21
- response.first["application"].should == "noah"
36
+ response.keys.size.should == 3
37
+ %w[redis_url json_config yaml_config].each do |c|
38
+ response.keys.member?(c).should == true
39
+ %w[id tags links format body created_at updated_at].each do |ck|
40
+ response[c].keys.member?(ck).should == true
41
+ end
42
+ end
22
43
  end
23
- it "named configuration for application should work" do
24
- get '/configurations/noah/redis'
44
+ it "named configuration should work" do
45
+ get '/configurations/redis_url'
25
46
  last_response.should be_ok
26
- response = last_response.body
27
- response.should == "redis://127.0.0.1:6379/0"
47
+ response = last_response.should return_json
48
+ response.is_a?(Hash).should == true
49
+ response['name'].should == @redis_config.name
50
+ response['id'].should == @redis_config.id
51
+ response["format"].should == @redis_config.format
52
+ response["body"].should == @redis_config.body
53
+ response["tags"].size.should == 0
54
+ response["links"].size.should == 0
28
55
  end
29
56
  it "named configuration should work with mime-type" do
30
57
  require 'yaml'
31
- get '/configurations/myrailsapp1/database.yml'
58
+ get '/configurations/yaml_config/data'
32
59
  last_response.should be_ok
33
60
  last_response.headers["Content-Type"].should == "text/x-yaml;charset=utf-8"
34
61
  response = YAML.load(last_response.body)
@@ -37,12 +64,12 @@ describe "Using the Configuration API", :reset_redis => false, :populate_sample_
37
64
  response["development"].keys.sort.should == ["adapter", "database", "password", "username"]
38
65
  response["development"].values.sort.should == ["dev_password", "dev_user", "development_database", "mysql"]
39
66
  end
40
- it "invalid application should not work" do
41
- get '/configurations/badapp'
67
+ it "invalid configuration should not work" do
68
+ get '/configurations/badconfig'
42
69
  last_response.should be_missing
43
70
  end
44
- it "invalid configuration for application should not work" do
45
- get '/configurations/badapp/badconfig'
71
+ it "invalid configuration data should not work" do
72
+ get '/configurations/badconfig/data'
46
73
  last_response.should be_missing
47
74
  end
48
75
  end
@@ -50,60 +77,56 @@ describe "Using the Configuration API", :reset_redis => false, :populate_sample_
50
77
  describe "PUT" do
51
78
  it "new configuration should work" do
52
79
  config_data = {:format => "string", :body => "sample_config_entry"}.to_json
53
- put '/configurations/newapp/newconfig', config_data, "CONTENT_TYPE" => "application/json"
80
+ put '/configurations/newconfig', config_data, "CONTENT_TYPE" => "application/json"
54
81
  last_response.should be_ok
55
82
  response = last_response.should return_json
56
83
  response["result"].should == "success"
57
84
  response["action"].should == "create"
58
- response["dependencies"].should == "created"
59
- response["application"].should == "newapp"
60
85
  response["item"].should == "newconfig"
61
86
  end
62
87
  it "existing configuration should work" do
63
88
  config_data = {:format => "string", :body => "sample_config_entry"}.to_json
89
+ put '/configurations/newconfig', config_data, "CONTENT_TYPE" => "application/json"
64
90
  sleep 3
65
- put '/configurations/newapp/newconfig', config_data, "CONTENT_TYPE" => "application/json"
91
+ put '/configurations/newconfig', config_data, "CONTENT_TYPE" => "application/json"
66
92
  last_response.should be_ok
67
93
  response = last_response.should return_json
68
94
  response["result"].should == "success"
69
95
  response["action"].should == "update"
70
- response["dependencies"].should == "updated"
71
- response["application"].should == "newapp"
72
96
  response["item"].should == "newconfig"
73
97
  end
74
98
  it "new configuration with missing format should not work" do
75
99
  config_data = {:body => "a string"}.to_json
76
- put '/configurations/newnewapp/someconfig', config_data, "CONTENT_TYPE" => "application/json"
100
+ put '/configurations/someconfig', config_data, "CONTENT_TYPE" => "application/json"
77
101
  last_response.should be_invalid
78
102
  end
79
103
  it "new configuration with missing body should not work" do
80
104
  config_data = {:body => "a string"}.to_json
81
- put '/configurations/newnewapp/someconfig', config_data, "CONTENT_TYPE" => "application/json"
105
+ put '/configurations/someconfig', config_data, "CONTENT_TYPE" => "application/json"
82
106
  last_response.should be_invalid
83
107
  end
84
108
  end
85
109
 
86
110
  describe "DELETE" do
87
- before(:all) do
88
- @a = Noah::Application.create(:name => 'delete_test_app')
89
- cparms = {:name => 'a', :format => 'string', :body => 'asdf', :application_id => @a.id}
90
- @a.configurations << Noah::Configuration.create(cparms)
91
- @a.save
92
- @c = @a.configurations.first
93
- end
94
-
95
111
  it "existing configuration should work" do
96
- delete "/configurations/#{@a.name}/#{@c.name}"
112
+ @a = Noah::Application.create(:name => 'delete_test_app')
113
+ cparms = {:name => 'asdf', :format => 'string', :body => 'asdf'}
114
+ @c = Noah::Configuration.create(cparms)
115
+ @a.configurations << @c
116
+ get "/configurations/asdf"
117
+ p last_response
118
+ delete "/configurations/#{@c.name}"
119
+ p last_response
97
120
  last_response.should be_ok
98
121
  response = last_response.should return_json
99
122
  response["result"].should == "success"
100
123
  response["id"].should == @c.id
101
124
  response["action"].should == "delete"
102
- response["application"].should == @a.name
125
+ response["affected_applications"].member?(@a.name).should == true
103
126
  response["item"].should == @c.name
104
127
  end
105
128
  it "invalid configuration should not work" do
106
- delete "/configurations/#{@a.name}/#{@c.name}"
129
+ delete "/configurations/somethingthatshouldnotexist"
107
130
  last_response.should be_missing
108
131
  end
109
132
  end