searchgasm 1.5.2 → 1.5.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,15 @@
1
+ == 1.5.3 released 2008-10-21
2
+
3
+ * Removed ilike conditions and let the like condition determine if it should use like or ilike depending on the connection adapter.
4
+ * Fixed bug where the keywords condition was removing foreign characters.
5
+ * Added configuration option for specifying your javascript library, to cut down on the javascript Searchgasm adds into the form helpers
6
+ * Fixed bug with "not" conditions to use sanitize method, like it should, instead of to_conditions.
7
+ * Only pass :distinct option for the count calculation
8
+ * Fixed not_nil and not_blank conditions to use boolean values configuration option.
9
+
1
10
  == 1.5.2 released 2008-10-21
2
11
 
3
- * Added ilike conditons
12
+ * Added ilike conditions
4
13
  * Removed configatron dependency (was accidentally added)
5
14
 
6
15
  == 1.5.1 released 2008-10-20
data/Manifest CHANGED
@@ -15,7 +15,6 @@ lib/searchgasm/condition/ends_with.rb
15
15
  lib/searchgasm/condition/equals.rb
16
16
  lib/searchgasm/condition/greater_than.rb
17
17
  lib/searchgasm/condition/greater_than_or_equal_to.rb
18
- lib/searchgasm/condition/ilike.rb
19
18
  lib/searchgasm/condition/inclusive_descendant_of.rb
20
19
  lib/searchgasm/condition/keywords.rb
21
20
  lib/searchgasm/condition/less_than.rb
@@ -27,7 +26,6 @@ lib/searchgasm/condition/not_blank.rb
27
26
  lib/searchgasm/condition/not_end_with.rb
28
27
  lib/searchgasm/condition/not_equal.rb
29
28
  lib/searchgasm/condition/not_have_keywords.rb
30
- lib/searchgasm/condition/not_ilike.rb
31
29
  lib/searchgasm/condition/not_like.rb
32
30
  lib/searchgasm/condition/not_nil.rb
33
31
  lib/searchgasm/condition/sibling_of.rb
@@ -35,7 +35,7 @@ Now try out some of the examples below:
35
35
  :first_name_contains => "Ben", # first_name like '%Ben%'
36
36
  :email_ends_with => "binarylogic.com", # email like '%binarylogic.com'
37
37
  :created_after => Time.now, # created_at > Time.now
38
- :created_at_hour_gt => 5 # HOUR(created_at) > 5 (depends on DB type)
38
+ :hour_of_created_at => 5 # HOUR(created_at) > 5 (depends on DB type)
39
39
  },
40
40
  :per_page => 20, # limit 20
41
41
  :page => 3, # offset 40, which starts us on page 3
@@ -49,7 +49,7 @@ same as above, but object based
49
49
  search.conditions.first_name_contains = "Ben"
50
50
  search.conditions.email_ends_with = "binarylogic.com"
51
51
  search.conditions.created_after = Time.now
52
- search.conditiona.created_at_hour_gt = 5
52
+ search.conditiona.hour_of_created_at = 5
53
53
  search.per_page = 20
54
54
  search.page = 3
55
55
  search.order_as = "ASC"
@@ -44,7 +44,7 @@ require "searchgasm/conditions/base"
44
44
  # Condition
45
45
  require "searchgasm/condition/base"
46
46
  require "searchgasm/condition/tree"
47
- SEARCHGASM_CONDITIONS = [:begins_with, :blank, :child_of, :descendant_of, :ends_with, :equals, :greater_than, :greater_than_or_equal_to, :inclusive_descendant_of, :ilike, :like, :nil, :not_begin_with, :not_blank, :not_end_with, :not_equal, :not_have_keywords, :not_ilike, :not_nil, :keywords, :less_than, :less_than_or_equal_to, :sibling_of]
47
+ SEARCHGASM_CONDITIONS = [:begins_with, :blank, :child_of, :descendant_of, :ends_with, :equals, :greater_than, :greater_than_or_equal_to, :inclusive_descendant_of, :like, :nil, :not_begin_with, :not_blank, :not_end_with, :not_equal, :not_have_keywords, :not_nil, :keywords, :less_than, :less_than_or_equal_to, :sibling_of]
48
48
  SEARCHGASM_CONDITIONS.each { |condition| require "searchgasm/condition/#{condition}" }
49
49
 
50
50
  # Modifiers
@@ -110,6 +110,10 @@ module Searchgasm
110
110
  end
111
111
 
112
112
  private
113
+ def like_condition_name
114
+ @like_condition_name ||= klass.connection.adapter_name == "PostgreSQL" ? "ILIKE" : "LIKE"
115
+ end
116
+
113
117
  def meaningless?(v)
114
118
  case v
115
119
  when Array
@@ -11,9 +11,9 @@ module Searchgasm
11
11
 
12
12
  def to_conditions(value)
13
13
  if value == true
14
- "#{column_sql} is NULL or #{column_sql} = '' or #{column_sql} = false"
14
+ "#{column_sql} IS NULL or #{column_sql} = '' or #{column_sql} = false"
15
15
  elsif value == false
16
- "#{column_sql} is NOT NULL and #{column_sql} != '' and #{column_sql} != false"
16
+ "#{column_sql} IS NOT NULL and #{column_sql} != '' and #{column_sql} != false"
17
17
  end
18
18
  end
19
19
  end
@@ -5,6 +5,7 @@ module Searchgasm
5
5
  self.join_arrays_with_or = true
6
6
 
7
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
+ FOREIGN_CHARACTERS = 'àáâãäåßéèêëìíîïñòóôõöùúûüýÿ'
8
9
 
9
10
  class << self
10
11
  def condition_names_for_column
@@ -16,16 +17,31 @@ module Searchgasm
16
17
  strs = []
17
18
  subs = []
18
19
 
19
- search_parts = value.gsub(/,/, " ").split(/ /).collect { |word| word.downcase.gsub(/[^[:alnum:]]/, ''); }.uniq.select { |word| !BLACKLISTED_WORDS.include?(word.downcase) && !word.blank? }
20
+ search_parts = value.gsub(/,/, " ").split(/ /)
21
+ replace_non_alnum_characters!(search_parts)
22
+ search_parts.uniq!
23
+ remove_blacklisted_words!(search_parts)
20
24
  return if search_parts.blank?
21
25
 
22
26
  search_parts.each do |search_part|
23
- strs << "#{column_sql} LIKE ?"
27
+ strs << "#{column_sql} #{like_condition_name} ?"
24
28
  subs << "%#{search_part}%"
25
29
  end
26
30
 
27
31
  [strs.join(" AND "), *subs]
28
32
  end
