From 88083a47eb042fd5b3f6cfd9cae1e087bc9fa072 Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 6 Jan 2014 10:05:47 +0100 Subject: add dummy integration test --- test/integration/tapicero_test.rb | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 test/integration/tapicero_test.rb (limited to 'test/integration') diff --git a/test/integration/tapicero_test.rb b/test/integration/tapicero_test.rb new file mode 100644 index 0000000..b83263a --- /dev/null +++ b/test/integration/tapicero_test.rb @@ -0,0 +1,4 @@ +require File.expand_path('../../test_helper.rb', __FILE__) + +class TapiceroTest < MiniTest::Unit::TestCase +end -- cgit v1.2.3 From 87d76281eb374f4c4538fe5bf5b774b73dd5d7e3 Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 6 Jan 2014 10:24:43 +0100 Subject: first interesting tests --- test/integration/tapicero_test.rb | 51 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'test/integration') diff --git a/test/integration/tapicero_test.rb b/test/integration/tapicero_test.rb index b83263a..d436e6d 100644 --- a/test/integration/tapicero_test.rb +++ b/test/integration/tapicero_test.rb @@ -1,4 +1,55 @@ require File.expand_path('../../test_helper.rb', __FILE__) class TapiceroTest < MiniTest::Unit::TestCase + + 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 + 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'] + sleep 1 + assert user_database(user_id) + end + + def test_configures_security + user_id = create_user['id'] + sleep 1 + assert_equal config.options[:security], user_database(user_id).get(_security) + end + + def create_user + database.save_doc :some => :content + 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) + end + + def config + Tapicero.config + end end -- cgit v1.2.3 From 890346ab671b679fb214f0ae78ca897cf54b9a74 Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 4 Feb 2014 09:49:05 +0100 Subject: set db name correctly in tests and test it --- test/integration/tapicero_test.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'test/integration') diff --git a/test/integration/tapicero_test.rb b/test/integration/tapicero_test.rb index d436e6d..d32415c 100644 --- a/test/integration/tapicero_test.rb +++ b/test/integration/tapicero_test.rb @@ -9,6 +9,7 @@ class TapiceroTest < MiniTest::Unit::TestCase def test_database_exists assert database + assert_equal "tapicero_test_users", database.name end def test_creates_user_db_fast -- cgit v1.2.3 From 1765981c8c0c3f2eddfd326e83505910be97e01c Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 4 Feb 2014 09:56:37 +0100 Subject: fix tests --- test/integration/tapicero_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/integration') diff --git a/test/integration/tapicero_test.rb b/test/integration/tapicero_test.rb index d32415c..bda05d3 100644 --- a/test/integration/tapicero_test.rb +++ b/test/integration/tapicero_test.rb @@ -3,7 +3,7 @@ require File.expand_path('../../test_helper.rb', __FILE__) class TapiceroTest < MiniTest::Unit::TestCase def test_loads_config - assert_equal "tapicero-test", config.connection[:prefix] + assert_equal "tapicero_test", config.connection[:prefix] assert_equal "debug", config.send(:log_level) end @@ -27,7 +27,7 @@ class TapiceroTest < MiniTest::Unit::TestCase def test_configures_security user_id = create_user['id'] sleep 1 - assert_equal config.options[:security], user_database(user_id).get(_security) + assert_equal config.options[:security], user_database(user_id).get('_security') end def create_user -- cgit v1.2.3 From 2836e9453618d9cc7dc64cb99651c4e5a40fb11c Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 4 Feb 2014 10:09:40 +0100 Subject: separate test setup test from actual test --- test/integration/tapicero_test.rb | 59 ++++++++++--------------------------- test/integration/test_setup_test.rb | 15 ++++++++++ 2 files changed, 31 insertions(+), 43 deletions(-) create mode 100644 test/integration/test_setup_test.rb (limited to 'test/integration') 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 -- cgit v1.2.3 From 630c38a0bcf4ca39ede98d354d8d43e6f735317c Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 4 Feb 2014 11:09:02 +0100 Subject: include sleep in the create_user part of the tests the changes feed and tapicero take some time to process the new user. Let's prevent timing issues by sleeping a second. --- test/integration/tapicero_test.rb | 3 --- 1 file changed, 3 deletions(-) (limited to 'test/integration') diff --git a/test/integration/tapicero_test.rb b/test/integration/tapicero_test.rb index 4c00ee2..b7a3dd4 100644 --- a/test/integration/tapicero_test.rb +++ b/test/integration/tapicero_test.rb @@ -4,7 +4,6 @@ class TapiceroTest < Tapicero::IntegrationTest def test_creates_user_db create_user - sleep 1 assert user_database assert user_database.name.start_with?(config.options[:db_prefix]) assert user_database.info @@ -12,13 +11,11 @@ class TapiceroTest < Tapicero::IntegrationTest def test_configures_security create_user - sleep 1 assert_equal config.options[:security], user_database.get('_security') end 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 -- cgit v1.2.3 From c3cb71ca5e6d32960e4493d85799f3706ea91fe8 Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 4 Feb 2014 11:25:43 +0100 Subject: test user deletion --- test/integration/tapicero_test.rb | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'test/integration') diff --git a/test/integration/tapicero_test.rb b/test/integration/tapicero_test.rb index b7a3dd4..88e3715 100644 --- a/test/integration/tapicero_test.rb +++ b/test/integration/tapicero_test.rb @@ -2,24 +2,35 @@ require_relative '../test_helper.rb' class TapiceroTest < Tapicero::IntegrationTest - def test_creates_user_db + def setup create_user + end + + def teardown + delete_user(true) + end + + def test_creates_user_db assert user_database assert user_database.name.start_with?(config.options[:db_prefix]) - assert user_database.info + assert user_database.info # ensure db exists in couch. end def test_configures_security - create_user assert_equal config.options[:security], user_database.get('_security') end def test_stores_design_docs - create_user assert_equal ['_design/docs', '_design/syncs', '_design/transactions'], design_docs(user_database).map{|doc| doc["id"]}.sort end + def test_cleares_user_db + assert user_database.info # ensure db exists in couch. + delete_user + assert !host.databases.include?(user_database.name) + end + def design_docs(db) db.documents(startkey: '_design', endkey: '_design'.succ)["rows"] end -- cgit v1.2.3