sunspot_rails 0.10.4 → 0.10.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/TODO ADDED
@@ -0,0 +1,4 @@
1
+ * Fix final status output for reindex
2
+ * Add batch-per-request option
3
+ * Optionally yield from reindex
4
+ * Access to all searchable classes
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :minor: 10
3
- :patch: 4
3
+ :patch: 5
4
4
  :major: 0
@@ -8,6 +8,7 @@ begin
8
8
  s.homepage = 'http://github.com/outoftime/sunspot_rails'
9
9
  s.description = 'Rails integration for the Sunspot Solr search library'
10
10
  s.authors = ['Mat Brown', 'Peer Allan', 'Michael Moen', 'Benjamin Krause']
11
+ s.rubyforge_project = 'sunspot'
11
12
  s.files = FileList['[A-Z]*',
12
13
  '{lib,tasks,dev_tasks}/**/*',
13
14
  'install.rb',
@@ -18,7 +19,7 @@ begin
18
19
  'spec/mock_app/{tmp,log,solr}']
19
20
  s.add_dependency 'rails', '~> 2.1'
20
21
  s.add_dependency 'escape', '>= 0.0.4'
21
- s.add_dependency 'sunspot', '>= 0.8.2'
22
+ s.add_dependency 'outoftime-sunspot', '>= 0.8.2'
22
23
  s.add_development_dependency 'rspec', '~> 1.2'
23
24
  s.add_development_dependency 'rspec-rails', '~> 1.2'
24
25
  s.add_development_dependency 'ruby-debug', '~> 0.10'
@@ -0,0 +1,4 @@
1
+ namespace :release do
2
+ desc 'Release gem on RubyForge and GitHub'
3
+ task :all => [:release, :"rubyforge:release:gem"]
4
+ end
@@ -25,6 +25,7 @@ module Sunspot #:nodoc:
25
25
  # <code>rake sunspot:solr:start</code> task.
26
26
  #
27
27
  class Configuration
28
+ attr_writer :user_configuration
28
29
  #
29
30
  # The host name at which to connect to Solr. Default 'localhost'.
30
31
  #
@@ -33,10 +34,7 @@ module Sunspot #:nodoc:
33
34
  # String:: host name
34
35
  #
35
36
  def hostname
36
- @hostname ||=
37
- if user_configuration.has_key?('solr')
38
- user_configuration['solr']['hostname']
39
- end || 'localhost'
37
+ @hostname ||= (user_configuration_from_key('solr', 'hostname') || 'localhost')
40
38
  end
41
39
 
42
40
  #
@@ -47,10 +45,7 @@ module Sunspot #:nodoc:
47
45
  # Integer:: port
48
46
  #
49
47
  def port
50
- @port ||=
51
- if user_configuration.has_key?('solr')
52
- user_configuration['solr']['port']
53
- end || 8983
48
+ @port ||= (user_configuration_from_key('solr', 'port') || 8983).to_i
54
49
  end
55
50
 
56
51
  #
@@ -62,13 +57,36 @@ module Sunspot #:nodoc:
62
57
  # String:: path
63
58
  #
64
59
  def path
65
- @path ||=
66
- if user_configuration.has_key?('solr')
67
- "#{user_configuration['solr']['path'] || '/solr'}"
68
- end
60
+ @path ||= (user_configuration_from_key('solr', 'path') || '/solr')
61
+ end
62
+
63
+ #
64
+ # Should the solr index receive a commit after each http-request.
65
+ # Default true
66
+ #
67
+ # ==== Returns
68
+ #
69
+ # Boolean:: bool
70
+ #
71
+
72
+ def auto_commit_after_request?
73
+ @auto_commit_after_request ||=
74
+ user_configuration_from_key('auto_commit_after_request') != false
69
75
  end
70
76
 
71
77
  private
78
+
79
+ #
80
+ # return a specific key from the user configuration in config/sunspot.yml
81
+ #
82
+ # ==== Returns
83
+ #
84
+ #
85
+ def user_configuration_from_key( *keys )
86
+ keys.inject(user_configuration) do |hash, key|
87
+ hash[key] if hash
88
+ end
89
+ end
72
90
 
73
91
  #
74
92
  # Memoized hash of configuration options for the current Rails environment
@@ -86,6 +104,8 @@ module Sunspot #:nodoc:
86
104
  File.open(path) do |file|
87
105
  YAML.load(file)[::Rails.env]
88
106
  end
107
+ else
108
+ {}
89
109
  end
90
110
  end
91
111
  end
