Sha256: f63af7db9c62c8d530e7b2486c4bf4aa35014b529454dea0002767d5705a048f

Contents?: true

Size: 1.33 KB

Versions: 1

Compression:

Stored size: 1.33 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
  
  def request
    o = OpenStruct.new
    o.params = {:name => 'George', :pass => 'Secret'}
    return o
  end
  
  $og1.manage_classes User, Login, Admin, Pet
  
  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
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

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