public
Rubygem
Fork of freelancing-god/thinking-sphinx
Description: Sphinx plugin for Rails and Merb
Homepage: http://ts.freelancing-gods.com
Clone URL: git://github.com/jaikoo/thinking-sphinx.git
Added gem building rake task. Completed specs for 
ThinkingSphinx::ActiveRecord::Delta. Added delta field to spec's Person 
model. Tweaked charset and morphology settings to allow index-specific 
values.
Mon Apr 21 02:24:33 -0700 2008
commit  70448dc7d9df9b8f419b41ec23a25d5158598b2d
tree    da98c30239d21ea891f0fad69e2d0eeb2f707aa9
parent  9f9e58b4b0be48907293427d883ac0f39c8be8f7
...
1
2
3
4
 
 
5
...
1
2
 
3
4
5
6
0
@@ -1,3 +1,4 @@
0
 gem_deploy.rake
0
 pkg
0
-coverage
0
\ No newline at end of file
0
+coverage
0
+*.tmproj
0
\ No newline at end of file
...
7
8
9
 
10
11
12
 
 
 
 
13
14
15
...
31
32
33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
35
...
7
8
9
10
11
12
 
13
14
15
16
17
18
19
...
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
0
@@ -7,9 +7,13 @@ end
0
 
0
 require 'rake/rdoctask'
0
 require 'spec/rake/spectask'
0
+require 'rake/gempackagetask'
0
 
0
 # allow require of spec/spec_helper
0
-$:.unshift File.dirname(__FILE__) + '/../'
0
+$LOAD_PATH.unshift File.dirname(__FILE__) + '/../'
0
+$LOAD_PATH.unshift File.dirname(__FILE__) + '/lib'
0
+
0
+require 'thinking_sphinx'
0
 
0
 desc 'Generate documentation'
0
 Rake::RDocTask.new(:rdoc) do |rdoc|
0
@@ -31,4 +35,32 @@ Spec::Rake::SpecTask.new(:rcov) do |t|
0
   t.spec_files = FileList['spec/**/*_spec.rb']
0
   t.rcov = true
0
   t.rcov_opts = ['--exclude', 'spec', '--exclude', 'gems', '--exclude', 'riddle']
0
+end
0
+
0
+spec = Gem::Specification.new do |s|
0
+ s.name = "thinking_sphinx"
0
+ s.version = ThinkingSphinx::Version::String
0
+ s.summary = "A concise and easy-to-use Ruby library that connects ActiveRecord to the Sphinx search daemon, managing configuration, indexing and searching."
0
+ s.description = "A concise and easy-to-use Ruby library that connects ActiveRecord to the Sphinx search daemon, managing configuration, indexing and searching."
0
+ s.author = "Pat Allan"
0
+ s.email = "pat@freelancing-gods.com"
0
+ s.homepage = "http://ts.freelancing-gods.com"
0
+ s.has_rdoc = true
0
+ s.rdoc_options << "--title" << "Thinking Sphinx -- Rails/Merb Sphinx Plugin" <<
0
+ "--line-numbers"
0
+ s.rubyforge_project = "thinking-sphinx"
0
+ s.test_files = FileList["spec/**/*_spec.rb"]
0
+ s.files = FileList[
0
+ "lib/**/*.rb",
0
+ "LICENCE",
0
+ "README",
0
+ "tasks/**/*.rb",
0
+ "tasks/**/*.rake"
0
+ ]
0
+end
0
+
0
+Rake::GemPackageTask.new(spec) do |p|
0
+ p.gem_spec = spec
0
+ p.need_tar = true
0
+ p.need_zip = true
0
 end
0
\ No newline at end of file
...
66
67
68
69
70
71
 
 
 
72
 
 
 
 
73
74
75
...
66
67
68
 
 
 
69
70
71
72
73
74
75
76
77
78
79
0
@@ -66,10 +66,14 @@ module ThinkingSphinx
0
           # if running in the test environment.
0
           #
0
           def index_delta
