searchlogic 1.6.4 → 1.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,12 @@
1
+ == 1.6.5 released 2009-04-2
2
+
3
+ * Skip all associations defined with the :finder_sql option, since conditions can not be chained to them, etc.
4
+ * Fixed bug when using non string values for the keywords condition.
5
+ * Fixed undefined methods link_options error.
6
+ * Return blank conditions when trying to scope blank conditions. Fixes the issue with groups that return a blank SQL string.
7
+ * Fixed issue with blank condition comparing boolean values to non boolean columns.
8
+ * Add utf-8 magic comment for ruby 1.9
9
+
1
10
  == 1.6.4 released 2009-01-22
2
11
 
3
12
  * Fixed calling attribute_condition with newer versions of rails.
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2007 Ben Johnson of Binary Logic (binarylogic.com)
1
+ Copyright (c) 2008 Ben Johnson of Binary Logic (binarylogic.com)
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -10,10 +10,13 @@ module Searchlogic
10
10
  end
11
11
 
12
12
  def to_conditions(value)
13
- if value == true
14
- "(#{column_sql} IS NULL or #{column_sql} = '' or #{column_sql} = false)"
15
- elsif value == false
16
- "(#{column_sql} IS NOT NULL and #{column_sql} != '' and #{column_sql} != false)"
13
+ case column.type
14
+ when :boolean
15
+ return "(#{column_sql} IS NULL or #{column_sql} = '' or #{column_sql} = false)" if value == true
16
+ return "(#{column_sql} IS NOT NULL and #{column_sql} != '' and #{column_sql} != false)" if value == false
17
+ else
18
+ return "(#{column_sql} IS NULL or #{column_sql} = '')" if value == true
19
+ return "(#{column_sql} IS NOT NULL and #{column_sql} != '')" if value == false
17
20
  end
18
21
  end
19
22
  end
@@ -1,23 +1,28 @@
1
+ # coding: utf-8
1
2
  module Searchlogic
2
3
  module Condition
3
4
  class Keywords < Base
4
- # Because be default it joins with AND, so padding an array just gives you more options. Joining with and is no different than combining all of the words.
5
- self.join_arrays_with_or = true
6
-
7
- BLACKLISTED_WORDS = ('a'..'z').to_a + ["about", "an", "are", "as", "at", "be", "by", "com", "de", "en", "for", "from", "how", "in", "is", "it", "la", "of", "on", "or", "that", "the", "the", "this", "to", "und", "was", "what", "when", "where", "who", "will", "with", "www"] # from ranks.nl
8
- ALLOWED_CHARACTERS = 'àáâãäåßéèêëìíîïñòóôõöùúûüýÿ\-_\.@'
9
-
10
5
  class << self
11
6
  def condition_names_for_column
12
7
  super + ["kwords", "kw"]
13
8
  end
9
+
10
+ attr_accessor :blacklisted_words, :allowed_characters
14
11
  end
15
12
 
13
+ # Because be default it joins with AND, so padding an array just gives you more options. Joining with and is no different than combining all of the words.
14
+ self.join_arrays_with_or = true
15
+
16
+ self.blacklisted_words ||= []
17
+ self.blacklisted_words << ('a'..'z').to_a + ["about", "an", "are", "as", "at", "be", "by", "com", "de", "en", "for", "from", "how", "in", "is", "it", "la", "of", "on", "or", "that", "the", "the", "this", "to", "und", "was", "what", "when", "where", "who", "will", "with", "www"] # from ranks.nl
18
+ self.allowed_characters ||= ""
19
+ self.allowed_characters += 'àáâãäåßéèêëìíîïñòóôõöùúûüýÿ\-_\.@'
20
+
16
21
  def to_conditions(value)
17
22
  strs = []
18
23
  subs = []
19
24
 
20
- search_parts = value.gsub(/,/, " ").split(/ /)
25
+ search_parts = value.to_s.gsub(/,/, " ").split(/ /)
21
26
  replace_non_alnum_characters!(search_parts)
22
27
  search_parts.uniq!
23
28
  remove_blacklisted_words!(search_parts)
@@ -35,12 +40,12 @@ module Searchlogic
35
40
  def replace_non_alnum_characters!(search_parts)
36
41
  search_parts.each do |word|
37
42
  word.downcase!
