Sha256: dc0eac2699f79b2ddf7e3f0f48ecb9b25af30bf8b978d91579c81ca8b9e46ff5

Contents?: true

Size: 1.1 KB

Versions: 2

Compression:

Stored size: 1.1 KB

Contents

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

# $DBG = true

require 'rubygems'
require 'facets'
require 'test/unit'

require 'og'

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

  class Category
    property :title, String
    
    def initialize(title)
      @title = title
    end
  end

  class Article
    property :title, String

    joins_many Category, :through => ArticleToCategory
        
    def initialize(title)
      @title = title
    end
  end
  
  class ArticleToCategory
    property :rate, Float
    property :hits, Fixnum
    has_one Article
    has_one Category
  end

  $og1.manage_classes(Category, Article, ArticleToCategory)

  def setup
  end

  def test_all
    c1 = Category.create('tech')
    c2 = Category.create('funny')

    a = Article.create('a1')
    a.categories.push(c1, :hits =>3, :rate => 2.3) 
    a.categories.push(c2, :rate => 1.2) 
        
    join = a.category_join_data(c1)
    assert_equal 2.3, join.rate
    assert_equal 3, join.hits

    join = a.category_join_data(c2)
    assert_equal 1.2, join.rate
    assert_equal nil, join.hits
  end
  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
og-0.28.0 test/og/tc_join.rb
og-0.29.0 test/og/tc_join.rb