@@ -9,7 +9,7 @@ module Sunspot #:nodoc:
9
9
  class <<self
10
10
  def included(base) #:nodoc:
11
11
  base.after_filter do
12
- Sunspot.commit_if_dirty
12
+ Sunspot.commit_if_dirty if Sunspot::Rails.configuration.auto_commit_after_request?
13
13
  end
14
14
  end
15
15
  end
@@ -208,7 +208,8 @@ module Sunspot #:nodoc:
208
208
  #
209
209
  # Array:: Collection of IDs that exist in Solr but not in the database
210
210
  def index_orphans
211
- indexed_ids = search_ids.to_set
211
+ count = self.count
212
+ indexed_ids = search_ids { paginate(:page => 1, :per_page => count) }.to_set
212
213
  all(:select => 'id').each do |object|
213
214
  indexed_ids.delete(object.id)
214
215
  end
data/lib/sunspot/rails.rb CHANGED
@@ -3,6 +3,8 @@ require 'sunspot'
3
3
  module Sunspot #:nodoc:
4
4
  module Rails #:nodoc:
5
5
  class <<self
6
+ attr_writer :configuration
7
+
6
8
  def configuration
7
9
  @configuration ||= Sunspot::Rails::Configuration.new
8
10
  end
@@ -1,16 +1,53 @@
1
1
  require File.join(File.dirname(__FILE__), 'spec_helper')
2
2
 
3
- describe "Configuration" do
3
+ describe Sunspot::Rails::Configuration, "default values" do
4
+ before(:each) do
5
+ File.should_receive(:exist?).and_return(false)
6
+ end
7
+
8
+ it "should handle the 'hostname' property when not set" do
9
+ config = Sunspot::Rails::Configuration.new
10
+ config.hostname.should == 'localhost'
11
+ end
12
+
4
13
  it "should handle the 'path' property when not set" do
5
14
  config = Sunspot::Rails::Configuration.new
6
15
  config.path.should == '/solr'
7
16
  end
8
17
 
18
+ it "should handle the 'port' property when not set" do
19
+ config = Sunspot::Rails::Configuration.new
20
+ config.port.should == 8983
21
+ end
22
+
23
+ it "should handle the 'auto_commit_after_request' propery when not set" do
24
+ config = Sunspot::Rails::Configuration.new
25
+ config.auto_commit_after_request?.should == true
26
+ end
27
+ end
28
+
29
+ describe Sunspot::Rails::Configuration, "user settings" do
30
+ before(:each) do
31
+ Rails.stub!(:env => 'config_test')
32
+ end
33
+
34
+ it "should handle the 'hostname' property when not set" do
35
+ config = Sunspot::Rails::Configuration.new
36
+ config.hostname.should == 'some.host'
37
+ end
38
+
39
+ it "should handle the 'port' property when not set" do
40
+ config = Sunspot::Rails::Configuration.new
41
+ config.port.should == 1234
42
+ end
43
+
9
44
  it "should handle the 'path' property when set" do
10
- silence_stderr do
11
- Rails.stub!(:env => 'path_test')
12
- config = Sunspot::Rails::Configuration.new
13
- config.path.should == '/solr/path_test'
14
- end
45
+ config = Sunspot::Rails::Configuration.new
46
+ config.path.should == '/solr/idx'
47
+ end
48
+
49
+ it "should handle the 'auto_commit_after_request' propery when set" do
50
+ config = Sunspot::Rails::Configuration.new
51
+ config.auto_commit_after_request?.should == false
15
52
  end
16
53
  end
@@ -6,8 +6,9 @@ development:
6
6
  solr:
7
7
  hostname: localhost
8
8
  port: 8981
9
- path_test:
9
+ config_test:
10
10
  solr:
11
- hostname: localhost
12
- port: 8981
13
- path: /solr/path_test
11
+ hostname: some.host
12
+ port: 1234
13
+ path: /solr/idx
14
+ auto_commit_after_request: false
@@ -1,10 +1,30 @@
1
1
  require File.join(File.dirname(__FILE__), 'spec_helper')
2
2
 
3
3
  describe 'request lifecycle', :type => :controller do
4
+ before(:each) do
5
+ Sunspot::Rails.configuration = @configuration = Sunspot::Rails::Configuration.new
6
+ end
7
+
8
+ after(:each) do
9
+ Sunspot::Rails.configuration = nil
10
+ end
4
11
  controller_name :posts
5
12
 
