Sha256: 40fa7dc64c6827406de2ebc162fcd996651e65843cf282993bbf4ce3d830e41c

Contents?: true

Size: 1.85 KB

Versions: 1

Compression:

Stored size: 1.85 KB

Contents

require File.join(File.dirname(__FILE__), '..', 'CONFIG.rb')

require 'rubygems'
require 'test/unit'
require 'ostruct'

require 'og'

class TC_STI2 < Test::Unit::TestCase
  
  class User
    is Og::SchemaInheritanceBase
    
    property :name, String

    has_one Login
    
    # This triggered a bug when called from a subclass
    has_many :pets, Pet#, :foreign_name => 'user'
  end

  class Admin < User
    property :admin_praise, String
  end
  
  class Login
    property :pass, String

    belongs_to User
  end
  
  class Pet
    property :name, String
    
    belongs_to User
  end
  
  # This has .initialize overridden, Bugreport from Rayman
  class PoorUser < User
    property :poorness, Integer
    
    def initialize(name = nil)
      @poorness = 26
      @name = name
    end
  end
  
  def request
    o = OpenStruct.new
    o.params = {:name => 'George', :pass => 'Secret'}
    return o
  end
  
  $og1.manage_classes User, Login, Admin, Pet, PoorUser
  
  def setup
    @user = Admin.create_with(request.params)
    @login = Login.create_with(request.params)
  end
  
  def teardown
    [User, Login, Pet].map {|x| x.delete_all}
  end
  
  def test_setup
    assert_equal 1, User.count
    assert_equal 1, Login.count
  end
  
  def test_assign
    @user.login = @login
  end
  
  def test_has_many
    pets = nil
    assert_nothing_raised do
      pets = @user.pets.size
    end
    
    assert_equal 0, pets
    
    p1 = Pet.create_with(:name => 'Ziza')
    
    @user.pets << p1
    
    assert_equal 1, @user.pets(:reload => true).size
  end
  
  def test_bugreport_rayman
    p1 = PoorUser.create("JoJo")
    p2 = PoorUser.find_one(:where => "name = 'JoJo'")
    assert_equal p1.class, p2.class
    assert_equal p1.oid, p2.oid
    
    p3 = User.find_one(:where => "name = 'JoJo'")
    assert_equal p1.class, p3.class
    assert_equal p1.oid, p3.oid
  end
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
og-0.41.0 test/og/store/tc_sti2.rb