Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
Noah
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Noah
Commits
f15ebc40
Commit
f15ebc40
authored
Mar 05, 2011
by
John E. Vincent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more watcher design. test done
parent
1a97bf10
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
82 additions
and
0 deletions
+82
-0
noah.rb
lib/noah.rb
+1
-0
watchers.rb
lib/noah/models/watchers.rb
+19
-0
watcher_spec.rb
spec/watcher_spec.rb
+62
-0
No files found.
lib/noah.rb
View file @
f15ebc40
...
...
@@ -11,5 +11,6 @@ require 'yaml'
require
'sinatra/base'
require
'sinatra/namespace'
require
File
.
join
(
File
.
dirname
(
__FILE__
),
'noah'
,
'validations'
)
require
File
.
join
(
File
.
dirname
(
__FILE__
),
'noah'
,
'models'
)
require
File
.
join
(
File
.
dirname
(
__FILE__
),
'noah'
,
'app'
)
lib/noah/models/watchers.rb
View file @
f15ebc40
...
...
@@ -3,6 +3,7 @@ module Noah
class
Watcher
<
Model
#NYI
# Don't trust anything in here yet
# I'm still trying a few things
include
WatcherValidations
attribute
:pattern
attribute
:endpoint
...
...
@@ -15,6 +16,8 @@ module Noah
assert_present
:endpoint
assert_present
:pattern
assert_unique
[
:endpoint
,
:pattern
]
assert_not_superset
assert_not_subset
end
def
name
...
...
@@ -26,6 +29,22 @@ module Noah
super
.
merge
(
h
)
end
def
self
.
watch_list
hsh
=
Hash
.
new
watch_list
=
self
.
all
.
sort_by
(
:pattern
)
watch_list
.
each
do
|
watch
|
p
=
watch
.
pattern
.
to_sym
e
=
watch
.
endpoint
if
hsh
.
has_key?
(
p
)
hsh
[
p
].
push
(
watch
.
endpoint
)
else
hsh
[
p
]
=
Array
.
new
hsh
[
p
].
push
(
watch
.
endpoint
)
end
end
hsh
end
private
# Not sure about these next two.
# Could get around patterns changing due to namespace changes
...
...
spec/watcher_spec.rb
0 → 100644
View file @
f15ebc40
require
File
.
expand_path
(
File
.
dirname
(
__FILE__
)
+
'/spec_helper'
)
describe
"Using the Watcher Model"
,
:reset_redis
=>
true
do
before
(
:each
)
do
Ohm
.
redis
.
flushdb
@test_endpoint
=
"http://localhost/webhook"
@test_pattern
=
"/foo/bar"
Noah
::
Watcher
.
create
:pattern
=>
@test_pattern
,
:endpoint
=>
@test_webhook
@test_watch
=
Noah
::
Watcher
.
new
:endpoint
=>
"http://localhost/webhook"
end
after
(
:each
)
do
#Ohm.redis.flushdb
end
describe
"should"
do
it
"create a new Noah::Watcher"
do
@test_watch
.
pattern
=
"/snarf"
@test_watch
.
valid?
.
should
==
true
@test_watch
.
save
a
=
Noah
::
Watcher
.
find
(
:endpoint
=>
@test_watch
.
endpoint
,
:pattern
=>
@test_watch
.
pattern
).
first
a
.
should
==
@test_watch
end
it
"delete an existing Noah::Watcher"
do
@test_watch
.
pattern
=
"/snarf"
@test_watch
.
save
@test_watch
.
delete
Noah
::
Watcher
.
find
(
:endpoint
=>
@test_endpoint
,
:pattern
=>
@test_pattern
).
first
.
should
==
nil
end
end
describe
"should not"
do
it
"create a new Noah::Watcher with missing endpoint"
do
a
=
Noah
::
Watcher
.
create
(
:pattern
=>
"/foo/bar"
)
a
.
valid?
.
should
==
false
a
.
errors
.
to_s
.
should
==
"[[:endpoint, :not_present]]"
end
it
"create a new Noah::Watcher with missing pattern"
do
a
=
Noah
::
Watcher
.
create
(
:endpoint
=>
"http://localhost/webhook"
)
a
.
valid?
.
should
==
false
a
.
errors
.
to_s
.
should
==
"[[:pattern, :not_present]]"
end
it
"create a new Noah::Watcher with subset pattern"
do
a
=
Noah
::
Watcher
.
create
(
:endpoint
=>
"http://localhost.domain.com/webhook"
,
:pattern
=>
"//noah/"
)
b
=
Noah
::
Watcher
.
create
(
:endpoint
=>
"http://localhost.domain.com/webhook"
,
:pattern
=>
"//noah/foobar"
)
b
.
valid?
.
should
==
false
b
.
errors
.
to_s
.
should
==
"[[:pattern, :already_provided]]"
end
it
"create a new Noah::Watcher with superset pattern"
do
a
=
Noah
::
Watcher
.
create
(
:endpoint
=>
"http://localhost.domain.com/webhook"
,
:pattern
=>
"//noah/foobar"
)
b
=
Noah
::
Watcher
.
create
(
:endpoint
=>
"http://localhost.domain.com/webhook"
,
:pattern
=>
"//noah"
)
b
.
valid?
.
should
==
false
b
.
errors
.
to_s
.
should
==
"[[:pattern, :replaces_existing]]"
end
it
"create a duplicate Noah::Watcher"
do
a
=
Noah
::
Watcher
.
create
(
:endpoint
=>
"http://localhost.domain.com/webhook"
,
:pattern
=>
"//noah/foobar"
)
b
=
Noah
::
Watcher
.
create
(
:endpoint
=>
"http://localhost.domain.com/webhook"
,
:pattern
=>
"//noah/foobar"
)
b
.
valid?
.
should
==
false
b
.
errors
.
to_s
.
should
==
"[[[:endpoint, :pattern], :not_unique]]"
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment