freelancing-god-thinking-sphinx 1.1.12 → 1.1.14

Sign up to get free protection for your applications and to get access to all the features.
@@ -53,10 +53,17 @@ describe ThinkingSphinx::Search do
53
53
 
54
54
  describe "facets method" do
55
55
  before :each do
56
- @results = [Person.find(:first)]
57
- @results.stub!(:each_with_groupby_and_count).
58
- and_yield(@results.first, @results.first.city.to_crc32, 1)
59
- ThinkingSphinx::Search.stub!(:search => @results)
56
+ @person = Person.find(:first)
57
+
58
+ @city_results = [@person]
59
+ @city_results.stub!(:each_with_groupby_and_count).
60
+ and_yield(@person, @person.city.to_crc32, 1)
61
+
62
+ @birthday_results = [@person]
63
+ @birthday_results.stub!(:each_with_groupby_and_count).
64
+ and_yield(@person, @person.birthday.to_i, 1)
65
+
66
+ ThinkingSphinx::Search.stub!(:search).and_return(@city_results, @birthday_results)
60
67
 
61
68
  @config = ThinkingSphinx::Configuration.instance
62
69
  @config.configuration.searchd.max_matches = 10_000
@@ -93,6 +100,26 @@ describe ThinkingSphinx::Search do
93
100
  :limit => 200
94
101
  )
95
102
  end
103
+
104
+ describe "conflicting facets" do
105
+ before :each do
106
+ @index = ThinkingSphinx::Index::Builder.generate(Alpha) do
107
+ indexes :name
108
+ has :value, :as => :city, :facet => true
109
+ end
110
+ end
111
+
112
+ after :each do
113
+ Alpha.sphinx_facets.delete_at(-1)
114
+ Alpha.sphinx_indexes.delete_at(-1)
115
+ end
116
+
117
+ it "should raise an error if searching with facets of same name but different type" do
118
+ lambda {
119
+ ThinkingSphinx::Search.facets :all_attributes => true
120
+ }.should raise_error
121
+ end
122
+ end
96
123
  end
97
124
  end
98
125
 
