<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[719] trunk/alexandria: Fixed bug, a crash caused by an unnecessary exception being raised</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd>719</dd>
<dt>Author</dt> <dd>cathalmagus</dd>
<dt>Date</dt> <dd>2007-09-12 20:20:05 -0400 (Wed, 12 Sep 2007)</dd>
</dl>
<h3>Log Message</h3>
<pre>Fixed bug, a crash caused by an unnecessary exception being raised
when a book was added and deleted several times in one session.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkalexandrialibalexandrialibraryrb">trunk/alexandria/lib/alexandria/library.rb</a></li>
<li><a href="#trunkalexandriaspecsalexandrialibrary_specrb">trunk/alexandria/specs/alexandria/library_spec.rb</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkalexandrialibalexandrialibraryrb"></a>
<div class="modfile"><h4>Modified: trunk/alexandria/lib/alexandria/library.rb (718 => 719)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/alexandria/lib/alexandria/library.rb        2007-09-06 21:07:48 UTC (rev 718)
+++ trunk/alexandria/lib/alexandria/library.rb        2007-09-13 00:20:05 UTC (rev 719)
</span><span class="lines">@@ -476,15 +476,18 @@
</span><span class="cx"> raise if @@deleted_libraries.include?(self)
</span><span class="cx"> @@deleted_libraries << self
</span><span class="cx"> else
</span><del>- raise if @deleted_books.include?(book)
</del><ins>+ if @deleted_books.include?(book)
+ doubles = @deleted_books.reject { |b| not b.equal? book }
+ raise "Book #{book.isbn} was already deleted" unless doubles.empty?
+ end
</ins><span class="cx"> @deleted_books << book
</span><span class="cx"> i = self.index(book)
</span><span class="cx"> # We check object IDs there because the user could have added
</span><span class="cx"> # a book with the same identifier as another book he/she
</span><span class="cx"> # previously deleted and that he/she is trying to redo.
</span><del>- if i != nil and self[i].object_id == book.object_id
</del><ins>+ if i and self[i].equal? book
</ins><span class="cx"> changed
</span><del>- old_delete(book)
</del><ins>+ old_delete(book) # FIX this will old_delete all '==' books
</ins><span class="cx"> notify_observers(self, BOOK_REMOVED, book)
</span><span class="cx"> end
</span><span class="cx"> end
</span></span></pre></div>
<a id="trunkalexandriaspecsalexandrialibrary_specrb"></a>
<div class="modfile"><h4>Modified: trunk/alexandria/specs/alexandria/library_spec.rb (718 => 719)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/alexandria/specs/alexandria/library_spec.rb        2007-09-06 21:07:48 UTC (rev 718)
+++ trunk/alexandria/specs/alexandria/library_spec.rb        2007-09-13 00:20:05 UTC (rev 719)
</span><span class="lines">@@ -8,12 +8,20 @@
</span><span class="cx"> TESTDIR = File.join(LIBDIR, 'test')
</span><span class="cx">
</span><span class="cx">
</span><del>-def useTestLibrary(version)
- FileUtils.rm_rf(TESTDIR)
- libVersion = File.join(LIBDIR, version)
- FileUtils.cp_r(libVersion, TESTDIR)
</del><ins>+#def useTestLibrary(version)
+# libVersion = File.join(LIBDIR, version)
+# FileUtils.cp_r(libVersion, TESTDIR)
+#end
+
+def an_artist_of_the_floating_world
+ Alexandria::Book.new("An Artist of the Floating World",
+ "Kazuo Ishiguro",
+ "9780571147168",
+ "Faber and Faber", 1999,
+ "Paperback")
</ins><span class="cx"> end
</span><span class="cx">
</span><ins>+
</ins><span class="cx"> # find a nicer way to do this... it generates a warning at the moment
</span><span class="cx"> module Alexandria
</span><span class="cx"> class Library
</span><span class="lines">@@ -21,18 +29,65 @@
</span><span class="cx"> end
</span><span class="cx"> end
</span><span class="cx">
</span><del>-describe "Library class" do
</del><ins>+describe Alexandria::Library do
</ins><span class="cx">
</span><ins>+ before(:each) do
+ FileUtils.mkdir(TESTDIR)
+ end
+
</ins><span class="cx"> it "has symbolic references to file extensions" do
</span><span class="cx"> extensions = Alexandria::Library::EXT
</span><span class="cx"> extensions[:book].should_not be_nil
</span><span class="cx"> extensions[:cover].should_not be_nil
</span><span class="cx"> end
</span><span class="cx">
</span><ins>+ it "disallows multiple deletion of the same copy of a book" do
+ myLibrary = Alexandria::Library.loadall()[0]
+ first_copy = an_artist_of_the_floating_world()
+ myLibrary << first_copy
+ myLibrary.delete(first_copy)
+ lambda { myLibrary.delete(first_copy) }.should raise_error
+ end
+
+ it "allows multiple copies of a book to be added and deleted in turn" do
+ myLibrary = Alexandria::Library.loadall()[0]
+ first_copy = an_artist_of_the_floating_world()
+ puts "first_copy #{first_copy.object_id}"
+ myLibrary << first_copy
+ myLibrary.delete(first_copy)
+
+ second_copy = an_artist_of_the_floating_world()
+ myLibrary << second_copy
+ third_copy = an_artist_of_the_floating_world()
+ myLibrary << third_copy
+
+ puts "AAA myLibrary.size #{myLibrary.size}"
+
+ puts "second_copy #{second_copy.object_id}"
+ #lambda { myLibrary.delete(second_copy) }.should raise_error
+ lambda { myLibrary.delete(second_copy) }.should_not raise_error
+
+
+ puts "BBB myLibrary.size #{myLibrary.size}"
+ # myLibrary.size.should == 1 # not yet an established feature...
+ end
+
+ after(:each) do
+ FileUtils.rm_rf(TESTDIR)
+ end
+
+end
+
+
+describe Alexandria::Library, " imported from 0.6.1 data files" do
+
+ before(:each) do
+ libVersion = File.join(LIBDIR, '0.6.1')
+ FileUtils.cp_r(libVersion, TESTDIR)
+ end
+
+
</ins><span class="cx"> it "imports cleanly from version 0.6.1 data format" do
</span><del>- #libraryDataVersion '0.6.1'
- puts "[#{Alexandria::Library::DIR}]"
- useTestLibrary '0.6.1'
</del><span class="cx"> libs = Alexandria::Library.loadall
</span><span class="cx"> libs.size.should == 1
</span><span class="cx"> myLibrary = libs[0]
</span><span class="lines">@@ -42,11 +97,15 @@
</span><span class="cx"> maloryBook.publisher.should == 'Oxford University Press'
</span><span class="cx"> maloryBook.authors.include?('Vinaver').should be_true
</span><span class="cx"> maloryBook.version.should == Alexandria::VERSION
</span><del>-
</del><ins>+
</ins><span class="cx"> # Guide to LaTeX
</span><span class="cx"> latexBook = myLibrary.select{|b| b.title.include? 'Latex'}[0]
</span><span class="cx"> latexBook.isbn.should == '9780201398250'
</span><span class="cx"> latexBook.publisher.should == 'Addison Wesley' # note, no Ruby-Amazon cruft
</span><span class="cx"> end
</span><span class="cx">
</span><ins>+ after(:each) do
+ FileUtils.rm_rf(TESTDIR)
+ end
+
</ins><span class="cx"> end
</span></span></pre>
</div>
</div>
</body>
</html>