package quotidian.web.controller

import org.apache.lucene.analysis.standard.StandardAnalyzer
import org.apache.lucene.index.{IndexReader,IndexWriter}
import org.apache.lucene.index.IndexWriter.MaxFieldLength.UNLIMITED
import org.apache.lucene.search.IndexSearcher
import quotidian.DatastoreSpecification
import quotidian.model.Quote
import quotidian.search.DatastoreDirectory

object DatastoreQuoteControllerSpecs extends DatastoreSpecification {
	val controller = new DatastoreQuoteController
	"A DatastoreDirectory" should {
		datastoreCleanup.before
		"be able to have Quotes written to it" >> {
			val quote = Quote("this is some text","this is a source","and this is context")
			val directory = new DatastoreDirectory()
			val writer = new IndexWriter(directory,new StandardAnalyzer(),UNLIMITED)
			writer.addDocument(quote)
			writer.commit
			val searcher = new IndexSearcher(directory)
			val reader = searcher.getIndexReader
			val terms = reader.terms
			terms.next mustEqual true
			reader.close
		}
	}
	"A controller" should {
		datastoreCleanup.before
		val quote = Quote("this is some text","this is a source","and this is context")
		"save a quote" >> {
			val key = controller.save(quote)
			key must notBeNull
		}
		"have a searcher with a reader with terms" >> {
			controller.save(quote)
			val reader = controller.searcher.getIndexReader
			val terms = reader.terms
			terms.next mustEqual true
			reader.close
		}
	}
}

package quotidian.web.controller

import org.apache.lucene.index.IndexReader
import quotidian.DatastoreSpecification
import quotidian.model.Quote

object DatastoreQuoteControllerSpecs extends DatastoreSpecification {
	val controller = new DatastoreQuoteController
	"A controller" should {
		datastoreCleanup.before
		val quote = Quote("this is some text","this is a source","and this is context")
		"save a quote" >> {
			val key = controller.save(quote)
			key must notBeNull
		}
		"have a searcher with a reader with terms" >> {
			controller.save(quote)
			val terms = controller.searcher.getIndexReader.terms
			terms.next mustEqual true
		}
	}
}

--- 
+++ 
@@ -1,11 +1,30 @@
 package quotidian.web.controller
 
-import org.apache.lucene.index.IndexReader
+import org.apache.lucene.analysis.standard.StandardAnalyzer
+import org.apache.lucene.index.{IndexReader,IndexWriter}
+import org.apache.lucene.index.IndexWriter.MaxFieldLength.UNLIMITED
+import org.apache.lucene.search.IndexSearcher
 import quotidian.DatastoreSpecification
 import quotidian.model.Quote
+import quotidian.search.DatastoreDirectory
 
 object DatastoreQuoteControllerSpecs extends DatastoreSpecification {
 	val controller = new DatastoreQuoteController
+	"A DatastoreDirectory" should {
+		datastoreCleanup.before
+		"be able to have Quotes written to it" >> {
+			val quote = Quote("this is some text","this is a source","and this is context")
+			val directory = new DatastoreDirectory()
+			val writer = new IndexWriter(directory,new StandardAnalyzer(),UNLIMITED)
+			writer.addDocument(quote)
+			writer.commit
+			val searcher = new IndexSearcher(directory)
+			val reader = searcher.getIndexReader
+			val terms = reader.terms
+			terms.next mustEqual true
+			reader.close
+		}
+	}
 	"A controller" should {
 		datastoreCleanup.before
 		val quote = Quote("this is some text","this is a source","and this is context")
@@ -15,8 +34,10 @@
 		}
 		"have a searcher with a reader with terms" >> {
 			controller.save(quote)
-			val terms = controller.searcher.getIndexReader.terms
+			val reader = controller.searcher.getIndexReader
+			val terms = reader.terms
 			terms.next mustEqual true
+			reader.close
 		}
 	}
 }
Add new specs isolating Quote writing to Index

Added a specification isolating the case of writing a Quote's Document
to the Index and some slight modifications to the existing controller
writing to Index spec