@@ -0,0 +1,156 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe ThinkingSphinx::Source do
4
+ before :each do
5
+ @index = ThinkingSphinx::Index.new(Person)
6
+ @source = ThinkingSphinx::Source.new(@index, :sql_range_step => 1000)
7
+ end
8
+
9
+ it "should generate the name from the model" do
10
+ @source.name.should == "person"
11
+ end
12
+
13
+ it "should handle namespaced models for name generation" do
14
+ index = ThinkingSphinx::Index.new(Admin::Person)
15
+ source = ThinkingSphinx::Source.new(index)
16
+ source.name.should == "admin_person"
17
+ end
18
+
19
+ describe "#to_riddle_for_core" do
20
+ before :each do
21
+ config = ThinkingSphinx::Configuration.instance
22
+ config.source_options[:sql_ranged_throttle] = 100
23
+
24
+ ThinkingSphinx::Field.new(
25
+ @source, ThinkingSphinx::Index::FauxColumn.new(:first_name)
26
+ )
27
+ ThinkingSphinx::Field.new(
28
+ @source, ThinkingSphinx::Index::FauxColumn.new(:last_name)
29
+ )
30
+
31
+ ThinkingSphinx::Attribute.new(
32
+ @source, ThinkingSphinx::Index::FauxColumn.new(:id), :as => :internal_id
33
+ )
34
+ ThinkingSphinx::Attribute.new(
35
+ @source, ThinkingSphinx::Index::FauxColumn.new(:birthday)
36
+ )
37
+ ThinkingSphinx::Attribute.new(
38
+ @source, ThinkingSphinx::Index::FauxColumn.new(:tags, :id), :as => :tag_ids
39
+ )
40
+
41
+ @source.conditions << "`birthday` <= NOW()"
42
+ @source.groupings << "`first_name`"
43
+
44
+ @riddle = @source.to_riddle_for_core(1, 0)
45
+ end
46
+
47
+ it "should generate a Riddle Source object" do
48
+ @riddle.should be_a_kind_of(Riddle::Configuration::SQLSource)
49
+ end
50
+
51
+ it "should use the index and name its own name" do
52
+ @riddle.name.should == "person_core_0"
53
+ end
54
+
55
+ it "should use the model's database connection to determine type" do
56
+ @riddle.type.should == "mysql"
57
+ end
58
+
59
+ it "should match the model's database settings" do
60
+ config = Person.connection.instance_variable_get(:@config)
61
+ @riddle.sql_db.should == config[:database]
62
+ @riddle.sql_user.should == config[:username]
63
+ @riddle.sql_pass.should == config[:password].to_s
64
+ @riddle.sql_host.should == config[:host]
65
+ @riddle.sql_port.should == config[:port]
66
+ @riddle.sql_sock.should == config[:socket]
67
+ end
68
+
69
+ it "should assign attributes" do
70
+ # 3 internal attributes plus the one requested
71
+ @riddle.sql_attr_uint.length.should == 4
72
+ @riddle.sql_attr_uint.last.should == :internal_id
73
+
74
+ @riddle.sql_attr_timestamp.length.should == 1
75
+ @riddle.sql_attr_timestamp.first.should == :birthday
76
+ end
77
+
78
+ it "should set Sphinx Source options" do
79
+ @riddle.sql_range_step.should == 1000
80
+ @riddle.sql_ranged_throttle.should == 100
81
+ end
82
+
83
+ describe "#sql_query" do
84
+ before :each do
85
+ @query = @riddle.sql_query
86
+ end
87
+
88
+ it "should select data from the model table" do
89
+ @query.should match(/FROM `people`/)
90
+ end
91
+
92
+ it "should select each of the fields" do
93
+ @query.should match(/`first_name`.+FROM/)
94
+ @query.should match(/`last_name`.+FROM/)
95
+ end
96
+
97
+ it "should select each of the attributes" do
98
+ @query.should match(/`id` AS `internal_id`.+FROM/)
99
+ @query.should match(/`birthday`.+FROM/)
100
+ @query.should match(/`tags`.`id`.+ AS `tag_ids`.+FROM/)
101
+ end
102
+
103
+ it "should include joins for required associations" do
104
+ @query.should match(/LEFT OUTER JOIN `tags`/)
105
+ end
106
+
107
+ it "should include any defined conditions" do
108
+ @query.should match(/WHERE.+`birthday` <= NOW()/)
109
+ end
110
+
111
+ it "should include any defined groupings" do
112
+ @query.should match(/GROUP BY.+`first_name`/)
113
+ end
114
+ end
115
+
116
+ describe "#sql_query_range" do
117
+ before :each do
118
+ @query = @riddle.sql_query_range
119
+ end
120
+
121
+ it "should select data from the model table" do
122
+ @query.should match(/FROM `people`/)
123
+ end
124
+
125
+ it "should select the minimum and the maximum ids" do
126
+ @query.should match(/SELECT.+MIN.+MAX.+FROM/)
127
+ end
128
+ end
129
+
130
+ describe "#sql_query_info" do
131
+ before :each do
132
+ @query = @riddle.sql_query_info
133
+ end
134
+
135
+ it "should select all fields from the model table" do
136
+ @query.should match(/SELECT \* FROM `people`/)
137
+ end
138
+
139
+ it "should filter the primary key with the offset" do
140
+ model_count = ThinkingSphinx.indexed_models.size
141
+ @query.should match(/WHERE `id` = \(\(\$id - 1\) \/ #{model_count}\)/)
142
+ end
143
+ end
144
+
145
+ describe "#sql_query_pre" do
146
+ before :each do
147
+ @queries = @riddle.sql_query_pre
148
+ end
149
+
150
+ it "should default to just the UTF8 statement" do
151
+ @queries.length.should == 1
152
+ @queries.first.should == "SET NAMES utf8"
153
+ end
154
+ end
155
+ end
156
+ end
data/tasks/testing.rb CHANGED
@@ -20,13 +20,7 @@ namespace :features do
20
20
  def add_task(name, description)
21
21
  Cucumber::Rake::Task.new(name, description) do |t|
22
22
  t.cucumber_opts = "--format pretty"
23
- t.step_pattern = [
24
- "features/support/env",
25
- "features/support/db/#{name}",
26
- "features/support/db/active_record",
27
- "features/support/post_database",
28
- "features/step_definitions/**.rb"
29
- ]
23
+ t.profile = name
30
24
  end
31
25
  end
32
26
 
@@ -46,13 +40,7 @@ namespace :rcov do
46
40
  def add_task(name, description)
47
41
  Cucumber::Rake::Task.new(name, description) do |t|
48
42
  t.cucumber_opts = "--format pretty"
49
- t.step_pattern = [
50
- "features/support/env",
51
- "features/support/db/#{name}",
52
- "features/support/db/active_record",
53
- "features/support/post_database",
54
- "features/step_definitions/**.rb"
55
- ]
43
+ t.profile = name
56
44
  t.rcov = true
57
45
  t.rcov_opts = [
58
46
  '--exclude', 'spec',
@@ -80,7 +68,11 @@ task :cucumber_defaults do
80
68
  "--require #{path}"
81
69
  }.join(" ")
82
70
 
71
+ features = FileList["features/*.feature"].join(" ")
72
+
83
73
  File.open('cucumber.yml', 'w') { |f|
84
- f.write "default: \"#{default_requires} #{step_definitions}\""
74
+ f.write "default: \"#{default_requires} #{step_definitions}\"\n\n"
75
+ f.write "mysql: \"#{default_requires} #{step_definitions} #{features}\"\n\n"
76
+ f.write "postgresql: \"#{default_requires.gsub(/mysql/, 'postgresql')} #{step_definitions} #{features}\""
85
77
  }
86
78
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: freelancing-god-thinking-sphinx
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.12
4
+ version: 1.1.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pat Allan
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-11 00:00:00 -07:00
12
+ date: 2009-05-18 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -52,7 +52,11 @@ files:
52
52
  - lib/thinking_sphinx/index.rb
53
53
  - lib/thinking_sphinx/property.rb
54
54
  - lib/thinking_sphinx/rails_additions.rb
55
+ - lib/thinking_sphinx/search/facets.rb
55
56
  - lib/thinking_sphinx/search.rb
57
+ - lib/thinking_sphinx/source/internal_properties.rb
58
+ - lib/thinking_sphinx/source/sql.rb
59
+ - lib/thinking_sphinx/source.rb
56
60
  - lib/thinking_sphinx/tasks.rb
57
61
  - lib/thinking_sphinx.rb
58
62
  - LICENCE
@@ -117,6 +121,7 @@ files:
117
121
  - spec/unit/thinking_sphinx/index_spec.rb
118
122
  - spec/unit/thinking_sphinx/rails_additions_spec.rb
119
123
  - spec/unit/thinking_sphinx/search_spec.rb
124
+ - spec/unit/thinking_sphinx/source_spec.rb
120
125
  - spec/unit/thinking_sphinx_spec.rb
121
126
  has_rdoc: true
122
127
  homepage: http://ts.freelancing-gods.com
@@ -164,4 +169,5 @@ test_files:
164
169
  - spec/unit/thinking_sphinx/index_spec.rb
165
170
  - spec/unit/thinking_sphinx/rails_additions_spec.rb
166
171
  - spec/unit/thinking_sphinx/search_spec.rb
172
+ - spec/unit/thinking_sphinx/source_spec.rb
167
173
  - spec/unit/thinking_sphinx_spec.rb