noah 0.0.5-jruby → 0.1-jruby

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. data/.gemtest +0 -0
  2. data/.gitignore +10 -0
  3. data/LICENSE +201 -0
  4. data/README.md +68 -212
  5. data/Rakefile +65 -41
  6. data/TODO.md +65 -0
  7. data/bin/noah +2 -1
  8. data/bin/noah-watcher.rb +103 -0
  9. data/config.ru +6 -3
  10. data/config/warble.rb +18 -0
  11. data/examples/README.md +116 -0
  12. data/examples/cluster.ru +2 -0
  13. data/examples/custom-watcher.rb +10 -0
  14. data/examples/httpclient-server.rb +7 -0
  15. data/examples/httpclient.rb +12 -0
  16. data/examples/httpclient2.rb +28 -0
  17. data/examples/js/FABridge.js +1452 -0
  18. data/examples/js/WebSocketMain.swf +830 -0
  19. data/examples/js/swfobject.js +851 -0
  20. data/examples/js/web_socket.js +312 -0
  21. data/examples/logger.rb +11 -0
  22. data/examples/reconfiguring-sinatra-watcher.rb +11 -0
  23. data/examples/reconfiguring-sinatra.rb +33 -0
  24. data/examples/simple-post.rb +17 -0
  25. data/examples/websocket.html +24 -0
  26. data/examples/websocket.rb +41 -0
  27. data/lib/noah.rb +6 -8
  28. data/lib/noah/app.rb +20 -268
  29. data/lib/noah/application_routes.rb +70 -0
  30. data/lib/noah/ark.rb +0 -0
  31. data/lib/noah/configuration_routes.rb +81 -0
  32. data/lib/noah/custom_watcher.rb +79 -0
  33. data/lib/noah/ephemeral_routes.rb +47 -0
  34. data/lib/noah/helpers.rb +37 -14
  35. data/lib/noah/host_routes.rb +69 -0
  36. data/lib/noah/models.rb +86 -5
  37. data/lib/noah/models/applications.rb +41 -0
  38. data/lib/noah/models/configurations.rb +49 -0
  39. data/lib/noah/models/ephemerals.rb +54 -0
  40. data/lib/noah/models/hosts.rb +56 -0
  41. data/lib/noah/models/services.rb +54 -0
  42. data/lib/noah/models/watchers.rb +62 -0
  43. data/lib/noah/passthrough.rb +11 -0
  44. data/lib/noah/service_routes.rb +71 -0
  45. data/lib/noah/validations.rb +1 -0
  46. data/lib/noah/validations/watcher_validations.rb +48 -0
  47. data/lib/noah/version.rb +1 -1
  48. data/lib/noah/watcher_routes.rb +45 -0
  49. data/noah.gemspec +25 -17
  50. data/spec/application_spec.rb +30 -30
  51. data/spec/configuration_spec.rb +78 -14
  52. data/spec/ephemeral_spec.rb +59 -0
  53. data/spec/host_spec.rb +21 -21
  54. data/spec/noahapp_application_spec.rb +6 -6
  55. data/spec/noahapp_configuration_spec.rb +5 -5
  56. data/spec/noahapp_ephemeral_spec.rb +115 -0
  57. data/spec/noahapp_host_spec.rb +3 -3
  58. data/spec/noahapp_service_spec.rb +10 -10
  59. data/spec/noahapp_watcher_spec.rb +123 -0
  60. data/spec/service_spec.rb +27 -27
  61. data/spec/spec_helper.rb +13 -22
  62. data/spec/support/db/.keep +0 -0
  63. data/spec/support/test-redis.conf +8 -0
  64. data/spec/watcher_spec.rb +62 -0
  65. data/views/index.haml +21 -15
  66. metadata +189 -146
  67. data/Gemfile.lock +0 -83
  68. data/doc/coverage/index.html +0 -138
  69. data/doc/coverage/jquery-1.3.2.min.js +0 -19
  70. data/doc/coverage/jquery.tablesorter.min.js +0 -15
  71. data/doc/coverage/lib-helpers_rb.html +0 -393
  72. data/doc/coverage/lib-models_rb.html +0 -1449
  73. data/doc/coverage/noah_rb.html +0 -2019
  74. data/doc/coverage/print.css +0 -12
  75. data/doc/coverage/rcov.js +0 -42
  76. data/doc/coverage/screen.css +0 -270
  77. data/lib/noah/applications.rb +0 -46
  78. data/lib/noah/configurations.rb +0 -49
  79. data/lib/noah/hosts.rb +0 -54
  80. data/lib/noah/services.rb +0 -57
  81. data/lib/noah/watchers.rb +0 -18
@@ -14,52 +14,52 @@ describe "Using the Application Model", :reset_redis => true do
14
14
  Ohm.redis.flushdb
15
15
  end
16
16
  describe "should" do
17
- it "create a new Application" do
18
- a = Application.create(@appdata1)
17
+ it "create a new Noah::Application" do
18
+ a = Noah::Application.create(@appdata1)
19
19
  a.valid?.should == true
20
20
  a.is_new?.should == true
21
- b = Application.find(@appdata1).first
21
+ b = Noah::Application.find(@appdata1).first
22
22
  b.should == a
23
23
  end
24
- it "create a new Application with Configurations" do
25
- a = Application.create(@appdata1)
26
- a.configurations << Configuration.create(@appconf_string.merge({:application => a}))
24
+ it "create a new Noah::Application with Configurations" do
25
+ a = Noah::Application.create(@appdata1)
26
+ a.configurations << Noah::Configuration.create(@appconf_string.merge({:application => a}))
27
27
  a.valid?.should == true
28
28
  a.is_new?.should == true
29
29
  a.save
30
- b = Application.find(@appdata1).first
30
+ b = Noah::Application.find(@appdata1).first
31
31
  b.should == a
32
32
  b.configurations.size.should == 1
33
33
  b.configurations.first.name.should == @appconf_string[:name]
34
34
  b.configurations.first.format.should == @appconf_string[:format]
35
35
  b.configurations.first.body.should == @appconf_string[:body]
36
36
  end
37
- it "create a new Application via find_or_create" do
38
- a = Application.find_or_create(@appdata2)
37
+ it "create a new Noah::Application via find_or_create" do
38
+ a = Noah::Application.find_or_create(@appdata2)
39
39
  a.valid?.should == true
40
40
  a.is_new?.should == true
41
- b = Application.find(@appdata2).first
41
+ b = Noah::Application.find(@appdata2).first
42
42
  b.should == a
43
43
  end
44
- it "update an existing Application via find_or_create" do
45
- a = Application.create(@appdata1)
44
+ it "update an existing Noah::Application via find_or_create" do
45
+ a = Noah::Application.create(@appdata1)
46
46
  a.is_new?.should == true
47
47
  sleep 2
48
- b = Application.find_or_create(@appdata1)
48
+ b = Noah::Application.find_or_create(@appdata1)
49
49
  b.is_new?.should == false
50
50
  end
51
- it "delete an existing Application" do
52
- a = Application.create(@appdata1)
53
- b = Application.find(@appdata1).first
51
+ it "delete an existing Noah::Application" do
52
+ a = Noah::Application.create(@appdata1)
53
+ b = Noah::Application.find(@appdata1).first
54
54
  b.should == a
55
55
  b.delete
56
- c = Application.find(@appdata1).first
56
+ c = Noah::Application.find(@appdata1).first
57
57
  c.nil?.should == true
58
58
  end
59
- it "return all Applications" do
60
- a = Application.create(@appdata1)
61
- b = Application.create(@appdata2)
62
- c = Applications.all
59
+ it "return all Noah::Applications" do
60
+ a = Noah::Application.create(@appdata1)
61
+ b = Noah::Application.create(@appdata2)
62
+ c = Noah::Applications.all
63
63
  c.size.should == 2
64
64
  c.member?(a).should == true
65
65
  c.member?(b).should == true
@@ -67,17 +67,17 @@ describe "Using the Application Model", :reset_redis => true do
67
67
  end
68
68
 
69
69
  describe "should not" do
70
- it "should not create a new Application without a name" do
71
- a = Application.create
70
+ it "should not create a new Noah::Application without a name" do
71
+ a = Noah::Application.create
72
72
  a.valid?.should == false
73
73
  a.errors.should == [[:name, :not_present]]
74
74
  end
75
- it "should not create a duplicate Application" do
76
- a = Application.create(@appdata1)
77
- a.valid?.should == true
78
- b = Application.create(@appdata1)
79
- b.valid?.should == false
80
- b.errors.should == [[:name, :not_unique]]
81
- end
75
+ # it "should not create a duplicate Noah::Application" do
76
+ # a = Noah::Application.create(@appdata1)
77
+ # a.valid?.should == true
78
+ # b = Noah::Application.create(@appdata1)
79
+ # b.valid?.should == false
80
+ # b.errors.should == [[:name, :not_unique]]
81
+ # end
82
82
  end
83
83
  end
@@ -1,25 +1,89 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe "Using the Configuration Model", :reset_redis => true do
4
+ before(:each) do
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}
9
+ @appconf_missing_name = @appconf_string.reject {|k, v| k == :name}
10
+ @appconf_missing_format = @appconf_string.reject {|k, v| k == :format}
11
+ @appconf_missing_body = @appconf_string.reject {|k, v| k == :body}
12
+ @appconf_missing_application = @appconf_string.reject {|k, v| k == :application_id}
13
+ end
14
+ after(:each) do
15
+ Ohm.redis.flushdb
16
+ end
4
17
 
5
18
  describe "should" do
6
-
7
- it "create a new Configuration"
8
- it "create a new Configuration via find_or_create"
9
- it "update an existing Configuration via find_or_create"
10
- it "delete an existing Configuration"
11
- it "return all Configurations"
12
-
19
+ it "create a new Configuration" do
20
+ c = Noah::Configuration.create(@appconf_string)
21
+ c.valid?.should == true
22
+ c.is_new?.should == true
23
+ b = Noah::Configuration[c.id]
24
+ b.should == c
25
+ end
26
+ it "create a new Configuration via find_or_create" do
27
+ c = Noah::Configuration.find_or_create(@appconf_string)
28
+ c.valid?.should == true
29
+ c.is_new?.should == true
30
+ a = Noah::Configuration[c.id]
31
+ a.should == c
32
+ end
33
+ it "update an existing Configuration via find_or_create" do
34
+ c = Noah::Configuration.find_or_create(@appconf_string)
35
+ c.valid?.should == true
36
+ c.is_new?.should == true
37
+ sleep(3)
38
+ c.body = "some_other_var"
39
+ c.save
40
+ c.body.should == "some_other_var"
41
+ c.is_new?.should == false
42
+ end
43
+ it "delete an existing Configuration" do
44
+ a = Noah::Configuration.find_or_create(@appconf_string)
45
+ b = Noah::Configuration.find(@appconf_string).first
46
+ b.should == a
47
+ a.delete
48
+ c = Noah::Configuration.find(@appconf_string).first
49
+ c.nil?.should == true
50
+ end
51
+ it "return all Configurations" do
52
+ a = Noah::Configuration.find_or_create(@appconf_string)
53
+ b = Noah::Configuration.find_or_create(@appconf_json)
54
+ c = Noah::Configurations.all
55
+ c.size.should == 2
56
+ c.member?(a).should == true
57
+ c.member?(b).should == true
58
+ end
13
59
  end
14
60
 
15
61
  describe "should not" do
16
-
17
- it "create a new Configuration without a name"
18
- it "create a new Configuration without a format"
19
- it "create a new Configuration without a body"
20
- it "create a new Configuration without an Application"
21
- it "create a duplicate Configuration"
22
-
62
+ it "create a new Configuration without a name" do
63
+ a = Noah::Configuration.create(@appconf_missing_name)
64
+ a.valid?.should == false
65
+ a.errors.should == [[:name, :not_present]]
66
+ end
67
+ it "create a new Configuration without a format" do
68
+ a = Noah::Configuration.create(@appconf_missing_format)
69
+ a.valid?.should == false
70
+ a.errors.should == [[:format, :not_present]]
71
+ end
72
+ it "create a new Configuration without a body" do
73
+ a = Noah::Configuration.create(@appconf_missing_body)
74
+ a.valid?.should == false
75
+ a.errors.should == [[:body, :not_present]]
76
+ 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
+ it "create a duplicate Configuration" do
83
+ a = Noah::Configuration.create(@appconf_string)
84
+ b = Noah::Configuration.create(@appconf_string)
85
+ b.errors.should == [[[:name, :application_id], :not_unique]]
86
+ end
23
87
  end
24
88
 
25
89
  end
@@ -0,0 +1,59 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Using the Ephemeral Model", :reset_redis => true do
4
+ before(:all) do
5
+ @edata = {:path => "/foo/bar/baz", :data => "some_value"}
6
+ @emissing_path = @edata.reject {|k, v| k == :path}
7
+ @emissing_data = @edata.reject {|k, v| k == :data}
8
+ @good_ephemeral = Noah::Ephemeral.new(@edata)
9
+ @missing_path = Noah::Ephemeral.new(@emissing_path)
10
+ @missing_data = Noah::Ephemeral.new(@emissing_data)
11
+ end
12
+ before(:each) do
13
+ Ohm.redis.flushdb
14
+ end
15
+ after(:each) do
16
+ Ohm.redis.flushdb
17
+ end
18
+ describe "should" do
19
+ it "create a new Noah::Ephemeral" do
20
+ @good_ephemeral.valid?.should == true
21
+ @good_ephemeral.save
22
+ b = Noah::Ephemeral[@good_ephemeral.id]
23
+ b.should == @good_ephemeral
24
+ end
25
+ it "create a new Noah::Ephemeral with missing data" do
26
+ @missing_data.valid?.should == true
27
+ @missing_data.save
28
+ b = Noah::Ephemeral[@missing_data.id]
29
+ b.should == @missing_data
30
+ end
31
+ it "update an existing Noah::Ephemeral" do
32
+ e = Noah::Ephemeral.create :path => "/is/new/test"
33
+ Noah::Ephemeral.all.size.should == 1
34
+ sleep(2)
35
+ c = Noah::Ephemeral[e.id]
36
+ c.data = "updated_data"
37
+ c.save
38
+ c.is_new?.should == false
39
+ end
40
+ it "delete an existing Noah::Ephemeral" do
41
+ @good_ephemeral.save
42
+ @good_ephemeral.delete
43
+ Noah::Ephemeral[@good_ephemeral.id].should == nil
44
+ end
45
+ end
46
+ describe "should not" do
47
+ it "create a new Noah::Ephemeral with missing path" do
48
+ e = Noah::Ephemeral.create
49
+ e.valid?.should == false
50
+ e.errors.should == [[:path, :not_present]]
51
+ end
52
+ it "create a duplicate Noah::Ephemeral" do
53
+ e = Noah::Ephemeral.create :path => "/random/path"
54
+ f = Noah::Ephemeral.create :path => "/random/path"
55
+ f.valid?.should == false
56
+ f.errors.should == [[:path, :not_unique]]
57
+ end
58
+ end
59
+ end
data/spec/host_spec.rb CHANGED
@@ -6,7 +6,7 @@ describe "Using the Host Model", :reset_redis => true do
6
6
  it "create a new Host with no services" do
7
7
  hostname = "host1.domain.com"
8
8
  hoststatus = "up"
9
- host = Host.create(:name => hostname, :status => hoststatus)
9
+ host = Noah::Host.create(:name => hostname, :status => hoststatus)
10
10
  host.valid?.should == true
11
11
  host.save
12
12
  host.name.should == hostname
@@ -19,10 +19,10 @@ describe "Using the Host Model", :reset_redis => true do
19
19
  hoststatus = "down"
20
20
  servicename = 'myservice'
21
21
  servicestatus = 'pending'
22
- host = Host.create(:name => hostname, :status => hoststatus)
22
+ host = Noah::Host.create(:name => hostname, :status => hoststatus)
23
23
  host.valid?.should == true
