sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit 3855a6997135aecdcc6b483ab7e85285b73f9490
parent 192e8e484a29b7807256c815f25c7bad887d4c96
Author: Zeger-Jan van de Weg <mail@zjvandeweg.nl>
Date:   Thu,  5 Feb 2015 21:18:50 +0100

Tests for Contact Manager Added

Diffstat:
M lib/sup/contact.rb | 4 +++-
M sup.gemspec | 1 +
A test/unit/fixtures/contacts.txt | 2 ++
A test/unit/test_contact.rb | 34 ++++++++++++++++++++++++++++++++++
4 files changed, 40 insertions(+), 1 deletion(-)
diff --git a/lib/sup/contact.rb b/lib/sup/contact.rb
@@ -29,11 +29,13 @@ class ContactManager
   def contacts_with_aliases; @a2p.values.uniq end
 
   def update_alias person, aalias=nil
+    ## Deleting old data if it exists
     old_aalias = @p2a[person]
-    if(old_aalias != nil and old_aalias != "") # remove old alias
+    unless old_aalias.nil?
       @a2p.delete old_aalias
       @e2p.delete person.email
     end
+    ## Update with new data
     @p2a[person] = aalias
     unless aalias.nil? || aalias.empty?
       @a2p[aalias] = person
diff --git a/sup.gemspec b/sup.gemspec
@@ -65,5 +65,6 @@ SUP: please note that our old mailing lists have been shut down,
   s.add_development_dependency 'minitest', '~> 5.5.1'
   s.add_development_dependency "rr", "~> 1.0.5"
   s.add_development_dependency "gpgme", ">= 2.0.2"
+  s.add_development_dependency "pry"
 
 end
diff --git a/test/unit/fixtures/contacts.txt b/test/unit/fixtures/contacts.txt
@@ -0,0 +1 @@
+RC: Random Contact <random_dude@gmail.com>
+\ No newline at end of file
diff --git a/test/unit/test_contact.rb b/test/unit/test_contact.rb
@@ -0,0 +1,33 @@
+require 'test_helper'
+require 'sup/contact'
+
+module Redwood
+
+class TestContact < Minitest::Test
+  def setup
+    @contact = ContactManager.init(File.expand_path("../fixtures/contacts.txt", __FILE__))
+    @person  = Person.new "Terrible Name", "terrible@name.com"
+  end
+
+  def teardown
+    runner = Redwood.const_get "ContactManager".to_sym
+    runner.deinstantiate!
+  end
+
+  def test_contact_manager
+    assert @contact
+    ## 1 contact is imported from the fixture file.
+    assert_equal 1, @contact.contacts.count
+    assert_equal @contact.contact_for("RC").name, "Random Contact"
+
+    assert_nil @contact.contact_for "TN"
+    @contact.update_alias @person, "TN"
+
+    assert @contact.is_aliased_contact?(@person)
+    assert_equal @person, @contact.contact_for("TN")
+
+    assert_equal "TN", @contact.alias_for(@person)
+  end
+end
+
+end
+\ No newline at end of file