Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make documents into directories for now. Zip files are too complicate…
…d to deal with right at the moment (but see zipfile branch). [#4]
- Loading branch information
Showing
4 changed files
with
101 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,89 @@ | ||
require File.dirname(__FILE__) + '/../spec_helper' | ||
require File.dirname(__FILE__) + '/../../src/document/document_model' | ||
require 'tmpdir' | ||
|
||
describe DocumentModel do | ||
before :each do | ||
@tmpdir = Dir.mktmpdir 'DocumentModel' | ||
end | ||
|
||
describe "constructor" do | ||
before :each do | ||
@model = DocumentModel.new | ||
end | ||
it "should set the data object to a kind of TableModel" do | ||
@model = DocumentModel.new File.join(@tmpdir, 'constructor') | ||
@model.data.class.included_modules.should include(javax.swing.table.TableModel) | ||
end | ||
|
||
it "should set the title" do | ||
@model.title.should_not be_nil | ||
it "should have a zero-argument form" do | ||
lambda {DocumentModel.new}.should_not raise_error(ArgumentError) | ||
end | ||
|
||
it "should set the data object to a kind of TableModel" do | ||
@model.data.class.included_modules.should include(javax.swing.table.TableModel) | ||
it "should take a filename as argument" do | ||
lambda {DocumentModel.new File.join(@tmpdir, 'foo')}.should_not raise_error(ArgumentError) | ||
end | ||
|
||
it "should create a new folder with the specified filename" do | ||
filename = File.join(@tmpdir, 'some crazy filename') | ||
File.should_not exist(filename) | ||
DocumentModel.new filename | ||
File.should exist(filename) | ||
File.stat(filename).should be_directory | ||
end | ||
|
||
it "should put an H2 database into the folder it creates" do | ||
pending "Does this really need to happen at creation time? \ | ||
It's probably OK if the DB springs into existence when the first table is added." do | ||
filename = File.join(@tmpdir, 'test file') | ||
@model = DocumentModel.new filename | ||
Dir[File.join filename, '*.h2.db'].should_not be_empty | ||
end | ||
end | ||
end | ||
|
||
describe "instance methods" do | ||
before :each do | ||
@model = DocumentModel.new | ||
end | ||
|
||
it "should have a title attribute (read/write)" do | ||
@model.should respond_to(:title) | ||
@model.should respond_to(:title=) | ||
it "should have a data attribute (read/write)" do | ||
@model.should respond_to(:data) | ||
@model.should respond_to(:data=) | ||
end | ||
|
||
it "should have a count writer" do | ||
@model.should respond_to(:count=) | ||
end | ||
describe "filename" do | ||
it "should be valid for reading and writing" do | ||
@model.should respond_to(:filename) | ||
@model.should respond_to(:filename=) | ||
end | ||
|
||
it "should incorporate the count in the title" do | ||
@model.title.should == 'Document-1' | ||
@model.count = 25 | ||
@model.title.should == 'Document-25' | ||
it "should raise an error if an existing filename is changed" do | ||
filename = File.join @tmpdir, 'foo' | ||
@model.filename.should be_nil | ||
@model.filename = filename | ||
@model.filename.should == filename | ||
lambda {@model.filename = File.join @tmpdir, 'bar'}.should raise_error | ||
end | ||
end | ||
|
||
it "should have a data attribute (read/write)" do | ||
@model.should respond_to(:data) | ||
@model.should respond_to(:data=) | ||
describe "title" do | ||
it "should be valid" do | ||
@model.should respond_to(:title) | ||
end | ||
|
||
it "should return the basename of the filename" do | ||
name = 'an arbitrary filename' | ||
subdirectory = 'an arbitrary subdirectory' | ||
Dir.mkdir File.join(@tmpdir, subdirectory) | ||
@model.filename = File.join @tmpdir, subdirectory, name | ||
@model.title.should == name | ||
end | ||
|
||
it "should return nil if the filename is nil" do | ||
@model.title.should be_nil | ||
end | ||
end | ||
end | ||
|
||
after :each do | ||
FileUtils.rm_r @tmpdir | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters