require 'rubygems' require 'test/unit' $:.push(File.dirname(__FILE__) +'/../../test/models') $:.push(File.dirname(__FILE__) +'/../../lib/not_relational') require File.dirname(__FILE__) +'/../../lib/not_relational/domain_model.rb' require File.dirname(__FILE__) +'/../../lib/not_relational/attribute_range.rb' require File.dirname(__FILE__) +'/../../lib/not_relational/memory_repository.rb' require File.dirname(__FILE__) +'/../../test/models/node.rb' require File.dirname(__FILE__) +'/../../test/models/user.rb' require File.dirname(__FILE__) +'/../../test/models/place.rb' require File.dirname(__FILE__) +'/../../test/models/album.rb' require File.dirname(__FILE__) +'/../../test/models/media_item.rb' require File.dirname(__FILE__) +'/../../test/models/media_file.rb' require File.dirname(__FILE__) +'/../../test/models/tag.rb' require File.dirname(__FILE__) +'/../../test/models/rating.rb' require File.dirname(__FILE__) +'/../../test/models/comment.rb' ENV['NOT_RELATIONAL_ENV']='testing' class MediaItemTest < Test::Unit::TestCase def MediaItemTest.set_up Node.find(:all).each do |node| node.destroy end Place.find(:all).each do |node| node.destroy end Album.find(:all).each do |node| node.destroy end Mediaitem.find(:all).each do |node| node.destroy end Mediafile.find(:all).each do |node| node.destroy end User.find(:all).each do |node| node.destroy end Tag.find(:all).each do |node| node.destroy end Rating.find(:all).each do |node| node.destroy end Comment.find(:all).each do |node| node.destroy end end def test_destroy_dependent_tags MediaItemTest.set_up item=Mediaitem.new item.save tag=Tag.new tag.created_time=Time.now.gmtime tag.mediaitem_id=item.id tag.save tag=Tag.new tag.mediaitem_id=item.id tag.created_time=Time.now.gmtime tag.save tag=Tag.new tag.save NotRelational::RepositoryFactory.instance.pause() all_tags=Tag.find(:all) assert(all_tags.length==3) item.destroy NotRelational::RepositoryFactory.instance.pause() all_tags=Tag.find(:all) assert(all_tags.length==1) end def test_destroy_dependent_ratings MediaItemTest.set_up item=Mediaitem.new item.save tag=Rating.new tag.mediaitem_id=item.id tag.save tag=Rating.new tag.mediaitem_id=item.id tag.save tag=Rating.new tag.save NotRelational::RepositoryFactory.instance.pause() all_tags=Rating.find(:all) assert(all_tags.length==3) item.destroy NotRelational::RepositoryFactory.instance.pause() all_tags=Rating.find(:all) assert(all_tags.length==1) end def test_destroy_dependent_comments MediaItemTest.set_up item=Mediaitem.new item.save tag=Comment.new tag.mediaitem_id=item.id tag.save tag=Comment.new tag.mediaitem_id=item.id tag.save tag=Comment.new tag.save NotRelational::RepositoryFactory.instance.pause() all_tags=Comment.find(:all) assert_equal(3,all_tags.length) item.destroy NotRelational::RepositoryFactory.instance.pause() all_tags=Comment.find(:all) assert_equal(1,all_tags.length) end def test_recent MediaItemTest.set_up items=[] (0..5).each do |i| item=Mediaitem.new item.created_time=Time.now+i*100 item.save items<