38
- word.gsub!(/[^[:alnum:]#{ALLOWED_CHARACTERS}]/, '')
43
+ word.gsub!(/[^[:alnum:]#{self.class.allowed_characters}]/, '')
39
44
  end
40
45
  end
41
46
 
42
47
  def remove_blacklisted_words!(search_parts)
43
- search_parts.delete_if { |word| word.blank? || BLACKLISTED_WORDS.include?(word.downcase) }
48
+ search_parts.delete_if { |word| word.blank? || self.class.blacklisted_words.include?(word.downcase) }
44
49
  end
45
50
  end
46
51
  end
@@ -54,6 +54,7 @@ module Searchlogic
54
54
  return true if self.class.added_associations
55
55
 
56
56
  klass.reflect_on_all_associations.each do |association|
57
+ next if !association.options[:finder_sql].nil? # associations with finder_sql should not be added since conditions can not be chained to them, etc.
57
58
  self.class.class_eval <<-"end_eval", __FILE__, __LINE__
58
59
  def #{association.name}
59
60
  return @#{association.name} unless @#{association.name}.nil?
@@ -20,7 +20,7 @@ module Searchlogic
20
20
  links_options.delete(:choices)
21
21
  html = ""
22
22
  options[:choices].each do |choice|
23
- link_options = links_option.deep_dup
23
+ link_options = links_options.deep_dup
24
24
  text, value = option_text_and_value(choice)
25
25
  link_options[:text] ||= text
26
26
  html += order_by_link(value, link_options)
@@ -46,7 +46,7 @@ module Searchlogic
46
46
  links_options.delete(:choices)
47
47
  html = ""
48
48
  options[:choices].each do |choice|
49
- link_options = links_option.deep_dup
49
+ link_options = links_options.deep_dup
50
50
  text, value = option_text_and_value(choice)
51
51
  link_options[:text] ||= text
52
52
  html += order_as_link(value, link_options)
@@ -82,7 +82,7 @@ module Searchlogic
82
82
 
83
83
  def frisk!(options)
84
84
  options.symbolize_keys.fast_assert_valid_keys(SAFE_OPTIONS)
85
- raise(ArgumentError, ":order_by can only contain colum names in the string, hash, or array format") unless order_by_safe?(get_order_by_value(options[:order_by]))
85
+ raise(ArgumentError, ":order_by can only contain colum names and relationships in the string, hash, or array format. You are trying to pass a value that does not meet this criteria.") unless order_by_safe?(get_order_by_value(options[:order_by]))
86
86
  end
87
87
  end
88
88
  end
@@ -29,6 +29,7 @@ module Searchlogic
29
29
  end
30
30
 
31
31
  def scope_condition(condition)
32
+ return condition if condition.blank?
32
33
  arr_condition = condition.is_a?(Array) ? condition : [condition]
33
34
  arr_condition[0] = "(#{arr_condition[0]})"
34
35
  arr_condition.size == 1 ? arr_condition.first : arr_condition
@@ -67,7 +67,7 @@ module Searchlogic
67
67
 
68
68
  MAJOR = 1
69
69
  MINOR = 6
70
- TINY = 4
70
+ TINY = 5
71
71
 
72
72
  # The current version as a Version instance
73
73
  CURRENT = new(MAJOR, MINOR, TINY)
data/searchlogic.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{searchlogic}
5
- s.version = "1.6.4"
5
+ s.version = "1.6.5"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Ben Johnson of Binary Logic"]
9
- s.date = %q{2009-02-22}
9
+ s.date = %q{2009-04-02}
10
10
  s.description = %q{Object based ActiveRecord searching, ordering, pagination, and more!}
11
11
  s.email = %q{bjohnson@binarylogic.com}
12
12
  s.extra_rdoc_files = ["CHANGELOG.rdoc", "lib/searchlogic/active_record/associations.rb", "lib/searchlogic/active_record/base.rb", "lib/searchlogic/active_record/connection_adapters/mysql_adapter.rb", "lib/searchlogic/active_record/connection_adapters/postgresql_adapter.rb", "lib/searchlogic/active_record/connection_adapters/sqlite_adapter.rb", "lib/searchlogic/condition/base.rb", "lib/searchlogic/condition/begins_with.rb", "lib/searchlogic/condition/blank.rb", "lib/searchlogic/condition/child_of.rb", "lib/searchlogic/condition/descendant_of.rb", "lib/searchlogic/condition/ends_with.rb", "lib/searchlogic/condition/equals.rb", "lib/searchlogic/condition/greater_than.rb", "lib/searchlogic/condition/greater_than_or_equal_to.rb", "lib/searchlogic/condition/inclusive_descendant_of.rb", "lib/searchlogic/condition/keywords.rb", "lib/searchlogic/condition/less_than.rb", "lib/searchlogic/condition/less_than_or_equal_to.rb", "lib/searchlogic/condition/like.rb", "lib/searchlogic/condition/nested_set.rb", "lib/searchlogic/condition/nil.rb", "lib/searchlogic/condition/not_begin_with.rb", "lib/searchlogic/condition/not_blank.rb", "lib/searchlogic/condition/not_end_with.rb", "lib/searchlogic/condition/not_equal.rb", "lib/searchlogic/condition/not_have_keywords.rb", "lib/searchlogic/condition/not_like.rb", "lib/searchlogic/condition/not_nil.rb", "lib/searchlogic/condition/sibling_of.rb", "lib/searchlogic/conditions/any_or_all.rb", "lib/searchlogic/conditions/base.rb", "lib/searchlogic/conditions/groups.rb", "lib/searchlogic/conditions/magic_methods.rb", "lib/searchlogic/conditions/multiparameter_attributes.rb", "lib/searchlogic/conditions/protection.rb", "lib/searchlogic/config/helpers.rb", "lib/searchlogic/config/search.rb", "lib/searchlogic/config.rb", "lib/searchlogic/core_ext/hash.rb", "lib/searchlogic/core_ext/object.rb", "lib/searchlogic/helpers/control_types/link.rb", "lib/searchlogic/helpers/control_types/links.rb", "lib/searchlogic/helpers/control_types/remote_link.rb", "lib/searchlogic/helpers/control_types/remote_links.rb", "lib/searchlogic/helpers/control_types/remote_select.rb", "lib/searchlogic/helpers/control_types/select.rb", "lib/searchlogic/helpers/form.rb", "lib/searchlogic/helpers/utilities.rb", "lib/searchlogic/modifiers/absolute.rb", "lib/searchlogic/modifiers/acos.rb", "lib/searchlogic/modifiers/asin.rb", "lib/searchlogic/modifiers/atan.rb", "lib/searchlogic/modifiers/avg.rb", "lib/searchlogic/modifiers/base.rb", "lib/searchlogic/modifiers/ceil.rb", "lib/searchlogic/modifiers/char_length.rb", "lib/searchlogic/modifiers/cos.rb", "lib/searchlogic/modifiers/cot.rb", "lib/searchlogic/modifiers/count.rb", "lib/searchlogic/modifiers/day_of_month.rb", "lib/searchlogic/modifiers/day_of_week.rb", "lib/searchlogic/modifiers/day_of_year.rb", "lib/searchlogic/modifiers/degrees.rb", "lib/searchlogic/modifiers/exp.rb", "lib/searchlogic/modifiers/floor.rb", "lib/searchlogic/modifiers/hex.rb", "lib/searchlogic/modifiers/hour.rb", "lib/searchlogic/modifiers/log.rb", "lib/searchlogic/modifiers/log10.rb", "lib/searchlogic/modifiers/log2.rb", "lib/searchlogic/modifiers/lower.rb", "lib/searchlogic/modifiers/ltrim.rb", "lib/searchlogic/modifiers/md5.rb", "lib/searchlogic/modifiers/microseconds.rb", "lib/searchlogic/modifiers/milliseconds.rb", "lib/searchlogic/modifiers/minute.rb", "lib/searchlogic/modifiers/month.rb", "lib/searchlogic/modifiers/octal.rb", "lib/searchlogic/modifiers/radians.rb", "lib/searchlogic/modifiers/round.rb", "lib/searchlogic/modifiers/rtrim.rb", "lib/searchlogic/modifiers/second.rb", "lib/searchlogic/modifiers/sign.rb", "lib/searchlogic/modifiers/sin.rb", "lib/searchlogic/modifiers/square_root.rb", "lib/searchlogic/modifiers/sum.rb", "lib/searchlogic/modifiers/tan.rb", "lib/searchlogic/modifiers/trim.rb", "lib/searchlogic/modifiers/upper.rb", "lib/searchlogic/modifiers/week.rb", "lib/searchlogic/modifiers/year.rb", "lib/searchlogic/search/base.rb", "lib/searchlogic/search/conditions.rb", "lib/searchlogic/search/ordering.rb", "lib/searchlogic/search/pagination.rb", "lib/searchlogic/search/protection.rb", "lib/searchlogic/search/searching.rb", "lib/searchlogic/shared/utilities.rb", "lib/searchlogic/shared/virtual_classes.rb", "lib/searchlogic/version.rb", "lib/searchlogic.rb", "README.rdoc", "TODO.rdoc"]
@@ -38,7 +38,7 @@ module ActiveRecordTests
38
38
  search = binary_logic.orders.new_search
39
39
  assert_kind_of Searchlogic::Search::Base, search
40
40
  assert_equal Order, search.klass
41
- assert_equal({:joins => "INNER JOIN users ON orders.user_id = users.id ", :conditions => "(\"users\".account_id = #{binary_logic.id})"}, search.scope)
41
+ assert_equal({:conditions => "(\"users\".account_id = 431064614)", :joins => "INNER JOIN \"users\" ON \"orders\".user_id = \"users\".id "}, search.scope)
42
42
 
43
43
  bens_order = orders(:bens_order)
44
44
  assert_equal [bens_order], search.all
@@ -37,7 +37,7 @@ module ActiveRecordTests
37
37
  end
38
38
 
39
39
  def test_valid_ar_options
40
- assert_equal [:conditions, :include, :joins, :limit, :offset, :order, :select, :readonly, :group, :from, :lock], ActiveRecord::Base.valid_find_options
40
+ assert_equal [:conditions, :include, :joins, :limit, :offset, :order, :select, :readonly, :group, :having, :from, :lock], ActiveRecord::Base.valid_find_options
41
41
  assert_equal [:conditions, :joins, :order, :select, :group, :having, :distinct, :limit, :offset, :include, :from], ActiveRecord::Base.valid_calculations_options
42
42
  end
43
43
 
@@ -5,19 +5,19 @@ module ConditionTests
5
5
  def test_sanitize
6
6
  condition = Searchlogic::Condition::Blank.new(Account, :column => Account.columns_hash["id"])
7
7
  condition.value = "true"
8
- assert_equal "(\"accounts\".\"id\" IS NULL or \"accounts\".\"id\" = '' or \"accounts\".\"id\" = false)", condition.sanitize
8
+ assert_equal "(\"accounts\".\"id\" IS NULL or \"accounts\".\"id\" = '')", condition.sanitize
9
9
 
10
10
  condition = Searchlogic::Condition::Blank.new(Account, :column => Account.columns_hash["id"])
11
11
  condition.value = "false"
12
- assert_equal "(\"accounts\".\"id\" IS NOT NULL and \"accounts\".\"id\" != '' and \"accounts\".\"id\" != false)", condition.sanitize
12
+ assert_equal "(\"accounts\".\"id\" IS NOT NULL and \"accounts\".\"id\" != '')", condition.sanitize
13
13
 
14
- condition = Searchlogic::Condition::Blank.new(Account, :column => Account.columns_hash["id"])
14
+ condition = Searchlogic::Condition::Blank.new(Account, :column => Account.columns_hash["active"])
15
15
  condition.value = true
16
- assert_equal "(\"accounts\".\"id\" IS NULL or \"accounts\".\"id\" = '' or \"accounts\".\"id\" = false)", condition.sanitize
16
+ assert_equal "(\"accounts\".\"active\" IS NULL or \"accounts\".\"active\" = '' or \"accounts\".\"active\" = false)", condition.sanitize
17
17
 
18
- condition = Searchlogic::Condition::Blank.new(Account, :column => Account.columns_hash["id"])
18
+ condition = Searchlogic::Condition::Blank.new(Account, :column => Account.columns_hash["active"])
19
19
  condition.value = false
20
- assert_equal "(\"accounts\".\"id\" IS NOT NULL and \"accounts\".\"id\" != '' and \"accounts\".\"id\" != false)", condition.sanitize
20
+ assert_equal "(\"accounts\".\"active\" IS NOT NULL and \"accounts\".\"active\" != '' and \"accounts\".\"active\" != false)", condition.sanitize
21
21
 
22
22
  condition = Searchlogic::Condition::Blank.new(Account, :column => Account.columns_hash["id"])
23
23
  condition.value = nil
data/test/test_helper.rb CHANGED
@@ -107,10 +107,11 @@ end
107
107
  class Cat < Animal
108
108
  end
109
109
 
110
- class Test::Unit::TestCase
110
+ class ActiveSupport::TestCase
111
+ include ActiveRecord::TestFixtures
111
112
  self.fixture_path = File.dirname(__FILE__) + "/fixtures"
112
- self.use_transactional_fixtures = true
113
+ self.use_transactional_fixtures = false
113
114
  self.use_instantiated_fixtures = false
114
- self.pre_loaded_fixtures = true
115
+ self.pre_loaded_fixtures = false
115
116
  fixtures :all
116
117
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: searchlogic
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.4
4
+ version: 1.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Johnson of Binary Logic
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-02-22 00:00:00 -05:00
12
+ date: 2009-04-02 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency