nuatt_sunspot_rails 1.1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. data/History.txt +40 -0
  2. data/LICENSE +18 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.rdoc +256 -0
  5. data/Rakefile +27 -0
  6. data/TODO +8 -0
  7. data/VERSION.yml +4 -0
  8. data/dev_tasks/gemspec.rake +33 -0
  9. data/dev_tasks/rdoc.rake +24 -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.rb +58 -0
  16. data/lib/sunspot/rails/adapters.rb +83 -0
  17. data/lib/sunspot/rails/configuration.rb +272 -0
  18. data/lib/sunspot/rails/request_lifecycle.rb +31 -0
  19. data/lib/sunspot/rails/searchable.rb +412 -0
  20. data/lib/sunspot/rails/server.rb +173 -0
  21. data/lib/sunspot/rails/solr_logging.rb +58 -0
  22. data/lib/sunspot/rails/spec_helper.rb +19 -0
  23. data/lib/sunspot/rails/stub_session_proxy.rb +88 -0
  24. data/lib/sunspot/rails/tasks.rb +61 -0
  25. data/lib/sunspot/rails/version.rb +5 -0
  26. data/rails/init.rb +7 -0
  27. data/spec/configuration_spec.rb +102 -0
  28. data/spec/mock_app/app/controllers/application.rb +10 -0
  29. data/spec/mock_app/app/controllers/application_controller.rb +10 -0
  30. data/spec/mock_app/app/controllers/posts_controller.rb +6 -0
  31. data/spec/mock_app/app/models/author.rb +8 -0
  32. data/spec/mock_app/app/models/blog.rb +12 -0
  33. data/spec/mock_app/app/models/location.rb +2 -0
  34. data/spec/mock_app/app/models/photo_post.rb +2 -0
  35. data/spec/mock_app/app/models/post.rb +10 -0
  36. data/spec/mock_app/app/models/post_with_auto.rb +10 -0
  37. data/spec/mock_app/config/boot.rb +110 -0
  38. data/spec/mock_app/config/database.yml +4 -0
  39. data/spec/mock_app/config/environment.rb +42 -0
  40. data/spec/mock_app/config/environments/development.rb +27 -0
  41. data/spec/mock_app/config/environments/test.rb +27 -0
  42. data/spec/mock_app/config/initializers/new_rails_defaults.rb +19 -0
  43. data/spec/mock_app/config/initializers/session_store.rb +15 -0
  44. data/spec/mock_app/config/routes.rb +43 -0
  45. data/spec/mock_app/config/sunspot.yml +19 -0
  46. data/spec/mock_app/db/schema.rb +27 -0
  47. data/spec/mock_app/db/test.db +0 -0
  48. data/spec/model_lifecycle_spec.rb +63 -0
  49. data/spec/model_spec.rb +409 -0
  50. data/spec/request_lifecycle_spec.rb +52 -0
  51. data/spec/schema.rb +27 -0
  52. data/spec/server_spec.rb +36 -0
  53. data/spec/session_spec.rb +24 -0
  54. data/spec/spec_helper.rb +51 -0
  55. data/spec/stub_session_proxy_spec.rb +122 -0
  56. metadata +183 -0
