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
@@ -82,15 +82,15 @@ describe "Using the Host API", :reset_redis => false, :populate_sample_data => t
82
82
  response = last_response.should return_json
83
83
 
84
84
  response["result"].should == "failure"
85
- response["error_message"].should == "[[:status, :not_member]]"
85
+ response["error_message"].should == "Status must be up, down or pending"
86
86
  end
87
87
  end
88
88
 
89
89
  describe "DELETE" do
90
90
  before(:all) do
91
- @h = Host.create(:name => 'h', :status => 'up')
91
+ @h = Noah::Host.create(:name => 'h', :status => 'up')
92
92
  sparms = {:name => 's', :status => "up"}
93
- @h.services << Service.create(sparms.merge({:host => @h}))
93
+ @h.services << Noah::Service.create(sparms.merge({:host => @h}))
94
94
  @h.save
95
95
  @s = @h.services.first
96
96
  end
@@ -4,10 +4,10 @@ describe "Using the Service API", :reset_redis => false, :populate_sample_data =
4
4
  before(:all) do
5
5
  @sample_host = {:name => 'rspec_sample_host', :status => 'up'}
6
6
  @sample_service = {:name => 'rspec_sample_service', :status => 'up'}
7
- @h = Host.create(:name => 'rspec_sample_host', :status => 'up')
8
- @h.services << Service.create({:host => @h}.merge(@sample_service))
7
+ @h = Noah::Host.create(:name => 'rspec_sample_host', :status => 'up')
8
+ @h.services << Noah::Service.create({:host => @h}.merge(@sample_service))
9
9
  @h.save
10
- @s = Service.find(@sample_service).first
10
+ @s = Noah::Service.find(@sample_service).first
11
11
  end
12
12
  describe "calling" do
13
13
 
@@ -57,8 +57,8 @@ describe "Using the Service API", :reset_redis => false, :populate_sample_data =
57
57
  response["id"].nil?.should == false
58
58
  response["name"].should == @payload[:name]
59
59
  response["host"].should == @payload[:host]
60
- Service.find(:name => @payload[:name]).size.should == 1
61
- Service.find(:name => @payload[:name]).first.is_new?.should == true
60
+ Noah::Service.find(:name => @payload[:name]).size.should == 1
61
+ Noah::Service.find(:name => @payload[:name]).first.is_new?.should == true
62
62
  end
63
63
  it "new service without host should not work" do
64
64
  put "/s/foobar", {:name => "foobar", :status => "up"}.to_json, "CONTENT_TYPE" => "application/json"
@@ -68,7 +68,7 @@ describe "Using the Service API", :reset_redis => false, :populate_sample_data =
68
68
  put "/s/foobar", {:name => "foobar", :status => "fsck", :host => @h.name}.to_json, "CONTENT_TYPE" => "application/json"
69
69
  last_response.should_not be_ok
70
70
  response = last_response.should return_json
71
- response["error_message"].should == "[[:status, :not_member]]"
71
+ response["error_message"].should == "Status must be up, down or pending"
72
72
  end
73
73
  it "new service with missing name should not work" do
74
74
  put "/s/foobar", {:status => "fsck", :host => @h.name}.to_json, "CONTENT_TYPE" => "application/json"
@@ -88,15 +88,15 @@ describe "Using the Service API", :reset_redis => false, :populate_sample_data =
88
88
  response["id"].nil?.should == false
89
89
  response["name"].should == @payload[:name]
90
90
  response["host"].should == @payload[:host]
91
- Service.find(:name => @payload[:name]).size.should == 1
92
- Service.find(:name => @payload[:name]).first.is_new?.should == false
91
+ Noah::Service.find(:name => @payload[:name]).size.should == 1
92
+ Noah::Service.find(:name => @payload[:name]).first.is_new?.should == false
93
93
  end
94
94
  end
95
95
 
96
96
  describe "DELETE" do
97
97
  before(:all) do
