]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
journal: even more tests
authorMatthias Hecker <apoc@geekosphere.org>
Sun, 14 Jun 2015 18:05:45 +0000 (20:05 +0200)
committerMatthias Hecker <apoc@geekosphere.org>
Sun, 14 Jun 2015 18:05:45 +0000 (20:05 +0200)
lib/rbot/journal.rb
test/test_journal.rb

index 71b0c7ff7c0754322d4a5cf88573a91b2ed4a86e..a25f3a9f9632aaf0d874223cf1b8fd345a5753d9 100644 (file)
@@ -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
index 3f1ce7667a5020538793277f612e52f68c32126b..9e8f06541dfb0ca333e191bb5f761820159601b0 100644 (file)
@@ -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