diff options
author | Matthias Hecker <apoc@geekosphere.org> | 2015-06-14 20:05:45 +0200 |
---|---|---|
committer | Matthias Hecker <apoc@geekosphere.org> | 2015-06-14 20:05:45 +0200 |
commit | dd06ceee0c26703a73acb225a6500579f38c8c3e (patch) | |
tree | 5d0ed8883a73f3ca0ec522a641a1f695178597d0 | |
parent | 075c7e031b3449ff026e51a2299f56df573ef688 (diff) |
journal: even more tests
-rw-r--r-- | lib/rbot/journal.rb | 10 | ||||
-rw-r--r-- | test/test_journal.rb | 25 |
2 files changed, 29 insertions, 6 deletions
diff --git a/lib/rbot/journal.rb b/lib/rbot/journal.rb index 71b0c7ff..a25f3a9f 100644 --- a/lib/rbot/journal.rb +++ b/lib/rbot/journal.rb @@ -355,7 +355,7 @@ module Journal @subscriptions.delete subscription end - def find(query, limit=100, offset=0, &block) + def find(query=nil, limit=100, offset=0, &block) if block_given? begin res = @storage.find(query, limit, offset) @@ -366,6 +366,14 @@ module Journal end end + def count(query=nil) + @storage.count(query) + end + + def remove(query=nil) + @storage.remove(query) + end + end end # Journal diff --git a/test/test_journal.rb b/test/test_journal.rb index 3f1ce766..9e8f0654 100644 --- a/test/test_journal.rb +++ b/test/test_journal.rb @@ -270,7 +270,7 @@ class JournalStoragePostgresTest < Test::Unit::TestCase @storage.insert(JournalMessage.create('test.topic', {name: 'two'})) @storage.insert(JournalMessage.create('test.topic', {name: 'three'})) @storage.insert(JournalMessage.create('archived.topic', {name: 'four'}, - timestamp: Time.now - DAY*100)) + timestamp: Time.now - DAY*100)) @storage.insert(JournalMessage.create('complex', {name: 'five', country: { name: 'Italy' }})) @@ -278,15 +278,30 @@ class JournalStoragePostgresTest < Test::Unit::TestCase name: 'Austria' }})) - + # query by topic + assert_equal(3, @storage.find(Query.define { topic 'test.*' }).length) + # query by payload + assert_equal(1, @storage.find(Query.define { + payload('country.name' => 'Austria') }).length) + # query by timestamp range + assert_equal(1, @storage.find(Query.define { + timestamp(from: Time.now - DAY*150, to: Time.now - DAY*50) }).length) + + # count with query + assert_equal(2, @storage.count(Query.define { topic('complex') })) + assert_equal(6, @storage.count) + @storage.remove(Query.define { topic('archived.*') }) + assert_equal(5, @storage.count) + @storage.remove + assert_equal(0, @storage.count) end def test_journal - received = [] # this journal persists messages in the test storage: journal = JournalBroker.new(storage: @storage) - - + journal.publish 'log.irc', action: 'message' + sleep 0.1 + assert_equal(1, journal.count) end end |