From b1d08c1c81f806871319775a64c62cd322c64487 Mon Sep 17 00:00:00 2001 From: Braulio Bhavamitra Date: Wed, 17 Sep 2014 17:04:42 -0300 Subject: [PATCH] solr-plugin: port to rails 3 --- plugins/solr/config/solr.yml.dist | 6 +++--- plugins/solr/install.rb | 2 +- plugins/solr/lib/ext/product.rb | 3 ++- plugins/solr/lib/ext/profile.rb | 2 +- plugins/solr/lib/solr_plugin.rb | 10 +++++----- plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/tasks/test.rake | 45 --------------------------------------------- 6 files changed, 12 insertions(+), 56 deletions(-) delete mode 100644 plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/tasks/test.rake diff --git a/plugins/solr/config/solr.yml.dist b/plugins/solr/config/solr.yml.dist index a24a59f..b56303a 100644 --- a/plugins/solr/config/solr.yml.dist +++ b/plugins/solr/config/solr.yml.dist @@ -9,18 +9,18 @@ production: url: http://127.0.0.1:8983/solr jvm_options: -server -Xmx192M -Xms64M - timeout: 0 + timeout: 600 data_path: /var/lib/noosfero-data/solr/index development: url: http://0.0.0.0:8982/solr jvm_options: -server -Xmx128M -Xms16M - timeout: 0 + timeout: 600 test: &TEST url: http://0.0.0.0:8981/solr jvm_options: -server -Xmx128M -Xms16M - timeout: 0 + timeout: 600 cucumber: <<: *TEST diff --git a/plugins/solr/install.rb b/plugins/solr/install.rb index 859aa89..84c15d3 100644 --- a/plugins/solr/install.rb +++ b/plugins/solr/install.rb @@ -1,4 +1,4 @@ -raise "Not ready yet. Some tests are failing." +#raise "Not ready yet. Some tests are failing." require 'rubygems' require 'rake' diff --git a/plugins/solr/lib/ext/product.rb b/plugins/solr/lib/ext/product.rb index e0a2380..1ea005f 100644 --- a/plugins/solr/lib/ext/product.rb +++ b/plugins/solr/lib/ext/product.rb @@ -27,7 +27,8 @@ class Product {:name => {:type => :text, :boost => 2.0}}, {:description => :text}, {:category_full_name => :text}, # filtered fields - {:solr_plugin_public => :boolean}, {:environment_id => :integer}, + {:solr_plugin_public => :boolean}, + {:environment_id => :integer}, {:profile_id => :integer}, {:enabled => :boolean}, {:solr_plugin_category_filter => :integer}, # ordered/query-boosted fields {:solr_plugin_price_sortable => :decimal}, {:solr_plugin_name_sortable => :string}, diff --git a/plugins/solr/lib/ext/profile.rb b/plugins/solr/lib/ext/profile.rb index f701a83..5a9cd9f 100644 --- a/plugins/solr/lib/ext/profile.rb +++ b/plugins/solr/lib/ext/profile.rb @@ -42,7 +42,7 @@ class Profile handle_asynchronously :solr_save handle_asynchronously :solr_destroy - class_inheritable_accessor :solr_plugin_extra_index_methods + class_attribute :solr_plugin_extra_index_methods self.solr_plugin_extra_index_methods = [] def solr_plugin_extra_data_for_index diff --git a/plugins/solr/lib/solr_plugin.rb b/plugins/solr/lib/solr_plugin.rb index 1ecc632..44fa4b7 100644 --- a/plugins/solr/lib/solr_plugin.rb +++ b/plugins/solr/lib/solr_plugin.rb @@ -33,8 +33,8 @@ class SolrPlugin < Noosfero::Plugin solr_options = solr_options(class_asset(klass), category) solr_options[:filter_queries] ||= [] - solr_options[:filter_queries] += scopes_to_solr_filters scope, klass, options - solr_options.merge! products_options(user) if klass == Product and empty_query + solr_options[:filter_queries] += scopes_to_solr_options scope, klass, options + solr_options.merge! products_options(user) if asset == :products and empty_query solr_options.merge! options.except(:category, :filter) scope.find_by_contents query, paginate_options, solr_options @@ -42,14 +42,14 @@ class SolrPlugin < Noosfero::Plugin protected - def scopes_to_solr_filters scope, klass = nil, options = {} + def scopes_to_solr_options scope, klass = nil, options = {} filter_queries = [] klass ||= scope.base_class solr_fields = klass.configuration[:solr_fields].keys scopes_applied = scope.scopes_applied.dup rescue [] #rescue association and class direct filtering - scope.current_scoped_methods[:create].each do |attr, value| - next unless solr_fields.include? attr.to_sym + scope.scope_attributes.each do |attr, value| + raise "Non-indexed attribute '#{attr}' speficied in scope_attributes" unless solr_fields.include? attr.to_sym # if the filter is present here, then prefer it scopes_applied.reject!{ |name| name == attr.to_sym } diff --git a/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/tasks/test.rake b/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/tasks/test.rake deleted file mode 100644 index e4201ea..0000000 --- a/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/tasks/test.rake +++ /dev/null @@ -1,45 +0,0 @@ - -desc "Default Task" -task :default => [:test] - -desc "Runs the unit tests" -task :test => "test:unit" - -namespace :test do - - task :migrate do - ActiveRecord::Base.logger = Logger.new(STDOUT) - ActiveRecord::Migrator.migrate("test/db/migrate/", ENV["VERSION"] ? ENV["VERSION"].to_i : nil) - end - - task :setup do - DB ||= 'sqlite' - puts "Using " + DB - %x(mysql -u#{MYSQL_USER} < #{File.dirname(__FILE__) + "/test/fixtures/db_definitions/mysql.sql"}) if DB == 'mysql' - - Rake::Task["test:migrate"].invoke - end - - desc 'Measures test coverage using rcov' - task :rcov => :setup do - rm_f "coverage" - rm_f "coverage.data" - rcov = "rcov --rails --aggregate coverage.data --text-summary -Ilib" - - system("#{rcov} --html #{Dir.glob('test/**/*_shoulda.rb').join(' ')}") - system("open coverage/index.html") if PLATFORM['darwin'] - end - - desc 'Runs the functional tests, testing integration with Solr' - Rake::TestTask.new(:functional => :setup) do |t| - t.pattern = "test/functional/*_test.rb" - t.verbose = true - end - - desc "Unit tests" - Rake::TestTask.new(:unit => :setup) do |t| - t.libs << 'test/unit' - t.pattern = "test/unit/*_shoulda.rb" - t.verbose = true - end -end -- libgit2 0.21.2