diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/integration/tapicero_test.rb | 59 | ||||
-rw-r--r-- | test/integration/test_setup_test.rb | 15 | ||||
-rw-r--r-- | test/support/integration_test.rb | 30 | ||||
-rw-r--r-- | test/test_helper.rb | 3 |
4 files changed, 64 insertions, 43 deletions
diff --git a/test/integration/tapicero_test.rb b/test/integration/tapicero_test.rb index bda05d3..4c00ee2 100644 --- a/test/integration/tapicero_test.rb +++ b/test/integration/tapicero_test.rb @@ -1,56 +1,29 @@ -require File.expand_path('../../test_helper.rb', __FILE__) +require_relative '../test_helper.rb' -class TapiceroTest < MiniTest::Unit::TestCase +class TapiceroTest < Tapicero::IntegrationTest - def test_loads_config - assert_equal "tapicero_test", config.connection[:prefix] - assert_equal "debug", config.send(:log_level) - end - - def test_database_exists - assert database - assert_equal "tapicero_test_users", database.name - end - - def test_creates_user_db_fast - user_id = create_user['id'] - database.save_doc :id => user_id - assert user_database(user_id) - end - - def test_creates_user_db_slow - user_id = create_user['id'] + def test_creates_user_db + create_user sleep 1 - assert user_database(user_id) + assert user_database + assert user_database.name.start_with?(config.options[:db_prefix]) + assert user_database.info end def test_configures_security - user_id = create_user['id'] + create_user sleep 1 - assert_equal config.options[:security], user_database(user_id).get('_security') - end - - def create_user - database.save_doc :some => :content + assert_equal config.options[:security], user_database.get('_security') end - def user_database(name) - host.database(config.options[:db_prefix] + name) - end - - def database - @database ||= host.database(database_name) - end - - def database_name - config.complete_db_name('users') - end - - def host - @host ||= CouchRest.new(config.couch_host) + def test_stores_design_docs + create_user + sleep 1 + assert_equal ['_design/docs', '_design/syncs', '_design/transactions'], + design_docs(user_database).map{|doc| doc["id"]}.sort end - def config - Tapicero.config + def design_docs(db) + db.documents(startkey: '_design', endkey: '_design'.succ)["rows"] end end diff --git a/test/integration/test_setup_test.rb b/test/integration/test_setup_test.rb new file mode 100644 index 0000000..525c14d --- /dev/null +++ b/test/integration/test_setup_test.rb @@ -0,0 +1,15 @@ +require_relative '../test_helper.rb' + +class TestSetupTest < Tapicero::IntegrationTest + + def test_loads_config + assert_equal "tapicero_test", config.connection[:prefix] + assert_equal "debug", config.send(:log_level) + end + + def test_database_exists + assert database + assert_equal "tapicero_test_users", database.name + end + +end diff --git a/test/support/integration_test.rb b/test/support/integration_test.rb new file mode 100644 index 0000000..58469b9 --- /dev/null +++ b/test/support/integration_test.rb @@ -0,0 +1,30 @@ +module Tapicero + class IntegrationTest < MiniTest::Unit::TestCase + + def create_user + result = database.save_doc :some => :content + raise RuntimeError.new(result.inspect) unless result['ok'] + @user_id = result['id'] + end + + def user_database + host.database(config.options[:db_prefix] + @user_id) + end + + def database + @database ||= host.database(database_name) + end + + def database_name + config.complete_db_name('users') + end + + def host + @host ||= CouchRest.new(config.couch_host) + end + + def config + Tapicero.config + end + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb index 4a9ca6b..da8b88c 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -9,3 +9,6 @@ require 'mocha/setup' require 'tapicero/version' Tapicero::CONFIGS << "test/config.yaml" require 'tapicero' + + +require_relative 'support/integration_test' |