sunspot_rails 0.11.5 → 1.0.0
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/History.txt +12 -0
- data/README.rdoc +12 -18
- data/TODO +1 -1
- data/VERSION.yml +4 -0
- data/dev_tasks/gemspec.rake +13 -14
- data/lib/sunspot/rails/adapters.rb +2 -2
- data/lib/sunspot/rails/searchable.rb +49 -21
- data/lib/sunspot/rails/server.rb +143 -220
- data/lib/sunspot/rails/solr_logging.rb +54 -0
- data/lib/sunspot/rails/spec_helper.rb +19 -0
- data/lib/sunspot/rails/stub_session_proxy.rb +83 -0
- data/lib/sunspot/rails/tasks.rb +15 -13
- data/lib/sunspot/rails/version.rb +1 -1
- data/lib/sunspot/rails.rb +42 -6
- data/rails/init.rb +1 -1
- data/spec/mock_app/app/models/photo_post.rb +2 -0
- data/spec/mock_app/db/schema.rb +1 -0
- data/spec/mock_app/db/test.db +0 -1
- data/spec/model_lifecycle_spec.rb +14 -4
- data/spec/model_spec.rb +24 -4
- data/spec/schema.rb +1 -0
- data/spec/server_spec.rb +21 -109
- data/spec/spec_helper.rb +2 -6
- data/spec/stub_session_proxy_spec.rb +117 -0
- metadata +52 -51
- data/lib/sunspot/rails/session_proxy.rb +0 -76
- data/lib/sunspot/rails/util.rb +0 -30
- data/lib/sunspot/spec/extension.rb +0 -45
- data/spec/mock_app/app/models/photo_post_with_auto.rb +0 -2
- data/spec/sunspot_mocking_spec.rb +0 -22
- data/spec/util_spec.rb +0 -21
@@ -0,0 +1,117 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
require File.join(File.dirname(__FILE__), '..', 'lib', 'sunspot', 'rails', 'spec_helper')
|
3
|
+
|
4
|
+
describe 'specs with Sunspot stubbed' do
|
5
|
+
disconnect_sunspot
|
6
|
+
|
7
|
+
before :each do
|
8
|
+
@session = Sunspot.session.original_session
|
9
|
+
@post = Post.create!
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should not send index to session' do
|
13
|
+
@session.should_not_receive(:index)
|
14
|
+
@post.index
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should not send index! to session' do
|
18
|
+
@session.should_not_receive(:index!)
|
19
|
+
@post.index!
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should not send commit to session' do
|
23
|
+
@session.should_not_receive(:commit)
|
24
|
+
Sunspot.commit
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should not send remove to session' do
|
28
|
+
@session.should_not_receive(:remove)
|
29
|
+
@post.remove_from_index
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should not send remove! to session' do
|
33
|
+
@session.should_not_receive(:remove)
|
34
|
+
@post.remove_from_index!
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should not send remove_by_id to session' do
|
38
|
+
@session.should_not_receive(:remove_by_id)
|
39
|
+
Sunspot.remove_by_id(Post, 1)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should not send remove_by_id! to session' do
|
43
|
+
@session.should_not_receive(:remove_by_id!)
|
44
|
+
Sunspot.remove_by_id!(Post, 1)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should not send remove_all to session' do
|
48
|
+
@session.should_not_receive(:remove_all)
|
49
|
+
Post.remove_all_from_index
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should not send remove_all! to session' do
|
53
|
+
@session.should_not_receive(:remove_all!)
|
54
|
+
Post.remove_all_from_index!
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should return false for dirty?' do
|
58
|
+
@session.should_not_receive(:dirty?)
|
59
|
+
Sunspot.dirty?.should == false
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should not send commit_if_dirty to session' do
|
63
|
+
@session.should_not_receive(:commit_if_dirty)
|
64
|
+
Sunspot.commit_if_dirty
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should return false for delete_dirty?' do
|
68
|
+
@session.should_not_receive(:delete_dirty?)
|
69
|
+
Sunspot.delete_dirty?.should == false
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'should not send commit_if_delete_dirty to session' do
|
73
|
+
@session.should_not_receive(:commit_if_delete_dirty)
|
74
|
+
Sunspot.commit_if_delete_dirty
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'should not execute a search when #search called' do
|
78
|
+
@session.should_not_receive(:search)
|
79
|
+
Post.search
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'should not execute a search when #search called' do
|
83
|
+
@session.should_not_receive(:search)
|
84
|
+
Post.search
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'should return a new search' do
|
88
|
+
@session.should_not_receive(:new_search)
|
89
|
+
Sunspot.new_search(Post).should respond_to(:execute)
|
90
|
+
end
|
91
|
+
|
92
|
+
describe 'stub search' do
|
93
|
+
before :each do
|
94
|
+
@search = Post.search
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'should return empty results' do
|
98
|
+
@search.results.should == []
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'should return empty hits' do
|
102
|
+
@search.hits.should == []
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'should return zero total' do
|
106
|
+
@search.total.should == 0
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'should return nil for a given facet' do
|
110
|
+
@search.facet(:category_id).should be_nil
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'should return nil for a given dynamic facet' do
|
114
|
+
@search.dynamic_facet(:custom).should be_nil
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
metadata
CHANGED
@@ -1,83 +1,82 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sunspot_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
version: 1.0.0
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Mat Brown
|
8
13
|
- Peer Allan
|
9
14
|
- Michael Moen
|
10
15
|
- Benjamin Krause
|
16
|
+
- Adam Salter
|
17
|
+
- Brandon Keepers
|
18
|
+
- Paul Canavese
|
11
19
|
autorequire:
|
12
20
|
bindir: bin
|
13
21
|
cert_chain: []
|
14
22
|
|
15
|
-
date:
|
23
|
+
date: 2010-03-04 00:00:00 -05:00
|
16
24
|
default_executable:
|
17
25
|
dependencies:
|
18
26
|
- !ruby/object:Gem::Dependency
|
19
27
|
name: escape
|
20
|
-
|
21
|
-
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
prerelease: false
|
29
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
30
|
requirements:
|
24
31
|
- - ">="
|
25
32
|
- !ruby/object:Gem::Version
|
33
|
+
segments:
|
34
|
+
- 0
|
35
|
+
- 0
|
36
|
+
- 4
|
26
37
|
version: 0.0.4
|
27
|
-
|
38
|
+
type: :runtime
|
39
|
+
version_requirements: *id001
|
28
40
|
- !ruby/object:Gem::Dependency
|
29
41
|
name: sunspot
|
30
|
-
|
31
|
-
|
32
|
-
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
prerelease: false
|
43
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
33
44
|
requirements:
|
34
|
-
- - "
|
35
|
-
- !ruby/object:Gem::Version
|
36
|
-
version: 0.10.6
|
37
|
-
- - <=
|
45
|
+
- - "="
|
38
46
|
- !ruby/object:Gem::Version
|
39
|
-
|
40
|
-
|
47
|
+
segments:
|
48
|
+
- 1
|
49
|
+
- 0
|
50
|
+
- 0
|
51
|
+
version: 1.0.0
|
52
|
+
type: :runtime
|
53
|
+
version_requirements: *id002
|
41
54
|
- !ruby/object:Gem::Dependency
|
42
55
|
name: rspec
|
43
|
-
|
44
|
-
|
45
|
-
version_requirements: !ruby/object:Gem::Requirement
|
56
|
+
prerelease: false
|
57
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
46
58
|
requirements:
|
47
59
|
- - ~>
|
48
60
|
- !ruby/object:Gem::Version
|
61
|
+
segments:
|
62
|
+
- 1
|
63
|
+
- 2
|
49
64
|
version: "1.2"
|
50
|
-
|
65
|
+
type: :development
|
66
|
+
version_requirements: *id003
|
51
67
|
- !ruby/object:Gem::Dependency
|
52
68
|
name: rspec-rails
|
53
|
-
|
54
|
-
|
55
|
-
version_requirements: !ruby/object:Gem::Requirement
|
69
|
+
prerelease: false
|
70
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
56
71
|
requirements:
|
57
72
|
- - ~>
|
58
73
|
- !ruby/object:Gem::Version
|
74
|
+
segments:
|
75
|
+
- 1
|
76
|
+
- 2
|
59
77
|
version: "1.2"
|
60
|
-
version:
|
61
|
-
- !ruby/object:Gem::Dependency
|
62
|
-
name: ruby-debug
|
63
78
|
type: :development
|
64
|
-
|
65
|
-
version_requirements: !ruby/object:Gem::Requirement
|
66
|
-
requirements:
|
67
|
-
- - ~>
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: "0.10"
|
70
|
-
version:
|
71
|
-
- !ruby/object:Gem::Dependency
|
72
|
-
name: technicalpickles-jeweler
|
73
|
-
type: :development
|
74
|
-
version_requirement:
|
75
|
-
version_requirements: !ruby/object:Gem::Requirement
|
76
|
-
requirements:
|
77
|
-
- - ~>
|
78
|
-
- !ruby/object:Gem::Version
|
79
|
-
version: "1.0"
|
80
|
-
version:
|
79
|
+
version_requirements: *id004
|
81
80
|
description: |
|
82
81
|
Sunspot::Rails is an extension to the Sunspot library for Solr search.
|
83
82
|
Sunspot::Rails adds integration between Sunspot and ActiveRecord, including
|
@@ -99,17 +98,18 @@ files:
|
|
99
98
|
- README.rdoc
|
100
99
|
- TODO
|
101
100
|
- History.txt
|
101
|
+
- VERSION.yml
|
102
102
|
- LICENSE
|
103
|
-
- lib/sunspot/
|
103
|
+
- lib/sunspot/rails/spec_helper.rb
|
104
104
|
- lib/sunspot/rails/searchable.rb
|
105
105
|
- lib/sunspot/rails/version.rb
|
106
|
+
- lib/sunspot/rails/stub_session_proxy.rb
|
106
107
|
- lib/sunspot/rails/adapters.rb
|
107
108
|
- lib/sunspot/rails/configuration.rb
|
108
109
|
- lib/sunspot/rails/server.rb
|
109
110
|
- lib/sunspot/rails/tasks.rb
|
110
111
|
- lib/sunspot/rails/request_lifecycle.rb
|
111
|
-
- lib/sunspot/rails/
|
112
|
-
- lib/sunspot/rails/session_proxy.rb
|
112
|
+
- lib/sunspot/rails/solr_logging.rb
|
113
113
|
- lib/sunspot/rails.rb
|
114
114
|
- dev_tasks/gemspec.rake
|
115
115
|
- dev_tasks/todo.rake
|
@@ -121,19 +121,18 @@ files:
|
|
121
121
|
- rails/init.rb
|
122
122
|
- spec/spec_helper.rb
|
123
123
|
- spec/session_spec.rb
|
124
|
+
- spec/stub_session_proxy_spec.rb
|
124
125
|
- spec/server_spec.rb
|
125
126
|
- spec/configuration_spec.rb
|
126
127
|
- spec/model_lifecycle_spec.rb
|
127
128
|
- spec/schema.rb
|
128
129
|
- spec/model_spec.rb
|
129
|
-
- spec/sunspot_mocking_spec.rb
|
130
|
-
- spec/util_spec.rb
|
131
130
|
- spec/request_lifecycle_spec.rb
|
132
131
|
- spec/mock_app/app/controllers/posts_controller.rb
|
133
132
|
- spec/mock_app/app/controllers/application_controller.rb
|
134
133
|
- spec/mock_app/app/controllers/application.rb
|
134
|
+
- spec/mock_app/app/models/photo_post.rb
|
135
135
|
- spec/mock_app/app/models/blog.rb
|
136
|
-
- spec/mock_app/app/models/photo_post_with_auto.rb
|
137
136
|
- spec/mock_app/app/models/post_with_auto.rb
|
138
137
|
- spec/mock_app/app/models/author.rb
|
139
138
|
- spec/mock_app/app/models/post.rb
|
@@ -161,18 +160,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
161
160
|
requirements:
|
162
161
|
- - ">="
|
163
162
|
- !ruby/object:Gem::Version
|
163
|
+
segments:
|
164
|
+
- 0
|
164
165
|
version: "0"
|
165
|
-
version:
|
166
166
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
167
|
requirements:
|
168
168
|
- - ">="
|
169
169
|
- !ruby/object:Gem::Version
|
170
|
+
segments:
|
171
|
+
- 0
|
170
172
|
version: "0"
|
171
|
-
version:
|
172
173
|
requirements: []
|
173
174
|
|
174
175
|
rubyforge_project: sunspot
|
175
|
-
rubygems_version: 1.3.
|
176
|
+
rubygems_version: 1.3.6
|
176
177
|
signing_key:
|
177
178
|
specification_version: 3
|
178
179
|
summary: Rails integration for the Sunspot Solr search library
|
@@ -1,76 +0,0 @@
|
|
1
|
-
module Sunspot
|
2
|
-
module Rails
|
3
|
-
class SessionProxy
|
4
|
-
extend MonitorMixin
|
5
|
-
|
6
|
-
class <<self
|
7
|
-
def instance
|
8
|
-
synchronize do
|
9
|
-
@instance ||=
|
10
|
-
begin
|
11
|
-
configuration = Sunspot::Rails::Configuration.new
|
12
|
-
if configuration.has_master?
|
13
|
-
new(configuration)
|
14
|
-
else
|
15
|
-
session = Sunspot::Session.new
|
16
|
-
session.config.solr.url = URI::HTTP.build(
|
17
|
-
:host => configuration.hostname,
|
18
|
-
:port => configuration.port,
|
19
|
-
:path => configuration.path
|
20
|
-
).to_s
|
21
|
-
session
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def reset!
|
28
|
-
synchronize do
|
29
|
-
@instance = nil
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
private :new
|
34
|
-
end
|
35
|
-
|
36
|
-
delegate :new_search, :search, :to => :read_session
|
37
|
-
delegate :index, :index!, :commit, :remove, :remove!, :remove_by_id,
|
38
|
-
:remove_by_id!, :remove_all, :remove_all!, :dirty?, :commit_if_dirty, :batch,
|
39
|
-
:to => :write_session
|
40
|
-
|
41
|
-
def initialize(configuration)
|
42
|
-
@configuration = configuration
|
43
|
-
end
|
44
|
-
|
45
|
-
private
|
46
|
-
|
47
|
-
def read_session
|
48
|
-
Thread.current[:sunspot_rails_read_session] ||=
|
49
|
-
begin
|
50
|
-
session = Sunspot::Session.new
|
51
|
-
session.config.solr.url = URI::HTTP.build(
|
52
|
-
:host => @configuration.hostname,
|
53
|
-
:port => @configuration.port,
|
54
|
-
:path => @configuration.path
|
55
|
-
).to_s
|
56
|
-
session
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def write_session
|
61
|
-
Thread.current[:sunspot_rails_write_session] ||=
|
62
|
-
if @configuration.has_master?
|
63
|
-
master_session = Sunspot::Session.new
|
64
|
-
master_session.config.solr.url = URI::HTTP.build(
|
65
|
-
:host => configuration.master_hostname,
|
66
|
-
:port => configuration.master_port,
|
67
|
-
:path => configuration.master_path
|
68
|
-
).to_s
|
69
|
-
master_session
|
70
|
-
else
|
71
|
-
read_session
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
data/lib/sunspot/rails/util.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'escape'
|
2
|
-
|
3
|
-
module Sunspot #:nodoc:
|
4
|
-
module Rails #:nodoc:
|
5
|
-
class Util
|
6
|
-
class << self
|
7
|
-
def sunspot_options
|
8
|
-
@sunspot_options ||= {}
|
9
|
-
end
|
10
|
-
|
11
|
-
def index_relevant_attribute_changed?( object )
|
12
|
-
class_key = object.class.to_s.underscore.to_sym
|
13
|
-
ignore_attributes = sunspot_options_for(object.class)[:ignore_attribute_changes_of] || []
|
14
|
-
!(object.changes.symbolize_keys.keys - ignore_attributes).blank?
|
15
|
-
end
|
16
|
-
|
17
|
-
private
|
18
|
-
|
19
|
-
def sunspot_options_for(clazz)
|
20
|
-
class_key = clazz.to_s.underscore.to_sym
|
21
|
-
if options = sunspot_options[class_key]
|
22
|
-
options
|
23
|
-
elsif superclass = clazz.superclass
|
24
|
-
sunspot_options_for(superclass)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
module Sunspot
|
2
|
-
module Rails
|
3
|
-
module Spec
|
4
|
-
module Extension
|
5
|
-
def self.included(base)
|
6
|
-
base.class_eval do
|
7
|
-
class_inheritable_accessor :sunspot_integration
|
8
|
-
extend ClassMethods
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def integrate_sunspot?
|
13
|
-
self.class.integrate_sunspot?
|
14
|
-
end
|
15
|
-
|
16
|
-
def mock_sunspot
|
17
|
-
[ :index, :remove_from_index ].each do |method_name|
|
18
|
-
Sunspot.stub!(method_name)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
module ClassMethods
|
25
|
-
def integrate_sunspot( integrate = true )
|
26
|
-
self.sunspot_integration = integrate
|
27
|
-
end
|
28
|
-
|
29
|
-
def integrate_sunspot?
|
30
|
-
!!self.sunspot_integration
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
module ActiveSupport
|
38
|
-
class TestCase
|
39
|
-
before(:each) do
|
40
|
-
mock_sunspot unless integrate_sunspot?
|
41
|
-
end
|
42
|
-
|
43
|
-
include Sunspot::Rails::Spec::Extension
|
44
|
-
end
|
45
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
-
|
3
|
-
describe 'Sunspot Spec Integration - integrate sunspot' do
|
4
|
-
integrate_sunspot
|
5
|
-
|
6
|
-
it "should call sunspot" do
|
7
|
-
Sunspot::Rails.reset
|
8
|
-
@post = PostWithAuto.create!
|
9
|
-
Sunspot.commit
|
10
|
-
PostWithAuto.search.results.should == [@post]
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
describe 'Sunspot Spec Integration - mock sunspot' do
|
15
|
-
it "should call sunspot" do
|
16
|
-
Sunspot.remove_all
|
17
|
-
Sunspot.commit
|
18
|
-
@post = PostWithAuto.create!
|
19
|
-
Sunspot.commit
|
20
|
-
PostWithAuto.search.results.should_not include(@post)
|
21
|
-
end
|
22
|
-
end
|
data/spec/util_spec.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
-
|
3
|
-
describe 'ActiveRecord mixin and instance methods' do
|
4
|
-
it "should know about relevant index attributes - relevant attribute changed" do
|
5
|
-
@post = PostWithAuto.new
|
6
|
-
@post.should_receive(:changes).and_return(:title => 'new title')
|
7
|
-
Sunspot::Rails::Util.index_relevant_attribute_changed?(@post).should == true
|
8
|
-
end
|
9
|
-
|
10
|
-
it "should know about relevant index attributes - no relevant attribute changed" do
|
11
|
-
@post = PostWithAuto.new
|
12
|
-
@post.should_receive(:changes).and_return(:updated_at => Date.tomorrow)
|
13
|
-
Sunspot::Rails::Util.index_relevant_attribute_changed?(@post).should == false
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should know about relevant index attributes with subclasses" do
|
17
|
-
@post = PhotoPostWithAuto.new
|
18
|
-
@post.should_receive(:changes).and_return(:title => 'new_title')
|
19
|
-
Sunspot::Rails::Util.index_relevant_attribute_changed?(@post).should == true
|
20
|
-
end
|
21
|
-
end
|