spec/unit/thinking_sphinx/attribute_spec.rb in freelancing-god-thinking-sphinx-1.1.12 vs spec/unit/thinking_sphinx/attribute_spec.rb in freelancing-god-thinking-sphinx-1.1.14
- old
+ new
@@ -1,25 +1,30 @@
require 'spec/spec_helper'
describe ThinkingSphinx::Attribute do
+ before :each do
+ @index = ThinkingSphinx::Index.new(Person)
+ @source = ThinkingSphinx::Source.new(@index)
+ end
+
describe '#initialize' do
it 'raises if no columns are provided so that configuration errors are easier to track down' do
lambda {
- ThinkingSphinx::Attribute.new([])
+ ThinkingSphinx::Attribute.new(@source, [])
}.should raise_error(RuntimeError)
end
it 'raises if an element of the columns param is an integer - as happens when you use id instead of :id - so that configuration errors are easier to track down' do
lambda {
- ThinkingSphinx::Attribute.new([1234])
+ ThinkingSphinx::Attribute.new(@source, [1234])
}.should raise_error(RuntimeError)
end
end
describe "unique_name method" do
before :each do
- @attribute = ThinkingSphinx::Attribute.new [
+ @attribute = ThinkingSphinx::Attribute.new @source, [
Object.stub_instance(:__stack => [], :__name => "col_name")
]
end
it "should use the alias if there is one" do
@@ -40,11 +45,11 @@
end
end
describe "column_with_prefix method" do
before :each do
- @attribute = ThinkingSphinx::Attribute.new [
+ @attribute = ThinkingSphinx::Attribute.new @source, [
ThinkingSphinx::Index::FauxColumn.new(:col_name)
]
@attribute.columns.each { |col| @attribute.associations[col] = [] }
@attribute.model = Person
@@ -86,11 +91,11 @@
@assoc_a = Object.stub_instance(:is_many? => true)
@assoc_b = Object.stub_instance(:is_many? => true)
@assoc_c = Object.stub_instance(:is_many? => true)
@attribute = ThinkingSphinx::Attribute.new(
- [ThinkingSphinx::Index::FauxColumn.new(:col_name)]
+ @source, [ThinkingSphinx::Index::FauxColumn.new(:col_name)]
)
@attribute.associations = {
:a => @assoc_a, :b => @assoc_b, :c => @assoc_c
}
end
@@ -120,11 +125,11 @@
@col_a = ThinkingSphinx::Index::FauxColumn.new("a")
@col_b = ThinkingSphinx::Index::FauxColumn.new("b")
@col_c = ThinkingSphinx::Index::FauxColumn.new("c")
@attribute = ThinkingSphinx::Attribute.new(
- [@col_a, @col_b, @col_c]
+ @source, [@col_a, @col_b, @col_c]
)
end
it "should return true if all columns return true to is_string?" do
@attribute.send(:is_string?).should be_true
@@ -144,11 +149,11 @@
end
describe "type method" do
before :each do
@column = ThinkingSphinx::Index::FauxColumn.new(:col_name)
- @attribute = ThinkingSphinx::Attribute.new([@column])
+ @attribute = ThinkingSphinx::Attribute.new(@source, [@column])
@attribute.model = Person
@attribute.stub_method(:is_many? => false)
end
it "should return :multi if is_many? is true" do
@@ -175,33 +180,33 @@
end
end
describe "all_ints? method" do
it "should return true if all columns are integers" do
- attribute = ThinkingSphinx::Attribute.new(
+ attribute = ThinkingSphinx::Attribute.new(@source,
[ ThinkingSphinx::Index::FauxColumn.new(:id),
ThinkingSphinx::Index::FauxColumn.new(:team_id) ]
)
attribute.model = Person
attribute.columns.each { |col| attribute.associations[col] = [] }
attribute.send(:all_ints?).should be_true
end
it "should return false if only some columns are integers" do
- attribute = ThinkingSphinx::Attribute.new(
+ attribute = ThinkingSphinx::Attribute.new(@source,
[ ThinkingSphinx::Index::FauxColumn.new(:id),
ThinkingSphinx::Index::FauxColumn.new(:first_name) ]
)
attribute.model = Person
attribute.columns.each { |col| attribute.associations[col] = [] }
attribute.send(:all_ints?).should be_false
end
it "should return false if no columns are integers" do
- attribute = ThinkingSphinx::Attribute.new(
+ attribute = ThinkingSphinx::Attribute.new(@source,
[ ThinkingSphinx::Index::FauxColumn.new(:first_name),
ThinkingSphinx::Index::FauxColumn.new(:last_name) ]
)
attribute.model = Person
attribute.columns.each { |col| attribute.associations[col] = [] }
@@ -211,10 +216,10 @@
end
describe "with custom queries" do
before :each do
index = CricketTeam.sphinx_indexes.first
- @statement = index.to_riddle_for_core(0, 0).sql_attr_multi.first
+ @statement = index.sources.first.to_riddle_for_core(0, 0).sql_attr_multi.last
end
it "should track the query type accordingly" do
@statement.should match(/uint tags from query/)
end
\ No newline at end of file