sunspot_rails 1.1.0 → 1.2.0

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 +11 -0
  2. data/README.rdoc +13 -11
  3. data/Rakefile +1 -10
  4. data/TESTING.md +35 -0
  5. data/dev_tasks/spec.rake +22 -0
  6. data/lib/generators/sunspot_rails/install/install_generator.rb +13 -0
  7. data/lib/generators/sunspot_rails/install/templates/config/sunspot.yml +17 -0
  8. data/lib/generators/sunspot_rails.rb +9 -0
  9. data/lib/sunspot/rails/adapters.rb +6 -6
  10. data/lib/sunspot/rails/configuration.rb +53 -6
  11. data/{rails → lib/sunspot/rails}/init.rb +0 -2
  12. data/lib/sunspot/rails/railtie.rb +26 -0
  13. data/lib/sunspot/rails/request_lifecycle.rb +7 -2
  14. data/lib/sunspot/rails/searchable.rb +11 -13
  15. data/lib/sunspot/rails/server.rb +1 -1
  16. data/lib/sunspot/rails/solr_logging.rb +6 -1
  17. data/lib/sunspot/rails/spec_helper.rb +8 -1
  18. data/lib/sunspot/rails/tasks.rb +1 -1
  19. data/lib/sunspot/rails/version.rb +1 -1
  20. data/lib/sunspot_rails.rb +7 -0
  21. data/spec/configuration_spec.rb +80 -9
  22. data/spec/model_spec.rb +19 -21
  23. data/spec/request_lifecycle_spec.rb +11 -2
  24. data/spec/server_spec.rb +2 -1
  25. data/spec/spec_helper.rb +18 -23
  26. metadata +45 -48
  27. data/dev_tasks/gemspec.rake +0 -33
  28. data/spec/mock_app/app/controllers/application.rb +0 -10
  29. data/spec/mock_app/app/controllers/application_controller.rb +0 -10
  30. data/spec/mock_app/app/controllers/posts_controller.rb +0 -6
  31. data/spec/mock_app/app/models/author.rb +0 -8
  32. data/spec/mock_app/app/models/blog.rb +0 -12
  33. data/spec/mock_app/app/models/location.rb +0 -2
  34. data/spec/mock_app/app/models/photo_post.rb +0 -2
  35. data/spec/mock_app/app/models/post.rb +0 -10
  36. data/spec/mock_app/app/models/post_with_auto.rb +0 -10
  37. data/spec/mock_app/config/boot.rb +0 -110
  38. data/spec/mock_app/config/database.yml +0 -4
  39. data/spec/mock_app/config/environment.rb +0 -42
  40. data/spec/mock_app/config/environments/development.rb +0 -27
  41. data/spec/mock_app/config/environments/test.rb +0 -27
  42. data/spec/mock_app/config/initializers/new_rails_defaults.rb +0 -19
  43. data/spec/mock_app/config/initializers/session_store.rb +0 -15
  44. data/spec/mock_app/config/routes.rb +0 -43
  45. data/spec/mock_app/config/sunspot.yml +0 -19
  46. data/spec/mock_app/db/schema.rb +0 -27
  47. data/spec/mock_app/db/test.db +0 -0
data/History.txt CHANGED
@@ -1,3 +1,14 @@
1
+ == 1.2.0 2010-12-28
2
+ * Compatible with both Rails 2 and Rails 3
3
+ * Configure Sunspot with a SOLR_URL or WEBSOLR_URL environment variable, also
4
+ provide a default port based on Rails.env.
5
+ * Fix the 'Anonymous modules' ArgumentError for Ruby 1.9.2 and Rails 2.3
6
+ * Fix SQL's ambiguous ID issue when tables are joined
7
+
8
+ == 1.1.0 2010-04-01
9
+ * Added include option to searchable options to allow definition of eager
10
+ loading associations when indexing
11
+
1
12
  == 1.0.4 2010-03-19
2
13
  * Fix StubSessionProxy to match new internal API
3
14
 
data/README.rdoc CHANGED
@@ -14,25 +14,25 @@ provides the following features:
14
14
  * Provide rake tasks for starting and stopping the development Solr instance,
15
15
  using the configuration in sunspot.yml
16
16
 
17
- Sunspot::Rails has been tested with Rails versions 2.1, 2.2, and 2.3
17
+ Sunspot::Rails has been tested with Rails versions 2.3 and 3.0
18
18
 
19
- == Installation
19
+ == Installation in Rails 3
20
20
 
