benjaminkrause-sunspot_rails 0.10.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/History.txt +13 -0
  2. data/LICENSE +18 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.rdoc +262 -0
  5. data/Rakefile +19 -0
  6. data/TODO +10 -0
  7. data/VERSION.yml +4 -0
  8. data/dev_tasks/gemspec.rake +28 -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 +54 -0
  16. data/lib/sunspot/rails/configuration.rb +166 -0
  17. data/lib/sunspot/rails/request_lifecycle.rb +18 -0
  18. data/lib/sunspot/rails/searchable.rb +305 -0
  19. data/lib/sunspot/rails/server.rb +204 -0
  20. data/lib/sunspot/rails/tasks.rb +24 -0
  21. data/lib/sunspot/rails.rb +17 -0
  22. data/lib/sunspot/spec/extension.rb +45 -0
  23. data/rails/init.rb +11 -0
  24. data/spec/configuration_spec.rb +68 -0
  25. data/spec/mock_app/app/controllers/application.rb +10 -0
  26. data/spec/mock_app/app/controllers/application_controller.rb +10 -0
  27. data/spec/mock_app/app/controllers/posts_controller.rb +6 -0
  28. data/spec/mock_app/app/models/blog.rb +2 -0
  29. data/spec/mock_app/app/models/post.rb +5 -0
  30. data/spec/mock_app/app/models/post_with_auto.rb +9 -0
  31. data/spec/mock_app/config/boot.rb +110 -0
  32. data/spec/mock_app/config/database.yml +4 -0
  33. data/spec/mock_app/config/environment.rb +41 -0
  34. data/spec/mock_app/config/environments/development.rb +27 -0
  35. data/spec/mock_app/config/environments/test.rb +27 -0
  36. data/spec/mock_app/config/initializers/new_rails_defaults.rb +19 -0
  37. data/spec/mock_app/config/initializers/session_store.rb +15 -0
  38. data/spec/mock_app/config/routes.rb +43 -0
  39. data/spec/mock_app/config/sunspot.yml +16 -0
  40. data/spec/model_lifecycle_spec.rb +40 -0
  41. data/spec/model_spec.rb +280 -0
  42. data/spec/request_lifecycle_spec.rb +30 -0
  43. data/spec/schema.rb +14 -0
  44. data/spec/server_spec.rb +113 -0
  45. data/spec/spec_helper.rb +46 -0
  46. data/spec/sunspot_mocking_spec.rb +21 -0
  47. metadata +184 -0