33
+
34
+ private
35
+ def replace_non_alnum_characters!(search_parts)
36
+ search_parts.each do |word|
37
+ word.downcase!
38
+ word.gsub!(/[^[:alnum:]#{FOREIGN_CHARACTERS}]/, '')
39
+ end
40
+ end
41
+
42
+ def remove_blacklisted_words!(search_parts)
43
+ search_parts.delete_if { |word| word.blank? || BLACKLISTED_WORDS.include?(word.downcase) }
44
+ end
29
45
  end
30
46
  end
31
47
  end
@@ -8,7 +8,7 @@ module Searchgasm
8
8
  end
9
9
 
10
10
  def to_conditions(value)
11
- ["#{column_sql} LIKE ?", "%#{value}%"]
11
+ ["#{column_sql} #{like_condition_name} ?", "%#{value}%"]
12
12
  end
13
13
  end
14
14
  end
@@ -11,9 +11,9 @@ module Searchgasm
11
11
 
12
12
  def to_conditions(value)
13
13
  if value == true
14
- "#{column_sql} is NULL"
14
+ "#{column_sql} IS NULL"
15
15
  elsif value == false
16
- "#{column_sql} is NOT NULL"
16
+ "#{column_sql} IS NOT NULL"
17
17
  end
18
18
  end
19
19
  end
@@ -10,7 +10,7 @@ module Searchgasm
10
10
  def to_conditions(value)
11
11
  begin_with = BeginWith.new(klass, options)
12
12
  begin_with.value = value
13
- conditions = being_with.to_conditions
13
+ conditions = being_with.sanitize
14
14
  return conditions if conditions.blank?
15
15
  conditions.first.gsub!(" LIKE ", " NOT LIKE ")
16
16
  conditions
@@ -1,6 +1,8 @@
1
1
  module Searchgasm
2
2
  module Condition
3
3
  class NotBlank < Base
4
+ self.value_type = :boolean
5
+
4
6
  class << self
5
7
  def condition_names_for_column
6
8
  super + ["is_not_blank"]
@@ -10,7 +12,7 @@ module Searchgasm
10
12
  def to_conditions(value)
11
13
  blank = Blank.new(klass, options)
12
14
  blank.value = !value
13
- blank.to_conditions
15
+ blank.sanitize
14
16
  end
15
17
  end
16
18
  end
@@ -10,7 +10,7 @@ module Searchgasm
10
10
  def to_conditions(value)
11
11
  ends_with = EndsWith.new(klass, options)
12
12
  ends_with.value = value
13
- conditions = ends_with.to_conditions
13
+ conditions = ends_with.sanitize
14
14
  return conditions if conditions.blank?
15
15
  conditions.first.gsub!(" LIKE ", " NOT LIKE ")
16
16
  conditions
@@ -14,7 +14,6 @@ module Searchgasm
14
14
  # Delegate to equals and then change
15
15
  condition = Equals.new(klass, options)
16
16
  condition.value = value
17
-
18
17
  conditions_array = condition.sanitize
19
18
  conditions_array.first.gsub!(/ IS /, " IS NOT ")
20
19
  conditions_array.first.gsub!(/ BETWEEN /, " NOT BETWEEN ")
@@ -10,9 +10,9 @@ module Searchgasm
10
10
  def to_conditions(value)
11
11
  keywords = Keywords.new(klass, options)
12
12
  keywords.value = value
13
- conditions = keywords.to_conditions
13
+ conditions = keywords.sanitize
14
14
  return conditions if conditions.blank?
15
- conditions.first.gsub!(" LIKE ", " NOT LIKE ")
15
+ conditions.first.gsub!(" #{like_condition_name} ", " NOT #{like_condition_name} ")
16
16
  conditions
17
17
  end
18
18
  end
@@ -10,9 +10,9 @@ module Searchgasm
10
10
  def to_conditions(value)
11
11
  like = Like.new(klass, options)
12
12
  like.value = value
13
- conditions = like.to_conditions
13
+ conditions = like.sanitize
14
14
  return conditions if conditions.blank?
15
- conditions.first.gsub!(" LIKE ", " NOT LIKE ")
15
+ conditions.first.gsub!(" #{like_condition_name} ", " NOT #{like_condition_name} ")
16
16
  conditions
17
17
  end
18
18
  end
@@ -1,6 +1,8 @@
1
1
  module Searchgasm
2
2
  module Condition
3
3
  class NotNil < Base
4
+ self.value_type = :boolean
5
+
4
6
  class << self
5
7
  def condition_names_for_column
6
8
  super + ["is_not_nil", "is_not_null", "not_null"]
@@ -10,7 +12,7 @@ module Searchgasm
10
12
  def to_conditions(value)
11
13
  is_nil = Nil.new(klass, options)
12
14
  is_nil.value = !value
13
- is_nil.to_conditions
15
+ is_nil.sanitize
14
16
  end
15
17
  end
16
18
  end
@@ -17,6 +17,16 @@ module Searchgasm
17
17
  @hidden_fields ||= (Searchgasm::Search::Base::SPECIAL_FIND_OPTIONS - [:page, :priority_order])
18
18
  end
19
19
  attr_writer :hidden_fields
20
+
21
+ # Searchgasm does some javascript magic when you use the form helpers with a Searchgasm object. To make configuration easier Searchgasm checks for the existence of Prototype and jQuery and uses the first
22
+ # one it finds. To cut back on the javascript output you can specify your library here.
23
+ #
24
+ # * <tt>Default:</tt> nil
25
+ # * <tt>Accepts:</tt> :prototype or :jquery
26
+ def javascript_library
27
+ @javascript_library
28
+ end
29
+ attr_writer :javascript_library
20
30
 
21
31
  # The class name for used in the order_as_link helper
22
32
  #
@@ -228,7 +228,7 @@ module Searchgasm
228
228
 
229
229
  if span
230
230
  searchgasm_add_class!(options[:html], Config.helpers.page_links_disabled_class_name)
231
- searchgasm_add_class!(options[:html], "page")
231
+ searchgasm_add_class!(options[:html], Config.helpers.page_link_class_name)
232
232
  end
233
233
  options[:text] = text
234
234
  span ? content_tag(:span, text, options[:html]) : page_link(page, options)
@@ -13,16 +13,16 @@ module Searchgasm
13
13
  # form_for([:admin, @search]) # is equivalent to form_for(:search, @search, :url => admin_addresses_path)
14
14
  # form_for(:search, @search, :url => whatever_path)
15
15
  #
16
- # The goal was to mimic ActiveRecord. You can also pass a Searchgasm::Conditions::Base object as well and it will function the same way.
16
+ # The goal was to mimic how ActiveRecord objects are treated. You can also pass a Searchgasm::Conditions::Base object as well and it will function the same way.
17
17
  #
18
18
  # === Automatic hidden fields generation
19
19
  #
20
- # If you pass a Searchgasm::Search::Base object it automatically adds the :order_by, :order_as, and :per_page hidden fields. This is done so that when someone
21
- # creates a new search, their options are remembered. It keeps the search consisten and is much more user friendly. If you want to override this you can pass the
20
+ # If you pass a Searchgasm::Search::Base object it automatically adds the :order_by, :order_as, :priority_order_by, :priority_order_as, and :per_page hidden fields. This is done so that when someone
21
+ # creates a new search, their options are remembered. It keeps the search consistent and is much more user friendly. If you want to override this you can pass the
22
22
  # following options or you can set this up in your configuration, see Searchgasm::Config for more details.
23
23
  #
24
- # Lastly some light javascript is added to the "onsubmit" action. You will notice the order_by, per_page, and page helpers also add in a single hidden tag in the page. The form
25
- # finds these elements, gets their values and updates its hidden fields so that the correct values will be submitted during the search. The end result is having the "ordering" and "per page" options remembered.
24
+ # Lastly some light javascript is added to the "onsubmit" action. You will notice that the control type helpers add in hidden fields in the page, as a way to declare its "state". The form
25
+ # finds these elements, gets their values and updates its hidden fields so that the correct values will be submitted during the search. The end result is having these search options remembered.
26
26
  #
27
27
  # === Options
28
28
  #
@@ -90,12 +90,13 @@ module Searchgasm
90
90
  if !search_options[:hidden_fields].blank?
91
91
  options[:html][:onsubmit] ||= ""
92
92
  options[:html][:onsubmit] += ";"
93
-
94
- javascript = "if(typeof(Prototype) != 'undefined') {"
95
- search_options[:hidden_fields].each { |field| javascript += "field = $('#{name}_#{field}'); if(field) { $('#{name}_#{field}_hidden').value = field.value; }" }
96
- javascript += "} else if(typeof(jQuery) != 'undefined') {"
97
- search_options[:hidden_fields].each { |field| javascript += "field = $('##{name}_#{field}'); if(field) { $('##{name}_#{field}_hidden').val(field.val()); }" }
98
- javascript += "}"
93
+
94
+ javascript = ""
95
+ javascript += "if(typeof(Prototype) != 'undefined') {" if Config.helpers.javascript_library.blank?
96
+ search_options[:hidden_fields].each { |field| javascript += "field = $('#{name}_#{field}'); if(field) { $('#{name}_#{field}_hidden').value = field.value; }" } if Config.helpers.javascript_library.blank? || Config.helpers.javascript_library == :prototype
97
+ javascript += "} else if(typeof(jQuery) != 'undefined') {" if Config.helpers.javascript_library.blank?
98
+ search_options[:hidden_fields].each { |field| javascript += "field = $('##{name}_#{field}'); if(field) { $('##{name}_#{field}_hidden').val(field.val()); }" } if Config.helpers.javascript_library.blank? || Config.helpers.javascript_library == :jquery
99
+ javascript += "}" if Config.helpers.javascript_library.blank?
99
100
 
100
101
  options[:html][:onsubmit] += javascript
101
102
  end
@@ -127,7 +128,7 @@ module Searchgasm
127
128
  # For edge rails and older version compatibility, passing a binding to concat was deprecated
128
129
  begin
129
130
  concat(html)
130
- rescue ArgumentError
131
+ rescue ArgumentError, NameError
131
132
  concat(html, block.binding)
132
133
  end
133
134
  end
@@ -17,7 +17,7 @@ module Searchgasm
17
17
  klass.send(:with_scope, :find => acting_as_filter? ? {} : scope) do
18
18
  options = sanitize(#{SEARCH_METHODS.include?(method)})
19
19
  if #{CALCULATION_METHODS.include?(method)}
20
- options[:distinct] = true
20
+ options[:distinct] = true if #{method == :count} && !joins.blank? && Config.search.remove_duplicates?
21
21
  args[0] = klass.primary_key if [nil, :all].include?(args[0])
22
22
  end
23
23
  args << options
@@ -67,7 +67,7 @@ module Searchgasm
67
67
 
68
68
  MAJOR = 1
69
69
  MINOR = 5
70
- TINY = 2
70
+ TINY = 3
71
71
 
72
72
  # The current version as a Version instance
73
73
  CURRENT = new(MAJOR, MINOR, TINY)
@@ -1,18 +1,18 @@
1
1
 
2
- # Gem::Specification for Searchgasm-1.5.2
2
+ # Gem::Specification for Searchgasm-1.5.3
3
3
  # Originally generated by Echoe
4
4
 
5
5
  --- !ruby/object:Gem::Specification
6
6
  name: searchgasm
7
7
  version: !ruby/object:Gem::Version
8
- version: 1.5.2
8
+ version: 1.5.3
9
9
  platform: ruby
10
10
  authors:
11
11
  - Ben Johnson of Binary Logic
12
12
  autorequire:
13
13
  bindir: bin
14
14
 
15
- date: 2008-10-21 00:00:00 -04:00
15
+ date: 2008-10-30 00:00:00 -04:00
16
16
  default_executable:
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
@@ -67,7 +67,6 @@ extra_rdoc_files:
67
67
  - lib/searchgasm/condition/equals.rb
68
68
  - lib/searchgasm/condition/greater_than.rb
69
69
  - lib/searchgasm/condition/greater_than_or_equal_to.rb
70
- - lib/searchgasm/condition/ilike.rb
71
70
  - lib/searchgasm/condition/inclusive_descendant_of.rb
72
71
  - lib/searchgasm/condition/keywords.rb
73
72
  - lib/searchgasm/condition/less_than.rb
@@ -79,7 +78,6 @@ extra_rdoc_files:
79
78
  - lib/searchgasm/condition/not_end_with.rb
80
79
  - lib/searchgasm/condition/not_equal.rb
81
80
  - lib/searchgasm/condition/not_have_keywords.rb
82
- - lib/searchgasm/condition/not_ilike.rb
83
81
  - lib/searchgasm/condition/not_like.rb
84
82
  - lib/searchgasm/condition/not_nil.rb
85
83
  - lib/searchgasm/condition/sibling_of.rb
@@ -168,7 +166,6 @@ files:
168
166
  - lib/searchgasm/condition/equals.rb
169
167
  - lib/searchgasm/condition/greater_than.rb
170
168
  - lib/searchgasm/condition/greater_than_or_equal_to.rb
171
- - lib/searchgasm/condition/ilike.rb
172
169
  - lib/searchgasm/condition/inclusive_descendant_of.rb
173
170
  - lib/searchgasm/condition/keywords.rb
174
171
  - lib/searchgasm/condition/less_than.rb
@@ -180,7 +177,6 @@ files:
180
177
  - lib/searchgasm/condition/not_end_with.rb
181
178
  - lib/searchgasm/condition/not_equal.rb
182
179
  - lib/searchgasm/condition/not_have_keywords.rb
183
- - lib/searchgasm/condition/not_ilike.rb
184
180
  - lib/searchgasm/condition/not_like.rb
185
181
  - lib/searchgasm/condition/not_nil.rb
186
182
  - lib/searchgasm/condition/sibling_of.rb
@@ -61,7 +61,7 @@ class TestActiveRecordAssociations < Test::Unit::TestCase
61
61
 
62
62
  assert_equal User.find(1, 2), search.all
63
63
  assert_equal User.find(1), search.first
64
- assert_equal 1.5, search.average("id")
64
+ assert_equal (1.5).to_s, search.average("id").to_s
65
65
  assert_equal 2, search.count
66
66
 
67
67
  search.conditions.first_name_contains = "Ben"
@@ -8,19 +8,19 @@ class TestConditionTypes < Test::Unit::TestCase
8
8
 
9
9
  condition = Searchgasm::Condition::Blank.new(Account, :column => Account.columns_hash["id"])
10
10
  condition.value = "true"
11
- assert_equal "\"accounts\".\"id\" is NULL or \"accounts\".\"id\" = '' or \"accounts\".\"id\" = false", condition.sanitize
11
+ assert_equal "\"accounts\".\"id\" IS NULL or \"accounts\".\"id\" = '' or \"accounts\".\"id\" = false", condition.sanitize
12
12
 
13
13
  condition = Searchgasm::Condition::Blank.new(Account, :column => Account.columns_hash["id"])
14
14
  condition.value = "false"
15
- assert_equal "\"accounts\".\"id\" is NOT NULL and \"accounts\".\"id\" != '' and \"accounts\".\"id\" != false", condition.sanitize
15
+ assert_equal "\"accounts\".\"id\" IS NOT NULL and \"accounts\".\"id\" != '' and \"accounts\".\"id\" != false", condition.sanitize
16
16
 
17
17
  condition = Searchgasm::Condition::Blank.new(Account, :column => Account.columns_hash["id"])
18
18
  condition.value = true
19
- assert_equal "\"accounts\".\"id\" is NULL or \"accounts\".\"id\" = '' or \"accounts\".\"id\" = false", condition.sanitize
19
+ assert_equal "\"accounts\".\"id\" IS NULL or \"accounts\".\"id\" = '' or \"accounts\".\"id\" = false", condition.sanitize
20
20
 
21
21
  condition = Searchgasm::Condition::Blank.new(Account, :column => Account.columns_hash["id"])
22
22
  condition.value = false
23
- assert_equal "\"accounts\".\"id\" is NOT NULL and \"accounts\".\"id\" != '' and \"accounts\".\"id\" != false", condition.sanitize
23
+ assert_equal "\"accounts\".\"id\" IS NOT NULL and \"accounts\".\"id\" != '' and \"accounts\".\"id\" != false", condition.sanitize
24
24
 
25
25
  condition = Searchgasm::Condition::Blank.new(Account, :column => Account.columns_hash["id"])
26
26
  condition.value = nil
@@ -76,19 +76,19 @@ class TestConditionTypes < Test::Unit::TestCase
76
76
 
77
77
  condition = Searchgasm::Condition::Nil.new(Account, :column => Account.columns_hash["id"])
78
78
  condition.value = true
79
- assert_equal "\"accounts\".\"id\" is NULL", condition.sanitize
79
+ assert_equal "\"accounts\".\"id\" IS NULL", condition.sanitize
80
80
 
81
81
  condition = Searchgasm::Condition::Nil.new(Account, :column => Account.columns_hash["id"])
82
82
  condition.value = false
83
- assert_equal "\"accounts\".\"id\" is NOT NULL", condition.sanitize
83
+ assert_equal "\"accounts\".\"id\" IS NOT NULL", condition.sanitize
84
84
 
85
85
  condition = Searchgasm::Condition::Nil.new(Account, :column => Account.columns_hash["id"])
86
86
  condition.value = "true"
87
- assert_equal "\"accounts\".\"id\" is NULL", condition.sanitize
87
+ assert_equal "\"accounts\".\"id\" IS NULL", condition.sanitize
88
88
 
89
89
  condition = Searchgasm::Condition::Nil.new(Account, :column => Account.columns_hash["id"])
90
90
  condition.value = "false"
91
- assert_equal "\"accounts\".\"id\" is NOT NULL", condition.sanitize
91
+ assert_equal "\"accounts\".\"id\" IS NOT NULL", condition.sanitize
92
92
 
93
93
  condition = Searchgasm::Condition::Nil.new(Account, :column => Account.columns_hash["id"])
94
94
  condition.value = nil
@@ -110,6 +110,12 @@ class TestConditionTypes < Test::Unit::TestCase
110
110
  condition.value = (1..10)
111
111
  assert_equal ["\"accounts\".\"id\" NOT BETWEEN ? AND ?", 1, 10], condition.sanitize
112
112
 
113
+ condition = Searchgasm::Condition::NotNil.new(Account, :column => Account.columns_hash["created_at"])
114
+ condition.value = "1"
115
+ assert_equal "\"accounts\".\"created_at\" IS NOT NULL", condition.sanitize
116
+ condition.value = "false"
117
+ assert_equal "\"accounts\".\"created_at\" IS NULL", condition.sanitize
118
+
113
119
  condition = Searchgasm::Condition::Keywords.new(Account, :column => Account.columns_hash["name"])
114
120
  condition.value = "freedom yeah, freedom YEAH right"
115
121
  assert_equal ["\"accounts\".\"name\" LIKE ? AND \"accounts\".\"name\" LIKE ? AND \"accounts\".\"name\" LIKE ?", "%freedom%", "%yeah%", "%right%"], condition.sanitize
@@ -118,6 +124,10 @@ class TestConditionTypes < Test::Unit::TestCase
118
124
  condition.value = "%^$*(^$)"
119
125
  assert_equal nil, condition.sanitize
120
126
 
127
+ condition = Searchgasm::Condition::Keywords.new(Account, :column => Account.columns_hash["name"])
128
+ condition.value = "%^$*(^$) àáâãäåßéèêëìíîïñòóôõöùúûüýÿ"
129
+ assert_equal ["\"accounts\".\"name\" LIKE ?", "%àáâãäåßéèêëìíîïñòóôõöùúûüýÿ%"], condition.sanitize
130
+
121
131
  condition = Searchgasm::Condition::LessThan.new(Account, :column => Account.columns_hash["id"])
122
132
  condition.value = 2
123
133
  assert_equal ["\"accounts\".\"id\" < ?", 2], condition.sanitize
@@ -171,9 +171,9 @@ class TestConditionsBase < Test::Unit::TestCase
171
171
  conditions.dow_of_created_at_most = 5
172
172
  assert_equal ["(strftime('%w', \"accounts\".\"created_at\") <= ?) AND (strftime('%H', \"accounts\".\"created_at\") > ?)", 5, 2], conditions.sanitize
173
173
  conditions.month_of_created_at_nil = true
174
- assert_equal ["(strftime('%w', \"accounts\".\"created_at\") <= ?) AND (strftime('%H', \"accounts\".\"created_at\") > ?) AND (strftime('%m', \"accounts\".\"created_at\") is NULL)", 5, 2], conditions.sanitize
174
+ assert_equal ["(strftime('%w', \"accounts\".\"created_at\") <= ?) AND (strftime('%H', \"accounts\".\"created_at\") > ?) AND (strftime('%m', \"accounts\".\"created_at\") IS NULL)", 5, 2], conditions.sanitize
175
175
  conditions.min_of_hour_of_month_of_created_at_nil = true
176
- assert_equal ["(strftime('%w', \"accounts\".\"created_at\") <= ?) AND (strftime('%H', \"accounts\".\"created_at\") > ?) AND (strftime('%m', strftime('%H', strftime('%M', \"accounts\".\"created_at\"))) is NULL) AND (strftime('%m', \"accounts\".\"created_at\") is NULL)", 5, 2], conditions.sanitize
176
+ assert_equal ["(strftime('%w', \"accounts\".\"created_at\") <= ?) AND (strftime('%H', \"accounts\".\"created_at\") > ?) AND (strftime('%m', strftime('%H', strftime('%M', \"accounts\".\"created_at\"))) IS NULL) AND (strftime('%m', \"accounts\".\"created_at\") IS NULL)", 5, 2], conditions.sanitize
177
177
  end
178
178
 
179
179
  def test_objects
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: searchgasm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.2
4
+ version: 1.5.3
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: 2008-10-21 00:00:00 -04:00
12
+ date: 2008-10-30 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -64,7 +64,6 @@ extra_rdoc_files:
64
64
  - lib/searchgasm/condition/equals.rb
65
65
  - lib/searchgasm/condition/greater_than.rb
66
66
  - lib/searchgasm/condition/greater_than_or_equal_to.rb
67
- - lib/searchgasm/condition/ilike.rb
68
67
  - lib/searchgasm/condition/inclusive_descendant_of.rb
69
68
  - lib/searchgasm/condition/keywords.rb
70
69
  - lib/searchgasm/condition/less_than.rb
@@ -76,7 +75,6 @@ extra_rdoc_files:
76
75
  - lib/searchgasm/condition/not_end_with.rb
77
76
  - lib/searchgasm/condition/not_equal.rb
78
77
  - lib/searchgasm/condition/not_have_keywords.rb
79
- - lib/searchgasm/condition/not_ilike.rb
80
78
  - lib/searchgasm/condition/not_like.rb
81
79
  - lib/searchgasm/condition/not_nil.rb
82
80
  - lib/searchgasm/condition/sibling_of.rb
@@ -165,7 +163,6 @@ files:
165
163
  - lib/searchgasm/condition/equals.rb
166
164
  - lib/searchgasm/condition/greater_than.rb
167
165
  - lib/searchgasm/condition/greater_than_or_equal_to.rb
168
- - lib/searchgasm/condition/ilike.rb
169
166
  - lib/searchgasm/condition/inclusive_descendant_of.rb
170
167
  - lib/searchgasm/condition/keywords.rb
171
168
  - lib/searchgasm/condition/less_than.rb
@@ -177,7 +174,6 @@ files:
177
174
  - lib/searchgasm/condition/not_end_with.rb
178
175
  - lib/searchgasm/condition/not_equal.rb
179
176
  - lib/searchgasm/condition/not_have_keywords.rb
180
- - lib/searchgasm/condition/not_ilike.rb
181
177
  - lib/searchgasm/condition/not_like.rb
182
178
  - lib/searchgasm/condition/not_nil.rb
183
179
  - lib/searchgasm/condition/sibling_of.rb
@@ -1,15 +0,0 @@
1
- module Searchgasm
2
- module Condition
3
- class Ilike < Base
4
- class << self
5
- def condition_names_for_column
6
- super + ["icontains", "ihas"]
7
- end
8
- end
9
-
10
- def to_conditions(value)
11
- ["#{column_sql} ILIKE ?", "%#{value}%"]
12
- end
13
- end
14
- end
15
- end
@@ -1,20 +0,0 @@
1
- module Searchgasm
2
- module Condition
3
- class NotIlike < Base
4
- class << self
5
- def condition_names_for_column
6
- super + ["not_icontain", "not_ihave"]
7
- end
8
- end
9
-
10
- def to_conditions(value)
11
- like = Ilike.new(klass, options)
12
- like.value = value
13
- conditions = like.to_conditions
14
- return conditions if conditions.blank?
15
- conditions.first.gsub!(" ILIKE ", " NOT ILIKE ")
16
- conditions
17
- end
18
- end
19
- end
20
- end