Sha256: c3f3e764584ef77c7fc93e5fb8050f5cac66a64469768182d160a7dd9974cf6e

Contents?: true

Size: 1.46 KB

Versions: 3

Compression:

Stored size: 1.46 KB

Contents

$DBG = true

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

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

require 'og'
require 'glue/taggable'

class TestOgTaggable < Test::Unit::TestCase # :nodoc: all

  class Article
    property :title, :body, String
    is Taggable
    
    def initialize(title = nil)
      @title = title
    end
  end

  $og1.manage_classes(Article)

  def test_all
    a1 = Article.create('Hello')
    a1.tag('navel gmosx sexy')
    a1.save
    
    a2 = Article.create('Other')
    a2.tag('gmosx rain')
    a2.save
    
    a3 = Article.create('George')
    a3.tag('phd name')
    a3.save


    assert_equal 6, Tag.count
    assert_equal 3, a1.tags.size 
    assert a1.tag_names.include?('navel')
    
    assert a1.tagged_with?('navel')
    
    assert_equal false, a1.tagged_with?('photo')
    
    res = Article.find_with_tags('navel', 'gmosx')
    assert_equal 1, res.size
    assert_equal 'Hello', res[0].title

    res = Article.find_with_tag('gmosx')
    assert_equal 2, res.size
    res = res.map { |o| o.title }
    assert res.include?('Hello')
    assert res.include?('Other')    

    res = Article.find_with_any_tag('navel', 'gmosx', 'phd')
    assert_equal 3, res.size

    a1.delete_all_tags
    assert_equal 0, a1.tags.size
    
=begin
    TODO:
    Article.fing_with_no_tag('gmosx')
    Article.find_by_tags('+name +gmosx -sexy')
    Article.find_by_tags(:with => '', :any => '', :no => '')
=end
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
og-0.29.0 test/og/mixin/tc_taggable.rb
og-0.30.0 test/og/mixin/tc_taggable.rb
og-0.31.0 test/og/mixin/tc_taggable.rb