24
24
  host.save
25
- host.services << Service.create(:name => servicename, :status => servicestatus, :host => host)
25
+ host.services << Noah::Service.create(:name => servicename, :status => servicestatus, :host => host)
26
26
  host.name.should == hostname
27
27
  host.status.should == hoststatus
28
28
  host.services.size.should == 1
@@ -35,7 +35,7 @@ describe "Using the Host Model", :reset_redis => true do
35
35
  it "create a Host via find_or_create" do
36
36
  hostname = "host3.domain.com"
37
37
  hoststatus = "up"
38
- host = Host.find_or_create(:name => hostname, :status => hoststatus)
38
+ host = Noah::Host.find_or_create(:name => hostname, :status => hoststatus)
39
39
  host.valid?.should == true
40
40
  host.save
41
41
  host.is_new?.should == true
@@ -45,12 +45,12 @@ describe "Using the Host Model", :reset_redis => true do
45
45
  hostname = "host3.domain.com"
46
46
  hoststatus = "pending"
47
47
  newstatus = "down"
48
- host = Host.find_or_create(:name => hostname, :status => hoststatus)
48
+ host = Noah::Host.find_or_create(:name => hostname, :status => hoststatus)
49
49
  host.valid?.should == true
50
50
  host.save
51
51
  host.is_new?.should == true
52
52
  sleep 1
53
- host1 = Host.find_or_create(:name => hostname, :status => newstatus)
53
+ host1 = Noah::Host.find_or_create(:name => hostname, :status => newstatus)
54
54
  host1.save
55
55
  host1.is_new?.should == false
56
56
  end
@@ -58,10 +58,10 @@ describe "Using the Host Model", :reset_redis => true do
58
58
  it "delete a Host" do
59
59
  hostname = "host3.domain.com"
60
60
  hoststatus = "pending"
61
- host = Host.create(:name => hostname, :status => hoststatus)
61
+ host = Noah::Host.create(:name => hostname, :status => hoststatus)
62
62
  host.save
63
63
  host.delete
64
- Host.find(:name => hostname).empty?.should == true
64
+ Noah::Host.find(:name => hostname).empty?.should == true
65
65
  end
66
66
 
67
67
  it "should return all Hosts" do
@@ -69,30 +69,30 @@ describe "Using the Host Model", :reset_redis => true do
69
69
  status1 = "up"
70
70
  hostname2 = "host2.domain.com"
71
71
  status2= "down"
72
- host1 = Host.create(:name => hostname1, :status => status1)
73
- host2 = Host.create(:name => hostname2, :status => status2)
72
+ host1 = Noah::Host.create(:name => hostname1, :status => status1)
73
+ host2 = Noah::Host.create(:name => hostname2, :status => status2)
74
74
  host1.save
75
75
  host2.save
76
- Hosts.all.class.should == Array
77
- Hosts.all.size.should == 2
78
- Hosts.all.first.name.should == hostname1
79
- Hosts.all.first.status.should == status1
80
- Hosts.all.last.name.should == hostname2
81
- Hosts.all.last.status.should == status2
76
+ Noah::Hosts.all.class.should == Array
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
82
82
  end
83
83
  end
84
84
 
85
85
  describe "should not" do
86
86
  it "create a new Host with missing status" do
87
87
  hostname ="host3.domain.com"
88
- host = Host.create(:name => hostname)
88
+ host = Noah::Host.create(:name => hostname)
89
89
  host.valid?.should == false
90
90
  host.errors.should == [[:status, :not_present], [:status, :not_member]]
91
91
  end
92
92
 
93
93
  it "create a new Host with missing hostname" do
94
94
  status = "up"
95
- host = Host.create(:status => status)
95
+ host = Noah::Host.create(:status => status)
96
96
  host.valid?.should == false
97
97
  host.errors.should == [[:name, :not_present]]
98
98
  end
@@ -100,7 +100,7 @@ describe "Using the Host Model", :reset_redis => true do
100
100
  it "create a new Host with an invalid status" do
