class TestPages

Public Instance Methods

nutest_cache() click to toggle source
# File vendor/qwik/lib/qwik/pages.rb, line 341
def nutest_cache
  pages = @site

  # Since this test takes long time, ignore this if under test suite.
  return if $0 != __FILE__  # just only for unit test.

  length, repeat = 100, 100

  page = pages.create_new
  page.store('a' * length)
  sleep 1
  repeat.times {
    str = page.load
  }
end
test_backup() click to toggle source
# File vendor/qwik/lib/qwik/pages.rb, line 357
    def test_backup
      pages = @site.get_pages

      page = pages.create('1')
      page.put_with_time('t', Time.at(0))
      ok_eq('t', page.load)

      bdb = pages.backupdb
      ar = bdb.map {|key, v, time| v }
#      ok_eq('t', ar[0])
#      ok_eq('', ar[1])

      page.put_with_time('t2', Time.at(1))

      ar = bdb.map {|key, v, time| v }
#      ok_eq('t', ar[0])
#      ok_eq('t2', ar[1])
#      ok_eq('', ar[2])
    end
test_compare() click to toggle source
# File vendor/qwik/lib/qwik/pages.rb, line 265
    def test_compare
      pages = @site.get_pages
      pages.erase_all
      a = pages.create('a')
      b = pages.create('b')
#      pages = pages.sort
#      ok_eq('a', pages[0].get_title)
#      ok_eq('b', pages[1].get_title)
    end
test_enumerable() click to toggle source
# File vendor/qwik/lib/qwik/pages.rb, line 309
def test_enumerable
  pages = @site.get_pages

  #test_find_title
  pages.create_new.store("* あ")
  pages.create_new.store("* い")
  pages.create_new.store("* う")

  #page = pages.find_title("い")
  page = pages.get_by_title("い")
  ok_eq('2', page.key)
  ok_eq(['1', '2', '3'], pages.keys)
end
test_last_article_time() click to toggle source
# File vendor/qwik/lib/qwik/pages.rb, line 300
def test_last_article_time
  pages = @site.get_pages
  a = pages.last_article_time
  ok_eq(nil, a)
  page = pages.create_new
  a = pages.last_article_time
  assert_instance_of(Time, a)
end
test_list() click to toggle source
# File vendor/qwik/lib/qwik/pages.rb, line 275
def test_list
  pages = @site.get_pages

  pages.create('t1').store('')
  pages.create('t2').store('')
  pages.create('1').store('t3')
  pages.create('2').store('t4')

  pages.each {|page|
    assert_instance_of(Qwik::Page, page)
  }

  tlist = pages.title_list
  ok_eq('1', tlist[0].key)
  ok_eq('2', tlist[1].key)
  ok_eq('t1', tlist[2].key)
  ok_eq('t2', tlist[3].key)
  tlist.each {|page|
    assert_instance_of(String, page.get_title)
  }
  
  list = pages.title_list_keys
  is [["1", "1"], ["2", "2"], ["t1", "t1"], ["t2", "t2"]], list
end
test_pages() click to toggle source
# File vendor/qwik/lib/qwik/pages.rb, line 208
def test_pages
  pages = @site.get_pages

  # test_create
  page = pages.create('1')

  # test_last_page_time
  page.put_with_time('test1', 0)
  ok_eq(0, pages.last_page_time.to_i)

  # test_each
  pages.each {|page|
    assert_instance_of(Qwik::Page, page)
    assert_instance_of(String, page.key)
  }

  # test_get_page
  page = pages['1']
  page.put('test2')
  ok_eq('test2', page.get)

  # test_page_exist_error
  assert_raises(Qwik::PageExistError) {
    pages.create('1')
  }

  # test_exist?
  ok_eq(true, pages.exist?('1'))

  # test_[]
  ok_eq('1', pages['1'].key)

  # test_delete
  pages.delete('1')
  ok_eq(false, pages.exist?('1'))
  ok_eq(nil, pages['1'])

  # test_get_new_id
  page = pages.create('0')
  page.store('t')
  ok_eq('1', pages.get_new_id)

  page = pages.create(pages.get_new_id)
  page.store('t')
  ok_eq(true, pages.exist?('1'))
  ok_eq('2', pages.get_new_id)

  page = pages.create('t')
  page.store('t')
  ok_eq('2', pages.get_new_id)
  ok_eq('2', pages.get_new_id)

  page = pages.create('4')
  page.store('t')
  ok_eq('5', pages.get_new_id)
end
test_recent_list() click to toggle source
# File vendor/qwik/lib/qwik/pages.rb, line 323
def test_recent_list
  pages = @site.get_pages

  pages.create('t1').put_with_time('t', Time.at(0))
  pages.create('t2').put_with_time('t', Time.at(1))
  pages.create('1').put_with_time('t3', Time.at(2))
  pages.create('2').put_with_time('t4', Time.at(3))

  dlist = pages.date_list
  eq ["t1", "t2", "1", "2"], dlist.map {|page| page.key }
  dlist.each {|page|
    assert_instance_of(Time, page.mtime)
  }

  list = pages.date_list_keys
  is [[0, "t1"], [1, "t2"], [2, "1"], [3, "2"]], list
end
test_super_pages() click to toggle source
# File vendor/qwik/lib/qwik/pages.rb, line 413
def test_super_pages
  pages = @site.get_pages

  # test_super_exist?
  ok_eq(true, pages.exist?('_SideMenu'))

  # test_baseexist?
  ok_eq(false, pages.baseexist?('_SideMenu'))

  # test_get_superpage
  page = pages['_SideMenu']
  ok_eq('Menu', page.get_title)

  # test_super_find_title
  page = pages.find_title('Menu')
  ok_eq('_SideMenu', page.key)

  # test_override_superpage
  page.store('* New menu')
  ok_eq('New menu', page.get_title)
  ok_eq(true, pages.baseexist?('_SideMenu'))
  page.delete
  ok_eq(false, pages.baseexist?('_SideMenu'))

  # test_override_create
  page = pages.create('_SideMenu')
  ok_eq(false, pages.baseexist?('_SideMenu')) # not yet
  page.store('t')
  ok_eq(true, pages.baseexist?('_SideMenu')) # become true here
end
test_touch() click to toggle source
# File vendor/qwik/lib/qwik/pages.rb, line 377
def test_touch
  pages = @site

  # touch does not affect the content.
  page = pages['FrontPage']
  org = page.load
  assert_match(/FrontPage/, page.load)

  page.touch
  assert_match(/FrontPage/, page.load)
  ok_eq(org, page.load)
end
test_with_underbar() click to toggle source
# File vendor/qwik/lib/qwik/pages.rb, line 390
def test_with_underbar
  pages = @site.get_pages

  page3 = pages.create('_t')
  page3.store('t')
  found = false
  pages.each {|page|
    found = true if page.key[0] == ?_
  }
  ok_eq(false, found)

  pages.each(true) {|page|
    found = true if page.key[0] == ?_
  }
  ok_eq(true, found)

  found = false
  pages.each_all {|page|
    found = true if page.key[0] == ?_
  }
  ok_eq(true, found)
end