robsharp-sunspot_rails 1.1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) 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 +160 -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 +464 -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 +62 -0
  25. data/lib/sunspot/rails/version.rb +5 -0
  26. data/rails/init.rb +10 -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/model_lifecycle_spec.rb +63 -0
  48. data/spec/model_spec.rb +409 -0
  49. data/spec/request_lifecycle_spec.rb +52 -0
  50. data/spec/schema.rb +27 -0
  51. data/spec/server_spec.rb +36 -0
  52. data/spec/session_spec.rb +24 -0
  53. data/spec/spec_helper.rb +51 -0
  54. data/spec/stub_session_proxy_spec.rb +122 -0
  55. metadata +170 -0
@@ -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,170 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: robsharp-sunspot_rails
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 1
8
+ - 0
9
+ - 2
10
+ version: 1.1.0.2
11
+ platform: ruby
12
+ authors:
13
+ - Mat Brown
14
+ - Peer Allan
15
+ - Michael Moen
16
+ - Benjamin Krause
17
+ - Adam Salter
18
+ - Brandon Keepers
19
+ - Paul Canavese
20
+ - John Eberly
21
+ - Gert Thiel
22
+ autorequire:
23
+ bindir: bin
24
+ cert_chain: []
25
+
26
+ date: 2010-06-22 00:00:00 +10:00
27
+ default_executable:
28
+ dependencies:
29
+ - !ruby/object:Gem::Dependency
30
+ name: sunspot
31
+ prerelease: false
32
+ requirement: &id001 !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - "="
35
+ - !ruby/object:Gem::Version
36
+ segments:
37
+ - 1
38
+ - 1
39
+ - 0
40
+ version: 1.1.0
41
+ type: :runtime
42
+ version_requirements: *id001
43
+ - !ruby/object:Gem::Dependency
44
+ name: rspec
45
+ prerelease: false
46
+ requirement: &id002 !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ~>
49
+ - !ruby/object:Gem::Version
50
+ segments:
51
+ - 1
52
+ - 2
53
+ version: "1.2"
54
+ type: :development
55
+ version_requirements: *id002
56
+ - !ruby/object:Gem::Dependency
57
+ name: rspec-rails
58
+ prerelease: false
59
+ requirement: &id003 !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ~>
62
+ - !ruby/object:Gem::Version
63
+ segments:
64
+ - 1
65
+ - 2
66
+ version: "1.2"
67
+ type: :development
68
+ version_requirements: *id003
69
+ description: |
70
+ Sunspot::Rails is an extension to the Sunspot library for Solr search.
71
+ Sunspot::Rails adds integration between Sunspot and ActiveRecord, including
72
+ defining search and indexing related methods on ActiveRecord models themselves,
73
+ running a Sunspot-compatible Solr instance for development and test
74
+ environments, and automatically commit Solr index changes at the end of each
75
+ Rails request.
76
+
77
+ email: rob@sharp.id.au
78
+ executables: []
79
+
80
+ extensions: []
81
+
82
+ extra_rdoc_files: []
83
+
84
+ files:
85
+ - README.rdoc
86
+ - VERSION.yml
87
+ - LICENSE
88
+ - MIT-LICENSE
89
+ - Rakefile
90
+ - TODO
91
+ - History.txt
92
+ - lib/sunspot/rails.rb
93
+ - lib/sunspot/rails/solr_logging.rb
94
+ - lib/sunspot/rails/request_lifecycle.rb
95
+ - lib/sunspot/rails/server.rb
96
+ - lib/sunspot/rails/searchable.rb
97
+ - lib/sunspot/rails/spec_helper.rb
98
+ - lib/sunspot/rails/version.rb
99
+ - lib/sunspot/rails/tasks.rb
100
+ - lib/sunspot/rails/stub_session_proxy.rb
101
+ - lib/sunspot/rails/adapters.rb
102
+ - lib/sunspot/rails/configuration.rb
103
+ - dev_tasks/gemspec.rake
104
+ - dev_tasks/rdoc.rake
105
+ - dev_tasks/release.rake
106
+ - dev_tasks/todo.rake
107
+ - generators/sunspot/sunspot_generator.rb
108
+ - generators/sunspot/templates/sunspot.yml
109
+ - install.rb
110
+ - rails/init.rb
111
+ - spec/model_spec.rb
112
+ - spec/model_lifecycle_spec.rb
113
+ - spec/configuration_spec.rb
114
+ - spec/spec_helper.rb
115
+ - spec/schema.rb
116
+ - spec/server_spec.rb
117
+ - spec/request_lifecycle_spec.rb
118
+ - spec/session_spec.rb
119
+ - spec/stub_session_proxy_spec.rb
120
+ - spec/mock_app/app/models/location.rb
121
+ - spec/mock_app/app/models/post_with_auto.rb
122
+ - spec/mock_app/app/models/author.rb
123
+ - spec/mock_app/app/models/photo_post.rb
124
+ - spec/mock_app/app/models/blog.rb
125
+ - spec/mock_app/app/models/post.rb
126
+ - spec/mock_app/app/controllers/application_controller.rb
127
+ - spec/mock_app/app/controllers/posts_controller.rb
128
+ - spec/mock_app/app/controllers/application.rb
129
+ - spec/mock_app/db/schema.rb
130
+ - spec/mock_app/config/environment.rb
131
+ - spec/mock_app/config/sunspot.yml
132
+ - spec/mock_app/config/database.yml
133
+ - spec/mock_app/config/boot.rb
134
+ - spec/mock_app/config/initializers/new_rails_defaults.rb
135
+ - spec/mock_app/config/initializers/session_store.rb
136
+ - spec/mock_app/config/environments/development.rb
137
+ - spec/mock_app/config/environments/test.rb
138
+ - spec/mock_app/config/routes.rb
139
+ has_rdoc: true
140
+ homepage: http://github.com/outoftime/sunspot_rails
141
+ licenses: []
142
+
143
+ post_install_message:
144
+ rdoc_options: []
145
+
146
+ require_paths:
147
+ - lib
148
+ required_ruby_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ segments:
153
+ - 0
154
+ version: "0"
155
+ required_rubygems_version: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ segments:
160
+ - 0
161
+ version: "0"
162
+ requirements: []
163
+
164
+ rubyforge_project: sunspot
165
+ rubygems_version: 1.3.6
166
+ signing_key:
167
+ specification_version: 3
168
+ summary: Rails integration for the Sunspot Solr search library
169
+ test_files: []
170
+