pduey-sunspot_rails 1.2.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. data/.gitignore +5 -0
  2. data/.rspec +1 -0
  3. data/History.txt +54 -0
  4. data/LICENSE +18 -0
  5. data/MIT-LICENSE +20 -0
  6. data/README.rdoc +282 -0
  7. data/Rakefile +18 -0
  8. data/TESTING.md +35 -0
  9. data/TODO +8 -0
  10. data/VERSION.yml +4 -0
  11. data/dev_tasks/rdoc.rake +24 -0
  12. data/dev_tasks/release.rake +4 -0
  13. data/dev_tasks/spec.rake +27 -0
  14. data/dev_tasks/todo.rake +4 -0
  15. data/generators/sunspot/sunspot_generator.rb +9 -0
  16. data/generators/sunspot/templates/sunspot.yml +18 -0
  17. data/install.rb +1 -0
  18. data/lib/generators/sunspot_rails.rb +9 -0
  19. data/lib/generators/sunspot_rails/install/install_generator.rb +13 -0
  20. data/lib/generators/sunspot_rails/install/templates/config/sunspot.yml +17 -0
  21. data/lib/sunspot/rails.rb +63 -0
  22. data/lib/sunspot/rails/adapters.rb +83 -0
  23. data/lib/sunspot/rails/configuration.rb +323 -0
  24. data/lib/sunspot/rails/init.rb +5 -0
  25. data/lib/sunspot/rails/log_subscriber.rb +33 -0
  26. data/lib/sunspot/rails/railtie.rb +36 -0
  27. data/lib/sunspot/rails/railties/controller_runtime.rb +36 -0
  28. data/lib/sunspot/rails/request_lifecycle.rb +36 -0
  29. data/lib/sunspot/rails/searchable.rb +420 -0
  30. data/lib/sunspot/rails/server.rb +173 -0
  31. data/lib/sunspot/rails/solr_instrumentation.rb +20 -0
  32. data/lib/sunspot/rails/solr_logging.rb +62 -0
  33. data/lib/sunspot/rails/spec_helper.rb +26 -0
  34. data/lib/sunspot/rails/stub_session_proxy.rb +142 -0
  35. data/lib/sunspot/rails/tasks.rb +66 -0
  36. data/lib/sunspot_rails.rb +12 -0
  37. data/spec/configuration_spec.rb +173 -0
  38. data/spec/model_lifecycle_spec.rb +63 -0
  39. data/spec/model_spec.rb +478 -0
  40. data/spec/rails2/.gitignore +2 -0
  41. data/spec/rails2/Gemfile +15 -0
  42. data/spec/rails2/Rakefile +17 -0
  43. data/spec/rails2/app/controllers/application.rb +10 -0
  44. data/spec/rails2/app/controllers/application_controller.rb +10 -0
  45. data/spec/rails2/app/controllers/posts_controller.rb +6 -0
  46. data/spec/rails2/app/models/author.rb +8 -0
  47. data/spec/rails2/app/models/blog.rb +12 -0
  48. data/spec/rails2/app/models/location.rb +2 -0
  49. data/spec/rails2/app/models/photo_post.rb +2 -0
  50. data/spec/rails2/app/models/post.rb +11 -0
  51. data/spec/rails2/app/models/post_with_auto.rb +10 -0
  52. data/spec/rails2/app/models/post_with_conditional_index.rb +13 -0
  53. data/spec/rails2/app/models/post_with_default_scope.rb +11 -0
  54. data/spec/rails2/config/boot.rb +116 -0
  55. data/spec/rails2/config/database.yml +4 -0
  56. data/spec/rails2/config/environment.rb +41 -0
  57. data/spec/rails2/config/environments/development.rb +27 -0
  58. data/spec/rails2/config/environments/test.rb +27 -0
  59. data/spec/rails2/config/initializers/new_rails_defaults.rb +19 -0
  60. data/spec/rails2/config/initializers/session_store.rb +15 -0
  61. data/spec/rails2/config/preinitializer.rb +19 -0
  62. data/spec/rails2/config/routes.rb +43 -0
  63. data/spec/rails2/config/sunspot.yml +19 -0
  64. data/spec/rails2/db/schema.rb +27 -0
  65. data/spec/rails2/script/console +3 -0
  66. data/spec/rails3/.gitignore +4 -0
  67. data/spec/rails3/Gemfile +15 -0
  68. data/spec/rails3/README +281 -0
  69. data/spec/rails3/Rakefile +7 -0
  70. data/spec/rails3/app/controllers/application.rb +4 -0
  71. data/spec/rails3/app/controllers/application_controller.rb +4 -0
  72. data/spec/rails3/app/controllers/posts_controller.rb +6 -0
  73. data/spec/rails3/app/models/author.rb +8 -0
  74. data/spec/rails3/app/models/blog.rb +12 -0
  75. data/spec/rails3/app/models/location.rb +2 -0
  76. data/spec/rails3/app/models/photo_post.rb +2 -0
  77. data/spec/rails3/app/models/post.rb +11 -0
  78. data/spec/rails3/app/models/post_with_auto.rb +10 -0
  79. data/spec/rails3/app/models/post_with_conditional_index.rb +13 -0
  80. data/spec/rails3/app/models/post_with_default_scope.rb +11 -0
  81. data/spec/rails3/config.ru +4 -0
  82. data/spec/rails3/config/application.rb +46 -0
  83. data/spec/rails3/config/boot.rb +13 -0
  84. data/spec/rails3/config/database.yml +22 -0
  85. data/spec/rails3/config/environment.rb +5 -0
  86. data/spec/rails3/config/environments/development.rb +19 -0
  87. data/spec/rails3/config/environments/test.rb +19 -0
  88. data/spec/rails3/config/initializers/backtrace_silencers.rb +7 -0
  89. data/spec/rails3/config/initializers/inflections.rb +10 -0
  90. data/spec/rails3/config/initializers/mime_types.rb +5 -0
  91. data/spec/rails3/config/initializers/new_rails_defaults.rb +19 -0
  92. data/spec/rails3/config/initializers/secret_token.rb +7 -0
  93. data/spec/rails3/config/initializers/session_store.rb +8 -0
  94. data/spec/rails3/config/locales/en.yml +5 -0
  95. data/spec/rails3/config/routes.rb +59 -0
  96. data/spec/rails3/config/sunspot.yml +19 -0
  97. data/spec/rails3/db/schema.rb +27 -0
  98. data/spec/rails3/script/console +3 -0
  99. data/spec/rails3/script/rails +6 -0
  100. data/spec/rails3/solr/.gitignore +1 -0
  101. data/spec/rails3/solr/conf/elevate.xml +36 -0
  102. data/spec/rails3/solr/conf/schema.xml +238 -0
  103. data/spec/rails3/solr/conf/solrconfig.xml +938 -0
  104. data/spec/rails3/solr/conf/spellings.txt +2 -0
  105. data/spec/rails3/solr/conf/stopwords.txt +58 -0
  106. data/spec/rails3/solr/conf/synonyms.txt +31 -0
  107. data/spec/rails3/solr/lib/lucene-spatial-2.9.1.jar +0 -0
  108. data/spec/rails3/solr/lib/solr-spatial-light-0.0.6.jar +0 -0
  109. data/spec/request_lifecycle_spec.rb +61 -0
  110. data/spec/schema.rb +27 -0
  111. data/spec/server_spec.rb +37 -0
  112. data/spec/session_spec.rb +24 -0
  113. data/spec/spec_helper.rb +46 -0
  114. data/spec/stub_session_proxy_spec.rb +122 -0
  115. data/sunspot_rails.gemspec +44 -0
  116. metadata +322 -0
