Skip to content

Commit

Permalink
Use vanilla Test::Unit::TestCase
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim Menard committed Jan 30, 2009
1 parent 410e81b commit 50d5a6f
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 34 deletions.
4 changes: 2 additions & 2 deletions test/log_device_test.rb
@@ -1,7 +1,7 @@
require 'test_helper'
require 'mongo_record/log_device'

class LoggerTest < ActiveSupport::TestCase
class LoggerTest < Test::Unit::TestCase

MAX_RECS = 3

Expand All @@ -18,7 +18,7 @@ def teardown

# We really don't have to test much more than this. We can trust that Mongo
# works properly.
test "max records enforced" do
def test_max_records_enforced
assert_equal $db.name, MongoRecord::LogDevice.connection.name
MAX_RECS.times { |i|
@logger.debug("test message #{i+1}")
Expand Down
38 changes: 19 additions & 19 deletions test/mongo_record_test.rb
Expand Up @@ -3,20 +3,20 @@
require 'mongo_record'
Dir[File.join(File.dirname(__FILE__), 'models/*.rb')].each { |f| require f }

class MongoRecordTest < ActiveSupport::TestCase
class MongoRecordTest < Test::Unit::TestCase

def setup
load "#{File.join(File.dirname(__FILE__), 'reload_data.rb')}"
end

test "count" do
def test_count
assert_equal 1, User.count
assert_equal 3, Product.count
assert_equal 2, Product.count(:conditions => "title in ('Book 01', 'Book 02')")
assert_equal 2, Product.count(:all, :conditions => "title in ('Book 01', 'Book 02')")
end

test "count returns 0 when collection does not exist" do
def test_count_returns_0_when_collection_does_not_exist
Order.collection.db.drop_collection('orders')
assert_equal 0, Order.count

Expand All @@ -26,12 +26,12 @@ def setup
assert_equal 0, Product.count
end

test "count by sql" do
def test_count_by_sql
assert_equal 2, Product.count_by_sql("select count(*) from products where title in ('Book 01', 'Book 02')")
assert_equal 3, Product.count_by_sql("select count(*) from products")
end

test "find" do
def test_find
p = Product.find_by_title('Book 01')
assert_not_nil p
assert_equal 'Book 01', p.title
Expand Down Expand Up @@ -60,7 +60,7 @@ def setup
assert_equal 1, a.to_a.length
end

test "find by id" do
def test_find_by_id
p = Product.find(:first, :conditions => "title = 'Book 03'")
pid = p.id

Expand All @@ -76,7 +76,7 @@ def setup
assert_equal "Book 03", p.title
end

test "sql like" do
def test_sql_like
a = Product.find(:all, :conditions => "title like 'Book%'")
assert_not_nil a
assert_equal 3, a.to_a.length
Expand All @@ -97,7 +97,7 @@ def setup
assert_equal 3, a.to_a.length
end

test "sql in" do
def test_sql_in
a = Product.find(:all, :conditions => "title in ('Book 01', 'Book 02', 'Book 03')")
assert_not_nil a
assert_equal 3, a.to_a.length
Expand All @@ -119,7 +119,7 @@ def setup
assert_equal 3, a.to_a.length
end

test "order and limit" do
def test_order_and_limit
a = Product.find(:all, :order => 'title desc')
obj_array = a.to_a
assert_equal 3, obj_array.length
Expand All @@ -133,7 +133,7 @@ def setup
assert_equal "Book 03", p.title
end

test "has many" do
def test_has_many
o = Order.new
3.times { |i|
p = Product.find_by_title("Book 0#{i+1}")
Expand All @@ -153,23 +153,23 @@ def setup
}
end

test "delete" do
def test_delete
p = Product.find_by_title('Book 01')
i = p.id
Product.delete(p.id)
assert_equal 2, Product.count
assert_nil Product.find_by_title('Book 01')
end

test "delete all" do
def test_delete_all
Product.delete_all("title in ('Book 01', 'Book 02')")
assert_equal 1, Product.count

Product.delete_all
assert_equal 0, Product.count
end

test "increment decrement counter" do
def test_increment_decrement_counter
li = LineItem.new(:quantity => 3, :total_price => 1.5)
li.save

Expand All @@ -180,12 +180,12 @@ def setup
assert_equal 3, LineItem.find(li.id).quantity
end

test "columns" do
def test_columns
sorted_names = LineItem.columns.collect { |c| c.name }.sort
assert_equal sorted_names, %w(_id order_id product_id quantity total_price)
end

test "find by sql raises exception" do
def test_find_by_sql_raises_exception
begin
Product.find_by_sql('blargh')
fail('expected "not implemented" exception')
Expand All @@ -194,7 +194,7 @@ def setup
end
end

test "update all raises exception" do
def test_update_all_raises_exception
begin
Product.update_all('blargh')
fail('expected "not implemented" exception')
Expand All @@ -203,20 +203,20 @@ def setup
end
end

test "connection" do
def test_connection
c = Product.connection
assert_not_nil c
assert_kind_of ActiveRecord::ConnectionAdapters::MongoPseudoConnection, c
end

test "collection" do
def test_collection
c = Product.collection
assert_not_nil c
assert_kind_of XGen::Mongo::Driver::Collection, c
assert_equal 'products', c.name
end

test "collection info" do
def test_collection_info
ci = Product.collection_info
assert_not_nil ci
p = ci['products']
Expand Down
6 changes: 3 additions & 3 deletions test/mongo_test.rb
@@ -1,15 +1,15 @@
require 'test_helper'

class MongoRecordTest < ActiveSupport::TestCase
class MongoRecordTest < Test::Unit::TestCase

test "can connect to database" do
def test_can_connect_to_database
assert_not_nil $db
list = $db.collection_names
assert_not_nil list
assert_kind_of Array, list
end

test "can see database names" do
def test_can_see_database_names
$db.collection('ar-mongo-adapter').insert('a' => 1)

list = $mongo.database_names
Expand Down
16 changes: 8 additions & 8 deletions test/pk_factory_test.rb
@@ -1,50 +1,50 @@
require 'test_helper'
require 'mongo_record/pk_factory'

class PKFactoryTest < ActiveSupport::TestCase
class PKFactoryTest < Test::Unit::TestCase

def setup
@pkf = MongoRecord::PKFactory.new
@known_id = XGen::Mongo::Driver::ObjectID.new
end

test "generates ObjectIDs" do
def test_generates_ObjectIDs
assert_kind_of XGen::Mongo::Driver::ObjectID, @pkf.create_pk({})['_id']
end

test "generates unique ids" do
def test_generates_unique_ids
assert_not_equal @pkf.create_pk({})['_id'], @pkf.create_pk({})['_id']
end

test "does not stomp on old ids" do
def test_does_not_stomp_on_old_ids
row = {'_id' => @known_id}
@pkf.create_pk(row)
assert_equal @known_id, row['_id']
end

test "stomps on old ids when nil" do
def test_stomps_on_old_ids_when_nil
row = {'_id' => nil}
@pkf.create_pk(row)
assert_not_nil row['_id']
assert_kind_of XGen::Mongo::Driver::ObjectID, row['_id']
end

test "does not stomp on old ids when id key is symbol" do
def test_does_not_stomp_on_old_ids_when_id_key_is_symbol
row = {:_id => @known_id}
@pkf.create_pk(row)
assert_equal @known_id, row[:_id]
assert_nil row['_id']
end

test "deletes id symbol key with nil value" do
def test_deletes_id_symbol_key_with_nil_value
row = {:_id => nil}
@pkf.create_pk(row)
assert_nil row[:_id]
assert_not_nil row['_id']
assert_kind_of XGen::Mongo::Driver::ObjectID, row['_id']
end

test "deletes id symbol key with nil value and id string key" do
def test_deletes_id_symbol_key_with_nil_value_and_id_string_key
row = {:_id => nil, '_id' => @known_id}
@pkf.create_pk(row)
assert_nil row[:_id]
Expand Down
3 changes: 1 addition & 2 deletions test/test_helper.rb
@@ -1,6 +1,5 @@
require 'rubygems'
require 'active_support'
require 'active_support/test_case'
# require 'active_support'
require 'test/unit'
require 'mongo'
require 'mongo_record/pk_factory'
Expand Down

0 comments on commit 50d5a6f

Please sign in to comment.