class TestFileSystemDB

Public Instance Methods

test_fsdb() click to toggle source
# File vendor/qwik/lib/qwik/db-filesystem.rb, line 217
def test_fsdb
  # setup
  config = Qwik::Config.new
  config.update Qwik::Config::DebugConfig
  config.update Qwik::Config::TestConfig
  spath = config.super_dir.path
  path = '.test/'.path
  path.setup
  db = Qwik::FileSystemDB.new(path, spath)

  # test_exist?
  assert_equal false, db.exist?('1')

  # test_create
  db.create('1')
  assert_equal true, db.exist?('1')
  assert_equal '', db.get('1')

  # test_put
  db.put('1', 't')
  assert_equal 't', db.get('1')

  # test_size
  assert_equal 1, db.size('1')

  # test_put_with_time
  db.put('1', 't', Time.at(0))
  assert_equal 0, db.mtime('1').to_i        # test_mtime
  # test_put_with_time_num
  db.put('1', 't', 1)
  assert_equal 1, db.mtime('1').to_i

  # test_last_page_time
  assert_equal Time.at(1), db.last_page_time
  # test_last_article_time
  assert_equal Time.at(1), db.last_article_time

  # test_add
  db.add('1', 's')
  assert_equal 'ts', db.get('1')

  # test_get_dir_list
  ar = []
  db.instance_eval {
    dir = @path.to_s
    ar += get_dir_list(dir)
  }
  assert_equal ['1'], ar

  # test_get_dir_list_spath
  ar = []
  db.instance_eval {
    dir = @spath.to_s
    ar += get_dir_list(dir)
  }
  assert_equal true, ar.include?('FrontPage')

  # test_each
  db.each {|f|
    assert_instance_of(String, f)
  }

  # test_each_all
  db.each(true) {|f|
    assert_instance_of(String, f)
  }
  db.each_all {|f|
    assert_instance_of(String, f)
  }

  # test_backup_db
 #assert_instance_of(Qwik::BackupDB, db.backup_db('1'))

  # test_touch
  db.touch('1')

  # test_delete
  db.delete('1')
  assert_equal false, db.exist?('1')

  # test_super_pages
  assert_equal true,  db.exist?('_SideMenu')
  assert_equal false, db.baseexist?('_SideMenu')

  # teardown
  path.teardown
end