Sha256: 77f0edc6fe7870c0951dd0f233552813b61b28c27a739802686af6e9d4f1002c

Contents?: true

Size: 1.23 KB

Versions: 4

Compression:

Stored size: 1.23 KB

Contents

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

$DBG = true

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

  def setup
    @og = Og.setup(
      :destroy => true,
      :store => :mysql,
#      :store => :sqlite,
#      :store => :psql,
#      :user => 'postgres',
      :user => 'root',
      :password => 'navelrulez',
      :name => 'test'
    )    
  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

4 entries across 4 versions & 1 rubygems

Version Path
og-0.21.0 test/og/tc_join.rb
og-0.21.2 test/og/tc_join.rb
og-0.22.0 test/og/tc_join.rb
og-0.23.0 test/og/tc_join.rb