diff --git a/Rakefile b/Rakefile index bb9d2f2..f0d6b05 100644 --- a/Rakefile +++ b/Rakefile @@ -6,7 +6,7 @@ task :default => :spec desc 'Run all specs' Spec::Rake::SpecTask.new(:spec) do |t| - t.spec_files = FileList['spec/**/*_spec.rb'] + t.spec_files = FileList['spec/*_spec.rb'] t.spec_opts << '--color' end diff --git a/lib/sunspot/rails/configuration.rb b/lib/sunspot/rails/configuration.rb index 91b66d7..3ec659f 100644 --- a/lib/sunspot/rails/configuration.rb +++ b/lib/sunspot/rails/configuration.rb @@ -142,18 +142,13 @@ def auto_commit_after_request? def log_file @log_file ||= (user_configuration_from_key('solr', 'log_file') || default_log_file_location ) end + + def data_path + @data_path ||= user_configuration_from_key('solr', 'data_path') || File.join(::Rails.root, 'solr', 'data', ::Rails.env) + end - # - # The solr home directory. Sunspot::Rails expects this directory - # to contain a config, data and pids directory. See - # Sunspot::Rails::Server.bootstrap for more information. - # - # ==== Returns - # - # String:: solr_home - # - def solr_home - @solr_home ||= (user_configuration_from_key('solr', 'solr_home') || File.join( ::Rails.root, 'solr' )) + def pid_path + @pids_path ||= user_configuration_from_key('solr', 'pid_path') || File.join(::Rails.root, 'solr', 'pids', ::Rails.env) end # @@ -168,6 +163,24 @@ def auto_commit_after_request? @auto_commit_after_request ||= user_configuration_from_key('auto_commit_after_request') != false end + + # + # The solr home directory. Sunspot::Rails expects this directory + # to contain a config, data and pids directory. See + # Sunspot::Rails::Server.bootstrap for more information. + # + # ==== Returns + # + # String:: solr_home + # + def solr_home + @solr_home ||= + if user_configuration_from_key('solr', 'solr_home') + user_configuration_from_key('solr', 'solr_home') + elsif %w(solrconfig schema).all? { |file| File.exist?(File.join(::Rails.root, 'solr', 'conf', "#{file}.xml")) } + File.join(::Rails.root, 'solr') + end + end private diff --git a/spec/.gitignore b/spec/.gitignore deleted file mode 100644 index c370cb6..0000000 --- a/spec/.gitignore +++ /dev/null @@ -1 +0,0 @@ -test.db diff --git a/spec/configuration_spec.rb b/spec/configuration_spec.rb index a2bd8a5..dc69737 100644 --- a/spec/configuration_spec.rb +++ b/spec/configuration_spec.rb @@ -1,8 +1,8 @@ -require File.join(File.dirname(__FILE__), 'spec_helper') +require File.dirname(__FILE__) + '/spec_helper' describe Sunspot::Rails::Configuration, "default values" do before(:each) do - File.should_receive(:exist?).and_return(false) + File.should_receive(:exist?).at_least(:once).and_return(false) @config = Sunspot::Rails::Configuration.new end @@ -31,6 +31,21 @@ @config.solr_home.should == '/some/path/solr' end + it "should handle the 'data_path' property when not set" do + config = Sunspot::Rails::Configuration.new + config.data_path.should == File.dirname(__FILE__) + '/mock_app/solr/data/test' + end + + it "should handle the 'pid_path' property when not set" do + config = Sunspot::Rails::Configuration.new + config.pid_path.should == File.dirname(__FILE__) + '/mock_app/solr/pids/test' + end + + it "should handle the 'solr_home' property when not set" do + config = Sunspot::Rails::Configuration.new + config.solr_home.should == nil + end + it "should handle the 'auto_commit_after_request' propery when not set" do @config.auto_commit_after_request?.should == true end @@ -38,16 +53,17 @@ describe Sunspot::Rails::Configuration, "user settings" do before(:each) do - Rails.stub!(:env => 'config_test') - @config = Sunspot::Rails::Configuration.new + ::Rails.stub!(:env => 'config_test') end - it "should handle the 'hostname' property when not set" do - @config.hostname.should == 'some.host' + it "should handle the 'hostname' property when set" do + config = Sunspot::Rails::Configuration.new + config.hostname.should == 'some.host' end - it "should handle the 'port' property when not set" do - @config.port.should == 1234 + it "should handle the 'port' property when set" do + config = Sunspot::Rails::Configuration.new + config.port.should == 1234 end it "should handle the 'path' property when set" do @@ -62,6 +78,21 @@ @config.solr_home.should == '/another/path/solr' end + it "should handle the 'data_path' property when set" do + config = Sunspot::Rails::Configuration.new + config.data_path.should == '/my_superior_path/data' + end + + it "should handle the 'pid_path' property when set" do + config = Sunspot::Rails::Configuration.new + config.pid_path.should == '/my_superior_path/pids' + end + + it "should handle the 'solr_home' property when set" do + config = Sunspot::Rails::Configuration.new + config.solr_home.should == '/my_superior_path' + end + it "should handle the 'auto_commit_after_request' propery when set" do @config.auto_commit_after_request?.should == false end diff --git a/spec/mock_app/.gitignore b/spec/mock_app/.gitignore index bbeacf9..21265dc 100644 --- a/spec/mock_app/.gitignore +++ b/spec/mock_app/.gitignore @@ -1 +1,2 @@ solr +db/test.db \ No newline at end of file diff --git a/spec/mock_app/Rakefile b/spec/mock_app/Rakefile new file mode 100644 index 0000000..adb3c90 --- /dev/null +++ b/spec/mock_app/Rakefile @@ -0,0 +1,17 @@ +# Add your own tasks in files placed in lib/tasks ending in .rake, +# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. + +require(File.join(File.dirname(__FILE__), 'config', 'boot')) + +require 'rake' +require 'rake/testtask' +require 'rake/rdoctask' +require 'tasks/rails' + +# Try to load gem tasks. rake gems:install fails if these gems have not yet been +# installed because the Rakefile falls over when it tries to require their tasks. +begin + require 'sunspot/rails/tasks' +rescue Exception => e + puts "Warning, couldn't load gem tasks: #{e.message}! Skipping..." +end \ No newline at end of file diff --git a/spec/mock_app/config/database.yml b/spec/mock_app/config/database.yml index 2a923c2..0306758 100644 --- a/spec/mock_app/config/database.yml +++ b/spec/mock_app/config/database.yml @@ -1,4 +1,4 @@ test: &test :adapter: sqlite3 - :dbfile: vendor/plugins/sunspot_rails/spec/test.db + :dbfile: db/test.db development: *test diff --git a/spec/mock_app/config/environment.rb b/spec/mock_app/config/environment.rb index e90b25b..7286dcf 100644 --- a/spec/mock_app/config/environment.rb +++ b/spec/mock_app/config/environment.rb @@ -1,7 +1,7 @@ # Be sure to restart your server when you modify this file # Specifies gem version of Rails to use when vendor/rails is not present -RAILS_GEM_VERSION = ENV['RAILS_GEM_VERSION'] || '2.3.2' unless defined? RAILS_GEM_VERSION +RAILS_GEM_VERSION = ENV['RAILS_GEM_VERSION'] || '2.3.3' unless defined? RAILS_GEM_VERSION # Bootstrap the Rails environment, frameworks, and default configuration require File.join(File.dirname(__FILE__), 'boot') @@ -19,6 +19,7 @@ # config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net" # config.gem "sqlite3-ruby", :lib => "sqlite3" # config.gem "aws-s3", :lib => "aws/s3" + config.gem "qoobaa-sqlite3-ruby", :lib => 'sqlite3', :source => "http://gems.github.com" if RUBY_VERSION > '1.9' # Only load the plugins named here, in the order given (default is alphabetical). # :all can be used as a placeholder for all plugins not explicitly named diff --git a/spec/mock_app/config/sunspot.yml b/spec/mock_app/config/sunspot.yml index e4131b6..7429ecd 100644 --- a/spec/mock_app/config/sunspot.yml +++ b/spec/mock_app/config/sunspot.yml @@ -12,5 +12,7 @@ config_test: port: 1234 path: /solr/idx log_level: WARNING - solr_home: /another/path/solr + data_path: /my_superior_path/data + pid_path: /my_superior_path/pids + solr_home: /my_superior_path auto_commit_after_request: false diff --git a/spec/schema.rb b/spec/mock_app/db/schema.rb similarity index 100% rename from spec/schema.rb rename to spec/mock_app/db/schema.rb diff --git a/spec/mock_app/script/console b/spec/mock_app/script/console new file mode 100755 index 0000000..498077a --- /dev/null +++ b/spec/mock_app/script/console @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +require File.dirname(__FILE__) + '/../config/boot' +require 'commands/console' diff --git a/spec/model_lifecycle_spec.rb b/spec/model_lifecycle_spec.rb index 7ef668a..ee9fb07 100644 --- a/spec/model_lifecycle_spec.rb +++ b/spec/model_lifecycle_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), 'spec_helper') +require File.dirname(__FILE__) + '/spec_helper' describe 'searchable with lifecycle' do integrate_sunspot diff --git a/spec/model_spec.rb b/spec/model_spec.rb index 8fc2e88..2a98af2 100644 --- a/spec/model_spec.rb +++ b/spec/model_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), 'spec_helper') +require File.dirname(__FILE__) + '/spec_helper' describe 'ActiveRecord mixin' do integrate_sunspot diff --git a/spec/request_lifecycle_spec.rb b/spec/request_lifecycle_spec.rb index 65308c5..05baaca 100644 --- a/spec/request_lifecycle_spec.rb +++ b/spec/request_lifecycle_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), 'spec_helper') +require File.dirname(__FILE__) + '/spec_helper' describe 'request lifecycle', :type => :controller do before(:each) do diff --git a/spec/spec.opts b/spec/spec.opts new file mode 100644 index 0000000..5052887 --- /dev/null +++ b/spec/spec.opts @@ -0,0 +1 @@ +--color \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 1a1ff63..903840d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -6,14 +6,14 @@ require 'spec' require 'spec/rails' require 'rake' -require 'ruby-debug' unless RUBY_VERSION =~ /1\.9/ +require 'ruby-debug' unless RUBY_VERSION > '1.9' require 'sunspot/rails/tasks' require 'sunspot/spec/extension' def load_schema stdout = $stdout $stdout = StringIO.new # suppress output while building the schema - load File.join(File.dirname(__FILE__), 'schema.rb') + load File.join(ENV['RAILS_ROOT'], 'db', 'schema.rb') $stdout = stdout end diff --git a/sunspot_rails.gemspec b/sunspot_rails.gemspec index 8f734ca..249ffa6 100644 --- a/sunspot_rails.gemspec +++ b/sunspot_rails.gemspec @@ -1,3 +1,6 @@ +# Generated by jeweler +# DO NOT EDIT THIS FILE +# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec` # -*- encoding: utf-8 -*- Gem::Specification.new do |s| @@ -5,8 +8,8 @@ Gem::Specification.new do |s| s.version = "0.10.5" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= - s.authors = ["Mat Brown", "Peer Allan", "Michael Moen", "Benjamin Krause", "Adam Salter", "Brandon Keepers"] - s.date = %q{2009-09-16} + s.authors = ["Mat Brown", "Peer Allan", "Michael Moen", "Benjamin Krause"] + s.date = %q{2009-09-01} s.description = %q{Rails integration for the Sunspot Solr search library} s.email = %q{mat@patch.com} s.extra_rdoc_files = [ @@ -14,13 +17,11 @@ Gem::Specification.new do |s| "README.rdoc" ] s.files = [ - "History.txt", - "LICENSE", + "LICENSE", "MIT-LICENSE", "MIT-LICENSE", "README.rdoc", "Rakefile", - "TODO", "VERSION.yml", "dev_tasks/gemspec.rake", "dev_tasks/rdoc.rake", @@ -34,9 +35,7 @@ Gem::Specification.new do |s| "lib/sunspot/rails/configuration.rb", "lib/sunspot/rails/request_lifecycle.rb", "lib/sunspot/rails/searchable.rb", - "lib/sunspot/rails/server.rb", "lib/sunspot/rails/tasks.rb", - "lib/sunspot/spec/extension.rb", "rails/init.rb", "spec/configuration_spec.rb", "spec/mock_app/app/controllers/application.rb", @@ -58,16 +57,13 @@ Gem::Specification.new do |s| "spec/model_spec.rb", "spec/request_lifecycle_spec.rb", "spec/schema.rb", - "spec/server_spec.rb", - "spec/spec_helper.rb", - "spec/sunspot_mocking_spec.rb" + "spec/spec_helper.rb" ] - s.has_rdoc = true s.homepage = %q{http://github.com/outoftime/sunspot_rails} s.rdoc_options = ["--charset=UTF-8"] s.require_paths = ["lib"] s.rubyforge_project = %q{sunspot} - s.rubygems_version = %q{1.3.1} + s.rubygems_version = %q{1.3.3} s.summary = %q{Rails integration for the Sunspot Solr search library} s.test_files = [ "spec/configuration_spec.rb", @@ -88,33 +84,34 @@ Gem::Specification.new do |s| "spec/model_spec.rb", "spec/request_lifecycle_spec.rb", "spec/schema.rb", - "spec/server_spec.rb", - "spec/spec_helper.rb", - "spec/sunspot_mocking_spec.rb" + "spec/spec_helper.rb" ] if s.respond_to? :specification_version then current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION - s.specification_version = 2 + s.specification_version = 3 if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then + s.add_runtime_dependency(%q, ["~> 2.1"]) s.add_runtime_dependency(%q, [">= 0.0.4"]) - s.add_runtime_dependency(%q, [">= 0.9.7"]) + s.add_runtime_dependency(%q, [">= 0.8.2"]) s.add_development_dependency(%q, ["~> 1.2"]) s.add_development_dependency(%q, ["~> 1.2"]) s.add_development_dependency(%q, ["~> 0.10"]) s.add_development_dependency(%q, ["~> 1.0"]) else + s.add_dependency(%q, ["~> 2.1"]) s.add_dependency(%q, [">= 0.0.4"]) - s.add_dependency(%q, [">= 0.9.7"]) + s.add_dependency(%q, [">= 0.8.2"]) s.add_dependency(%q, ["~> 1.2"]) s.add_dependency(%q, ["~> 1.2"]) s.add_dependency(%q, ["~> 0.10"]) s.add_dependency(%q, ["~> 1.0"]) end else + s.add_dependency(%q, ["~> 2.1"]) s.add_dependency(%q, [">= 0.0.4"]) - s.add_dependency(%q, [">= 0.9.7"]) + s.add_dependency(%q, [">= 0.8.2"]) s.add_dependency(%q, ["~> 1.2"]) s.add_dependency(%q, ["~> 1.2"]) s.add_dependency(%q, ["~> 0.10"])