nxa-sunspot_rails 0.11.3

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.
Files changed (53) hide show
  1. data/History.txt +15 -0
  2. data/LICENSE +18 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.rdoc +260 -0
  5. data/Rakefile +27 -0
  6. data/TODO +8 -0
  7. data/VERSION.yml +4 -0
  8. data/dev_tasks/gemspec.rake +55 -0
  9. data/dev_tasks/rdoc.rake +7 -0
  10. data/dev_tasks/release.rake +4 -0
  11. data/dev_tasks/todo.rake +4 -0
  12. data/generators/sunspot/sunspot_generator.rb +9 -0
  13. data/generators/sunspot/templates/sunspot.yml +18 -0
  14. data/install.rb +1 -0
  15. data/lib/sunspot/rails/adapters.rb +79 -0
  16. data/lib/sunspot/rails/configuration.rb +248 -0
  17. data/lib/sunspot/rails/request_lifecycle.rb +22 -0
  18. data/lib/sunspot/rails/searchable.rb +309 -0
  19. data/lib/sunspot/rails/server.rb +229 -0
  20. data/lib/sunspot/rails/session_proxy.rb +62 -0
  21. data/lib/sunspot/rails/tasks.rb +35 -0
  22. data/lib/sunspot/rails/util.rb +20 -0
  23. data/lib/sunspot/rails.rb +22 -0
  24. data/lib/sunspot/spec/extension.rb +45 -0
  25. data/rails/init.rb +7 -0
  26. data/spec/configuration_spec.rb +102 -0
  27. data/spec/mock_app/app/controllers/application.rb +10 -0
  28. data/spec/mock_app/app/controllers/application_controller.rb +10 -0
  29. data/spec/mock_app/app/controllers/posts_controller.rb +6 -0
  30. data/spec/mock_app/app/models/author.rb +8 -0
  31. data/spec/mock_app/app/models/blog.rb +2 -0
  32. data/spec/mock_app/app/models/post.rb +5 -0
  33. data/spec/mock_app/app/models/post_with_auto.rb +9 -0
  34. data/spec/mock_app/config/boot.rb +110 -0
  35. data/spec/mock_app/config/database.yml +4 -0
  36. data/spec/mock_app/config/environment.rb +42 -0
  37. data/spec/mock_app/config/environments/development.rb +27 -0
  38. data/spec/mock_app/config/environments/test.rb +27 -0
  39. data/spec/mock_app/config/initializers/new_rails_defaults.rb +19 -0
  40. data/spec/mock_app/config/initializers/session_store.rb +15 -0
  41. data/spec/mock_app/config/routes.rb +43 -0
  42. data/spec/mock_app/config/sunspot.yml +19 -0
  43. data/spec/mock_app/db/schema.rb +20 -0
  44. data/spec/model_lifecycle_spec.rb +53 -0
  45. data/spec/model_spec.rb +314 -0
  46. data/spec/request_lifecycle_spec.rb +52 -0
  47. data/spec/schema.rb +20 -0
  48. data/spec/server_spec.rb +124 -0
  49. data/spec/session_spec.rb +24 -0
  50. data/spec/spec_helper.rb +51 -0
  51. data/spec/sunspot_mocking_spec.rb +22 -0
  52. data/spec/util_spec.rb +15 -0
  53. metadata +203 -0