@@ -0,0 +1,52 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
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
11
+ controller_name :posts
12
+
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)
28
+ post :create, :post => { :title => 'Test 1' }
29
+ end
30
+
31
+ ### auto_commit_if_delete_dirty
32
+
33
+ it 'should automatically commit after each delete if specified' do
34
+ @configuration.user_configuration = { 'auto_commit_after_request' => false,
35
+ 'auto_commit_after_delete_request' => true }
36
+ Sunspot.should_receive(:commit_if_delete_dirty)
37
+ post :create, :post => { :title => 'Test 1' }
38
+ end
39
+
40
+ it 'should not automatically commit on delete if configuration is set to false' do
41
+ @configuration.user_configuration = { 'auto_commit_after_request' => false,
42
+ 'auto_commit_after_delete_request' => false }
43
+ Sunspot.should_not_receive(:commit_if_delete_dirty)
44
+ post :create, :post => { :title => 'Test 1' }
45
+ end
46
+
47
+ it 'should not automatically commit on delete if configuration is not specified' do
48
+ @configuration.user_configuration = { 'auto_commit_after_request' => false }
49
+ Sunspot.should_not_receive(:commit_if_delete_dirty)
50
+ post :create, :post => { :title => 'Test 1' }
51
+ end
52
+ end
@@ -0,0 +1,27 @@
1
+ ActiveRecord::Schema.define(:version => 0) do
2
+ create_table :posts, :force => true do |t|
3
+ t.string :title
4
+ t.string :type
5
+ t.integer :location_id
6
+ t.text :body
7
+ t.references :blog
8
+ t.timestamps
9
+ end
10
+
11
+ create_table :locations, :force => true do |t|
12
+ t.float :lat
13
+ t.float :lng
14
+ end
15
+
16
+ create_table :blogs, :force => true do |t|
17
+ t.string :name
18
+ t.string :subdomain
19
+ t.timestamps
20
+ end
21
+
22
+ create_table :writers, :force => true, :primary_key => :writer_id do |t|
23
+ t.string :name
24
+ t.timestamps
25
+ end
26
+
27
+ end
@@ -0,0 +1,36 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe Sunspot::Rails::Server do
4
+ before :each do
5
+ @server = Sunspot::Rails::Server.new
6
+ @solr_home = File.expand_path(File.join(Rails.root, 'solr'))
7
+ end
8
+
9
+ it "sets the correct Solr home" do
10
+ @server.solr_home.should == @solr_home
11
+ end
12
+
13
+ it "sets the correct Solr library path" do
14
+ @server.lib_path.should == File.join(@solr_home, 'lib')
15
+ end
16
+
17
+ it "sets the correct Solr PID path" do
18
+ @server.pid_path.should == File.join(Rails.root, 'tmp', 'pids', 'sunspot-solr-test.pid')
19
+ end
20
+
21
+ it "sets the correct Solr data dir" do
22
+ @server.solr_data_dir.should == File.join(@solr_home, 'data', 'test')
23
+ end
24
+
25
+ it "sets the correct port" do
26
+ @server.port.should == 8980
27
+ end
28
+
29
+ it "sets the correct log level" do
30
+ @server.log_level.should == "FINE"
31
+ end
32
+
33
+ it "sets the correct log file" do
34
+ @server.log_file.should == File.join(Rails.root, 'log', 'sunspot-solr-test.log')
35
+ end
36
+ 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
+ if rsolr_version = ENV['RSOLR_GEM_VERSION']
4
+ STDERR.puts("Forcing RSolr version #{rsolr_version}")
5
+ gem "rsolr", rsolr_version
6
+ end
7
+
8
+ if File.exist?(sunspot_lib = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'sunspot', 'lib')))
9
+ STDERR.puts("Using sunspot lib at #{sunspot_lib}")
10
+ $: << sunspot_lib
11
+ end
12
+
13
+ require File.expand_path(File.join(ENV['RAILS_ROOT'], 'config', 'environment.rb'))
14
+
15
+ require 'spec'
16
+ require 'spec/rails'
17
+ require 'rake'
18
+ require 'ruby-debug' unless RUBY_VERSION > '1.9'
19
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'sunspot', 'rails', 'solr_logging')
20
+
21
+ def load_schema
22
+ stdout = $stdout
23
+ $stdout = StringIO.new # suppress output while building the schema
24
+ load File.join(ENV['RAILS_ROOT'], 'db', 'schema.rb')
25
+ $stdout = stdout
26
+ end
27
+
28
+ def silence_stderr(&block)
29
+ stderr = $stderr
30
+ $stderr = StringIO.new
31
+ yield
32
+ $stderr = stderr
33
+ end
34
+
35
+ Spec::Runner.configure do |config|
36
+ config.before(:each) do
37
+ load_schema
38
+ Sunspot.remove_all!
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,122 @@
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 not execute a search when #search called with parameters' do
88
+ @session.should_not_receive(:search)
89
+ Post.search(:include => :blog, :select => 'id, title')
90
+ end
91
+
92
+ it 'should return a new search' do
93
+ @session.should_not_receive(:new_search)
94
+ Sunspot.new_search(Post).should respond_to(:execute)
95
+ end
96
+
97
+ describe 'stub search' do
98
+ before :each do
99
+ @search = Post.search
100
+ end
101
+
102
+ it 'should return empty results' do
103
+ @search.results.should == []
104
+ end
105
+
106
+ it 'should return empty hits' do
107
+ @search.hits.should == []
108
+ end
109
+
110
+ it 'should return zero total' do
111
+ @search.total.should == 0
112
+ end
113
+
114
+ it 'should return nil for a given facet' do
115
+ @search.facet(:category_id).should be_nil
116
+ end
117
+
118
+ it 'should return nil for a given dynamic facet' do
119
+ @search.dynamic_facet(:custom).should be_nil
120
+ end
121
+ end
122
+ end
metadata ADDED
@@ -0,0 +1,183 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nuatt_sunspot_rails
3
+ version: !ruby/object:Gem::Version
4
+ hash: 81
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 1
9
+ - 0
10
+ - 3
11
+ version: 1.1.0.3
12
+ platform: ruby
13
+ authors:
14
+ - Mat Brown
15
+ - Peer Allan
16
+ - Michael Moen
17
+ - Benjamin Krause
18
+ - Adam Salter
19
+ - Brandon Keepers
20
+ - Paul Canavese
21
+ - John Eberly
22
+ - Gert Thiel
23
+ autorequire:
24
+ bindir: bin
25
+ cert_chain: []
26
+
27
+ date: 2010-09-21 00:00:00 +02:00
28
+ default_executable:
29
+ dependencies:
30
+ - !ruby/object:Gem::Dependency
31
+ name: nuatt_sunspot
32
+ prerelease: false
33
+ requirement: &id001 !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - "="
37
+ - !ruby/object:Gem::Version
38
+ hash: 81
39
+ segments:
40
+ - 1
41
+ - 1
42
+ - 0
43
+ - 3
44
+ version: 1.1.0.3
45
+ type: :runtime
46
+ version_requirements: *id001
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec
49
+ prerelease: false
50
+ requirement: &id002 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ hash: 11
56
+ segments:
57
+ - 1
58
+ - 2
59
+ version: "1.2"
60
+ type: :development
61
+ version_requirements: *id002
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec-rails
64
+ prerelease: false
65
+ requirement: &id003 !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ~>
69
+ - !ruby/object:Gem::Version
70
+ hash: 11
71
+ segments:
72
+ - 1
73
+ - 2
74
+ version: "1.2"
75
+ type: :development
76
+ version_requirements: *id003
77
+ description: |
78
+ Sunspot::Rails is an extension to the Sunspot library for Solr search.
79
+ Sunspot::Rails adds integration between Sunspot and ActiveRecord, including
80
+ defining search and indexing related methods on ActiveRecord models themselves,
81
+ running a Sunspot-compatible Solr instance for development and test
82
+ environments, and automatically commit Solr index changes at the end of each
83
+ Rails request.
84
+
85
+ email: sistemas@nuatt.es
86
+ executables: []
87
+
88
+ extensions: []
89
+
90
+ extra_rdoc_files: []
91
+
92
+ files:
93
+ - History.txt
94
+ - LICENSE
95
+ - MIT-LICENSE
96
+ - Rakefile
97
+ - README.rdoc
98
+ - TODO
99
+ - VERSION.yml
100
+ - lib/sunspot/rails/adapters.rb
101
+ - lib/sunspot/rails/configuration.rb
102
+ - lib/sunspot/rails/request_lifecycle.rb
103
+ - lib/sunspot/rails/searchable.rb
104
+ - lib/sunspot/rails/server.rb
105
+ - lib/sunspot/rails/solr_logging.rb
106
+ - lib/sunspot/rails/spec_helper.rb
107
+ - lib/sunspot/rails/stub_session_proxy.rb
108
+ - lib/sunspot/rails/tasks.rb
109
+ - lib/sunspot/rails/version.rb
110
+ - lib/sunspot/rails.rb
111
+ - dev_tasks/gemspec.rake
112
+ - dev_tasks/rdoc.rake
113
+ - dev_tasks/release.rake
114
+ - dev_tasks/todo.rake
115
+ - generators/sunspot/sunspot_generator.rb
116
+ - generators/sunspot/templates/sunspot.yml
117
+ - install.rb
118
+ - rails/init.rb
119
+ - spec/configuration_spec.rb
120
+ - spec/model_lifecycle_spec.rb
121
+ - spec/model_spec.rb
122
+ - spec/request_lifecycle_spec.rb
123
+ - spec/schema.rb
124
+ - spec/server_spec.rb
125
+ - spec/session_spec.rb
126
+ - spec/spec_helper.rb
127
+ - spec/stub_session_proxy_spec.rb
128
+ - spec/mock_app/app/controllers/application.rb
129
+ - spec/mock_app/app/controllers/application_controller.rb
130
+ - spec/mock_app/app/controllers/posts_controller.rb
131
+ - spec/mock_app/app/models/author.rb
132
+ - spec/mock_app/app/models/blog.rb
133
+ - spec/mock_app/app/models/location.rb
134
+ - spec/mock_app/app/models/photo_post.rb
135
+ - spec/mock_app/app/models/post.rb
136
+ - spec/mock_app/app/models/post_with_auto.rb
137
+ - spec/mock_app/db/schema.rb
138
+ - spec/mock_app/db/test.db
139
+ - spec/mock_app/config/boot.rb
140
+ - spec/mock_app/config/database.yml
141
+ - spec/mock_app/config/environment.rb
142
+ - spec/mock_app/config/environments/development.rb
143
+ - spec/mock_app/config/environments/test.rb
144
+ - spec/mock_app/config/initializers/new_rails_defaults.rb
145
+ - spec/mock_app/config/initializers/session_store.rb
146
+ - spec/mock_app/config/routes.rb
147
+ - spec/mock_app/config/sunspot.yml
148
+ has_rdoc: true
149
+ homepage: http://github.com/outoftime/sunspot_rails
150
+ licenses: []
151
+
152
+ post_install_message:
153
+ rdoc_options: []
154
+
155
+ require_paths:
156
+ - lib
157
+ required_ruby_version: !ruby/object:Gem::Requirement
158
+ none: false
159
+ requirements:
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ hash: 3
163
+ segments:
164
+ - 0
165
+ version: "0"
166
+ required_rubygems_version: !ruby/object:Gem::Requirement
167
+ none: false
168
+ requirements:
169
+ - - ">="
170
+ - !ruby/object:Gem::Version
171
+ hash: 3
172
+ segments:
173
+ - 0
174
+ version: "0"
175
+ requirements: []
176
+
177
+ rubyforge_project: sunspot
178
+ rubygems_version: 1.3.7
179
+ signing_key:
180
+ specification_version: 3
181
+ summary: Rails integration for the Sunspot Solr search library
182
+ test_files: []
183
+