Permalink
Browse files

Starting to test chunk_processor - and fixing bugs as a result.

  • Loading branch information...
1 parent a2a0004 commit ff0d9e1edac03a35bb0b79aa6da7ed2f873ac3ba @infovore committed Apr 3, 2012
Showing with 51 additions and 1 deletion.
  1. +4 −1 app/models/chunk_processor.rb
  2. +47 −0 spec/models/chunk_processor_spec.rb
@@ -13,11 +13,14 @@ def dechunk_title_and_author(title_and_author)
def location_string_to_array(locations)
start_loc, end_string = locations.split("-")
- if end_string
+ if end_string && end_string.to_i - start_loc.to_i < 0
i = start_loc.size - end_string.size - 1
prefix = start_loc[0..i]
end_loc = prefix + end_string
[start_loc.to_i, end_loc.to_i]
+ elsif end_string
+ end_loc = end_string
+ [start_loc.to_i, end_loc.to_i]
else
[start_loc.to_i, start_loc.to_i]
end
@@ -0,0 +1,47 @@
+require 'app/models/chunk_processor.rb'
+include ChunkProcessor
+
+class ChunkProcessorSpec
+ describe "when dechunking title and author" do
+ describe "and there is no author" do
+ before(:each) do
+ @string = "Capital without an Author"
+ end
+
+ it "should return nil as the author" do
+ dechunk_title_and_author(@string)[1].should be_nil
+ end
+
+ it "should return the full title of the book as the title" do
+ dechunk_title_and_author(@string)[0].should == @string
+ end
+ end
+
+ describe "and there is an author" do
+ it "should extract the author"
+ it "should extract the title"
+ end
+ end
+
+ describe "extracting locations to an array" do
+ describe "and there is a single location" do
+ it "should return an array containing that location as start and end" do
+ location_string_to_array("275").should == [275,275]
+ end
+ end
+
+ describe "and there is a start and end location" do
+ it "should return an array containing that start and end location" do
+ location_string_to_array("284-312").should == [284,312]
+ end
+
+ it "should return an array containing that start and end location even if going over a unit boundary" do
+ location_string_to_array("978-1024").should == [978,1024]
+ end
+
+ it "should return an array containing the full start and end location even if abbreviatons are used" do
+ location_string_to_array("284-87").should == [284,287]
+ end
+ end
+ end
+end

0 comments on commit ff0d9e1

Please sign in to comment.