21
- For recent versions of Rails, In your project's <code>config/environment.rb</code>, add the following gem dependencies:
21
+ In your <code>Gemfile</code>:
22
22
 
23
- config.gem 'sunspot', :lib => 'sunspot'
24
- config.gem 'sunspot_rails', :lib => 'sunspot/rails'
23
+ gem 'sunspot_rails'
24
+
25
+ == Installation in Rails 2
26
+
27
+ In your project's <code>config/environment.rb</code>, add the following gem dependencies:
28
+
29
+ config.gem 'sunspot'
30
+ config.gem 'sunspot_rails'
25
31
 
26
32
  Install the gems with:
27
33
 
28
34
  rake gems:install
29
35
 
30
- If you are using an older version of Rails that doesn't support plugins-as-gems, install the gems manually and install the plugin:
31
-
32
- sudo gem install sunspot sunspot_rails --source=http://gems.github.com
33
-
34
- script/plugin install git://github.com/outoftime/sunspot_rails.git
35
-
36
36
  Generate the file <code>config/sunspot.yml</code>:
37
37
 
38
38
  script/generate sunspot
@@ -43,6 +43,8 @@ Sunspot::Rails as a gem, add the following line to your project's Rakefile:
43
43
 
44
44
  require 'sunspot/rails/tasks'
45
45
 
46
+ == Using Sunspot::Rails
47
+
46
48
  If you wish to make modifications to the Solr schema, you can create a custom
47
49
  Solr home in your project directory. In order to do so, create the directory
48
50
  <code>RAILS_ROOT/solr/conf</code>, and copy in the contents of the Solr gem's
data/Rakefile CHANGED
@@ -1,25 +1,16 @@
1
1
  require 'rake'
2
- require 'spec/rake/spectask'
3
2
  require 'rake/rdoctask'
4
3
 
5
- task :default => :spec
6
-
7
4
  if File.exist?(sunspot_lib = File.expand_path(File.join(File.dirname(__FILE__), '..', 'sunspot', 'lib')))
8
5
  STDERR.puts("Using sunspot lib at #{sunspot_lib}")
9
6
  $: << sunspot_lib
10
7
  end
11
8
 
12
- desc 'Run all specs'
13
- Spec::Rake::SpecTask.new(:spec) do |t|
14
- t.spec_files = FileList['spec/*_spec.rb']
15
- t.spec_opts << '--color'
16
- end
17
-
18
9
  task :environment do
19
10
  if ENV['SUNSPOT_LIB']
20
11
  $: << ENV['SUNSPOT_LIB']
21
12
  end
22
- ENV['RAILS_ROOT'] ||= File.join(File.dirname(__FILE__), 'spec', 'mock_app')
13
+ ENV['RAILS_ROOT'] ||= File.join(File.dirname(__FILE__), 'spec', 'rails3')
23
14
  ENV['RAILS_ENV'] ||= 'test'
24
15
  require File.expand_path(File.join(ENV['RAILS_ROOT'], 'config', 'environment.rb'))
25
16
  end
data/TESTING.md ADDED
@@ -0,0 +1,35 @@
1
+ # Testing `sunspot_rails`
2
+
3
+ Note: All the paths mentioned in here are relative to the current directory, or `sunspot/sunspot_rails`.
4
+
5
+ The `sunspot_rails` gem is tested with RSpec, and its spec suite is located in `spec`.
6
+
7
+ These specs are to be run against up to date Rails 2 and Rails 3 applications, included at `spec/rails2` and `spec/rails3`, respectively. The `spec_helper.rb` file loads the environment for these applications based on the `RAILS_ROOT` provided when invoking tests, outlined below.
8
+
9
+ ## Start Solr
10
+
11
+ Specs expect to connect to Solr on `http://localhost:8980/solr`
12
+
13
+ rake sunspot:solr:start
14
+
15
+ ## Install dependencies
16
+
17
+ Each application uses Bundler to manage its dependencies. The `Gemfile` also installs the `sunspot` and `sunspot_rails` gems from your copies checked out locally. Because Bundler expands the full path to `sunspot` and `sunspot_rails`, we're excluding its generated `Gemfile.lock` file from version control.
18
+
19
+ pushd spec/rails2
20
+ bundle install
21
+ cd ../rails3
22
+ bundle install
23
+ popd
24
+
25
+ ## Invoke specs
26
+
27
+ The project contains wrapper scripts that set up the environment to run the
28
+ specs under Rails 2 and Rails 3 respectively:
29
+
30
+ rake spec:rails2
31
+ rake spec:rails3
32
+
33
+ Or you can run them both:
34
+
35
+ rake spec
@@ -0,0 +1,22 @@
1
+ desc 'Run spec suite in both Rails 2 and Rails 3'
2
+ task :spec => [:"spec:rails2", :"spec:rails3"]
3
+
4
+ namespace :spec do
5
+ desc 'Run spec suite in Rails 2 application'
6
+ task :rails2 do
7
+ ENV['BUNDLE_GEMFILE'] = 'spec/rails2/Gemfile'
8
+ ENV['RAILS_ROOT'] = 'spec/rails2'
9
+ require 'bundler'
10
+ Bundler.setup(:default, :test)
11
+ system "spec --color #{ENV['SPEC'] || 'spec'}"
12
+ end
13
+
14
+ desc 'Run spec suite in Rails 3 application'
15
+ task :rails3 do
16
+ ENV['BUNDLE_GEMFILE'] = 'spec/rails3/Gemfile'
17
+ ENV['RAILS_ROOT'] = 'spec/rails3'
18
+ require 'bundler'
19
+ Bundler.setup(:default, :test)
20
+ system "rspec --color #{ENV['SPEC'] || 'spec'}"
21
+ end
22
+ end
@@ -0,0 +1,13 @@
1
+ module SunspotRails
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ def self.source_root
5
+ @source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
6
+ end
7
+ def copy_config_file
8
+ template 'config/sunspot.yml'
9
+ end
10
+ end
11
+ end
12
+ end
13
+
@@ -0,0 +1,17 @@
1
+ production:
2
+ solr:
3
+ hostname: localhost
4
+ port: 8983
5
+ log_level: WARNING
6
+
7
+ development:
8
+ solr:
9
+ hostname: localhost
10
+ port: 8982
11
+ log_level: INFO
12
+
13
+ test:
14
+ solr:
15
+ hostname: localhost
16
+ port: 8981
17
+ log_level: WARNING
@@ -0,0 +1,9 @@
1
+ module SunspotRails
2
+ module Generators
3
+ class Base < Rails::Generators::NamedBase
4
+ def self.source_root
5
+ @_sunspot_rails_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'sunspot_rails', generator_name, 'templates'))
6
+ end
7
+ end
8
+ end
9
+ end
@@ -48,7 +48,7 @@ module Sunspot #:nodoc:
48
48
  #
49
49
  def load(id)
50
50
  @clazz.first(options_for_find.merge(
51
- :conditions => { @clazz.primary_key => id.to_i}
51
+ :conditions => { @clazz.primary_key => id}
52
52
  ))
53
53
  end
54
54
 
@@ -65,17 +65,17 @@ module Sunspot #:nodoc:
65
65
  #
66
66
  def load_all(ids)
67
67
  @clazz.all(options_for_find.merge(
68
- :conditions => { @clazz.primary_key => ids.map { |id| id.to_i }}
68
+ :conditions => { @clazz.primary_key => ids.map { |id| id }}
69
69
  ))
70
70
  end
71
71
 
72
72
  private
73
73
 
74
74
  def options_for_find
75
- returning({}) do |options|
76
- options[:include] = @include unless @include.blank?
77
- options[:select] = @select unless @select.blank?
78
- end
75
+ options = {}
76
+ options[:include] = @include unless @include.blank?
77
+ options[:select] = @select unless @select.blank?
78
+ options
79
79
  end
80
80
  end
81
81
  end
@@ -48,18 +48,30 @@ module Sunspot #:nodoc:
48
48
  # String:: host name
49
49
  #
50
50
  def hostname
51
- @hostname ||= (user_configuration_from_key('solr', 'hostname') || 'localhost')
51
+ unless defined?(@hostname)
52
+ @hostname = solr_url.host if solr_url
53
+ @hostname ||= user_configuration_from_key('solr', 'hostname')
54
+ @hostname ||= default_hostname
55
+ end
56
+ @hostname
52
57
  end
53
-
58
+
54
59
  #
55
- # The port at which to connect to Solr. Default 8983.
60
+ # The port at which to connect to Solr.
61
+ # Defaults to 8981 in test, 8982 in development and 8983 in production.
56
62
  #
57
63
  # ==== Returns
58
64
  #
59
65
  # Integer:: port
60
66
  #
61
67
  def port
62
- @port ||= (user_configuration_from_key('solr', 'port') || 8983).to_i
68
+ unless defined?(@port)
69
+ @port = solr_url.port if solr_url
70
+ @port ||= user_configuration_from_key('solr', 'port')
71
+ @port ||= default_port
72
+ @port = @port.to_i
73
+ end
74
+ @port
63
75
  end
64
76
 
65
77
  #
@@ -71,7 +83,12 @@ module Sunspot #:nodoc:
71
83
  # String:: path
72
84
  #
73
85
  def path
74
- @path ||= (user_configuration_from_key('solr', 'path') || '/solr')
86
+ unless defined?(@path)
87
+ @path = solr_url.path if solr_url
88
+ @path ||= user_configuration_from_key('solr', 'path')
89
+ @path ||= default_path
90
+ end
91
+ @path
75
92
  end
76
93
 
77
94
  #
@@ -245,7 +262,7 @@ module Sunspot #:nodoc:
245
262
  hash[key] if hash
246
263
  end
247
264
  end
248
-
265
+
249
266
  #
250
267
  # Memoized hash of configuration options for the current Rails environment
251
268
  # as specified in config/sunspot.yml
@@ -267,6 +284,36 @@ module Sunspot #:nodoc:
267
284
  end
268
285
  end
269
286
  end
287
+
288
+ protected
289
+
290
+ #
291
+ # When a specific hostname, port and path aren't provided in the
292
+ # sunspot.yml file, look for a key named 'url', then check the
293
+ # environment, then fall back to a sensible localhost default.
294
+ #
295
+
296
+ def solr_url
297
+ if ENV['SOLR_URL'] || ENV['WEBSOLR_URL']
298
+ URI.parse(ENV['SOLR_URL'] || ENV['WEBSOLR_URL'])
299
+ end
300
+ end
301
+
302
+ def default_hostname
303
+ 'localhost'
304
+ end
305
+
306
+ def default_port
307
+ { 'test' => 8981,
308
+ 'development' => 8982,
309
+ 'production' => 8983
310
+ }[::Rails.env] || 8983
311
+ end
312
+
313
+ def default_path
314
+ '/solr'
315
+ end
316
+
270
317
  end
271
318
  end
272
319
  end
@@ -1,5 +1,3 @@
1
- require 'sunspot'
2
-
3
1
  Sunspot.session = Sunspot::Rails.build_session
4
2
  Sunspot::Adapters::InstanceAdapter.register(Sunspot::Rails::Adapters::ActiveRecordInstanceAdapter, ActiveRecord::Base)
5
3
  Sunspot::Adapters::DataAccessor.register(Sunspot::Rails::Adapters::ActiveRecordDataAccessor, ActiveRecord::Base)
@@ -0,0 +1,26 @@
1
+ module Sunspot
2
+ module Rails
3
+ class Railtie < ::Rails::Railtie
4
+ initializer 'sunspot_rails.init' do
5
+ Sunspot.session = Sunspot::Rails.build_session
6
+ ActiveSupport.on_load(:active_record) do
7
+ Sunspot::Adapters::InstanceAdapter.register(Sunspot::Rails::Adapters::ActiveRecordInstanceAdapter, ActiveRecord::Base)
8
+ Sunspot::Adapters::DataAccessor.register(Sunspot::Rails::Adapters::ActiveRecordDataAccessor, ActiveRecord::Base)
9
+ include(Sunspot::Rails::Searchable)
10
+ end
11
+ ActiveSupport.on_load(:action_controller) do
12
+ include(Sunspot::Rails::RequestLifecycle)
13
+ end
14
+ end
15
+
16
+ rake_tasks do
17
+ load 'sunspot/rails/tasks.rb'
18
+ end
19
+
20
+ generators do
21
+ load "generators/sunspot_rails.rb"
22
+ end
23
+
24
+ end
25
+ end
26
+ end
@@ -8,8 +8,13 @@ module Sunspot #:nodoc:
8
8
  module RequestLifecycle
9
9
  class <<self
10
10
  def included(base) #:nodoc:
11
- loaded_controllers =
12
- [base].concat(base.subclasses.map { |subclass| subclass.constantize })
11
+ subclasses = base.subclasses.map do |subclass|
12
+ begin
13
+ subclass.constantize
14
+ rescue NameError
15
+ end
16
+ end.compact
17
+ loaded_controllers = [base].concat(subclasses)
13
18
  # Depending on how Sunspot::Rails is loaded, there may already be
14
19
  # controllers loaded into memory that subclass this controller. In
15
20
  # this case, since after_filter uses the inheritable_attribute
