KITAITI Makoto
null+****@clear*****
Tue Dec 30 21:27:51 JST 2014
KITAITI Makoto 2014-12-30 21:27:51 +0900 (Tue, 30 Dec 2014) New Revision: 4dd9eb886546e27b9b552e3d2f15bd45ee64f847 https://github.com/ranguba/epub-searcher/commit/4dd9eb886546e27b9b552e3d2f15bd45ee64f847 Message: Add a test for book list page Modified files: test/app/controllers/main_controller_test.rb Modified: test/app/controllers/main_controller_test.rb (+56 -0) =================================================================== --- test/app/controllers/main_controller_test.rb 2014-12-30 20:14:29 +0900 (9992c90) +++ test/app/controllers/main_controller_test.rb 2014-12-30 21:27:51 +0900 (8fe8bd4) @@ -1,4 +1,14 @@ +# -*- coding: utf-8 -*- class MainControllerTest < Test::Unit::TestCase + class << self + def startup + @@test_documents ||= %w[kk1.epub kk2.epub css21.epub].map {|filename| + path = Padrino.root("data/test-setup/#{filename}") + EPUBSearcher::EPUBDocument.open(path) + } + end + end + def test_get_index get '/' @@ -26,4 +36,50 @@ class MainControllerTest < Test::Unit::TestCase assert_equal '<', find('form input[type="search"]').value end + + def test_get_books + omit_on_travis + + truncate_books + load_test_data + + visit '/books' + + [ + 'ケヴィン・ケリー著作選集 1', + 'ケヴィン・ケリー著作選集 2', + 'CSS2.1仕様 日本語訳 EPUB版' + ].each do |title| + assert page.has_content?(title) + end + end + + def db + @db ||= EPUBSearcher::RemoteDatabase.new(db_options) + end + + def db_options + { + host: EPUBSearcher::App.settings.droonga_host, + port: EPUBSearcher::App.settings.droonga_port, + } + end + + def truncate_books + books = db.select( + table: :Books, + output_columns: '_id' + ) + books.each do |book| + params = { + table: :Books, + id: book['_id'] + } + db.delete params + end + end + + def load_test_data + db.load_records @@test_documents + end end -------------- next part -------------- HTML����������������������������... Download