101
101
  hostname = "host3.domain.com"
102
102
  status = "online"
103
- host = Host.create(:name => hostname, :status => status)
103
+ host = Noah::Host.create(:name => hostname, :status => status)
104
104
  host.valid?.should == false
105
105
  host.errors.should == [[:status, :not_member]]
106
106
  end
@@ -108,9 +108,9 @@ describe "Using the Host Model", :reset_redis => true do
108
108
  it "create a duplicate Host" do
109
109
  hostname = "host1.domain.com"
110
110
  status = "up"
111
- host1 = Host.create(:name => hostname, :status => status)
111
+ host1 = Noah::Host.create(:name => hostname, :status => status)
112
112
  host1.save
113
- host2 = Host.create(:name => hostname, :status => status)
113
+ host2 = Noah::Host.create(:name => hostname, :status => status)
114
114
  host2.valid?.should == false
115
115
  host2.errors.should == [[:name, :not_unique]]
116
116
  end
@@ -2,8 +2,8 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe "Using the Application API", :reset_redis => false do
4
4
  before(:all) do
5
- @a = Application.create(:name => 'rspec_sample_app')
6
- @a.configurations << Configuration.create(:name => 'rspec_config', :format => 'string', :body => 'rspec is great', :application => @a)
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)
7
7
  @a.save
8
8
  @c = @a.configurations.first
9
9
  end
@@ -62,8 +62,8 @@ describe "Using the Application API", :reset_redis => false do
62
62
  response["id"].nil?.should == false
63
63
  response["name"].should == @appdata[:name]
64
64
  response["action"].should == "create"
65
- Application.find(:name => @appdata[:name]).size.should == 1
66
- Application.find(:name => @appdata[:name]).first.is_new?.should == true
65
+ Noah::Application.find(:name => @appdata[:name]).size.should == 1
66
+ Noah::Application.find(:name => @appdata[:name]).first.is_new?.should == true
67
67
  end
68
68
  it "new application with missing name should not work" do
69
69
  put "/a/should_not_work", '{"foo":"bar"}', "CONTENT_TYPE" => "application/json"
@@ -79,8 +79,8 @@ describe "Using the Application API", :reset_redis => false do
79
79
  response["id"].nil?.should == false
80
80
  response["name"].should == @appdata[:name]
81
81
  response["action"].should == "update"
82
- Application.find(:name => @appdata[:name]).size.should == 1
83
- Application.find(:name => @appdata[:name]).first.is_new?.should == false
82
+ Noah::Application.find(:name => @appdata[:name]).size.should == 1
83
+ Noah::Application.find(:name => @appdata[:name]).first.is_new?.should == false
84
84
  end
85
85
  end
86
86
 
@@ -34,8 +34,8 @@ describe "Using the Configuration API", :reset_redis => false, :populate_sample_
34
34
  response = YAML.load(last_response.body)
35
35
  response.is_a?(Hash).should == true
36
36
  response.keys.should == ["development"]
37
- response["development"].keys.should == ["database", "adapter", "username", "password"]
38
- response["development"].values.should == ["development_database", "mysql", "dev_user", "dev_password"]
37
+ response["development"].keys.sort.should == ["adapter", "database", "password", "username"]
38
+ response["development"].values.sort.should == ["dev_password", "dev_user", "development_database", "mysql"]
39
39
  end
40
40
  it "invalid application should not work" do
41
41
  get '/c/badapp'
@@ -85,9 +85,9 @@ describe "Using the Configuration API", :reset_redis => false, :populate_sample_
85
85
 
86
86
  describe "DELETE" do
87
87
  before(:all) do
88
- cparms = {:name => 'a', :format => 'string', :body => 'asdf'}
89
- @a = Application.create(:name => 'delete_test_app')
90
- @a.configurations << Configuration.create(cparms)
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
91
  @a.save
92
92
  @c = @a.configurations.first
93
93
  end