@@ -223,25 +223,23 @@ module Sunspot #:nodoc:
223
223
  # Post.index(:include => :author)
224
224
  #
225
225
  def solr_index(opts={})
226
- options = { :batch_size => 500, :batch_commit => true, :include => self.sunspot_options[:include], :first_id => 0}.merge(opts)
227
- unless options[:batch_size]
228
- Sunspot.index!(all(:include => options[:include]))
229
- else
230
- offset = 0
231
- counter = 1
232
- record_count = count
233
- last_id = options[:first_id]
234
- while(offset < record_count)
226
+ options = {
227
+ :batch_size => 500,
228
+ :batch_commit => true,
229
+ :include => self.sunspot_options[:include],
230
+ :first_id => 0
231
+ }.merge(opts)
232
+
233
+ if options[:batch_size]
234
+ find_in_batches(:include => options[:include], :batch_size => options[:batch_size]) do |records|
235
235
  solr_benchmark options[:batch_size], counter do
236
- records = all(:include => options[:include], :conditions => ["#{table_name}.#{primary_key} > ?", last_id], :limit => options[:batch_size], :order => primary_key)
237
236
  Sunspot.index(records)
238
- last_id = records.last.id
239
237
  end
240
238
  Sunspot.commit if options[:batch_commit]
241
- offset += options[:batch_size]
242
- counter += 1
243
239
  end
244
240
  Sunspot.commit unless options[:batch_commit]
241
+ else
242
+ Sunspot.index!(all(:include => options[:include]))
245
243
  end
246
244
  end
247
245
 
@@ -66,7 +66,7 @@ module Sunspot
66
66
  # Directory to use for Solr home.
67
67
  #
68
68
  def solr_home
69
- File.join(::Rails.root, 'solr')
69
+ File.join(configuration.solr_home)
70
70
  end
71
71
 
72
72
  #
@@ -38,7 +38,12 @@ module Sunspot
38
38
  private
39
39
 
40
40
  def format_log_entry(message, dump = nil)
41
- if ActiveRecord::Base.colorize_logging
41
+ @colorize_logging ||= begin
42
+ ::Rails.application.config.colorize_logging # Rails 3
43
+ rescue NoMethodError
44
+ ActiveRecord::Base.colorize_logging # Rails 2
45
+ end
46
+ if @colorize_logging
42
47
  message_color, dump_color = "4;32;1", "0;1"
43
48
  log_entry = " \e[#{message_color}m#{message}\e[0m "
44
49
  log_entry << "\e[#{dump_color}m%#{String === dump ? 's' : 'p'}\e[0m" % dump if dump
@@ -14,6 +14,13 @@ module Sunspot
14
14
  end
15
15
  end
16
16
 
17
- Spec::Runner.configure do |config|
17
+ rspec =
18
+ begin
19
+ RSpec
20
+ rescue NameError, ArgumentError
21
+ Spec::Runner
22
+ end
23
+
24
+ rspec.configure do |config|
18
25
  config.extend(Sunspot::Rails::SpecHelper)
19
26
  end
@@ -47,7 +47,7 @@ namespace :sunspot do
47
47
  reindex_options[:batch_size] = args[:batch_size].to_i if args[:batch_size].to_i > 0
48
48
  end
49
49
  unless args[:models]
50
- all_files = Dir.glob(File.join(RAILS_ROOT, 'app', 'models', '*.rb'))
50
+ all_files = Dir.glob(Rails.root.join('app', 'models', '*.rb'))
51
51
  all_models = all_files.map { |path| File.basename(path, '.rb').camelize.constantize }
52
52
  sunspot_models = all_models.select { |m| m < ActiveRecord::Base and m.searchable? }
53
53
  else
@@ -1,5 +1,5 @@
1
1
  module Sunspot
2
2
  module Rails
3
- VERSION = '1.1.0'
3
+ VERSION = '1.2.0'
4
4
  end
5
5
  end
@@ -0,0 +1,7 @@
1
+ require 'sunspot/rails'
2
+
3
+ if Rails::VERSION::MAJOR == 3
4
+ require 'sunspot/rails/railtie'
5
+ else
6
+ require 'sunspot/rails/init'
7
+ end
@@ -1,8 +1,8 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
- describe Sunspot::Rails::Configuration, "default values" do
3
+ describe Sunspot::Rails::Configuration, "default values without a sunspot.yml" do
4
4
  before(:each) do
5
- File.should_receive(:exist?).at_least(:once).and_return(false)
5
+ File.stub!(:exist?).and_return(false) # simulate sunspot.yml not existing
6
6
  @config = Sunspot::Rails::Configuration.new
