Sha256: 6935244a92d2203dc42ba2cfb58728e6d500c80f5234f5ba33ac6f6a253739b1
Contents?: true
Size: 1.94 KB
Versions: 3
Compression:
Stored size: 1.94 KB
Contents
require File.join(File.dirname(__FILE__), 'CONFIG.rb') require 'test/unit' require 'og' require 'og/relation' =begin 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($og_config) og.manage_classes end def test_refers_to og = Og.setup($og_config) og.manage_classes # test refers_to accessor is correctly updated 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) # Note! Og doesn't automatically reload object referred by active_user # so this won't equal. assert_not_equal(u2.object_id, a.active_user.object_id) # Even forced reload won't help here as it won't reload relations. a.reload assert_not_equal(u2.object_id, a.active_user.object_id) # But forcing enchanted accessor to reload in refers_to.rb helps! a.active_user(true) # assert_equal(u2.object_id, a.active_user.object_id) # and just to be sure oids are still correct assert_equal(u2.oid, a.active_user_oid) end end class Dummer property :dum, String end =end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
og-0.24.0 | test/og/tc_relation.rb |
og-0.25.0 | test/og/tc_relation.rb |
og-0.26.0 | test/og/tc_relation.rb |