@@ -0,0 +1,115 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Using the Ephemeral API", :reset_redis => true do
4
+ before(:each) do
5
+ Ohm.redis.flushdb
6
+ Noah::Ephemeral.create(:path => "/foo/bar/baz", :data => "value1")
7
+ Noah::Ephemeral.create(:path => "/baz/bar")
8
+ end
9
+ after(:each) do
10
+ Ohm.redis.flushdb
11
+ end
12
+ describe "calling" do
13
+
14
+ describe "GET" do
15
+ it "all ephemerals should return 404" do
16
+ get '/e'
17
+ last_response.should_not be_ok
18
+ last_response.status.should == 404
19
+ response = last_response.should return_json
20
+ response['error_message'].should == 'Resource not found'
21
+ response['result'].should == 'failure'
22
+ end
23
+
24
+ it "named path with data should work" do
25
+ get '/e/foo/bar/baz'
26
+ last_response.should be_ok
27
+ last_response.body.should == 'value1'
28
+ end
29
+
30
+ it "named path without data should work" do
31
+ get '/e/baz/bar'
32
+ last_response.status.should == 200
33
+ last_response.body.should == ""
34
+ end
35
+
36
+ it "invalid path should not work" do
37
+ get '/e/ssss/dddd'
38
+ last_response.should_not be_ok
39
+ last_response.status.should == 404
40
+ response = last_response.should return_json
41
+ response['error_message'].should == 'Resource not found'
42
+ response['result'].should == 'failure'
43
+ end
44
+ end
45
+
46
+ describe "PUT" do
47
+ it "new ephemeral with data should work" do
48
+ put '/e/whiz/bang/', 'value3'
49
+ last_response.should be_ok
50
+ response = last_response.should return_json
51
+ response['result'].should == 'success'
52
+ response['id'].nil?.should == false
53
+ response['path'].should == '/whiz/bang/'
54
+ response['data'].should == 'value3'
55
+ end
56
+
57
+ it "new ephemeral without data should work" do
58
+ put '/e/bang/whiz'
59
+ last_response.should be_ok
60
+ response = last_response.should return_json
61
+ response['result'].should == 'success'
62
+ response['action'].should == 'create'
63
+ response['id'].nil?.should == false
64
+ response['path'].should == '/bang/whiz'
65
+ response['data'].should == nil
66
+ end
67
+
68
+ it "existing ephemeral with data should work" do
69
+ Noah::Ephemeral.create(:path => '/new/ephemeral', :data => 'old_value')
70
+ get '/e/new/ephemeral'
71
+ last_response.should be_ok
72
+ last_response.body.should == 'old_value'
73
+ put '/e/new/ephemeral', 'new_value'
74
+ last_response.should be_ok
75
+ get '/e/new/ephemeral'
76
+ last_response.should be_ok
77
+ last_response.body.should == 'new_value'
78
+ end
79
+ it "existing ephemeral without data should work" do
80
+ Noah::Ephemeral.create(:path => '/a/random/key')
81
+ get '/e/a/random/key'
82
+ last_response.should be_ok
83
+ last_response.body.should == ""
84
+ put '/e/a/random/key', 'a new value'
85
+ last_response.should be_ok
86
+ get '/e/a/random/key'
87
+ last_response.should be_ok
88
+ last_response.body.should == 'a new value'
89
+ end
90
+ end
91
+
92
+ describe "DELETE" do
93
+ it "existing path should work" do
94
+ e = Noah::Ephemeral.new(:path => '/slart/i/bart/fast', :data => 'someddata')
95
+ e.save
96
+ delete "/e/slart/i/bart/fast"
97
+ last_response.should be_ok
98
+ response = last_response.should return_json
99
+ response['result'].should == 'success'
100
+ response['action'].should == 'delete'
101
+ response['id'].should == e.id
102
+ response['path'].should == e.name
103
+ end
104
+
105
+ it "invalid path should not work" do
106
+ delete '/e/fork/spoon/knife'
107
+ last_response.should_not be_ok
108
+ last_response.status.should == 404
109
+ response = last_response.should return_json
110
+ response['error_message'].should == 'Resource not found'
111
+ response['result'].should == 'failure'
112
+ end
113
+ end
114
+ end
115
+ end