adamsalter-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/README.rdoc CHANGED
@@ -18,41 +18,26 @@ Sunspot::Rails has been tested with Rails versions 2.1, 2.2, and 2.3
18
18
 
19
19
  == Installation
20
20
 
21
- First, install the Sunspot and Sunspot::Rails gems:
21
+ For recent versions of Rails, In your project's <code>config/environment.rb</code>, add the following gem dependencies:
22
22
 
23
- sudo gem install outoftime-sunspot outoftime-sunspot_rails --source=http://gems.github.com
24
-
25
- In your project's <code>config/environment.rb</code>, add the following gem dependencies:
23
+ config.gem 'outoftime-sunspot', :lib => 'sunspot',
24
+ :source => 'http://gems.github.com'
25
+ config.gem 'outoftime-sunspot_rails', :lib => 'sunspot/rails',
26
+ :source => 'http://gems.github.com'
27
+
28
+ Install the gems with:
26
29
 
27
- config.gem 'outoftime-sunspot', :lib => 'sunspot'
28
- config.gem 'outoftime-sunspot_rails', :lib => 'sunspot/rails'
30
+ rake gems:install
29
31
 
30
- If you are using an older version of Rails that doesn't support plugins-as-gems,
31
- use:
32
+ If you are using an older version of Rails that doesn't support plugins-as-gems, install the gems manually and install the plugin:
32
33
 
34
+ sudo gem install outoftime-sunspot outoftime-sunspot_rails --source=http://gems.github.com
35
+
33
36
  script/plugin install git://github.com/outoftime/sunspot_rails.git
37
+
38
+ Generate the file <code>config/sunspot.yml</code>:
34
39
 
35
- Create the file <code>config/sunspot.yml</code> and set it up for your environments. Here is a sample:
36
-
37
- common: &common
38
- solr:
39
- hostname: localhost
40
- port: 8983
41
-
42
- production:
43
- <<: *common
44
- solr:
45
- path: /solr/myindex
46
-
47
- development:
48
- <<: *common
49
- solr:
50
- port: 8982
51
-
52
- test:
53
- <<: *common
54
- solr:
55
- port: 8981
40
+ script/generate sunspot
56
41
 
57
42
  Rails doesn't automatically load rake tasks from plugins installed as gems
58
43
  (https://rails.lighthouseapp.com/projects/8994/tickets/59). If you installed
@@ -240,6 +225,8 @@ http://outoftime.lighthouseapp.com/projects/20339-sunspot
240
225
  - Peer Allan (peer.allan@gmail.com)
241
226
  - Michael Moen (michael@underpantsgnome.com)
242
227
  - Benjamin Krause (bk@benjaminkrause.com)
228
+ - Adam Salter (adam@codebright.net)
229
+ - Brandon Keepers (brandon@opensoul.org)
243
230
 
244
231
  == License
245
232
 
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ task :default => :spec
6
6
 
7
7
  desc 'Run all specs'
8
8
  Spec::Rake::SpecTask.new(:spec) do |t|
9
- t.spec_files = FileList['spec/**/*_spec.rb']
9
+ t.spec_files = FileList['spec/*_spec.rb']
10
10
  t.spec_opts << '--color'
11
11
  end
12
12
 
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :minor: 10
3
- :patch: 4
3
+ :patch: 5
4
4
  :major: 0
@@ -7,9 +7,11 @@ begin
7
7
  s.email = 'mat@patch.com'
8
8
  s.homepage = 'http://github.com/outoftime/sunspot_rails'
9
9
  s.description = 'Rails integration for the Sunspot Solr search library'
10
- s.authors = ['Mat Brown', 'Peer Allan', 'Michael Moen', 'Benjamin Krause']
10
+ s.authors = ['Mat Brown', 'Peer Allan', 'Michael Moen', 'Benjamin Krause', 'Adam Salter', 'Brandon Keepers']
11
+ s.rubyforge_project = 'sunspot'
11
12
  s.files = FileList['[A-Z]*',
12
13
  '{lib,tasks,dev_tasks}/**/*',
14
+ 'generators/**/*',
13
15
  'install.rb',
14
16
  'MIT-LICENSE',
15
17
  'rails/*',
@@ -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
@@ -0,0 +1,9 @@
1
+ class SunspotGenerator < Rails::Generator::Base
2
+
3
+ def manifest
4
+ record do |m|
5
+ m.template 'sunspot.yml', 'config/sunspot.yml'
6
+ end
7
+ end
8
+
9
+ end
@@ -0,0 +1,19 @@
1
+ common: &common
2
+ solr:
3
+ hostname: localhost
4
+ port: 8983
5
+
6
+ production:
7
+ <<: *common
8
+ solr:
9
+ path: /solr/myindex
10
+
11
+ development:
12
+ <<: *common
13
+ solr:
14
+ port: 8982
15
+
16
+ test:
17
+ <<: *common
18
+ solr:
19
+ port: 8981
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
@@ -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,10 +57,21 @@ 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
  #
@@ -77,10 +83,7 @@ module Sunspot #:nodoc:
77
83
  # String:: path
78
84
  #
79
85
  def data_path
80
- @data_path ||=
81
- if user_configuration.has_key?('solr')
82
- "#{user_configuration['solr']['data_path'] || File.join(::Rails.root, 'solr', 'data', ::Rails.env)}"
83
- end
86
+ @data_path ||= user_configuration_from_key('solr', 'data_path') || File.join(::Rails.root, 'solr', 'data', ::Rails.env)
84
87
  end
85
88
 
86
89
  #
@@ -92,10 +95,7 @@ module Sunspot #:nodoc:
92
95
  # String:: path
93
96
  #
94
97
  def pid_path
95
- @pids_path ||=
96
- if user_configuration.has_key?('solr')
97
- "#{user_configuration['solr']['pid_path'] || File.join(::Rails.root, 'solr', 'pids', ::Rails.env)}"
98
- end
98
+ @pids_path ||= user_configuration_from_key('solr', 'pid_path') || File.join(::Rails.root, 'solr', 'pids', ::Rails.env)
99
99
  end
100
100
 
101
101
  #
@@ -114,18 +114,26 @@ module Sunspot #:nodoc:
114
114
  #
115
115
  def solr_home
116
116
  @solr_home ||=
117
- if user_configuration.has_key?('solr')
118
- if user_configuration['solr']['solr_home'].present?
119
- user_configuration['solr']['solr_home']
120
- elsif %w(solrconfig schema).all? { |file| File.exist?(File.join(::Rails.root, 'solr', 'conf', "#{file}.xml")) }
121
- File.join(::Rails.root, 'solr')
122
- else
123
- nil
124
- end
117
+ if user_configuration_from_key('solr', 'solr_home')
118
+ user_configuration_from_key('solr', 'solr_home')
119
+ elsif %w(solrconfig schema).all? { |file| File.exist?(File.join(::Rails.root, 'solr', 'conf', "#{file}.xml")) }
120
+ File.join(::Rails.root, 'solr')
125
121
  end
126
122
  end
127
123
 
128
124
  private
125
+
126
+ #
127
+ # return a specific key from the user configuration in config/sunspot.yml
128
+ #
129
+ # ==== Returns
130
+ #
131
+ #
132
+ def user_configuration_from_key( *keys )
133
+ keys.inject(user_configuration) do |hash, key|
134
+ hash[key] if hash
135
+ end
136
+ end
129
137
 
130
138
  #
131
139
  # Memoized hash of configuration options for the current Rails environment
@@ -143,6 +151,8 @@ module Sunspot #:nodoc:
143
151
  File.open(path) do |file|
144
152
  YAML.load(file)[::Rails.env]
145
153
  end
154
+ else
155
+ {}
146
156
  end
147
157
  end
148
158
  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
@@ -1,16 +1,83 @@
1
- require File.join(File.dirname(__FILE__), 'spec_helper')
1
+ require 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?).at_least(:once).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 'data_path' property when not set" do
24
+ config = Sunspot::Rails::Configuration.new
25
+ config.data_path.should == File.dirname(__FILE__) + '/mock_app/solr/data/test'
26
+ end
27
+
28
+ it "should handle the 'pid_path' property when not set" do
29
+ config = Sunspot::Rails::Configuration.new
30
+ config.pid_path.should == File.dirname(__FILE__) + '/mock_app/solr/pids/test'
31
+ end
32
+
33
+ it "should handle the 'solr_home' property when not set" do
34
+ config = Sunspot::Rails::Configuration.new
35
+ config.solr_home.should == nil
36
+ end
37
+
38
+ it "should handle the 'auto_commit_after_request' propery when not set" do
39
+ config = Sunspot::Rails::Configuration.new
40
+ config.auto_commit_after_request?.should == true
41
+ end
42
+ end
43
+
44
+ describe Sunspot::Rails::Configuration, "user settings" do
45
+ before(:each) do
46
+ ::Rails.stub!(:env => 'config_test')
47
+ end
48
+
49
+ it "should handle the 'hostname' property when set" do
50
+ config = Sunspot::Rails::Configuration.new
51
+ config.hostname.should == 'some.host'
52
+ end
53
+
54
+ it "should handle the 'port' property when set" do
55
+ config = Sunspot::Rails::Configuration.new
56
+ config.port.should == 1234
57
+ end
58
+
9
59
  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
60
+ config = Sunspot::Rails::Configuration.new
61
+ config.path.should == '/solr/idx'
62
+ end
63
+
64
+ it "should handle the 'data_path' property when set" do
65
+ config = Sunspot::Rails::Configuration.new
66
+ config.data_path.should == '/my_superior_path/data'
67
+ end
68
+
69
+ it "should handle the 'pid_path' property when set" do
70
+ config = Sunspot::Rails::Configuration.new
71
+ config.pid_path.should == '/my_superior_path/pids'
72
+ end
73
+
74
+ it "should handle the 'solr_home' property when set" do
75
+ config = Sunspot::Rails::Configuration.new
76
+ config.solr_home.should == '/my_superior_path'
77
+ end
78
+
79
+ it "should handle the 'auto_commit_after_request' propery when set" do
80
+ config = Sunspot::Rails::Configuration.new
81
+ config.auto_commit_after_request?.should == false
15
82
  end
16
83
  end
@@ -1,4 +1,4 @@
1
1
  test: &test
2
2
  :adapter: sqlite3
3
- :dbfile: vendor/plugins/sunspot_rails/spec/test.db
3
+ :dbfile: db/test.db
4
4
  development: *test
@@ -1,7 +1,7 @@
1
1
  # Be sure to restart your server when you modify this file
2
2
 
3
3
  # Specifies gem version of Rails to use when vendor/rails is not present
4
- RAILS_GEM_VERSION = ENV['RAILS_GEM_VERSION'] || '2.3.2' unless defined? RAILS_GEM_VERSION
4
+ RAILS_GEM_VERSION = ENV['RAILS_GEM_VERSION'] || '2.3.3' unless defined? RAILS_GEM_VERSION
5
5
 
6
6
  # Bootstrap the Rails environment, frameworks, and default configuration
7
7
  require File.join(File.dirname(__FILE__), 'boot')
@@ -19,6 +19,7 @@ Rails::Initializer.run do |config|
19
19
  # config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"
20
20
  # config.gem "sqlite3-ruby", :lib => "sqlite3"
21
21
  # config.gem "aws-s3", :lib => "aws/s3"
22
+ config.gem "qoobaa-sqlite3-ruby", :lib => 'sqlite3', :source => "http://gems.github.com" if RUBY_VERSION > '1.9'
22
23
 
23
24
  # Only load the plugins named here, in the order given (default is alphabetical).
24
25
  # :all can be used as a placeholder for all plugins not explicitly named
@@ -6,8 +6,12 @@ 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
+ data_path: /my_superior_path/data
15
+ pid_path: /my_superior_path/pids
16
+ solr_home: /my_superior_path
17
+ auto_commit_after_request: false
File without changes
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), 'spec_helper')
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
3
  describe 'searchable with lifecycle' do