98
- @h = Host.create(:name => "h1", :status => "up")
99
- @h.services << Service.create(:name => "s1", :status => "up", :host => @h)
98
+ @h = Noah::Host.create(:name => "h1", :status => "up")
99
+ @h.services << Noah::Service.create(:name => "s1", :status => "up", :host => @h)
100
100
  @h.save
101
101
  @s = @h.services.first
102
102
  end
@@ -0,0 +1,123 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Using the Watcher API", :reset_redis => true do
4
+ before(:each) do
5
+ endpoint = 'http://localhost:4567/webhook'
6
+ Ohm.redis.flushdb
7
+ a = Noah::Application.create :name => 'fooapp'
8
+ a.watch! :endpoint => endpoint
9
+ c = Noah::Configuration.create :name => 'fooconfig'
10
+ c.watch! :endpoint => endpoint
11
+ h = Noah::Host.create :name => 'localhost', :status => 'up'
12
+ h.watch! :endpoint => endpoint
13
+ s = Noah::Service.create :name => 'localhostservice', :status => 'up', :host => h
14
+ s.watch! :endpoint => endpoint
15
+ end
16
+
17
+ after(:all) do
18
+ Ohm.redis.flushdb
19
+ end
20
+
21
+ describe "calling" do
22
+
23
+ describe "GET" do
24
+ it "all watches should work" do
25
+ get '/w'
26
+ last_response.should be_ok
27
+ response = last_response.should return_json
28
+ response.is_a?(Array).should == true
29
+ response.size.should == 4
30
+ end
31
+
32
+ it "named watch should work" do
33
+ w = Noah::Watcher.create(:pattern => '//noah/application/myapp', :endpoint => 'http://localhost/webhook')
34
+ get "/w/#{w.name}"
35
+ last_response.should be_ok
36
+ response = last_response.should return_json
37
+ response['pattern'].should == w.pattern
38
+ response['endpoint'].should == w.endpoint
39
+ end
40
+
41
+ it "invalid watch should not work" do
42
+ get '/w/asdfasdfasdfasdfasdfsdf'
43
+ last_response.should be_missing
44
+ end
45
+ end
46
+
47
+ describe "PUT" do
48
+ it "new watch should work" do
49
+ data = {:pattern => "//noah/application", :endpoint => "http://myendpoint/webhook"}
50
+ put '/w', data.to_json, "CONTENT_TYPE" => "application/json"
51
+ last_response.should be_ok
52
+ response = last_response.should return_json
53
+ response['pattern'].should == data[:pattern]
54
+ response['endpoint'].should == data[:endpoint]
55
+ w = Noah::Watcher.find(data).first
56
+ w.pattern.should == data[:pattern]
57
+ w.endpoint.should == data[:endpoint]
58
+ end
59
+
60
+ it "new watch without pattern should not work" do
61
+ data = {:endpoint => "http://myendpoint/webhook"}
62
+ put '/w', data.to_json, "CONTENT_TYPE" => "application/json"
63
+ last_response.should be_invalid
64
+ end
65
+
66
+ it "new watch without endpoint should not work" do
67
+ data = {:pattern => "//noah/application"}
68
+ put '/w', data.to_json, "CONTENT_TYPE" => "application/json"
69
+ last_response.should be_invalid
70
+ end
71
+
72
+ it "new watch that supercedes existing should not work" do
73
+ Noah::Watcher.create(:endpoint => 'http://myendpoint/webhook', :pattern => '//noah/application/foo')
74
+ data = {:endpoint => "http://myendpoint/webhook", :pattern => '//noah/application'}
75
+ put '/w', data.to_json, "CONTENT_TYPE" => "application/json"
76
+ last_response.should_not be_ok
77
+ response = last_response.should return_json
78
+ response['error_message'].should == 'Pattern would overwrite existing'
79
+ end
80
+
81
+ it "new watch that subsets an existing should not work" do
82
+ Noah::Watcher.create(:endpoint => 'http://myendpoint/webhook', :pattern => '//noah/application')
83
+ data = {:endpoint => "http://myendpoint/webhook", :pattern => '//noah/application/foo'}
84
+ put '/w', data.to_json, "CONTENT_TYPE" => "application/json"
85
+ last_response.should_not be_ok
86
+ response = last_response.should return_json
87
+ response['error_message'].should == 'Pattern is already provided'
88
+ end
89
+ end
90
+
91
+ describe "DELETE" do
92
+ it "delete an existing watch should work" do
93
+ data = {:endpoint => "http://myendpoint/webhookd", :pattern => '//noah/application/d'}
94
+ w = Noah::Watcher.create(data)
95
+ delete '/w', data.to_json, "CONTENT_TYPE" => "application/json"
96
+ last_response.should be_ok
97
+ response = last_response.should return_json
98
+ response['pattern'].should == data[:pattern]
99
+ response['endpoint'].should == data[:endpoint]
100
+ response['name'].should_not == "null"
101
+ Noah::Watcher.find(data).size.should == 0
102
+ end
103
+
104
+ it "delete an invalid watch should not work" do
105
+ data = {:endpoint => 'missing', :pattern => '//noah/application/dag'}
106
+ delete '/w', data.to_json, "CONTENT_TYPE" => "application/json"
107
+ last_response.should be_missing
108
+ end
109
+
110
+ it "delete without pattern should not work" do
111
+ data = {:endpoint => "invalid"}
112
+ delete '/w', data.to_json, "CONTENT_TYPE" => "application/json"
113
+ last_response.should be_invalid
114
+ end
115
+
116
+ it "delete without endpoint should not work" do
117
+ data = {:pattern => "//noah/invalid"}
118
+ delete '/w', data.to_json, "CONTENT_TYPE" => "application/json"
119
+ last_response.should be_invalid
120
+ end
121
+ end
122
+ end
123
+ end
data/spec/service_spec.rb CHANGED
@@ -8,9 +8,9 @@ describe "Noah Service Model", :reset_redis => true do
8
8
  servicestatus = "up"
9
9
  hostname = "mytesthost1"
10
10
  hoststatus = "up"
11
- host = Host.create(:name => hostname, :status => hoststatus)
11
+ host = Noah::Host.create(:name => hostname, :status => hoststatus)
12
12
  host.save
13
- service = Service.create(:name => servicename, :status => servicestatus, :host => host)
13
+ service = Noah::Service.create(:name => servicename, :status => servicestatus, :host => host)
14
14
  service.valid?.should == true
15
15
  service.save
16
16
  service.name.should == servicename
@@ -20,45 +20,45 @@ describe "Noah Service Model", :reset_redis => true do
20
20
  end
21
21
 
22
22
  it "create a new Service with find_or_create" do
23
- host = Host.create(:name => "h1", :status => "up")
23
+ host = Noah::Host.create(:name => "h1", :status => "up")
24
24
  host.save
25
- service = Service.find_or_create(:name => "s1", :status => "up", :host => host)
25
+ service = Noah::Service.find_or_create(:name => "s1", :status => "up", :host => host)
26
26
  service.save
27
27
  service.is_new?.should == true
28
28
  end
29
29
 
30
30
  it "update an existing Service with find_or_create" do
31
- host = Host.create(:name => "h2", :status => "up")
31
+ host = Noah::Host.create(:name => "h2", :status => "up")
32
32
  host.save
33
- service = Service.find_or_create(:name => "s2", :status => "up", :host => host)
33
+ service = Noah::Service.find_or_create(:name => "s2", :status => "up", :host => host)
34
34
  service.save
35
35
  sleep 1
36
- service2 = Service.find_or_create(:name => "s2", :status => "up", :host => host)
36
+ service2 = Noah::Service.find_or_create(:name => "s2", :status => "up", :host => host)
37
37
  service2.save