@@ -0,0 +1,124 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe Sunspot::Rails::Server do
4
+ before(:each) do
5
+ @sunspot_configuration = Sunspot::Rails::Configuration.new
6
+ end
7
+
8
+ describe "rake task commands" do
9
+ before(:each) do
10
+ Sunspot::Rails::Server.should_receive(:pid_path).and_return('/tmp')
11
+ end
12
+
13
+ it "should generate and execute the start command" do
14
+ Sunspot::Rails::Server.should_receive(:start_command).and_return('sunspot-start')
15
+ Sunspot::Rails::Server.should_respond_to_and_receive(:bootstrap_neccessary?).and_return(false)
16
+ Kernel.should_receive(:system).with('sunspot-start').and_return(true)
17
+ Sunspot::Rails::Server.start.should == true
18
+ end
19
+
20
+ it "should generate and execute the stop command" do
21
+ Sunspot::Rails::Server.should_receive(:stop_command).and_return('sunspot-stop')
22
+ Sunspot::Rails::Server.should_not_receive(:bootstrap_neccessary?)
23
+ Kernel.should_receive(:system).with('sunspot-stop').and_return(true)
24
+ Sunspot::Rails::Server.stop.should == true
25
+ end
26
+
27
+ it "should generate and execute the run command" do
28
+ Sunspot::Rails::Server.should_receive(:run_command).and_return('sunspot-run')
29
+ Sunspot::Rails::Server.should_respond_to_and_receive(:bootstrap_neccessary?).and_return(false)
30
+ Kernel.should_receive(:system).with('sunspot-run').and_return(true)
31
+ Sunspot::Rails::Server.run.should == true
32
+ end
33
+ end
34
+
35
+ describe "bootstraping" do
36
+ before(:each) do
37
+ @temp_dir = File.join( Dir.tmpdir, 'solr_rspec', Time.now.to_i.to_s, rand(1000).to_s )
38
+ Sunspot::Rails::Server.should_receive(:solr_home).at_least(1).and_return( @temp_dir )
39
+ end
40
+
41
+ it "should require bootstraping" do
42
+ Sunspot::Rails::Server.bootstrap_neccessary?.should == true
43
+ end
44
+
45
+ it "should not require bootstrapping again" do
46
+ Sunspot::Rails::Server.bootstrap_neccessary?.should == true
47
+ Sunspot::Rails::Server.bootstrap
48
+ Sunspot::Rails::Server.bootstrap_neccessary?.should == false
49
+ end
50
+ end
51
+
52
+ describe "delegate methods" do
53
+ before(:each) do
54
+ Sunspot::Rails::Server.should_receive(:configuration).at_least(1).and_return(@sunspot_configuration)
55
+ end
56
+
57
+ it "should delegate the port method to the configuration" do
58
+ @sunspot_configuration.should_respond_to_and_receive(:port).and_return(1234)
59
+ Sunspot::Rails::Server.port.should == 1234
60
+ end
61
+
62
+ it "should delegate the solr_home method to the configuration" do
63
+ @sunspot_configuration.should_respond_to_and_receive(:solr_home).and_return('/some/path')
64
+ Sunspot::Rails::Server.solr_home.should == '/some/path'
65
+ end
66
+
67
+ it "should delegate the log_level method to the configuration" do
68
+ @sunspot_configuration.should_respond_to_and_receive(:log_level).and_return('LOG_LEVEL')
69
+ Sunspot::Rails::Server.log_level.should == 'LOG_LEVEL'
70
+ end
71
+
72
+ it "should delegate the log_dir method to the configuration" do
73
+ @sunspot_configuration.should_respond_to_and_receive(:log_file).and_return('log_file')
74
+ Sunspot::Rails::Server.log_file.should =~ /log_file/
75
+ end
76
+
77
+ end
78
+
79
+ describe "protected methods" do
80
+ it "should generate the start command" do
81
+ Sunspot::Rails::Server.should_respond_to_and_receive(:port).and_return('1')
82
+ Sunspot::Rails::Server.should_respond_to_and_receive(:solr_home).and_return('home')
83
+ Sunspot::Rails::Server.should_respond_to_and_receive(:data_path).and_return('data')
84
+ Sunspot::Rails::Server.should_respond_to_and_receive(:log_level).and_return('LOG')
85
+ Sunspot::Rails::Server.should_respond_to_and_receive(:log_file).and_return('log_file')
86
+ Sunspot::Rails::Server.send(:start_command).should == \
87
+ [ 'sunspot-solr', 'start', '-p', '1', '-d', 'data', '-s', 'home', '-l', 'LOG', '--log-file', 'log_file' ]
88
+ end
89
+
90
+ it "should generate the stop command" do
91
+ Sunspot::Rails::Server.send(:stop_command).should == [ 'sunspot-solr', 'stop' ]
92
+ end
93
+
94
+ it "should generate the run command" do
95
+ Sunspot::Rails::Server.should_respond_to_and_receive(:port).and_return('1')
96
+ Sunspot::Rails::Server.should_respond_to_and_receive(:solr_home).and_return('home')
97
+ Sunspot::Rails::Server.should_respond_to_and_receive(:data_path).and_return('data')
98
+ Sunspot::Rails::Server.should_respond_to_and_receive(:log_level).and_return('LOG')
99
+ Sunspot::Rails::Server.should_respond_to_and_receive(:log_file).and_return('log_file')
100
+ Sunspot::Rails::Server.send(:run_command).should == \
101
+ [ 'sunspot-solr', 'run', '-p', '1', '-d', 'data', '-s', 'home', '-l', 'LOG', '-lf', 'log_file' ]
102
+ end
103
+
104
+ it "should generate the path for config files" do
105
+ Sunspot::Rails::Server.should_receive(:solr_home).and_return('/solr/home')
106
+ Sunspot::Rails::Server.config_path.should == '/solr/home/conf'
107
+ end
108
+
109
+ it "should generate the path for custom libraries" do
110
+ Sunspot::Rails::Server.should_receive(:solr_home).and_return('/solr/home')
111
+ Sunspot::Rails::Server.lib_path.should == '/solr/home/lib'
112
+ end
113
+
114
+ it "should generate the path for the index data" do
115
+ Sunspot::Rails::Server.should_receive(:solr_home).and_return('/solr/home')
116
+ Sunspot::Rails::Server.data_path.should == '/solr/home/data/test'
117
+ end
118
+
119
+ it "should generate the path for pid files" do
120
+ Sunspot::Rails::Server.should_receive(:solr_home).and_return('/solr/home')
121
+ Sunspot::Rails::Server.pid_path.should == '/solr/home/pids/test'
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,24 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe 'Sunspot::Rails session' do
4
+ it 'should be a different object for each thread' do
5
+ end
6
+
7
+ it 'should create a separate master/slave session if configured' do
8
+ end
9
+
10
+ it 'should not create a separate master/slave session if no master configured' do
11
+ end
12
+
13
+ private
14
+
15
+ def with_configuration(options)
16
+ original_configuration = Sunspot::Rails.configuration
17
+ Sunspot::Rails.reset
18
+ Sunspot::Rails.configuration = Sunspot::Rails::Configuration.new
19
+ Sunspot::Rails.configuration.user_configuration = options
20
+ yield
21
+ Sunspot::Rails.reset
22
+ Sunspot::Rails.configuration = original_configuration
23
+ end
24
+ end
@@ -0,0 +1,51 @@
1
+ ENV['RAILS_ENV'] = 'test'
2
+ ENV['RAILS_ROOT'] ||= File.join(File.dirname(__FILE__), 'mock_app')
3
+
4
+ if File.exist?(sunspot_lib = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'sunspot', 'lib')))
5
+ STDERR.puts("Using sunspot lib at #{sunspot_lib}")
6
+ $: << sunspot_lib
7
+ end
8
+
9
+ require File.expand_path(File.join(ENV['RAILS_ROOT'], 'config', 'environment.rb'))
10
+
11
+ require 'spec'
12
+ require 'spec/rails'
13
+ require 'rake'
14
+ require 'ruby-debug' unless RUBY_VERSION > '1.9'
15
+ require 'sunspot/rails/tasks'
16
+ require 'sunspot/spec/extension'
17
+
18
+ def load_schema
19
+ stdout = $stdout
20
+ $stdout = StringIO.new # suppress output while building the schema
21
+ load File.join(ENV['RAILS_ROOT'], 'db', 'schema.rb')
22
+ $stdout = stdout
23
+ end
24
+
25
+ def silence_stderr(&block)
26
+ stderr = $stderr
27
+ $stderr = StringIO.new
28
+ yield
29
+ $stderr = stderr
30
+ end
31
+
32
+ Spec::Runner.configure do |config|
33
+ config.before(:each) do
34
+ if integrate_sunspot?
35
+ Sunspot.remove_all
36
+ Sunspot.commit
37
+ end
38
+ load_schema
39
+ end
40
+ end
41
+
42
+ module Spec
43
+ module Mocks
44
+ module Methods
45
+ def should_respond_to_and_receive(*args, &block)
46
+ respond_to?(args.first).should ==(true)
47
+ should_receive(*args, &block)
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,22 @@
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 ADDED
@@ -0,0 +1,15 @@
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
+ end
metadata ADDED
@@ -0,0 +1,203 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nxa-sunspot_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.11.3
5
+ platform: ruby
6
+ authors:
7
+ - Mat Brown
8
+ - Peer Allan
9
+ - Michael Moen
10
+ - Benjamin Krause
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+
15
+ date: 2009-11-19 00:00:00 -08:00
16
+ default_executable:
17
+ dependencies:
18
+ - !ruby/object:Gem::Dependency
19
+ name: escape
20
+ type: :runtime
21
+ version_requirement:
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.0.4
27
+ version:
28
+ - !ruby/object:Gem::Dependency
29
+ name: nxa-sunspot
30
+ type: :runtime
31
+ version_requirement:
32
+ version_requirements: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 0.10.6
37
+ - - <=
38
+ - !ruby/object:Gem::Version
39
+ version: 0.10.7
40
+ version:
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ type: :development
44
+ version_requirement:
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ~>
48
+ - !ruby/object:Gem::Version
49
+ version: "1.2"
50
+ version:
51
+ - !ruby/object:Gem::Dependency
52
+ name: rspec-rails
53
+ type: :development
54
+ version_requirement:
55
+ version_requirements: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ version: "1.2"
60
+ version:
61
+ - !ruby/object:Gem::Dependency
62
+ name: ruby-debug
63
+ type: :development
64
+ version_requirement:
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:
81
+ description: |
82
+ Sunspot::Rails is an extension to the Sunspot library for Solr search.
83
+ Sunspot::Rails adds integration between Sunspot and ActiveRecord, including
84
+ defining search and indexing related methods on ActiveRecord models themselves,
85
+ running a Sunspot-compatible Solr instance for development and test
86
+ environments, and automatically commit Solr index changes at the end of each
87
+ Rails request.
88
+
89
+ email: mat@patch.com
90
+ executables: []
91
+
92
+ extensions: []
93
+
94
+ extra_rdoc_files:
95
+ - LICENSE
96
+ - README.rdoc
97
+ files:
98
+ - History.txt
99
+ - LICENSE
100
+ - MIT-LICENSE
101
+ - README.rdoc
102
+ - Rakefile
103
+ - TODO
104
+ - VERSION.yml
105
+ - dev_tasks/gemspec.rake
106
+ - dev_tasks/rdoc.rake
107
+ - dev_tasks/release.rake
108
+ - dev_tasks/todo.rake
109
+ - generators/sunspot/sunspot_generator.rb
110
+ - generators/sunspot/templates/sunspot.yml
111
+ - install.rb
112
+ - lib/sunspot/rails.rb
113
+ - lib/sunspot/rails/adapters.rb
114
+ - lib/sunspot/rails/configuration.rb
115
+ - lib/sunspot/rails/request_lifecycle.rb
116
+ - lib/sunspot/rails/searchable.rb
117
+ - lib/sunspot/rails/server.rb
118
+ - lib/sunspot/rails/session_proxy.rb
119
+ - lib/sunspot/rails/tasks.rb
120
+ - lib/sunspot/rails/util.rb
121
+ - lib/sunspot/spec/extension.rb
122
+ - rails/init.rb
123
+ - spec/configuration_spec.rb
124
+ - spec/mock_app/app/controllers/application.rb
125
+ - spec/mock_app/app/controllers/application_controller.rb
126
+ - spec/mock_app/app/controllers/posts_controller.rb
127
+ - spec/mock_app/app/models/author.rb
128
+ - spec/mock_app/app/models/blog.rb
129
+ - spec/mock_app/app/models/post.rb
130
+ - spec/mock_app/app/models/post_with_auto.rb
131
+ - spec/mock_app/config/boot.rb
132
+ - spec/mock_app/config/database.yml
133
+ - spec/mock_app/config/environment.rb
134
+ - spec/mock_app/config/environments/development.rb
135
+ - spec/mock_app/config/environments/test.rb
136
+ - spec/mock_app/config/initializers/new_rails_defaults.rb
137
+ - spec/mock_app/config/initializers/session_store.rb
138
+ - spec/mock_app/config/routes.rb
139
+ - spec/mock_app/config/sunspot.yml
140
+ - spec/mock_app/db/schema.rb
141
+ - spec/model_lifecycle_spec.rb
142
+ - spec/model_spec.rb
143
+ - spec/request_lifecycle_spec.rb
144
+ - spec/schema.rb
145
+ - spec/server_spec.rb
146
+ - spec/session_spec.rb
147
+ - spec/spec_helper.rb
148
+ - spec/sunspot_mocking_spec.rb
149
+ - spec/util_spec.rb
150
+ has_rdoc: true
151
+ homepage: http://github.com/outoftime/sunspot_rails
152
+ licenses: []
153
+
154
+ post_install_message:
155
+ rdoc_options:
156
+ - --charset=UTF-8
157
+ require_paths:
158
+ - lib
159
+ required_ruby_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: "0"
164
+ version:
165
+ required_rubygems_version: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - ">="
168
+ - !ruby/object:Gem::Version
169
+ version: "0"
170
+ version:
171
+ requirements: []
172
+
173
+ rubyforge_project: sunspot
174
+ rubygems_version: 1.3.5
175
+ signing_key:
176
+ specification_version: 3
177
+ summary: Rails integration for the Sunspot Solr search library
178
+ test_files:
179
+ - spec/configuration_spec.rb
180
+ - spec/mock_app/app/controllers/application.rb
181
+ - spec/mock_app/app/controllers/application_controller.rb
182
+ - spec/mock_app/app/controllers/posts_controller.rb
183
+ - spec/mock_app/app/models/author.rb
184
+ - spec/mock_app/app/models/blog.rb
185
+ - spec/mock_app/app/models/post.rb
186
+ - spec/mock_app/app/models/post_with_auto.rb
187
+ - spec/mock_app/config/boot.rb
188
+ - spec/mock_app/config/environment.rb
189
+ - spec/mock_app/config/environments/development.rb
190
+ - spec/mock_app/config/environments/test.rb
191
+ - spec/mock_app/config/initializers/new_rails_defaults.rb
192
+ - spec/mock_app/config/initializers/session_store.rb
193
+ - spec/mock_app/config/routes.rb
194
+ - spec/mock_app/db/schema.rb
195
+ - spec/model_lifecycle_spec.rb
196
+ - spec/model_spec.rb
197
+ - spec/request_lifecycle_spec.rb
198
+ - spec/schema.rb
199
+ - spec/server_spec.rb
200
+ - spec/session_spec.rb
201
+ - spec/spec_helper.rb
202
+ - spec/sunspot_mocking_spec.rb
203
+ - spec/util_spec.rb