Permalink
Browse files

version 0.2.9 release, 'note edit Foo' edits last note when no note n…

…umber specified
  • Loading branch information...
1 parent d6eec12 commit 7926dba7aeb36d03aa48873b5b8b6c274b36a3c8 @banister committed Dec 12, 2012
Showing with 19 additions and 20 deletions.
  1. +7 −10 lib/pry-note/commands.rb
  2. +1 −1 lib/pry-note/version.rb
  3. +1 −1 pry-note.gemspec
  4. +10 −8 test/test_pry_note.rb
View
@@ -123,20 +123,16 @@ def add_note(name, message=nil)
# @param [String] co_name Name of note object.
# @param [String, nil] note_number_s The note number as a string
- # @param [Boolean] must_provide_number Whether note number is
- # allowed to be nil.
- def ensure_note_number_in_range(co_name, note_number_s, must_provide_number=true)
+ def ensure_note_number_in_range(co_name, note_number_s)
if notes[co_name]
total_notes = notes[co_name].count
else
raise Pry::CommandError, "No notes available for #{co_name}"
end
- if !note_number_s && !must_provide_number
+ if !note_number_s
# we're allowed nil, so just return
return
- elsif !note_number_s
- raise Pry::CommandError, "Must specify a note number. Allowable range is 1-#{total_notes}."
elsif note_number_s.to_i < 1 || note_number_s.to_i > total_notes
raise Pry::CommandError, "Invalid note number (#{note_number_s}). Allowable range is 1-#{total_notes}."
end
@@ -147,23 +143,24 @@ def reedit_note(name, message=nil)
co_name = code_object_name(retrieve_code_object_safely(name))
ensure_note_number_in_range(co_name, note_number_s)
+ note_number_i = note_number_s ? note_number_s.to_i : notes[co_name].count
if message
new_content = message
else
- old_content = notes[co_name][note_number_s.to_i - 1]
+ old_content = notes[co_name][note_number_i - 1]
new_content = edit_note(co_name, old_content.to_s)
end
- notes[co_name][note_number_s.to_i - 1] = new_content
- output.puts "Updated note #{note_number_s} for #{co_name}!\n"
+ notes[co_name][note_number_i - 1] = new_content
+ output.puts "Updated note #{note_number_i} for #{co_name}!\n"
end
def delete_note(name)
name, note_number_s = name.split(/:(\d+)$/)
co_name = code_object_name(retrieve_code_object_safely(name))
- ensure_note_number_in_range(co_name, note_number_s, false)
+ ensure_note_number_in_range(co_name, note_number_s)
if note_number_s
notes[co_name].delete_at(note_number_s.to_i - 1)
View
@@ -1,3 +1,3 @@
module PryNote
- VERSION = "0.2.8"
+ VERSION = "0.2.9"
end
View
@@ -2,7 +2,7 @@
Gem::Specification.new do |s|
s.name = "pry-note"
- s.version = "0.2.8"
+ s.version = "0.2.9"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["John Mair (banisterfiend)"]
View
@@ -160,14 +160,6 @@ def ping
describe "note edit" do
describe "errors" do
- it 'should error when not given a note number' do
- @t.process_command "note add PryNote::TestClass -m 'my note1'"
-
- capture_exception do
- @t.process_command "note edit PryNote::TestClass -m 'bing'"
- end.message.should =~ /Must specify a note number/
- end
-
it 'should error when given out of range note number' do
@t.process_command "note add PryNote::TestClass -m 'my note1'"
@@ -183,6 +175,16 @@ def ping
end
end
+ it 'should edit last note when not given a note number' do
+ @t.process_command "note add PryNote::TestClass -m 'my note1'"
+ @t.process_command "note add PryNote::TestClass -m 'my note2'"
+ @t.process_command "note add PryNote::TestClass -m 'my note3'"
+
+ @t.process_command "note edit PryNote::TestClass -m 'modified note'"
+ PryNote.notes["PryNote::TestClass"].count.should == 3
+ PryNote.notes["PryNote::TestClass"].last.should =~ /modified note/
+ end
+
it 'should amend the content of a note with -m' do
@t.process_command "note add PryNote::TestClass -m 'my note1'"
@t.process_command "note edit PryNote::TestClass:1 -m 'bing'"

0 comments on commit 7926dba

Please sign in to comment.