38
38
  service2.is_new?.should == false
39
39
  end
40
40
 
41
41
  it "delete a Service" do
42
- h = Host.create(:name => "h1", :status => "up")
42
+ h = Noah::Host.create(:name => "h1", :status => "up")
43
43
  h.save
44
- s = Service.create(:name => "s1", :status => "up", :host => h)
44
+ s = Noah::Service.create(:name => "s1", :status => "up", :host => h)
45
45
  s.save
46
- s = Service.find(:name => "s1").first
46
+ s = Noah::Service.find(:name => "s1").first
47
47
  s.delete
48
- s = Service.find(:name => "s1").first
48
+ s = Noah::Service.find(:name => "s1").first
49
49
  s.should == nil
50
50
  end
51
51
 
52
52
  it "find multiple Services" do
53
- h = Host.create(:name => "h1", :status => "up")
53
+ h = Noah::Host.create(:name => "h1", :status => "up")
54
54
  if h.valid?
55
- h.services << Service.create(:name => "s1", :status => "up", :host => h)
56
- h.services << Service.create(:name => "s2", :status => "up", :host => h)
55
+ h.services << Noah::Service.create(:name => "s1", :status => "up", :host => h)
56
+ h.services << Noah::Service.create(:name => "s2", :status => "up", :host => h)
57
57
  h.save
58
58
  end
59
- Services.all.size.should == 2
60
- Services.all.first.name.should == "s1"
61
- Services.all.last.name.should == "s2"
59
+ Noah::Services.all.size.should == 2
60
+ Noah::Services.all.first.name.should == "s1"
61
+ Noah::Services.all.last.name.should == "s2"
62
62
  end
63
63
 
64
64
  end
@@ -68,41 +68,41 @@ describe "Noah Service Model", :reset_redis => true do
68
68
  it "create a new Service when missing a Host" do
69
69
  servicename = "myservice1"
70
70
  servicestatus = "up"
71
- service = Service.create(:name => servicename, :status => servicestatus)
71
+ service = Noah::Service.create(:name => servicename, :status => servicestatus)
72
72
  service.valid?.should == false
73
73
  service.errors.should == [[:host_id, :not_present]]
74
74
  end
75
75
 
76
76
  it "create a new Service when missing a name" do
77
- host = Host.create(:name => "host1.domain.com", :status => "up")
77
+ host = Noah::Host.create(:name => "host1.domain.com", :status => "up")
78
78
  host.save
79
- service = Service.create(:status => "up", :host => host)
79
+ service = Noah::Service.create(:status => "up", :host => host)
80
80
  service.valid?.should == false
81
81
  service.errors.should == [[:name, :not_present]]
82
82
  end
83
83
 
84
84
  it "create a new Service when missing a status" do
85
- host = Host.create(:name => "host1.domain.com", :status => "up")
85
+ host = Noah::Host.create(:name => "host1.domain.com", :status => "up")
86
86
  host.save
87
- service = Service.create(:name => 'foo', :host => host)
87
+ service = Noah::Service.create(:name => 'foo', :host => host)
88
88
  service.valid?.should == false
89
89
  service.errors.should == [[:status, :not_present], [:status, :not_member]]
90
90
  end
91
91
 
92
92
  it "create a new Service with an invalid status" do
93
- host = Host.create(:name => "host1.domain.com", :status => "up")
93
+ host = Noah::Host.create(:name => "host1.domain.com", :status => "up")
94
94
  host.save
95
- service = Service.create(:name => "myservice", :status => "invalid_status", :host => host)
95
+ service = Noah::Service.create(:name => "myservice", :status => "invalid_status", :host => host)
96
96
  service.valid?.should == false
97
97
  service.errors.should == [[:status, :not_member]]
98
98
  end
99
99
 
100
100
  it "create a duplicate Service" do
101
- host = Host.create(:name => "host1.domain.com", :status => "up")
101
+ host = Noah::Host.create(:name => "host1.domain.com", :status => "up")
102
102
  host.save