7
7
  end
8
8
 
@@ -14,8 +14,27 @@ describe Sunspot::Rails::Configuration, "default values" do
14
14
  @config.path.should == '/solr'
15
15
  end
16
16
 
17
- it "should handle the 'port' property when not set" do
18
- @config.port.should == 8983
17
+ describe "port" do
18
+ it "should default to port 8981 in test" do
19
+ ::Rails.stub!(:env => 'test')
20
+ @config = Sunspot::Rails::Configuration.new
21
+ @config.port.should == 8981
22
+ end
23
+ it "should default to port 8982 in development" do
24
+ ::Rails.stub!(:env => 'development')
25
+ @config = Sunspot::Rails::Configuration.new
26
+ @config.port.should == 8982
27
+ end
28
+ it "should default to 8983 in production" do
29
+ ::Rails.stub!(:env => 'production')
30
+ @config = Sunspot::Rails::Configuration.new
31
+ @config.port.should == 8983
32
+ end
33
+ it "should generally default to 8983" do
34
+ ::Rails.stub!(:env => 'staging')
35
+ @config = Sunspot::Rails::Configuration.new
36
+ @config.port.should == 8983
37
+ end
19
38
  end
20
39
 
21
40
  it "should handle the 'log_level' property when not set" do
@@ -41,10 +60,6 @@ describe Sunspot::Rails::Configuration, "default values" do
41
60
  @config.pid_path.should == '/some/path/solr/pids/test'
42
61
  end
43
62
 
44
- it "should handle the 'solr_home' property when not set" do
45
- @config.solr_home.should_not == nil
46
- end
47
-
48
63
  it "should handle the 'auto_commit_after_request' propery when not set" do
49
64
  @config.auto_commit_after_request?.should == true
50
65
  end
@@ -54,7 +69,7 @@ describe Sunspot::Rails::Configuration, "default values" do
54
69
  end
55
70
  end
56
71
 
57
- describe Sunspot::Rails::Configuration, "user settings" do
72
+ describe Sunspot::Rails::Configuration, "user provided sunspot.yml" do
58
73
  before(:each) do
59
74
  ::Rails.stub!(:env => 'config_test')
60
75
  @config = Sunspot::Rails::Configuration.new
@@ -100,3 +115,59 @@ describe Sunspot::Rails::Configuration, "user settings" do
100
115
  @config.auto_commit_after_delete_request?.should == true
101
116
  end
102
117
  end
118
+
119
+
120
+ describe Sunspot::Rails::Configuration, "with ENV['SOLR_URL'] overriding sunspot.yml" do
121
+ before(:all) do
122
+ ENV['SOLR_URL'] = 'http://environment.host:5432/solr/env'
123
+ end
124
+
125
+ before(:each) do
126
+ ::Rails.stub!(:env => 'config_test')
127
+ @config = Sunspot::Rails::Configuration.new
128
+ end
129
+
130
+ after(:all) do
131
+ ENV.delete('SOLR_URL')
132
+ end
133
+
134
+ it "should handle the 'hostname' property when set" do
135
+ @config.hostname.should == 'environment.host'
136
+ end
137
+
138
+ it "should handle the 'port' property when set" do
139
+ @config.port.should == 5432
140
+ end
141
+
142
+ it "should handle the 'path' property when set" do
143
+ @config.path.should == '/solr/env'
144
+ end
145
+ end
146
+
147
+ describe Sunspot::Rails::Configuration, "with ENV['WEBSOLR_URL'] overriding sunspot.yml" do
148
+ before(:all) do
149
+ ENV['WEBSOLR_URL'] = 'http://index.websolr.test/solr/a1b2c3d4e5f'
150
+ end
151
+
152
+ before(:each) do
153
+ ::Rails.stub!(:env => 'config_test')
154
+ @config = Sunspot::Rails::Configuration.new
155
+ end
156
+
157
+ after(:all) do
158
+ ENV.delete('WEBSOLR_URL')
159
+ end
160
+
161
+ it "should handle the 'hostname' property when set" do
162
+ @config.hostname.should == 'index.websolr.test'
163
+ end
164
+
165
+ it "should handle the 'port' property when set" do
166
+ @config.port.should == 80
167
+ end
168
+
169
+ it "should handle the 'path' property when set" do
170
+ @config.path.should == '/solr/a1b2c3d4e5f'
171
+ end
172
+ end
173
+