forked from pat/thinking-sphinx
/
excerpter_spec.rb
49 lines (39 loc) · 1.25 KB
/
excerpter_spec.rb
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
require 'spec_helper'
describe ThinkingSphinx::Excerpter do
before :each do
@alpha = Alpha.find(:first)
@search = mock 'search', :excerpt_for => 'excerpted value'
@excerpter = ThinkingSphinx::Excerpter.new(@search, @alpha)
end
it "should not respond to id" do
@excerpter.should_not respond_to(:id)
end
describe '#method_missing' do
it "should return the excerpt from Sphinx" do
@excerpter.name.should == 'excerpted value'
end
it "should send through the instance class to excerpt_for" do
@search.should_receive(:excerpt_for) do |string, model|
model.should == Alpha
end
@excerpter.name
end
it "should use attribute methods for excerpts calls" do
@search.should_receive(:excerpt_for) do |string, model|
string.should == 'one'
end
@excerpter.name
end
it "should use instance methods for excerpts calls" do
@search.should_receive(:excerpt_for) do |string, model|
string.should == 'ONE'
end
@excerpter.big_name
end
it "should still raise an exception if no column or method exists" do
lambda {
@excerpter.foo
}.should raise_error(NoMethodError)
end
end
end