@@ -0,0 +1,2 @@
1
+ pizza
2
+ history
@@ -0,0 +1,58 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright ownership.
4
+ # The ASF licenses this file to You under the Apache License, Version 2.0
5
+ # (the "License"); you may not use this file except in compliance with
6
+ # the License. You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ #-----------------------------------------------------------------------
17
+ # a couple of test stopwords to test that the words are really being
18
+ # configured from this file:
19
+ stopworda
20
+ stopwordb
21
+
22
+ #Standard english stop words taken from Lucene's StopAnalyzer
23
+ a
24
+ an
25
+ and
26
+ are
27
+ as
28
+ at
29
+ be
30
+ but
31
+ by
32
+ for
33
+ if
34
+ in
35
+ into
36
+ is
37
+ it
38
+ no
39
+ not
40
+ of
41
+ on
42
+ or
43
+ s
44
+ such
45
+ t
46
+ that
47
+ the
48
+ their
49
+ then
50
+ there
51
+ these
52
+ they
53
+ this
54
+ to
55
+ was
56
+ will
57
+ with
58
+
@@ -0,0 +1,31 @@
1
+ # The ASF licenses this file to You under the Apache License, Version 2.0
2
+ # (the "License"); you may not use this file except in compliance with
3
+ # the License. You may obtain a copy of the License at
4
+ #
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+
13
+ #-----------------------------------------------------------------------
14
+ #some test synonym mappings unlikely to appear in real input text
15
+ aaa => aaaa
16
+ bbb => bbbb1 bbbb2
17
+ ccc => cccc1,cccc2
18
+ a\=>a => b\=>b
19
+ a\,a => b\,b
20
+ fooaaa,baraaa,bazaaa
21
+
22
+ # Some synonym groups specific to this example
23
+ GB,gib,gigabyte,gigabytes
24
+ MB,mib,megabyte,megabytes
25
+ Television, Televisions, TV, TVs
26
+ #notice we use "gib" instead of "GiB" so any WordDelimiterFilter coming
27
+ #after us won't split it into two words.
28
+
29
+ # Synonym mappings can be used for spelling correction too
30
+ pixima => pixma
31
+
@@ -0,0 +1,61 @@
1
+ require File.expand_path('spec_helper', File.dirname(__FILE__))
2
+
3
+ describe PostsController, :type => :controller do
4
+ begin
5
+ include ::RSpec::Rails::ControllerExampleGroup
6
+ rescue NameError
7
+ # Silent -- rspec-rails 1.x catches the :type => :controller
8
+ end
9
+
10
+ before(:each) do
11
+ Sunspot::Rails.configuration = @configuration = Sunspot::Rails::Configuration.new
12
+ end
13
+
14
+ after(:each) do
15
+ Sunspot::Rails.configuration = nil
16
+ end
17
+
18
+ unless respond_to?(:describes)
19
+ controller_name :posts # RSpec 1
20
+ end
21
+
22
+ it 'should automatically commit after each action if specified' do
23
+ @configuration.user_configuration = { 'auto_commit_after_request' => true }
24
+ Sunspot.should_receive(:commit_if_dirty)
25
+ post :create, :post => { :title => 'Test 1' }
26
+ end
27
+
28
+ it 'should not commit, if configuration is set to false' do
29
+ @configuration.user_configuration = { 'auto_commit_after_request' => false }
30
+ Sunspot.should_not_receive(:commit_if_dirty)
31
+ post :create, :post => { :title => 'Test 1' }
32
+ end
33
+
34
+ it 'should commit if configuration is not specified' do
35
+ @configuration.user_configuration = {}
36
+ Sunspot.should_receive(:commit_if_dirty)
37
+ post :create, :post => { :title => 'Test 1' }
38
+ end
39
+
40
+ ### auto_commit_if_delete_dirty
41
+
42
+ it 'should automatically commit after each delete if specified' do
43
+ @configuration.user_configuration = { 'auto_commit_after_request' => false,
44
+ 'auto_commit_after_delete_request' => true }
45
+ Sunspot.should_receive(:commit_if_delete_dirty)
46
+ post :create, :post => { :title => 'Test 1' }
47
+ end
48
+
49
+ it 'should not automatically commit on delete if configuration is set to false' do
50
+ @configuration.user_configuration = { 'auto_commit_after_request' => false,
51
+ 'auto_commit_after_delete_request' => false }
52
+ Sunspot.should_not_receive(:commit_if_delete_dirty)
53
+ post :create, :post => { :title => 'Test 1' }
54
+ end
55
+
56
+ it 'should not automatically commit on delete if configuration is not specified' do
57
+ @configuration.user_configuration = { 'auto_commit_after_request' => false }
58
+ Sunspot.should_not_receive(:commit_if_delete_dirty)
59
+ post :create, :post => { :title => 'Test 1' }
60
+ end
61
+ 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,37 @@
1
+ require File.expand_path('spec_helper', File.dirname(__FILE__))
2
+
3
+ describe Sunspot::Rails::Server do
4
+ before :each do
5
+ @server = Sunspot::Rails::Server.new
6
+ @config = Sunspot::Rails::Configuration.new
7
+ @solr_home = File.join(@config.solr_home)
8
+ end
9
+
10
+ it "sets the correct Solr home" do
11
+ @server.solr_home.should == @solr_home
12
+ end
13
+
14
+ it "sets the correct Solr library path" do
15
+ @server.lib_path.should == File.join(@solr_home, 'lib')
16
+ end
17
+
18
+ it "sets the correct Solr PID path" do
19
+ @server.pid_path.should == File.join(@server.pid_dir, 'sunspot-solr-test.pid')
20
+ end
21
+
22
+ it "sets the correct Solr data dir" do
23
+ @server.solr_data_dir.should == File.join(@solr_home, 'data', 'test')
24
+ end
25
+
26
+ it "sets the correct port" do
27
+ @server.port.should == 8980
28
+ end
29
+
30
+ it "sets the correct log level" do
31
+ @server.log_level.should == "FINE"
32
+ end
33
+
34
+ it "sets the correct log file" do
35
+ @server.log_file.should == File.join(Rails.root, 'log', 'sunspot-solr-test.log')
36
+ end
37
+ end
@@ -0,0 +1,24 @@
1
+ require File.expand_path('spec_helper', File.dirname(__FILE__))
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,46 @@
1
+ ENV['RAILS_ENV'] = 'test'
2
+ ENV['RAILS_ROOT'] ||= File.join(File.dirname(__FILE__), 'rails3')
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
+ require File.expand_path('config/environment', ENV['RAILS_ROOT'])
9
+
10
+ begin
11
+ require 'rspec'
12
+ require 'rspec/rails'
13
+ rescue LoadError => e
14
+ require 'spec'
15
+ require 'spec/rails'
16
+ end
17
+ require 'rake'
18
+ require File.join('sunspot', 'rails', 'solr_logging')
19
+
20
+ def load_schema
21
+ stdout = $stdout
22
+ $stdout = StringIO.new # suppress output while building the schema
23
+ load File.join(ENV['RAILS_ROOT'], 'db', 'schema.rb')
24
+ $stdout = stdout
25
+ end
26
+
27
+ def silence_stderr(&block)
28
+ stderr = $stderr
29
+ $stderr = StringIO.new
30
+ yield
31
+ $stderr = stderr
32
+ end
33
+
34
+ rspec =
35
+ begin
36
+ RSpec
37
+ rescue NameError, ArgumentError
38
+ Spec::Runner
39
+ end
40
+
41
+ rspec.configure do |config|
42
+ config.before(:each) do
43
+ load_schema
44
+ Sunspot.remove_all!
45
+ end
46
+ end
@@ -0,0 +1,122 @@
1
+ require File.expand_path('spec_helper', File.dirname(__FILE__))
2
+ require File.expand_path('../lib/sunspot/rails/spec_helper', File.dirname(__FILE__))
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
@@ -0,0 +1,44 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../../sunspot/lib/', __FILE__)
3
+
4
+ $:.unshift(lib) unless $:.include?(lib)
5
+
6
+ require 'sunspot/version'
7
+
8
+ Gem::Specification.new do |s|
9
+ s.name = "sunspot_rails"
10
+ s.version = Sunspot::VERSION
11
+ s.platform = Gem::Platform::RUBY
12
+ s.authors = ['Mat Brown', 'Peer Allan', 'Dmitriy Dzema', 'Benjamin Krause', 'Marcel de Graaf', 'Brandon Keepers', 'Peter Berkenbosch',
13
+ 'Brian Atkinson', 'Tom Coleman', 'Matt Mitchell', 'Nathan Beyer', 'Kieran Topping', 'Nicolas Braem', 'Jeremy Ashkenas',
14
+ 'Dylan Vaughn', 'Brian Durand', 'Sam Granieri', 'Nick Zadrozny', 'Jason Ronallo']
15
+ s.email = ["mat@patch.com"]
16
+ s.homepage = 'http://github.com/outoftime/sunspot/tree/master/sunspot_rails'
17
+ s.summary = 'Rails integration for the Sunspot Solr search library'
18
+ s.description = <<-TEXT
19
+ Sunspot::Rails is an extension to the Sunspot library for Solr search.
20
+ Sunspot::Rails adds integration between Sunspot and ActiveRecord, including
21
+ defining search and indexing related methods on ActiveRecord models themselves,
22
+ running a Sunspot-compatible Solr instance for development and test
23
+ environments, and automatically commit Solr index changes at the end of each
24
+ Rails request.
25
+ TEXT
26
+
27
+ s.rubyforge_project = "sunspot"
28
+
29
+ s.files = `git ls-files`.split("\n")
30
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
31
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
32
+ s.require_paths = ["lib"]
33
+
34
+ s.add_dependency 'sunspot', Sunspot::VERSION
35
+ s.add_dependency "progress_bar", "0.3.4"
36
+ s.add_dependency 'nokogiri'
37
+
38
+ s.add_development_dependency 'rspec', '~> 1.2'
39
+ s.add_development_dependency 'rspec-rails', '~> 1.2'
40
+
41
+ s.rdoc_options << '--webcvs=http://github.com/outoftime/sunspot/tree/master/%s' <<
42
+ '--title' << 'Sunspot-Rails - Rails integration for the Sunspot Solr search library - API Documentation' <<
43
+ '--main' << 'README.rdoc'
44
+ end