public
Rubygem
Description: Sphinx plugin for Rails and Merb
Homepage: http://ts.freelancing-gods.com
Clone URL: git://github.com/freelancing-god/thinking-sphinx.git
Click here to lend your support to: thinking-sphinx and make a donation at www.pledgie.com !
Add name to list of reserved methods in index/builder docs, make Field raise if 
you try and create one with no columns (which happens if you use a reserved word 
like id or name)
Xavier Shay (author)
Mon May 19 02:32:57 -0700 2008
freelancing-god (committer)
Fri May 23 22:51:29 -0700 2008
commit  f37c22815f05b704549e4ed9bc4c54d8475b2105
tree    efe579b473ea94920308b930df612a7ac60d8eca
parent  fad37950195e33700a2d3181404102a76e0a5e5b
...
47
48
49
 
 
50
51
52
...
183
184
185
186
187
 
...
47
48
49
50
51
52
53
54
...
185
186
187
 
188
189
0
@@ -47,6 +47,8 @@ module ThinkingSphinx
0
     def initialize(columns, options = {})
0
       @columns      = Array(columns)
0
       @associations = {}
0
+
0
+      raise "Cannot define a field with no columns. Maybe you are trying to index a field with a reserved name (id, name). You can fix this error by using a symbol rather than a bare name (:id instead of id)." if @columns.empty? || @columns.any? {|column| !column.respond_to?(:__stack) }
0
       
0
       @alias        = options[:as]
0
       @sortable     = options[:sortable] || false
0
@@ -183,4 +185,4 @@ module ThinkingSphinx
0
       associations.values.flatten.any? { |assoc| assoc.is_many? }
0
     end
0
   end
0
-end
0
\ No newline at end of file
0
+end
...
48
49
50
 
51
52
53
54
55
56
 
57
58
 
59
60
61
...
194
195
196
197
198
 
...
48
49
50
51
52
 
53
54
55
 
56
57
 
58
59
60
61
...
194
195
196
 
197
198
0
@@ -48,14 +48,14 @@ module ThinkingSphinx
0
         # get access down the associations tree.
0
         # 
0
         #   indexes :id, :as => :my_id
0
+        #   indexes :name, :sortable => true
0
         #   indexes first_name, last_name, :sortable => true
0
-        #   indexes name, :sortable => true
0
         #   indexes users.posts.content, :as => :post_content
0
         #   indexes users(:id), :as => :user_ids
0
         #
0
-        # Keep in mind that if any keywords for Ruby methods - such as id -
0
+        # Keep in mind that if any keywords for Ruby methods - such as id or name -
0
         # clash with your column names, you need to use the symbol version (see
0
-        # the first and last examples above).
0
+        # the first, second and last examples above).
0
         #
0
         # If you specify multiple columns (example #2), a field will be created
0
         # for each. Don't use the :as option in this case. If you want to merge
0
@@ -194,4 +194,4 @@ module ThinkingSphinx
0
       end
0
     end
0
   end
0
-end
0
\ No newline at end of file
0
+end
...
22
23
24
25
 
26
27
28
...
41
42
43
 
44
45
46
...
48
49
50
51
52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
22
23
24
 
25
26
27
28
...
41
42
43
44
45
46
47
...
49
50
51
 
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
0
@@ -22,7 +22,7 @@ describe ThinkingSphinx::Field do
0
   
0
   describe "to_group_sql method" do
0
     before :each do
0
-      @field = ThinkingSphinx::Field.new([])
0
+      @field = ThinkingSphinx::Field.new([Object.stub_instance(:__stack => [])])
0
       @field.stub_methods(:is_many? => false)
0
       
0
       ThinkingSphinx.stub_method(:use_group_by_shortcut? => false)
0
@@ -41,6 +41,7 @@ describe ThinkingSphinx::Field do
0
     end
0
     
0
     it "should return an array if neither is_many? or shortcut allowed" do
0
+      @field.stub_method(:column_with_prefix => 'hello')
0
       @field.to_group_sql.should be_a_kind_of(Array)
0
     end
0
     
0
@@ -48,4 +49,18 @@ describe ThinkingSphinx::Field do
0
       ThinkingSphinx.unstub_method(:use_group_by_shortcut?)
0
     end
0
   end
0
-end
0
\ No newline at end of file
0
+
0
+  describe '#initialize' do
0
+    it 'raises if no columns are provided so that configuration errors are easier to track down' do
0
+      lambda {
0
+        ThinkingSphinx::Field.new([])
0
+      }.should raise_error(RuntimeError)
0
+    end
0
+
0
+    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
0
+      lambda {
0
+        ThinkingSphinx::Field.new([1234])
0
+      }.should raise_error(RuntimeError)
0
+    end
0
+  end
0
+end

Comments