Permalink
Browse files

return nil when you fetch a note that doesn't exist

  • Loading branch information...
1 parent 9f3fe05 commit db7040b16bb89ea0916372834a1c4197da69725f @apeckham apeckham committed Jul 3, 2010
Showing with 84 additions and 2 deletions.
  1. +2 −1 lib/simplenote.rb
  2. +73 −0 test/fixtures/get_note_with_bad_key.yml
  3. +9 −1 test/simplenote_test.rb
View
@@ -20,7 +20,8 @@ def get_index
end
def get_note(key)
- self.class.get "/note", :query => request_hash.merge(:key => key)
+ out = self.class.get "/note", :query => request_hash.merge(:key => key)
+ out.response.is_a?(Net::HTTPNotFound) ? nil : out
end
def delete_note(key)
@@ -0,0 +1,73 @@
+---
+- !ruby/struct:VCR::HTTPInteraction
+ request: !ruby/struct:VCR::Request
+ method: :post
+ uri: https://simple-note.appspot.com:443/api/login
+ body: |
+ cGFzc3dvcmQ9cGFzc3dvcmQhJmVtYWlsPXNpbXBsZW5vdGV0ZXN0JTQwbWFp
+ bGluYXRvci5jb20=
+
+ headers:
+ connection:
+ - close
+ content-type:
+ - application/x-www-form-urlencoded
+ content-length:
+ - "78"
+ host:
+ - simple-note.appspot.com
+ response: !ruby/struct:VCR::Response
+ status: !ruby/struct:VCR::ResponseStatus
+ code: 200
+ message: OK
+ headers:
+ expires:
+ - Fri, 01 Jan 1990 00:00:00 GMT
+ content-type:
+ - text/html; charset=utf-8
+ connection:
+ - close
+ date:
+ - Sat, 03 Jul 2010 23:23:55 GMT
+ server:
+ - Google Frontend
+ account-type:
+ - "000"
+ set-cookie:
+ - auth=2D3D3762E9204476AF991F3347C50CA9379980415D32962552C40FBE3EE4CBB6; expires=Sat, 17-Jul-2010 23:23:55 GMT
+ - email=simplenotetest@mailinator.com; expires=Sat, 17-Jul-2010 23:23:55 GMT
+ cache-control:
+ - no-cache
+ body: 2D3D3762E9204476AF991F3347C50CA9379980415D32962552C40FBE3EE4CBB6
+ http_version: "1.1"
+- !ruby/struct:VCR::HTTPInteraction
+ request: !ruby/struct:VCR::Request
+ method: :get
+ uri: https://simple-note.appspot.com:443/api/note?email=simplenotetest%40mailinator.com&key=key%20that%20doesn't%20exist&auth=2D3D3762E9204476AF991F3347C50CA9379980415D32962552C40FBE3EE4CBB6
+ body:
+ headers:
+ connection:
+ - close
+ host:
+ - simple-note.appspot.com
+ response: !ruby/struct:VCR::Response
+ status: !ruby/struct:VCR::ResponseStatus
+ code: 404
+ message: Not Found
+ headers:
+ expires:
+ - Fri, 01 Jan 1990 00:00:00 GMT
+ content-type:
+ - text/html; charset=utf-8
+ connection:
+ - close
+ date:
+ - Sat, 03 Jul 2010 23:23:55 GMT
+ server:
+ - Google Frontend
+ content-length:
+ - "0"
+ cache-control:
+ - no-cache
+ body: ""
+ http_version: "1.1"
View
@@ -61,7 +61,15 @@ class SimpleNoteTest < Test::Unit::TestCase
end
end
- should_eventually "return nil when a note doesn't exist"
+ should "return nil when you fetch a note that doesn't exist" do
+ VCR.use_cassette('get_note_with_bad_key', :record => :none) do
+ simplenote = SimpleNote.new
+ simplenote.login("simplenotetest@mailinator.com", "password!")
+
+ assert_nil simplenote.get_note("key that doesn't exist")
+ end
+ end
+
should_eventually "raise if you try to delete a note that doesn't exist"
end

0 comments on commit db7040b

Please sign in to comment.