Permalink
Browse files

Add --delete flag to "ppl email" enabling email addresses to be deleted

  • Loading branch information...
1 parent 4c9bc1c commit 0c7ddb7fe502dd93a75c78eadba8b7cbcfd7768c @hnrysmth hnrysmth committed Dec 27, 2012
Showing with 40 additions and 4 deletions.
  1. +1 −1 lib/ppl.rb
  2. +16 −1 lib/ppl/command/email.rb
  3. BIN ppl-1.6.0.gem
  4. +2 −2 ppl.gemspec
  5. +21 −0 spec/ppl/command/email_spec.rb
View
@@ -1,7 +1,7 @@
module Ppl
- Version = "1.5.3"
+ Version = "1.6.0"
module Adapter
end
@@ -14,6 +14,10 @@ def initialize
def options(parser, options)
parser.banner = "usage: ppl email <contact> [<email-address>]"
+
+ parser.on("-d", "--delete", "delete email address") do
+ options[:delete] = true
+ end
end
def execute(input, output)
@@ -29,6 +33,8 @@ def determine_action(input)
:list_email_addresses
elsif input.arguments[1].nil?
:show_email_addresses
+ elsif input.options[:delete]
+ :delete_email_address
else
:set_email_address
end
@@ -51,10 +57,19 @@ def show_email_addresses(input, output)
end
end
- def set_email_address(input, output)
+ def delete_email_address(input, output)
contact = @storage.require_contact(input.arguments[0])
email_address = input.arguments[1].dup
+ contact.email_addresses.delete(email_address) do
+ message = sprintf("%s has no such email address %s", contact.id, email_address)
+ raise Ppl::Error::IncorrectUsage, message
+ end
+ @storage.save_contact(contact)
+ end
+ def set_email_address(input, output)
+ contact = @storage.require_contact(input.arguments[0])
+ email_address = input.arguments[1].dup
if contact.has_email_address?(email_address)
message = sprintf("%s already has email address %s", contact.id, email_address)
raise Ppl::Error::IncorrectUsage, message
View
Binary file not shown.
View
@@ -2,8 +2,8 @@
Gem::Specification.new do |spec|
spec.name = "ppl"
- spec.version = "1.5.3"
- spec.date = "2012-12-26"
+ spec.version = "1.6.0"
+ spec.date = "2012-12-27"
spec.required_ruby_version = ">= 1.9.3"
@@ -48,6 +48,27 @@
@command.execute(@input, @output).should eq false
end
+ it "should delete the given address to the contact if requested" do
+ @contact.email_addresses.push("jim@example.org")
+ @contact.email_addresses.push("jim@example.com")
+ @storage.should_receive(:require_contact).and_return(@contact)
+ @storage.should_receive(:save_contact) do |contact|
+ contact.email_addresses.should eq ["jim@example.com"]
+ end
+ @input.arguments = ["jim", "jim@example.org"]
+ @input.options = { :delete => true }
+ @command.execute(@input, @output)
+ end
+
+ it "should raise an error when deleting a non-existent email address" do
+ @contact.email_addresses.push("jim@example.org")
+ @contact.email_addresses.push("jim@example.com")
+ @storage.should_receive(:require_contact).and_return(@contact)
+ @input.arguments = ["jim", "jim@example.net"]
+ @input.options = { :delete => true }
+ expect{@command.execute(@input, nil)}.to raise_error(Ppl::Error::IncorrectUsage)
+ end
+
it "should add the given address to the contact if it's new" do
@storage.should_receive(:require_contact).and_return(@contact)
@storage.should_receive(:save_contact) do |contact|

0 comments on commit 0c7ddb7

Please sign in to comment.