direct access to the index works - thanks to Thomas Nichols for the idea

--- test: contact_test.rb
require File.dirname(__FILE__) + '/../test_helper'
require 'fileutils'
require 'ferret'

class ContactTest < Test::Unit::TestCase
  fixtures :contacts

  def setup
    if File.exists?('index')
      FileUtils.rm_rf('index')
    end
  end

  def test_new_field
    Contact.acts_as_ferret :fields => [ :first_name ]
    assert_equal 1, Contact.find_by_contents('first_name:Y*').total_hits
    assert_equal 1, Contact.find_by_contents('Y*').total_hits

    Contact.aaf_index.close
    FileUtils.rm_rf('index')

    Contact.acts_as_ferret :fields => [ :first_name, :last_name ]

    assert_equal 1, Contact.find_by_contents('last_name:K*').total_hits

    # it fails on the following line!! a bug here?
    #assert_equal 1, Contact.find_by_contents('K*').total_hits

    idx = Ferret::Index::Index.new(ath => 'index/test/contact', 
:create_if_missing => false)
    assert_equal 1, idx.search('last_name:K*').total_hits
    assert_equal 1, idx.search('K*').total_hits
  end
end


Yury Kotlyarov wrote:
> send all code we have so far and full test case code.
>
> --- model: contact.rb
> class Contact < ActiveRecord::Base
> end
>
> --- migration: 001_create_contacts_table.rb
> class CreateContacts < ActiveRecord::Migration
>   def self.up
>     create_table :contacts do |t|
>       t.column :first_name, :string
>       t.column :last_name, :string
>     end
>   end
>
>   def self.down
>     drop_table :contacts
>   end
> end
>
> --- fixture: contacts.yml
> renat:
>   id: 1
>   first_name: Renat
>   last_name: Akhmerov
> yura:
>   id: 2
>   first_name: Yury
>   last_name: Kotlyarov
>
> --- test: contact_test.rb
>
> require File.dirname(__FILE__) + '/../test_helper'
> require 'fileutils'
>
> class ContactTest < Test::Unit::TestCase
>   fixtures :contacts
>
>   def setup
>     if File.exists?('index')
>       FileUtils.rm_rf('index')
>     end
>   end
>
>   def test_new_field
>     Contact.acts_as_ferret :fields => [ :first_name ]
>     assert_equal 1, Contact.find_by_contents('first_name:Y*').total_hits
>     assert_equal 1, Contact.find_by_contents('Y*').total_hits
>
>     Contact.aaf_index.close
>     FileUtils.rm_rf('index')
>
>     Contact.acts_as_ferret :fields => [ :first_name, :last_name ]
>
>     assert_equal 1, Contact.find_by_contents('last_name:K*').total_hits
>     # it fails on the following line!! a bug here?
>     assert_equal 1, Contact.find_by_contents('K*').total_hits
>   end
> end
>
>
> _______________________________________________
> Ferret-talk mailing list
> [email protected]
> http://rubyforge.org/mailman/listinfo/ferret-talk
>
>   


-- 

Best regards,
Yury Kotlyarov
<;-) BrainHouse

web: http://www.brainhouse.ru
email: [EMAIL PROTECTED]
skype: yura__115
phone: +7 905 758 1491
jabber: [EMAIL PROTECTED]


_______________________________________________
Ferret-talk mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ferret-talk

Reply via email to