4
4
  describe 'on create' do
data/spec/model_spec.rb CHANGED
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), 'spec_helper')
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
3
  describe 'ActiveRecord mixin' do
4
4
  describe 'index()' do
@@ -1,10 +1,30 @@
1
- require File.join(File.dirname(__FILE__), 'spec_helper')
1
+ require 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,12 +5,14 @@ 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 'ruby-debug' unless RUBY_VERSION =~ /1.9/
8
+ require 'rake'
9
+ require 'ruby-debug' unless RUBY_VERSION > '1.9'
10
+ require 'sunspot/rails/tasks'
9
11
 
10
12
  def load_schema
11
13
  stdout = $stdout
12
14
  $stdout = StringIO.new # suppress output while building the schema
13
- load File.join(File.dirname(__FILE__), 'schema.rb')
15
+ load File.join(ENV['RAILS_ROOT'], 'db', 'schema.rb')
14
16
  $stdout = stdout
15
17
  end
16
18
 
metadata CHANGED
@@ -1,18 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adamsalter-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
8
8
  - Peer Allan
9
9
  - Michael Moen
10
10
  - Benjamin Krause
11
+ - Adam Salter
12
+ - Brandon Keepers
11
13
  autorequire:
12
14
  bindir: bin
13
15
  cert_chain: []
