Sha256: ea13ab5776884dadf08e3345cbd1a101dafdd123d353092d508b4a1f2d0ebe50

Contents?: true

Size: 1.5 KB

Versions: 1

Compression:

Stored size: 1.5 KB

Contents

$:.unshift File.join(File.dirname(__FILE__), 'lib')

require 'test/unit'

require 'og'
require 'og/relation'

class TestCaseOgRelation < Test::Unit::TestCase # :nodoc: all
  include Og

  class User
    property :name
    has_many Dummer
    has_many Article
    def initialize(name)
      @name = name
    end
  end
  
  class Article
    property :body, String
    refers_to :active_user, User
    def initialize(body)
      @body = body
    end
  end

  def test_all
    # no-namespace case.
    rel = User.relation(:dummers)
    rel.resolve_target
    assert_equal Dummer, rel.target_class  
  
    # namespace case.
    rel = User.relation(:articles)
    rel.resolve_target
    assert_equal TestCaseOgRelation::Article, rel.target_class    
    
    # bug: test the no belongs_to case in Article
    
    og = Og.setup(:store => :memory, :name => 'test')
    og.manage_classes    
  end

  def test_refers_to
    og = Og.setup(:store => :memory, :name => 'test')
    og.manage_classes

    # test refers_to accessor is correctly updated even without reload
    u = User.create("George")
    a = Article.create("Og is a good thing!")
    assert_equal(nil, a.active_user)

    a.active_user = u
    a.save!
    assert_equal(u.oid, a.active_user_oid)
    assert_equal(u.object_id, a.active_user.object_id)

    u2 = User.create("Another user")
    a.active_user = u2
    a.save!
    assert_equal(u2.oid, a.active_user_oid)
    assert_equal(u2.object_id, a.active_user.object_id)
  end
end

class Dummer
  property :dum, String
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
og-0.21.0 test/og/tc_relation.rb