0
- unless ThinkingSphinx::Configuration.environment == "test" || !ThinkingSphinx.deltas_enabled?
0
- configuration = ThinkingSphinx::Configuration.new
0
- system "indexer --config #{configuration.config_file} --rotate #{self.class.name.downcase}_delta"
0
+ if ThinkingSphinx::Configuration.environment == "test" ||
0
+ !ThinkingSphinx.deltas_enabled?
0
+ return true
0
             end
0
+
0
+ configuration = ThinkingSphinx::Configuration.new
0
+ system "indexer --config #{configuration.config_file} --rotate #{self.class.name.downcase}_delta"
0
+
0
             true
0
           end
0
         end
...
156
157
158
159
 
160
161
 
162
163
 
164
165
 
166
167
168
...
156
157
158
 
159
160
 
161
162
 
163
164
 
165
166
167
168
0
@@ -156,13 +156,13 @@ source #{model.name.downcase}_#{i}_delta : #{model.name.downcase}_#{i}_core
0
 index #{model.name.downcase}_core
0
 {
0
   #{source_list}
0
- morphology = #{self.morphology}
0
+ morphology = #{index.options[:morphology] || self.morphology}
0
   path = #{self.searchd_file_path}/#{model.name.downcase}_core
0
- charset_type = #{self.charset_type}
0
+ charset_type = #{index.options[:charset_type] || self.charset_type}
0
   INDEX
0
- unless self.charset_table.nil?
0
+ unless index.options[:charset_type].nil? && self.charset_table.nil?
0
             file.write <<-INDEX
0
- charset_table = #{self.charset_table}
0
+ charset_table = #{index.options[:charset_type] || self.charset_table}
0
             INDEX
0
           end
0
           
...
14
15
16
 
17
18
19
...
14
15
16
17
18
19
20
0
@@ -14,6 +14,7 @@ CREATE TABLE `people` (
0
   `birthday` datetime NOT NULL,
0
   `team_id` int(11) NULL,
0
   `team_type` varchar(50) NULL,
0
+ `delta` tinyint(1) NOT NULL DEFAULT 0,
0
   PRIMARY KEY (`id`)
0
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
0
 
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
0
@@ -0,0 +1,184 @@
0
+require 'spec/spec_helper'
0
+
0
+describe "ThinkingSphinx::ActiveRecord::Delta" do
0
+ describe "after_commit callback" do
0
+ before :each do
0
+ Person.stub_method(:write_inheritable_array => true)
0
+ end
0
+
0
+ after :each do
0
+ Person.unstub_method(:write_inheritable_array)
0
+ end
0
+
0
+ it "should add callbacks" do
0
+ Person.after_commit :toggle_delta
0
+
0
+ Person.should have_received(:write_inheritable_array).with(
0
+ :after_commit, [:toggle_delta]
0
+ )
0
+ end
0
+ end
0
+
0
+ describe "save_with_after_commit_callback method" do
0
+ before :each do
0
+ @person = Person.new
0
+ @person.stub_methods(
0
+ :save_without_after_commit_callback => true,
0
+ :callback => true
0
+ )
0
+ end
0
+
0
+ it "should call the normal save method" do
0
+ @person.save
0
+
0
+ @person.should have_received(:save_without_after_commit_callback)
0
+ end
0
+
0
+ it "should call the callbacks if the save was successful" do
0
+ @person.save
0
+
0
+ @person.should have_received(:callback).with(:after_commit)
0
+ end
0
+
0
+ it "shouldn't call the callbacks if the save failed" do
0
+ @person.stub_method(:save_without_after_commit_callback => false)
0
+
0
+ @person.save
0
+
0
+ @person.should_not have_received(:callback)
0
+ end
0
+
0
+ it "should return the normal save's result" do
0
+ @person.save.should be_true
0
+
0
+ @person.stub_method(:save_without_after_commit_callback => false)
0
+
0
+ @person.save.should be_false
0
+ end
0
+ end
0
+
0
+ describe "save_with_after_commit_callback! method" do
0
+ before :each do
0
+ @person = Person.new
0
+ @person.stub_methods(
0
+ :save_without_after_commit_callback! => true,
0
+ :callback => true
0
+ )
0
+ end
0
+
0
+ it "should call the normal save! method" do
0
+ @person.save!
0
+
0
+ @person.should have_received(:save_without_after_commit_callback!)
0
+ end
0
+
0
+ it "should call the callbacks if the save! was successful" do
0
+ @person.save!
0
+
0
+ @person.should have_received(:callback).with(:after_commit)
0
+ end
0
+
0
+ it "shouldn't call the callbacks if the save! failed" do
0
+ @person.stub_method(:save_without_after_commit_callback! => false)
0
+
0
+ @person.save!
0
+
0
+ @person.should_not have_received(:callback)
0
+ end
0
+
0
+ it "should return the normal save's result" do
0
+ @person.save!.should be_true
0
+
0
+ @person.stub_method(:save_without_after_commit_callback! => false)
0
+
0
+ @person.save!.should be_false
0
+ end
0
+ end
0
+
0
+ describe "destroy_with_after_commit_callback method" do
0
+ before :each do
0
+ @person = Person.new
0
+ @person.stub_methods(
0
+ :destroy_without_after_commit_callback => true,
0
+ :callback => true
0
+ )
0
+ end
0
+
0
+ it "should call the normal destroy method" do
0
+ @person.destroy
0
+
0
+ @person.should have_received(:destroy_without_after_commit_callback)
0
+ end
0
+
0
+ it "should call the callbacks if the destroy was successful" do
0
+ @person.destroy
0
+
0
+ @person.should have_received(:callback).with(:after_commit)
0
+ end
0
+
0
+ it "shouldn't call the callbacks if the destroy failed" do
0
+ @person.stub_method(:destroy_without_after_commit_callback => false)
0
+
0
+ @person.destroy
0
+
0
+ @person.should_not have_received(:callback)
0
+ end
0
+
0
+ it "should return the normal save's result" do
0
+ @person.destroy.should be_true
0
+
0
+ @person.stub_method(:destroy_without_after_commit_callback => false)
0
+
0
+ @person.destroy.should be_false
0
+ end
0
+ end
0
+
0
+ describe "toggle_delta method" do
0
+ it "should set the delta value to true" do
0
+ @person = Person.new
0
+
0
+ @person.delta.should be_false
0
+ @person.send(:toggle_delta)
0
+ @person.delta.should be_true
0
+ end
0
+ end
0
+
0
+ describe "index_delta method" do
0
+ before :each do
0
+ ThinkingSphinx::Configuration.stub_method(:environment => "spec")
0
+ ThinkingSphinx.stub_method(:deltas_enabled? => true)
0
+
0
+ @person = Person.new
0
+ @person.stub_method(:system => true)
0
+ end
0
+
0
+ after :each do
0
+ ThinkingSphinx::Configuration.unstub_method(:environment)
0
+ ThinkingSphinx.unstub_method(:deltas_enabled?)
0
+ end
0
+
0
+ it "shouldn't index if delta indexing is disabled" do
0
+ ThinkingSphinx.stub_method(:deltas_enabled? => false)
0
+
0
+ @person.send(:index_delta)
0
+
0
+ @person.should_not have_received(:system)
0
+ end
0
+
0
+ it "shouldn't index if the environment is 'test'" do
0
+ ThinkingSphinx::Configuration.stub_method(:environment => "test")
0
+
0
+ @person.send(:index_delta)
0
+
0
+ @person.should_not have_received(:system)
0
+ end
0
+
0
+ it "should call indexer for the delta index" do
0
+ @person.send(:index_delta)
0
+
0
+ @person.should have_received(:system).with(
0
+ "indexer --config #{ThinkingSphinx::Configuration.new.config_file} --rotate person_delta"
0
+ )
0
+ end
0
+ end
0
+end
0
\ No newline at end of file

Comments

    No one has commented yet.