103
- s = Service.create(:name => "myservice", :status => "up", :host => host)
103
+ s = Noah::Service.create(:name => "myservice", :status => "up", :host => host)
104
104
  s.save
105
- s1 = Service.create(:name => "myservice", :status => "up", :host => host)
105
+ s1 = Noah::Service.create(:name => "myservice", :status => "up", :host => host)
106
106
  s1.valid?.should == false
107
107
  s1.errors.should == [[[:name, :host_id], :not_unique]]
108
108
  end
data/spec/spec_helper.rb CHANGED
@@ -1,19 +1,10 @@
1
- require 'bundler/setup'
2
- require 'ohm'
3
- begin
4
- require 'yajl'
5
- rescue LoadError
6
- require 'json'
7
- end
8
-
9
- ENV['RACK_ENV'] = 'test'
10
- ENV['REDIS_URL'] = 'redis://localhost:6379/3'
11
- Ohm::connect
12
-
13
1
  require File.join(File.dirname(__FILE__), '..', 'lib', 'noah')
14
2
  require File.join(File.dirname(__FILE__), '..', 'lib', 'noah', 'app')
15
3
  require 'rspec'
16
4
  require 'rack/test'
5
+ ENV['RACK_ENV'] = 'test'
6
+ ENV['REDIS_URL'] = 'redis://localhost:6379/3'
7
+ Ohm::connect
17
8
 
18
9
  RSpec.configure do |config|
19
10
  config.color_enabled = true
@@ -23,19 +14,19 @@ RSpec.configure do |config|
23
14
  config.after(:all, :populate_sample_data => true) {Ohm::redis.flushdb }
24
15
  config.before(:all, :populate_sample_data => true) do
25
16
  Ohm::redis.flushdb
26
- h = Host.create(:name => 'localhost', :status => "up")
17
+ h = Noah::Host.create(:name => 'localhost', :status => "up")
27
18
  if h.save
28
19
  %w[redis noah].each do |service|
29
- s = Service.create(:name => service, :status => "up", :host => h)
20
+ s = Noah::Service.create(:name => service, :status => "up", :host => h)
30
21
  h.services << s
31
22
  end
32
23
  end
33
24
 
34
- a = Application.create(:name => 'noah')
25
+ a = Noah::Application.create(:name => 'noah')
35
26
  if a.save
36
- cr = Configuration.create(:name => 'redis', :format => 'string', :body => 'redis://127.0.0.1:6379/0', :application => a)
37
- ch = Configuration.create(:name => 'host', :format => 'string', :body => 'localhost', :application => a)
38
- cp = Configuration.create(:name => 'port', :format => 'string', :body => '9292', :application => a)
27
+ cr = Noah::Configuration.create(:name => 'redis', :format => 'string', :body => 'redis://127.0.0.1:6379/0', :application => a)
28
+ ch = Noah::Configuration.create(:name => 'host', :format => 'string', :body => 'localhost', :application => a)
29
+ cp = Noah::Configuration.create(:name => 'port', :format => 'string', :body => '9292', :application => a)
39
30
  %w[cr ch cp].each do |c|
40
31
  a.configurations << eval(c)
41
32
  end
@@ -55,15 +46,15 @@ EOY
55
46
  }
56
47
  EOJ
57
48
 
58
- a1 = Application.create(:name => 'myrailsapp1')
49
+ a1 = Noah::Application.create(:name => 'myrailsapp1')
59
50
  if a1.save
60
- c1 = Configuration.create(:name => 'database.yml', :format => 'yaml', :body => my_yaml, :application => a1)
51
+ c1 = Noah::Configuration.create(:name => 'database.yml', :format => 'yaml', :body => my_yaml, :application => a1)
61
52
  a1.configurations << c1
62
53
  end
63
54
 
64
- a2 = Application.create(:name => 'myrestapp1')
55
+ a2 = Noah::Application.create(:name => 'myrestapp1')
65
56
  if a2.save
