outoftime-sunspot_rails 0.9.4
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/MIT-LICENSE +20 -0
- data/README.rdoc +246 -0
- data/Rakefile +19 -0
- data/VERSION.yml +4 -0
- data/dev_tasks/gemspec.rake +20 -0
- data/dev_tasks/rdoc.rake +7 -0
- data/dev_tasks/todo.rake +4 -0
- data/install.rb +1 -0
- data/lib/sunspot/rails/adapters.rb +54 -0
- data/lib/sunspot/rails/configuration.rb +73 -0
- data/lib/sunspot/rails/request_lifecycle.rb +18 -0
- data/lib/sunspot/rails/searchable.rb +256 -0
- data/lib/sunspot/rails.rb +11 -0
- data/spec/mock_app/app/controllers/application.rb +10 -0
- data/spec/mock_app/app/controllers/application_controller.rb +10 -0
- data/spec/mock_app/app/controllers/posts_controller.rb +6 -0
- data/spec/mock_app/app/models/blog.rb +2 -0
- data/spec/mock_app/app/models/post.rb +5 -0
- data/spec/mock_app/app/models/post_with_auto.rb +9 -0
- data/spec/mock_app/config/boot.rb +110 -0
- data/spec/mock_app/config/database.yml +4 -0
- data/spec/mock_app/config/environment.rb +41 -0
- data/spec/mock_app/config/environments/development.rb +27 -0
- data/spec/mock_app/config/environments/test.rb +27 -0
- data/spec/mock_app/config/initializers/new_rails_defaults.rb +19 -0
- data/spec/mock_app/config/initializers/session_store.rb +15 -0
- data/spec/mock_app/config/routes.rb +43 -0
- data/spec/mock_app/config/sunspot.yml +8 -0
- data/spec/model_lifecycle_spec.rb +38 -0
- data/spec/model_spec.rb +181 -0
- data/spec/request_lifecycle_spec.rb +10 -0
- data/spec/schema.rb +14 -0
- data/spec/spec_helper.rb +23 -0
- data/tasks/sunspot.rake +23 -0
- data/tasks/sunspot_rails_tasks.rake +4 -0
- metadata +173 -0
data/spec/model_spec.rb
ADDED
@@ -0,0 +1,181 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
describe 'ActiveRecord mixin' do
|
4
|
+
describe 'index()' do
|
5
|
+
before :each do
|
6
|
+
@post = Post.create!
|
7
|
+
@post.index
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should not commit the model' do
|
11
|
+
Post.search.results.should be_empty
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should index the model' do
|
15
|
+
Sunspot.commit
|
16
|
+
Post.search.results.should == [@post]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe 'index!()' do
|
21
|
+
before :each do
|
22
|
+
@post = Post.create!
|
23
|
+
@post.index!
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should immediately index and commit' do
|
27
|
+
Post.search.results.should == [@post]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe 'remove_from_index()' do
|
32
|
+
before :each do
|
33
|
+
@post = Post.create!
|
34
|
+
@post.index!
|
35
|
+
@post.remove_from_index
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should not commit immediately' do
|
39
|
+
Post.search.results.should == [@post]
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should remove the model from the index' do
|
43
|
+
Sunspot.commit
|
44
|
+
Post.search.results.should be_empty
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe 'remove_from_index!()' do
|
49
|
+
before :each do
|
50
|
+
@post = Post.create!
|
51
|
+
@post.index!
|
52
|
+
@post.remove_from_index!
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should immediately remove the model and commit' do
|
56
|
+
Post.search.results.should be_empty
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe 'remove_all_from_index' do
|
61
|
+
before :each do
|
62
|
+
@posts = Array.new(10) { Post.create! }.each { |post| Sunspot.index(post) }
|
63
|
+
Sunspot.commit
|
64
|
+
Post.remove_all_from_index
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should not commit immediately' do
|
68
|
+
Post.search.results.to_set.should == @posts.to_set
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should remove all instances from the index' do
|
72
|
+
Sunspot.commit
|
73
|
+
Post.search.results.should be_empty
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe 'remove_all_from_index!' do
|
78
|
+
before :each do
|
79
|
+
Array.new(10) { Post.create! }.each { |post| Sunspot.index(post) }
|
80
|
+
Sunspot.commit
|
81
|
+
Post.remove_all_from_index!
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'should remove all instances from the index and commit immediately' do
|
85
|
+
Post.search.results.should be_empty
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe 'search()' do
|
90
|
+
before :each do
|
91
|
+
@post = Post.create!(:title => 'Test Post')
|
92
|
+
@post.index!
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'should return results specified by search' do
|
96
|
+
Post.search do
|
97
|
+
with :title, 'Test Post'
|
98
|
+
end.results.should == [@post]
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'should not return results excluded by search' do
|
102
|
+
Post.search do
|
103
|
+
with :title, 'Bogus Post'
|
104
|
+
end.results.should be_empty
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe 'search_ids()' do
|
109
|
+
before :each do
|
110
|
+
@posts = Array.new(2) { Post.create! }.each { |post| post.index }
|
111
|
+
Sunspot.commit
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'should return IDs' do
|
115
|
+
Post.search_ids.to_set.should == @posts.map { |post| post.id }.to_set
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
describe 'searchable?()' do
|
120
|
+
it 'should not be true for models that have not been configured for search' do
|
121
|
+
Blog.should_not be_searchable
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'should be true for models that have been configured for search' do
|
125
|
+
Post.should be_searchable
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
describe 'index_orphans()' do
|
130
|
+
before :each do
|
131
|
+
@posts = Array.new(2) { Post.create }.each { |post| post.index }
|
132
|
+
Sunspot.commit
|
133
|
+
@posts.first.destroy
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'should return IDs of objects that are in the index but not the database' do
|
137
|
+
Post.index_orphans.should == [@posts.first.id]
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
describe 'clean_index_orphans()' do
|
142
|
+
before :each do
|
143
|
+
@posts = Array.new(2) { Post.create }.each { |post| post.index }
|
144
|
+
Sunspot.commit
|
145
|
+
@posts.first.destroy
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'should remove orphans from the index' do
|
149
|
+
Post.clean_index_orphans
|
150
|
+
Sunspot.commit
|
151
|
+
Post.search.results.should == [@posts.last]
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
describe 'reindex()' do
|
156
|
+
before :each do
|
157
|
+
@posts = Array.new(2) { Post.create }
|
158
|
+
end
|
159
|
+
|
160
|
+
it 'should index all instances' do
|
161
|
+
Post.reindex
|
162
|
+
Sunspot.commit
|
163
|
+
Post.search.results.to_set.should == @posts.to_set
|
164
|
+
end
|
165
|
+
|
166
|
+
it 'should index with a batch size' do
|
167
|
+
Post.reindex(1)
|
168
|
+
Sunspot.commit
|
169
|
+
Post.search.results.to_set.should == @posts.to_set
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'should remove all currently indexed instances' do
|
173
|
+
old_post = Post.create!
|
174
|
+
old_post.index!
|
175
|
+
old_post.destroy
|
176
|
+
Post.reindex
|
177
|
+
Sunspot.commit
|
178
|
+
Post.search.results.to_set.should == @posts.to_set
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
describe 'request lifecycle', :type => :controller do
|
4
|
+
controller_name :posts
|
5
|
+
|
6
|
+
it 'should automatically commit after each action' do
|
7
|
+
post :create, :post => { :title => 'Test 1' }
|
8
|
+
PostWithAuto.search { with :title, 'Test 1' }.results.should_not be_empty
|
9
|
+
end
|
10
|
+
end
|
data/spec/schema.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
ActiveRecord::Schema.define(:version => 0) do
|
2
|
+
create_table :posts, :force => true do |t|
|
3
|
+
t.string :title
|
4
|
+
t.text :body
|
5
|
+
t.references :blog
|
6
|
+
t.timestamps
|
7
|
+
end
|
8
|
+
|
9
|
+
create_table :blogs, :force => true do |t|
|
10
|
+
t.string :name
|
11
|
+
t.string :subdomain
|
12
|
+
t.timestamps
|
13
|
+
end
|
14
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
ENV['RAILS_ENV'] = 'test'
|
2
|
+
ENV['RAILS_ROOT'] ||= File.join(File.dirname(__FILE__), 'mock_app')
|
3
|
+
|
4
|
+
require File.expand_path(File.join(ENV['RAILS_ROOT'], 'config', 'environment.rb'))
|
5
|
+
|
6
|
+
require 'spec'
|
7
|
+
require 'spec/rails'
|
8
|
+
require 'ruby-debug'
|
9
|
+
|
10
|
+
def load_schema
|
11
|
+
stdout = $stdout
|
12
|
+
$stdout = StringIO.new # suppress output while building the schema
|
13
|
+
load File.join(File.dirname(__FILE__), 'schema.rb')
|
14
|
+
$stdout = stdout
|
15
|
+
end
|
16
|
+
|
17
|
+
Spec::Runner.configure do |config|
|
18
|
+
config.before(:each) do
|
19
|
+
Sunspot.remove_all
|
20
|
+
Sunspot.commit
|
21
|
+
load_schema
|
22
|
+
end
|
23
|
+
end
|
data/tasks/sunspot.rake
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'escape'
|
2
|
+
|
3
|
+
namespace :sunspot do
|
4
|
+
namespace :solr do
|
5
|
+
desc 'Start the Solr instance'
|
6
|
+
task :start => :environment do
|
7
|
+
data_path = File.join(::Rails.root, 'solr', 'data', ::Rails.env)
|
8
|
+
pid_path = File.join(::Rails.root, 'solr', 'pids', ::Rails.env)
|
9
|
+
[data_path, pid_path].each { |path| FileUtils.mkdir_p(path) }
|
10
|
+
port = Sunspot::Rails.configuration.port
|
11
|
+
FileUtils.cd(File.join(pid_path)) do
|
12
|
+
system(Escape.shell_command(['sunspot-solr', 'start', '--', '-p', port.to_s, '-d', data_path]))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
desc 'Stop the Solr instance'
|
17
|
+
task :stop => :environment do
|
18
|
+
FileUtils.cd(File.join(::Rails.root, 'solr', 'pids', ::Rails.env)) do
|
19
|
+
system(Escape.shell_command(['sunspot-solr', 'stop']))
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,173 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: outoftime-sunspot_rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mat Brown
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-05-21 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rails
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ~>
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "2.1"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: escape
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.0.4
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: outoftime-sunspot
|
37
|
+
type: :runtime
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.7.2
|
44
|
+
version:
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: rspec
|
47
|
+
type: :development
|
48
|
+
version_requirement:
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "1.2"
|
54
|
+
version:
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec-rails
|
57
|
+
type: :development
|
58
|
+
version_requirement:
|
59
|
+
version_requirements: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ~>
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: "1.2"
|
64
|
+
version:
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: ruby-debug
|
67
|
+
type: :development
|
68
|
+
version_requirement:
|
69
|
+
version_requirements: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ~>
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: "0.10"
|
74
|
+
version:
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: technicalpickles-jeweler
|
77
|
+
type: :development
|
78
|
+
version_requirement:
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ~>
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: "1.0"
|
84
|
+
version:
|
85
|
+
description: Rails integration for the Sunspot Solr search library
|
86
|
+
email: mat@patch.com
|
87
|
+
executables: []
|
88
|
+
|
89
|
+
extensions: []
|
90
|
+
|
91
|
+
extra_rdoc_files:
|
92
|
+
- README.rdoc
|
93
|
+
files:
|
94
|
+
- MIT-LICENSE
|
95
|
+
- README.rdoc
|
96
|
+
- Rakefile
|
97
|
+
- VERSION.yml
|
98
|
+
- dev_tasks/gemspec.rake
|
99
|
+
- dev_tasks/rdoc.rake
|
100
|
+
- dev_tasks/todo.rake
|
101
|
+
- install.rb
|
102
|
+
- lib/sunspot/rails.rb
|
103
|
+
- lib/sunspot/rails/adapters.rb
|
104
|
+
- lib/sunspot/rails/configuration.rb
|
105
|
+
- lib/sunspot/rails/request_lifecycle.rb
|
106
|
+
- lib/sunspot/rails/searchable.rb
|
107
|
+
- spec/mock_app/app/controllers/application.rb
|
108
|
+
- spec/mock_app/app/controllers/application_controller.rb
|
109
|
+
- spec/mock_app/app/controllers/posts_controller.rb
|
110
|
+
- spec/mock_app/app/models/blog.rb
|
111
|
+
- spec/mock_app/app/models/post.rb
|
112
|
+
- spec/mock_app/app/models/post_with_auto.rb
|
113
|
+
- spec/mock_app/config/boot.rb
|
114
|
+
- spec/mock_app/config/database.yml
|
115
|
+
- spec/mock_app/config/environment.rb
|
116
|
+
- spec/mock_app/config/environments/development.rb
|
117
|
+
- spec/mock_app/config/environments/test.rb
|
118
|
+
- spec/mock_app/config/initializers/new_rails_defaults.rb
|
119
|
+
- spec/mock_app/config/initializers/session_store.rb
|
120
|
+
- spec/mock_app/config/routes.rb
|
121
|
+
- spec/mock_app/config/sunspot.yml
|
122
|
+
- spec/model_lifecycle_spec.rb
|
123
|
+
- spec/model_spec.rb
|
124
|
+
- spec/request_lifecycle_spec.rb
|
125
|
+
- spec/schema.rb
|
126
|
+
- spec/spec_helper.rb
|
127
|
+
- tasks/sunspot.rake
|
128
|
+
- tasks/sunspot_rails_tasks.rake
|
129
|
+
has_rdoc: true
|
130
|
+
homepage: http://github.com/outoftime/sunspot_rails
|
131
|
+
post_install_message:
|
132
|
+
rdoc_options:
|
133
|
+
- --charset=UTF-8
|
134
|
+
require_paths:
|
135
|
+
- lib
|
136
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: "0"
|
141
|
+
version:
|
142
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: "0"
|
147
|
+
version:
|
148
|
+
requirements: []
|
149
|
+
|
150
|
+
rubyforge_project:
|
151
|
+
rubygems_version: 1.2.0
|
152
|
+
signing_key:
|
153
|
+
specification_version: 2
|
154
|
+
summary: Rails integration for the Sunspot Solr search library
|
155
|
+
test_files:
|
156
|
+
- spec/mock_app/app/controllers/application.rb
|
157
|
+
- spec/mock_app/app/controllers/application_controller.rb
|
158
|
+
- spec/mock_app/app/controllers/posts_controller.rb
|
159
|
+
- spec/mock_app/app/models/blog.rb
|
160
|
+
- spec/mock_app/app/models/post.rb
|
161
|
+
- spec/mock_app/app/models/post_with_auto.rb
|
162
|
+
- spec/mock_app/config/boot.rb
|
163
|
+
- spec/mock_app/config/environment.rb
|
164
|
+
- spec/mock_app/config/environments/development.rb
|
165
|
+
- spec/mock_app/config/environments/test.rb
|
166
|
+
- spec/mock_app/config/initializers/new_rails_defaults.rb
|
167
|
+
- spec/mock_app/config/initializers/session_store.rb
|
168
|
+
- spec/mock_app/config/routes.rb
|
169
|
+
- spec/model_lifecycle_spec.rb
|
170
|
+
- spec/model_spec.rb
|
171
|
+
- spec/request_lifecycle_spec.rb
|
172
|
+
- spec/schema.rb
|
173
|
+
- spec/spec_helper.rb
|