6
- it 'should automatically commit after each action' do
13
+ it 'should automatically commit after each action if specified' do
14
+ @configuration.user_configuration = { 'auto_commit_after_request' => true }
15
+ Sunspot.should_receive(:commit_if_dirty)
16
+ post :create, :post => { :title => 'Test 1' }
17
+ end
18
+
19
+ it 'should not commit, if configuration is set to false' do
20
+ @configuration.user_configuration = { 'auto_commit_after_request' => false }
21
+ Sunspot.should_not_receive(:commit_if_dirty)
22
+ post :create, :post => { :title => 'Test 1' }
23
+ end
24
+
25
+ it 'should commit if configuration is not specified' do
26
+ @configuration.user_configuration = {}
27
+ Sunspot.should_receive(:commit_if_dirty)
7
28
  post :create, :post => { :title => 'Test 1' }
8
- PostWithAuto.search { with :title, 'Test 1' }.results.should_not be_empty
9
29
  end
10
30
  end
data/spec/spec_helper.rb CHANGED
@@ -5,7 +5,9 @@ require File.expand_path(File.join(ENV['RAILS_ROOT'], 'config', 'environment.rb'
5
5
 
6
6
  require 'spec'
7
7
  require 'spec/rails'
8
+ require 'rake'
8
9
  require 'ruby-debug'
10
+ require 'sunspot/rails/tasks'
9
11
 
10
12
  def load_schema
11
13
  stdout = $stdout
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sunspot_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.4
4
+ version: 0.10.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mat Brown
@@ -12,7 +12,7 @@ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
14
 
15
- date: 2009-08-10 00:00:00 -07:00
15
+ date: 2009-08-28 00:00:00 -04:00
16
16
  default_executable:
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
@@ -36,7 +36,7 @@ dependencies:
36
36
  version: 0.0.4
37
37
  version:
38
38
  - !ruby/object:Gem::Dependency
39
- name: sunspot
39
+ name: outoftime-sunspot
40
40
  type: :runtime
41
41
  version_requirement:
42
42
  version_requirements: !ruby/object:Gem::Requirement
@@ -99,9 +99,11 @@ files:
99
99
  - MIT-LICENSE
100
100
  - README.rdoc
101
101
  - Rakefile
102
+ - TODO
102
103
  - VERSION.yml
103
104
  - dev_tasks/gemspec.rake
104
105
  - dev_tasks/rdoc.rake
106
+ - dev_tasks/release.rake
105
107
  - dev_tasks/todo.rake
106
108
  - install.rb
107
109
  - lib/sunspot/rails.rb
@@ -155,28 +157,28 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
157
  version:
156
158
  requirements: []
157
159
 
158
- rubyforge_project:
159
- rubygems_version: 1.3.3
160
+ rubyforge_project: sunspot
161
+ rubygems_version: 1.3.2
160
162
  signing_key:
161
163
  specification_version: 3
162
164
  summary: Rails integration for the Sunspot Solr search library
163
165
  test_files:
166
+ - spec/spec_helper.rb
164
167
  - spec/configuration_spec.rb
165
- - spec/mock_app/app/controllers/application.rb
166
- - spec/mock_app/app/controllers/application_controller.rb
168
+ - spec/model_lifecycle_spec.rb
169
+ - spec/schema.rb
170
+ - spec/model_spec.rb
167
171
  - spec/mock_app/app/controllers/posts_controller.rb
172
+ - spec/mock_app/app/controllers/application_controller.rb
173
+ - spec/mock_app/app/controllers/application.rb
168
174
  - spec/mock_app/app/models/blog.rb
169
- - spec/mock_app/app/models/post.rb
170
175
  - spec/mock_app/app/models/post_with_auto.rb
171
- - spec/mock_app/config/boot.rb
176
+ - spec/mock_app/app/models/post.rb
172
177
  - spec/mock_app/config/environment.rb
178
+ - spec/mock_app/config/initializers/session_store.rb
179
+ - spec/mock_app/config/initializers/new_rails_defaults.rb
173
180
  - spec/mock_app/config/environments/development.rb
174
181
  - spec/mock_app/config/environments/test.rb
175
- - spec/mock_app/config/initializers/new_rails_defaults.rb
176
- - spec/mock_app/config/initializers/session_store.rb
177
182
  - spec/mock_app/config/routes.rb
178
- - spec/model_lifecycle_spec.rb
179
- - spec/model_spec.rb
183
+ - spec/mock_app/config/boot.rb
180
184
  - spec/request_lifecycle_spec.rb
181
- - spec/schema.rb
182
- - spec/spec_helper.rb