66
- c2 = Configuration.create(:name => 'config.json', :format => 'json', :body => my_json, :application => a2)
57
+ c2 = Noah::Configuration.create(:name => 'config.json', :format => 'json', :body => my_json, :application => a2)
67
58
  a2.configurations << c2
68
59
  end
69
60
  end
File without changes
@@ -0,0 +1,8 @@
1
+ dir spec/support/db
2
+ pidfile spec/support/db/redis.pid
3
+ port 6379
4
+ timeout 300
5
+ loglevel debug
6
+ logfile stdout
7
+ databases 16
8
+ daemonize yes
@@ -0,0 +1,62 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Using the Watcher Model", :reset_redis => true do
4
+ before(:each) do
5
+ Ohm.redis.flushdb
6
+ @test_endpoint = "http://localhost/webhook"
7
+ @test_pattern = "/foo/bar"
8
+ Noah::Watcher.create :pattern => @test_pattern, :endpoint => @test_webhook
9
+ @test_watch = Noah::Watcher.new :endpoint => "http://localhost/webhook"
10
+ end
11
+ after(:each) do
12
+ #Ohm.redis.flushdb
13
+ end
14
+
15
+ describe "should" do
16
+ it "create a new Noah::Watcher" do
17
+ @test_watch.pattern = "/snarf"
18
+ @test_watch.valid?.should == true
19
+ @test_watch.save
20
+ a = Noah::Watcher.find(:endpoint => @test_watch.endpoint, :pattern => @test_watch.pattern).first
21
+ a.should == @test_watch
22
+ end
23
+ it "delete an existing Noah::Watcher" do
24
+ @test_watch.pattern = "/snarf"
25
+ @test_watch.save
26
+ @test_watch.delete
27
+ Noah::Watcher.find(:endpoint => @test_endpoint, :pattern => @test_pattern).first.should == nil
28
+ end
29
+ end
30
+
31
+ describe "should not" do
32
+ it "create a new Noah::Watcher with missing endpoint" do
33
+ a = Noah::Watcher.create(:pattern => "/foo/bar")
34
+ a.valid?.should == false
35
+ a.errors.should == [[:endpoint, :not_present]]
36
+ end
37
+ it "create a new Noah::Watcher with missing pattern" do
38
+ a = Noah::Watcher.create(:endpoint => "http://localhost/webhook")
39
+ a.valid?.should == false
40
+ a.errors.should == [[:pattern, :not_present]]
41
+ end
42
+ it "create a new Noah::Watcher with subset pattern" do
43
+ a = Noah::Watcher.create(:endpoint => "http://localhost.domain.com/webhook", :pattern => "//noah/")
44
+ b = Noah::Watcher.create(:endpoint => "http://localhost.domain.com/webhook", :pattern => "//noah/foobar")
45
+ b.valid?.should == false
46
+ b.errors.should == [[:pattern, :already_provided]]
47
+ end
48
+ it "create a new Noah::Watcher with superset pattern" do
49
+ a = Noah::Watcher.create(:endpoint => "http://localhost.domain.com/webhook", :pattern => "//noah/foobar")
50
+ b = Noah::Watcher.create(:endpoint => "http://localhost.domain.com/webhook", :pattern => "//noah")
51
+ b.valid?.should == false
52
+ b.errors.should == [[:pattern, :replaces_existing]]
53
+ end
54
+ it "create a duplicate Noah::Watcher" do
55
+ a = Noah::Watcher.create(:endpoint => "http://localhost.domain.com/webhook", :pattern => "//noah/foobar")
56
+ b = Noah::Watcher.create(:endpoint => "http://localhost.domain.com/webhook", :pattern => "//noah/foobar")
57
+ b.valid?.should == false
58
+ b.errors.should == [[[:endpoint, :pattern], :not_unique]]
59
+ end
60
+ end
61
+
62
+ end