14
16
 
15
- date: 2009-07-23 00:00:00 -07:00
17
+ date: 2009-09-05 00:00:00 -07:00
16
18
  default_executable:
17
19
  dependencies:
18
20
  - !ruby/object:Gem::Dependency
@@ -102,7 +104,10 @@ files:
102
104
  - VERSION.yml
103
105
  - dev_tasks/gemspec.rake
104
106
  - dev_tasks/rdoc.rake
107
+ - dev_tasks/release.rake
105
108
  - dev_tasks/todo.rake
109
+ - generators/sunspot/sunspot_generator.rb
110
+ - generators/sunspot/templates/sunspot.yml
106
111
  - install.rb
107
112
  - lib/sunspot/rails.rb
108
113
  - lib/sunspot/rails/adapters.rb
@@ -127,12 +132,12 @@ files:
127
132
  - spec/mock_app/config/initializers/session_store.rb
128
133
  - spec/mock_app/config/routes.rb
129
134
  - spec/mock_app/config/sunspot.yml
135
+ - spec/mock_app/db/schema.rb
130
136
  - spec/model_lifecycle_spec.rb
131
137
  - spec/model_spec.rb
132
138
  - spec/request_lifecycle_spec.rb
133
- - spec/schema.rb
134
139
  - spec/spec_helper.rb
135
- has_rdoc: true
140
+ has_rdoc: false
136
141
  homepage: http://github.com/outoftime/sunspot_rails
137
142
  post_install_message:
138
143
  rdoc_options:
@@ -153,28 +158,28 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
158
  version:
154
159
  requirements: []
155
160
 
156
- rubyforge_project:
161
+ rubyforge_project: sunspot
157
162
  rubygems_version: 1.2.0
158
163
  signing_key:
159
164
  specification_version: 3
160
165
  summary: Rails integration for the Sunspot Solr search library
161
166
  test_files:
162
- - spec/spec_helper.rb
163
167
  - spec/configuration_spec.rb
164
- - spec/model_lifecycle_spec.rb
165
- - spec/schema.rb
166
- - spec/model_spec.rb
167
- - spec/mock_app/app/controllers/posts_controller.rb
168
- - spec/mock_app/app/controllers/application_controller.rb
169
168
  - spec/mock_app/app/controllers/application.rb
169
+ - spec/mock_app/app/controllers/application_controller.rb
170
+ - spec/mock_app/app/controllers/posts_controller.rb
170
171
  - spec/mock_app/app/models/blog.rb
171
- - spec/mock_app/app/models/post_with_auto.rb
172
172
  - spec/mock_app/app/models/post.rb
173
+ - spec/mock_app/app/models/post_with_auto.rb
174
+ - spec/mock_app/config/boot.rb
173
175
  - spec/mock_app/config/environment.rb
174
- - spec/mock_app/config/initializers/session_store.rb
175
- - spec/mock_app/config/initializers/new_rails_defaults.rb
176
176
  - spec/mock_app/config/environments/development.rb
177
177
  - spec/mock_app/config/environments/test.rb
178
+ - spec/mock_app/config/initializers/new_rails_defaults.rb
179
+ - spec/mock_app/config/initializers/session_store.rb
178
180
  - spec/mock_app/config/routes.rb
179
- - spec/mock_app/config/boot.rb
181
+ - spec/mock_app/db/schema.rb
182
+ - spec/model_lifecycle_spec.rb
183
+ - spec/model_spec.rb
180
184
  - spec/request_lifecycle_spec.rb
185
+ - spec/spec_helper.rb