spec/unit/thinking_sphinx/attribute_spec.rb in freelancing-god-thinking-sphinx-1.1.18 vs spec/unit/thinking_sphinx/attribute_spec.rb in freelancing-god-thinking-sphinx-1.1.19
- old
+ new
@@ -213,9 +213,115 @@
attribute.send(:all_ints?).should be_false
end
end
+ describe "MVA with source query" do
+ before :each do
+ @attribute = ThinkingSphinx::Attribute.new(@source,
+ [ThinkingSphinx::Index::FauxColumn.new(:tags, :id)],
+ :as => :tag_ids, :source => :query
+ )
+ end
+
+ it "should use a query" do
+ @attribute.type_to_config.should == :sql_attr_multi
+
+ declaration, query = @attribute.config_value.split('; ')
+ declaration.should == "uint tag_ids from query"
+ query.should == "SELECT `tags`.`person_id` #{ThinkingSphinx.unique_id_expression} AS `id`, `tags`.`id` AS `tag_ids` FROM `tags`"
+ end
+ end
+
+ describe "MVA via a HABTM association with a source query" do
+ before :each do
+ @attribute = ThinkingSphinx::Attribute.new(@source,
+ [ThinkingSphinx::Index::FauxColumn.new(:links, :id)],
+ :as => :link_ids, :source => :query
+ )
+ end
+
+ it "should use a ranged query" do
+ @attribute.type_to_config.should == :sql_attr_multi
+
+ declaration, query = @attribute.config_value.split('; ')
+ declaration.should == "uint link_ids from query"
+ query.should == "SELECT `links_people`.`person_id` #{ThinkingSphinx.unique_id_expression} AS `id`, `links_people`.`link_id` AS `link_ids` FROM `links_people`"
+ end
+ end
+
+ describe "MVA with ranged source query" do
+ before :each do
+ @attribute = ThinkingSphinx::Attribute.new(@source,
+ [ThinkingSphinx::Index::FauxColumn.new(:tags, :id)],
+ :as => :tag_ids, :source => :ranged_query
+ )
+ end
+
+ it "should use a ranged query" do
+ @attribute.type_to_config.should == :sql_attr_multi
+
+ declaration, query, range_query = @attribute.config_value.split('; ')
+ declaration.should == "uint tag_ids from ranged-query"
+ query.should == "SELECT `tags`.`person_id` #{ThinkingSphinx.unique_id_expression} AS `id`, `tags`.`id` AS `tag_ids` FROM `tags` WHERE `tags`.`person_id` >= $start AND `tags`.`person_id` <= $end"
+ range_query.should == "SELECT MIN(`tags`.`person_id`), MAX(`tags`.`person_id`) FROM `tags`"
+ end
+ end
+
+ describe "MVA via a has-many :through with a ranged source query" do
+ before :each do
+ @attribute = ThinkingSphinx::Attribute.new(@source,
+ [ThinkingSphinx::Index::FauxColumn.new(:football_teams, :id)],
+ :as => :football_team_ids, :source => :ranged_query
+ )
+ end
+
+ it "should use a ranged query" do
+ @attribute.type_to_config.should == :sql_attr_multi
+
+ declaration, query, range_query = @attribute.config_value.split('; ')
+ declaration.should == "uint football_team_ids from ranged-query"
+ query.should == "SELECT `tags`.`person_id` #{ThinkingSphinx.unique_id_expression} AS `id`, `tags`.`football_team_id` AS `football_team_ids` FROM `tags` WHERE `tags`.`person_id` >= $start AND `tags`.`person_id` <= $end"
+ range_query.should == "SELECT MIN(`tags`.`person_id`), MAX(`tags`.`person_id`) FROM `tags`"
+ end
+ end
+
+ describe "MVA via a has-many :through using a foreign key with a ranged source query" do
+ before :each do
+ @attribute = ThinkingSphinx::Attribute.new(@source,
+ [ThinkingSphinx::Index::FauxColumn.new(:friends, :id)],
+ :as => :friend_ids, :source => :ranged_query
+ )
+ end
+
+ it "should use a ranged query" do
+ @attribute.type_to_config.should == :sql_attr_multi
+
+ declaration, query, range_query = @attribute.config_value.split('; ')
+ declaration.should == "uint friend_ids from ranged-query"
+ query.should == "SELECT `friendships`.`person_id` #{ThinkingSphinx.unique_id_expression} AS `id`, `friendships`.`friend_id` AS `friend_ids` FROM `friendships` WHERE `friendships`.`person_id` >= $start AND `friendships`.`person_id` <= $end"
+ range_query.should == "SELECT MIN(`friendships`.`person_id`), MAX(`friendships`.`person_id`) FROM `friendships`"
+ end
+ end
+
+ describe "MVA via a HABTM with a ranged source query" do
+ before :each do
+ @attribute = ThinkingSphinx::Attribute.new(@source,
+ [ThinkingSphinx::Index::FauxColumn.new(:links, :id)],
+ :as => :link_ids, :source => :ranged_query
+ )
+ end
+
+ it "should use a ranged query" do
+ @attribute.type_to_config.should == :sql_attr_multi
+
+ declaration, query, range_query = @attribute.config_value.split('; ')
+ declaration.should == "uint link_ids from ranged-query"
+ query.should == "SELECT `links_people`.`person_id` #{ThinkingSphinx.unique_id_expression} AS `id`, `links_people`.`link_id` AS `link_ids` FROM `links_people` WHERE `links_people`.`person_id` >= $start AND `links_people`.`person_id` <= $end"
+ range_query.should == "SELECT MIN(`links_people`.`person_id`), MAX(`links_people`.`person_id`) FROM `links_people`"
+ end
+ end
+
describe "with custom queries" do
before :each do
index = CricketTeam.sphinx_indexes.first
@statement = index.sources.first.to_riddle_for_core(0, 0).sql_attr_multi.last
end
\ No newline at end of file