public
Fork of moro/search_do
Description: AR: Hyperestraier integration
Homepage:
Clone URL: git://github.com/grosser/search_do.git
grosser (author)
Sat Jan 17 00:49:59 -0800 2009
commit  ca31ae6215d74cde1f05c1a9f7f6d391022924cd
tree    47921598bd2f06efb0165d358d3760dc7fdcd3f5
parent  34eaaa29aac7643a51a769bcc503c58fd0c43b64
search_do / spec / indexer_spec.rb
100755 60 lines (47 sloc) 1.94 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
require File.expand_path("spec_helper", File.dirname(__FILE__))
require 'search_do/indexer'
 
describe SearchDo::Indexer,"new(AR[created_at updated_at]) / and set some attrs" do
  before do
    @ar_klass = mock("ar_klass")
    @ar_klass.stub!(:column_names).and_return(%[created_at updated_at])
 
    @indexer = SearchDo::Indexer.new(@ar_klass, {})
    @indexer.searchable_fields = %w[title body]
    @indexer.attributes_to_store = {:user_id => :user_id}
    @indexer.if_changed = %w[popularity]
  end
 
  it "#searchable_fields should == %w[title body]" do
    @indexer.searchable_fields.should == %w[title body]
  end
 
  it "#attributes_to_store['user_id'].should == :user_id" do
    @indexer.attributes_to_store['user_id'].should == :user_id
  end
 
  it "#observing_fields.should == Set.new(%w[title body user_id popularity])" do
    @indexer.observing_fields.should == Set.new(%w[title body user_id popularity])
  end
 
  describe "call '.record_timestamps!'" do
    before do
      @indexer.record_timestamps!
    end
 
    it "#attributes_to_store['cdate'] should == 'created_at'" do
      @indexer.attributes_to_store['cdate'].should == 'created_at'
    end
 
    it "#attributes_to_store['mdate'] should == 'updated_at'" do
      @indexer.attributes_to_store['mdate'].should == 'updated_at'
    end
 
    it "#observing_fields.should include 'updated_at' and 'created_at'" do
      @indexer.observing_fields.should include('created_at')
      @indexer.observing_fields.should include('updated_at')
    end
  end
 
  describe "#add_callbacks!() " do
    before do
      @ar_klass.should_receive(:after_update).with(:update_index)
      @ar_klass.should_receive(:after_create).with(:add_to_index)
      @ar_klass.should_receive(:after_save).with(:clear_changed_attributes)
      @ar_klass.should_receive(:after_destroy).with(:remove_from_index)
    end
 
    it "adds appropriate callbacks" do
      @indexer.add_callbacks!
    end
  end
end