spec/unit/thinking_sphinx/configuration_spec.rb in freelancing-god-thinking-sphinx-0.9.7 vs spec/unit/thinking_sphinx/configuration_spec.rb in freelancing-god-thinking-sphinx-0.9.8
- old
+ new
@@ -57,17 +57,17 @@
"option" => "value"
}
})
@person_index_a = ThinkingSphinx::Index.stub_instance(
- :to_config => "", :adapter => :mysql, :delta? => false
+ :to_config => "", :adapter => :mysql, :delta? => false, :name => "person"
)
@person_index_b = ThinkingSphinx::Index.stub_instance(
- :to_config => "", :adapter => :mysql, :delta? => false
+ :to_config => "", :adapter => :mysql, :delta? => false, :name => "person"
)
@friendship_index_a = ThinkingSphinx::Index.stub_instance(
- :to_config => "", :adapter => :mysql, :delta? => false
+ :to_config => "", :adapter => :mysql, :delta? => false, :name => "friendship"
)
Person.stub_method(:indexes => [@person_index_a, @person_index_b])
Friendship.stub_method(:indexes => [@friendship_index_a])
@@ -210,10 +210,12 @@
"pid_file" => "pid_file.pid",
"searchd_file_path" => "searchd/file/path",
"address" => "127.0.0.1",
"port" => 3333,
"allow_star" => true,
+ "min_prefix_len" => 2,
+ "min_infix_len" => 3,
"mem_limit" => "128M",
"max_matches" => 1001,
"morphology" => "stem_ru",
"charset_type" => "latin1",
"charset_table" => "table",
@@ -236,25 +238,24 @@
describe "core_index_for_model method" do
before :each do
@config = ThinkingSphinx::Configuration.new
@model = Class.stub_instance(
- :indexes => [],
- :name => "SpecModel"
+ :indexes => [ThinkingSphinx::Index.new(Person)]
)
end
it "should take its name from the model, with _core appended" do
@config.send(:core_index_for_model, @model, "my sources").should match(
- /index specmodel_core/
+ /index person_core/
)
end
it "should set the path to follow the name" do
@config.searchd_file_path = "/my/file/path"
@config.send(:core_index_for_model, @model, "my sources").should match(
- /path = \/my\/file\/path\/specmodel_core/
+ /path = \/my\/file\/path\/person_core/
)
end
it "should include the charset type setting" do
@config.charset_type = "specchars"
@@ -317,25 +318,34 @@
text.should match(/enable_star\s+= 1/)
text.should match(/min_prefix_len\s+= 1/)
text.should match(/min_infix_len\s+= 1/)
end
+ it "should use the configuration's infix and prefix length values if set" do
+ @config.allow_star = true
+ @config.min_prefix_len = 3
+ @config.min_infix_len = 2
+ text = @config.send(:core_index_for_model, @model, "my sources")
+
+ text.should match(/min_prefix_len\s+= 3/)
+ text.should match(/min_infix_len\s+= 2/)
+ end
+
it "should not include the star-related settings when allow_star is false" do
@config.allow_star = false
text = @config.send(:core_index_for_model, @model, "my sources")
text.should_not match(/enable_star\s+=/)
text.should_not match(/min_prefix_len\s+=/)
text.should_not match(/min_infix_len\s+=/)
end
it "should set prefix_fields if any fields are flagged explicitly" do
- @index = ThinkingSphinx::Index.stub_instance(
+ @model.indexes.first.stub_methods(
:prefix_fields => ["a", "b", "c"],
:infix_fields => ["d", "e", "f"]
)
- @model.stub_method(:indexes => [@index])
@config.send(:core_index_for_model, @model, "my sources").should match(
/prefix_fields\s+= a, b, c/
)
end
@@ -345,15 +355,14 @@
/prefix_fields\s+=/
)
end
it "should set infix_fields if any fields are flagged explicitly" do
- @index = ThinkingSphinx::Index.stub_instance(
+ @model.indexes.first.stub_methods(
:prefix_fields => ["a", "b", "c"],
:infix_fields => ["d", "e", "f"]
)
- @model.stub_method(:indexes => [@index])
@config.send(:core_index_for_model, @model, "my sources").should match(
/infix_fields\s+= d, e, f/
)
end
@@ -361,52 +370,73 @@
it "shouldn't set infix_fields if none are flagged explicitly" do
@config.send(:core_index_for_model, @model, "my sources").should_not match(
/infix_fields\s+=/
)
end
+
+ it "should include html_strip if value is set" do
+ @config.html_strip = 1
+ text = @config.send(:core_index_for_model, @model, "my sources")
+ text.should match(/html_strip\s+= 1/)
+ end
+
+ it "shouldn't include html_strip if value is not set" do
+ text = @config.send(:core_index_for_model, @model, "my sources")
+ text.should_not match(/html_strip/)
+ end
+
+ it "should include html_remove_elements if values are set" do
+ @config.html_remove_elements = 'script'
+ text = @config.send(:core_index_for_model, @model, "my sources")
+ text.should match(/html_remove_elements\s+= script/)
+ end
+
+ it "shouldn't include html_remove_elements if no values are set" do
+ text = @config.send(:core_index_for_model, @model, "my sources")
+ text.should_not match(/html_remove_elements/)
+ end
end
describe "delta_index_for_model method" do
before :each do
@config = ThinkingSphinx::Configuration.new
@model = Class.stub_instance(
- :name => "SpecModel"
+ :indexes => [ThinkingSphinx::Index.new(Person)]
)
end
it "should take its name from the model, with _delta appended" do
@config.send(:delta_index_for_model, @model, "delta_sources").should match(
- /index specmodel_delta/
+ /index person_delta/
)
end
it "should inherit from the equivalent core index" do
@config.send(:delta_index_for_model, @model, "delta_sources").should match(
- /index specmodel_delta : specmodel_core/
+ /index person_delta : person_core/
)
end
it "should set the path to follow the name" do
@config.searchd_file_path = "/my/file/path"
@config.send(:delta_index_for_model, @model, "delta_sources").should match(
- /path = \/my\/file\/path\/specmodel_delta/
+ /path = \/my\/file\/path\/person_delta/
)
end
end
describe "distributed_index_for_model method" do
before :each do
@config = ThinkingSphinx::Configuration.new
@model = Class.stub_instance(
- :name => "SpecModel",
- :indexes => []
+ :indexes => [ThinkingSphinx::Index.new(Person)]
)
end
it "should take its name from the model" do
@config.send(:distributed_index_for_model, @model).should match(
- /index specmodel/
+ /index person/
)
end
it "should have a type of distributed" do
@config.send(:distributed_index_for_model, @model).should match(
@@ -414,21 +444,29 @@
)
end
it "should include the core as a local source" do
@config.send(:distributed_index_for_model, @model).should match(
- /local = specmodel_core/
+ /local = person_core/
)
end
it "should only include the delta as a local source if an index is flagged to be delta" do
@config.send(:distributed_index_for_model, @model).should_not match(
- /local = specmodel_delta/
+ /local = person_delta/
)
- @model.stub_method(:indexes => [ThinkingSphinx::Index.stub_instance(:delta? => true)])
+ @model.indexes.first.stub_method(:delta? => true)
@config.send(:distributed_index_for_model, @model).should match(
- /local = specmodel_delta/
+ /local = person_delta/
+ )
+ end
+
+ it "should handle namespaced models correctly" do
+ Person.stub_method(:name => "Namespaced::Model")
+
+ @config.send(:distributed_index_for_model, @model).should match(
+ /index namespaced_model/
)
end
end
describe "create_array_accum method" do
\ No newline at end of file