@@ -0,0 +1,30 @@
1
+ require File.join(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
+ end
data/spec/schema.rb ADDED
@@ -0,0 +1,14 @@
1
+ ActiveRecord::Schema.define(:version => 0) do
2
+ create_table :posts, :force => true do |t|
3
+ t.string :title
4
+ t.text :body
5
+ t.references :blog
6
+ t.timestamps
7
+ end
8
+
9
+ create_table :blogs, :force => true do |t|
10
+ t.string :name
11
+ t.string :subdomain
12
+ t.timestamps
13
+ end
14
+ end
@@ -0,0 +1,113 @@
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).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', '-lf', '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.send(:run_command).should == [ 'sunspot-solr', 'run' ]
96
+ end
97
+
98
+ it "should generate the path for config files" do
99
+ Sunspot::Rails::Server.should_receive(:solr_home).and_return('/solr/home')
100
+ Sunspot::Rails::Server.config_path.should == '/solr/home/conf'
101
+ end
102
+
103
+ it "should generate the path for the index data" do
104
+ Sunspot::Rails::Server.should_receive(:solr_home).and_return('/solr/home')
105
+ Sunspot::Rails::Server.data_path.should == '/solr/home/data/test'
106
+ end
107
+
108
+ it "should generate the path for pid files" do
109
+ Sunspot::Rails::Server.should_receive(:solr_home).and_return('/solr/home')
110
+ Sunspot::Rails::Server.pid_path.should == '/solr/home/pids/test'
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,46 @@
1
+ ENV['RAILS_ENV'] = 'test'
2
+ ENV['RAILS_ROOT'] ||= File.join(File.dirname(__FILE__), 'mock_app')
3
+
4
+ require File.expand_path(File.join(ENV['RAILS_ROOT'], 'config', 'environment.rb'))
5
+
6
+ require 'spec'
7
+ require 'spec/rails'
8
+ require 'rake'
9
+ require 'ruby-debug' unless RUBY_VERSION =~ /1\.9/
10
+ require 'sunspot/rails/tasks'
11
+ require 'sunspot/spec/extension'
12
+
13
+ def load_schema
14
+ stdout = $stdout
15
+ $stdout = StringIO.new # suppress output while building the schema
16
+ load File.join(File.dirname(__FILE__), 'schema.rb')
17
+ $stdout = stdout
18
+ end
19
+
20
+ def silence_stderr(&block)
21
+ stderr = $stderr
22
+ $stderr = StringIO.new
23
+ yield
24
+ $stderr = stderr
25
+ end
26
+
27
+ Spec::Runner.configure do |config|
28
+ config.before(:each) do
29
+ if integrate_sunspot?
30
+ Sunspot.remove_all
31
+ Sunspot.commit
32
+ end
33
+ load_schema
34
+ end
35
+ end
36
+
37
+ module Spec
38
+ module Mocks
39
+ module Methods
40
+ def should_respond_to_and_receive(*args, &block)
41
+ respond_to?(args.first).should ==(true)
42
+ should_receive(*args, &block)
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,21 @@
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
+ @post = PostWithAuto.create!
8
+ Sunspot.commit
9
+ PostWithAuto.search.results.should == [@post]
10
+ end
11
+ end
12
+
13
+ describe 'Sunspot Spec Integration - mock sunspot' do
14
+ it "should call sunspot" do
15
+ Sunspot.remove_all
16
+ Sunspot.commit
17
+ @post = PostWithAuto.create!
18
+ Sunspot.commit
19
+ PostWithAuto.search.results.should_not include(@post)
20
+ end
21
+ end
metadata ADDED
@@ -0,0 +1,184 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: benjaminkrause-sunspot_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.10.5
5
+ platform: ruby
6
+ authors:
7
+ - Mat Brown
8
+ - Peer Allan
9
+ - Michael Moen
10
+ - Benjamin Krause
11
+ - Adam Salter
12
+ - Brandon Keepers
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2009-09-16 00:00:00 -07:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: escape
22
+ type: :runtime
23
+ version_requirement:
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: 0.0.4
29
+ version:
30
+ - !ruby/object:Gem::Dependency
31
+ name: outoftime-sunspot
32
+ type: :runtime
33
+ version_requirement:
34
+ version_requirements: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: 0.9.7
39
+ version:
40
+ - !ruby/object:Gem::Dependency
41
+ name: rspec
42
+ type: :development
43
+ version_requirement:
44
+ version_requirements: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ~>
47
+ - !ruby/object:Gem::Version
48
+ version: "1.2"
49
+ version:
50
+ - !ruby/object:Gem::Dependency
51
+ name: rspec-rails
52
+ type: :development
53
+ version_requirement:
54
+ version_requirements: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ~>
57
+ - !ruby/object:Gem::Version
58
+ version: "1.2"
59
+ version:
60
+ - !ruby/object:Gem::Dependency
61
+ name: ruby-debug
62
+ type: :development
63
+ version_requirement:
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: "0.10"
69
+ version:
70
+ - !ruby/object:Gem::Dependency
71
+ name: technicalpickles-jeweler
72
+ type: :development
73
+ version_requirement:
74
+ version_requirements: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ~>
77
+ - !ruby/object:Gem::Version
78
+ version: "1.0"
79
+ version:
80
+ description: Rails integration for the Sunspot Solr search library
81
+ email: mat@patch.com
82
+ executables: []
83
+
84
+ extensions: []
85
+
86
+ extra_rdoc_files:
87
+ - LICENSE
88
+ - README.rdoc
89
+ files:
90
+ - History.txt
91
+ - LICENSE
92
+ - MIT-LICENSE
93
+ - README.rdoc
94
+ - Rakefile
95
+ - TODO
96
+ - VERSION.yml
97
+ - dev_tasks/gemspec.rake
98
+ - dev_tasks/rdoc.rake
99
+ - dev_tasks/release.rake
100
+ - dev_tasks/todo.rake
101
+ - generators/sunspot/sunspot_generator.rb
102
+ - generators/sunspot/templates/sunspot.yml
103
+ - install.rb
104
+ - lib/sunspot/rails.rb
105
+ - lib/sunspot/rails/adapters.rb
106
+ - lib/sunspot/rails/configuration.rb
107
+ - lib/sunspot/rails/request_lifecycle.rb
108
+ - lib/sunspot/rails/searchable.rb
109
+ - lib/sunspot/rails/server.rb
110
+ - lib/sunspot/rails/tasks.rb
111
+ - lib/sunspot/spec/extension.rb
112
+ - rails/init.rb
113
+ - spec/configuration_spec.rb
114
+ - spec/mock_app/app/controllers/application.rb
115
+ - spec/mock_app/app/controllers/application_controller.rb
116
+ - spec/mock_app/app/controllers/posts_controller.rb
117
+ - spec/mock_app/app/models/blog.rb
118
+ - spec/mock_app/app/models/post.rb
119
+ - spec/mock_app/app/models/post_with_auto.rb
120
+ - spec/mock_app/config/boot.rb
121
+ - spec/mock_app/config/database.yml
122
+ - spec/mock_app/config/environment.rb
123
+ - spec/mock_app/config/environments/development.rb
124
+ - spec/mock_app/config/environments/test.rb
125
+ - spec/mock_app/config/initializers/new_rails_defaults.rb
126
+ - spec/mock_app/config/initializers/session_store.rb
127
+ - spec/mock_app/config/routes.rb
128
+ - spec/mock_app/config/sunspot.yml
129
+ - spec/model_lifecycle_spec.rb
130
+ - spec/model_spec.rb
131
+ - spec/request_lifecycle_spec.rb
132
+ - spec/schema.rb
133
+ - spec/server_spec.rb
134
+ - spec/spec_helper.rb
135
+ - spec/sunspot_mocking_spec.rb
136
+ has_rdoc: true
137
+ homepage: http://github.com/outoftime/sunspot_rails
138
+ licenses:
139
+ post_install_message:
140
+ rdoc_options:
141
+ - --charset=UTF-8
142
+ require_paths:
143
+ - lib
144
+ required_ruby_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: "0"
149
+ version:
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: "0"
155
+ version:
156
+ requirements: []
157
+
158
+ rubyforge_project: sunspot
159
+ rubygems_version: 1.3.5
160
+ signing_key:
161
+ specification_version: 2
162
+ summary: Rails integration for the Sunspot Solr search library
163
+ test_files:
164
+ - spec/configuration_spec.rb
165
+ - spec/mock_app/app/controllers/application.rb
166
+ - spec/mock_app/app/controllers/application_controller.rb
167
+ - spec/mock_app/app/controllers/posts_controller.rb
168
+ - spec/mock_app/app/models/blog.rb
169
+ - spec/mock_app/app/models/post.rb
170
+ - spec/mock_app/app/models/post_with_auto.rb
171
+ - spec/mock_app/config/boot.rb
172
+ - spec/mock_app/config/environment.rb
173
+ - spec/mock_app/config/environments/development.rb
174
+ - spec/mock_app/config/environments/test.rb
175
+ - spec/mock_app/config/initializers/new_rails_defaults.rb
176
+ - spec/mock_app/config/initializers/session_store.rb
177
+ - spec/mock_app/config/routes.rb
178
+ - spec/model_lifecycle_spec.rb
179
+ - spec/model_spec.rb
180
+ - spec/request_lifecycle_spec.rb
181
+ - spec/schema.rb
182
+ - spec/server_spec.rb
183
+ - spec/spec_helper.rb
184
+ - spec/sunspot_mocking_spec.rb