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 NodeTest < Test::Unit::TestCase def NodeTest.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 User.find(:all).each do |node| node.destroy end NotRelational::RepositoryFactory.instance.clear end def test_content_persists node= Node.fill_new_node('david', "my title", 'hello world') node.save found=Node.find(node.id) assert_not_nil(found) assert(!found.is_dirty(:latestContent)) assert_equal('hello world',found.latestContent) assert(!found.is_dirty(:latestContent)) found.latestContent="goodbye" assert(found.is_dirty(:latestContent)) end def test_select_by_clicks NodeTest.set_up (0..5).each do | i| node= Node.fill_new_node('david', "#{i}", 'hello world') node.clicks=i node.save end NotRelational::RepositoryFactory.instance.pause(); found=Node.find( :all, :conditions=>{:clicks=>NotRelational::AttributeRange.new(:greater_than=>3)}) assert_equal(2,found.length) end def test_recent NodeTest.set_up nodes=[] (0..5).each do | i| node= Node.fill_new_node('david', "#{i}", 'hello world') node.language_id='en' node.publicRead=true node.save nodes<:id) assert_equal(1,found.length) assert_equal(node.id,found[0].id) end def test_segmented_media NodeTest.set_up node= Node.fill_new_node('david', 'my new post', 'hello world') node.save node2= Node.fill_new_node('david2', 'my new post2', 'hello world2') node2.save node_album=Album.new node_album.guid=node.album_guid node_album.user_name='david' node_album.save mediaitem1=Mediaitem.new mediaitem1.title="mediaitem1" mediaitem1.HasVideo=true mediaitem1.save! mediaitem2=Mediaitem.new mediaitem2.title="mediaitem1" mediaitem2.HasVideo=true mediaitem2.save! mediaitem3=Mediaitem.new mediaitem3.title="mediaitem1" mediaitem3.HasAudio=true mediaitem3.save! mediaitem4=Mediaitem.new mediaitem4.title="mediaitem1" mediaitem4.HasImage=true mediaitem4.save! #no flag means image mediaitem5=Mediaitem.new mediaitem5.title="mediaitem1" mediaitem5.save! node_album.connect_mediaitem(mediaitem1) node_album.connect_mediaitem(mediaitem2) node_album.connect_mediaitem(mediaitem3) node_album.connect_mediaitem(mediaitem4) node_album.connect_mediaitem(mediaitem5) NotRelational::RepositoryFactory.instance.pause() found=node.video_media assert(found!=nil) assert_equal(2,found.length) found=node.still_image_media assert(found!=nil) assert_equal(2,found.length) found=node.audio_media assert(found!=nil) assert_equal(1,found.length) end def test_recent_public_for_user joe=User.find('joe') if joe joe.destroy end NodeTest.set_up user=User.new user.login='joe' user.save! node_x= Node.fill_new_node('222', 'title222', 'content222') node_x.save node1= Node.fill_new_node('joe', 'title', 'content') node1.save node2= Node.fill_new_node('joe', 'title', 'content') node2.isChannel=true node2.save node3= Node.fill_new_node('joe', 'title', 'content') node3.publicRead=false node3.save NotRelational::RepositoryFactory.instance.clear_session_cache found=Node.recent_public_for_user('joe', 50) assert_equal(1,found .length) assert_equal(node1.id,found[0].id) found=Node.recent_public_for_user('Joe', 50) assert_equal(1,found.length) assert_equal(node1.id,found[0].id) found=Node.recent_for_user('Joe', 50) assert_equal(3,found.length) found=Node.channels_for_user('Joe', 50) assert_equal(1,found.length) assert_equal(node2.id,found[0].id) end # def test_trackers # User.find(:all).each do |old_user | # old_user.destroy # # end # Node.find(:all).each do |old_node | # old_node.destroy # end # # user = User.new( # :login=>'aaa', # :last_login => Time.now.gmtime, # :created_at => Time.now.gmtime, # :password=>"guid2", # :profile_mediaitem_guid=>"duh1" # ) # # user.save # parent_node=Node.fill_new_node(user.login, "my title", 'hello world') # user.add_to_nodes(parent_node) # # node= Node.fill_new_node(user.login, "my title", 'hello world') # user.add_to_nodes(node) # user.save! # parent_node.add_to_child_nodes(node) # parent_node.save! # found=user.nodes # assert_equal(2,found.length) # # # user=User.find(user.login) # # found=user.nodes # assert_equal(2,found.length) # # # # parent_node=Node.find(parent_node.id) # # found=parent_node.child_nodes # assert_equal(1,found.length) # # assert_equal(node.id,found[0].id) # end end