test/test_rhubarb.rb in rhubarb-0.2.7 vs test/test_rhubarb.rb in rhubarb-0.3.0

- old
+ new

@@ -117,10 +117,29 @@ include Rhubarb::Persisting declare_column :otype, :string declare_column :obj, :object end +class NoColumnsTestTable + include Rhubarb::Persisting +end + +class Create + include Rhubarb::Persisting + declare_column :name, :string +end + +class Group + include Rhubarb::Persisting + declare_column :other, :int, references(Create, :on_delete=>:cascade) +end + +class Order + include Rhubarb::Persisting + declare_column :group, :int +end + class PreparedStmtBackendTests < Test::Unit::TestCase def dbfile ENV['RHUBARB_TEST_DB'] || ":memory:" end @@ -157,10 +176,48 @@ def teardown Rhubarb::Persistence::close() end + def test_reserved_word_table + assert_nothing_raised do + Create.create_table + Create.create(:name=>"bar") + c = Create.find_first_by_name("bar") + c.name = "blah" + c.name = "bar" + assert(c.name == "bar") + c.delete + end + end + + def test_reserved_word_column + assert_nothing_raised do + Order.create_table + Order.create(:group=>42) + o = Order.find_first_by_group(42) + o.group = 37 + assert(o.group == 37) + end + end + + def test_reserved_word_fk_table + assert_nothing_raised do + Create.create_table + Group.create_table + Create.create(:name=>"bar") + Group.create(:other=>Create.create(:name=>"blah")) + assert(Group.find_all[0].other.name=="blah") + end + end + + def test_no_columns_table + assert_nothing_raised do + NoColumnsTestTable.create_table + end + end + def test_persistence_setup assert Rhubarb::Persistence::db.type_translation, "type translation not enabled for db" assert Rhubarb::Persistence::db.results_as_hash, "rows-as-hashes not enabled for db" end @@ -829,9 +886,45 @@ btrow = ZBlobTestTable.find(row.row_id) cbtrow = ZBlobTestTable.find(crow.row_id) assert_equal(text, btrow.info) assert_equal(text, Zlib::Inflate.inflate(cbtrow.info)) + end + + def test_mutable_object_data + things = [] + + words = %w{It is a truth universally acknowledged that a single man in possession of a good fortune must be in want of a wife} + + 100.times do + things << words.sort_by {rand} + end + + things.each_with_index do |thing, idx| + ObjectTestTable.create(:otype=>thing.class.name.to_s, :obj=>thing) + end + + otts = ObjectTestTable.find_all + + assert_equal otts.size, things.size + + things.zip(otts) do |thing, ott| + assert_equal thing.class.name.to_s, ott.otype + assert_equal thing, ott.obj + end + + otts.each_with_index do |ott, i| + obj = ott.obj.reverse + ott.obj = obj.dup + assert_equal obj, ott.obj + assert_equal obj, ObjectTestTable.find(ott.row_id).obj + things[i].reverse! + end + + things.zip(otts) do |thing, ott| + assert_equal thing.class.name.to_s, ott.otype + assert_equal thing, ott.obj + end end def test_object_data things = []