Sha256: 71dfbc28c15c4f68a6317c2fbc2adab52287a0e3504111d320f2a24ed1062a8a
Contents?: true
Size: 1.63 KB
Versions: 5
Compression:
Stored size: 1.63 KB
Contents
$:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib') require 'test/unit' require 'ostruct' require 'og' require 'og/mixin/orderable' $og = Og.setup( :store => 'psql', # :store => :memory, :name => 'test', :user => 'postgres', :password => 'navelrulez', :destroy => true ) class TestCaseOgOrderable < Test::Unit::TestCase # :nodoc: all class Comment; end class Article property :title, :body, String has_many :comments, Comment, :list => true, :order => 'position DESC' def initialize(title = nil) @title = title end end class Comment property :body, String belongs_to :article, Article include Og::Orderable #, :scope => :article def initialize(body = nil) @body = body end end def test_all $og.manage_classes a = Article.create('article') a.save c1 = Comment.create('1') a.comments << c1 c2 = Comment.create('2') a.comments << c2 c3 = Comment.create('3') a.comments << c3 assert_equal 1, c1.position assert_equal 2, c2.position assert_equal 3, c3.position c3.move_higher c1.reload c2.reload c3.reload assert_equal 1, c1.position assert_equal 2, c3.position assert_equal 3, c2.position c2.move_to_top c1.reload c2.reload c3.reload assert_equal 1, c2.position assert_equal 2, c1.position assert_equal 3, c3.position c2.move_to_bottom c1.reload c2.reload c3.reload assert_equal 1, c1.position assert_equal 2, c3.position assert_equal 3, c2.position c3.delete! c1.reload c2.reload assert_equal 1, c1.position assert_equal 2, c2.position c2.delete! c1.reload assert_equal 1, c1.position c1.delete! end end
Version data entries
5 entries across 5 versions & 1 rubygems