Skip to content

Commit

Permalink
The find method will now return nil when a note
Browse files Browse the repository at this point in the history
doesn't exist.  Added the find! method which will
raise a CatchNotes::NotFound error.
  • Loading branch information
wadewest committed Nov 7, 2010
1 parent 595d90d commit 80534fb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
8 changes: 7 additions & 1 deletion lib/catch_notes/base.rb
Expand Up @@ -54,12 +54,18 @@ def all
end
end

def find(id)
def find!(id)
res = get "/notes/#{id}"
if send(:ok?, res)
send :build_from_hash, res.parsed_response['notes'].first
end
end

def find(id)
find!(id)
rescue CatchNotes::NotFound
nil
end

def first
all.first
Expand Down
9 changes: 7 additions & 2 deletions test/test_catch_notes.rb
Expand Up @@ -60,9 +60,14 @@ def setup
assert !note.destroy
end

should "raise a NotFound error when a note doesn't exist" do
should "raise a nil error when a note doesn't exist: find" do
assert_nil NoteClass.find 13
end


should "raise a NotFound error when a note doesn't exist: find!" do
assert_raise CatchNotes::NotFound do
NoteClass.find 13
NoteClass.find! 13
end
end

Expand Down

0 comments on commit 80534fb

Please sign in to comment.