diff options
-rw-r--r-- | lib/nickserver/couch/fetch_key.rb | 2 | ||||
-rw-r--r-- | test/files/empty_couchdb_result | 5 | ||||
-rw-r--r-- | test/unit/nickserver_test.rb | 14 |
3 files changed, 20 insertions, 1 deletions
diff --git a/lib/nickserver/couch/fetch_key.rb b/lib/nickserver/couch/fetch_key.rb index d729ebc..db1e390 100644 --- a/lib/nickserver/couch/fetch_key.rb +++ b/lib/nickserver/couch/fetch_key.rb @@ -37,7 +37,7 @@ module Nickserver; module Couch def parse_key_from_response(uid, response) json = JSON.load(response) - if json["offset"] == 0 + if json["rows"].empty? self.fail 404, "Not Found" else return json["rows"].first["value"] diff --git a/test/files/empty_couchdb_result b/test/files/empty_couchdb_result new file mode 100644 index 0000000..5cde81a --- /dev/null +++ b/test/files/empty_couchdb_result @@ -0,0 +1,5 @@ +{ + "total_rows":2, + "offset":2, + "rows":[] +} diff --git a/test/unit/nickserver_test.rb b/test/unit/nickserver_test.rb index 46e69ca..6a23d0d 100644 --- a/test/unit/nickserver_test.rb +++ b/test/unit/nickserver_test.rb @@ -60,6 +60,20 @@ class NickserverTest < MiniTest::Unit::TestCase end end + def test_GET_served_via_couch_empty_results + domain = "example.org" + uid = "stompy@" + domain + stub_couch_response(uid, :body => file_content(:empty_couchdb_result)) do + start do + params = {:query => {"address" => uid}, :head => {:host => domain}} + get(params) do |http| + assert_equal 404, http.response_header.status + stop + end + end + end + end + def test_GET_served_via_couch_success domain = "example.org" uid = "blue@" + domain |