searchgasm 1.1.1 → 1.1.2

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.
Files changed (35) hide show
  1. data/CHANGELOG.rdoc +8 -0
  2. data/Manifest +2 -4
  3. data/README.rdoc +3 -4
  4. data/lib/searchgasm/active_record/base.rb +23 -20
  5. data/lib/searchgasm/condition/base.rb +18 -7
  6. data/lib/searchgasm/condition/does_not_equal.rb +2 -4
  7. data/lib/searchgasm/condition/equals.rb +2 -4
  8. data/lib/searchgasm/condition/is_blank.rb +23 -0
  9. data/lib/searchgasm/condition/is_nil.rb +23 -0
  10. data/lib/searchgasm/conditions/base.rb +9 -9
  11. data/lib/searchgasm/config.rb +14 -14
  12. data/lib/searchgasm/helpers/control_types/link.rb +55 -0
  13. data/lib/searchgasm/helpers/control_types/links.rb +4 -9
  14. data/lib/searchgasm/helpers/control_types/select.rb +7 -4
  15. data/lib/searchgasm/helpers/form.rb +2 -2
  16. data/lib/searchgasm/helpers/utilities.rb +3 -2
  17. data/lib/searchgasm/search/base.rb +20 -2
  18. data/lib/searchgasm/search/conditions.rb +4 -14
  19. data/lib/searchgasm/search/ordering.rb +30 -29
  20. data/lib/searchgasm/search/pagination.rb +16 -10
  21. data/lib/searchgasm/shared/searching.rb +21 -19
  22. data/lib/searchgasm/shared/utilities.rb +18 -0
  23. data/lib/searchgasm/version.rb +1 -1
  24. data/lib/searchgasm.rb +3 -1
  25. data/searchgasm.gemspec +7 -11
  26. data/test/test_active_record_associations.rb +2 -2
  27. data/test/test_condition_base.rb +2 -2
  28. data/test/test_condition_types.rb +48 -0
  29. data/test/test_conditions_base.rb +5 -5
  30. data/test/test_search_base.rb +8 -8
  31. metadata +6 -10
  32. data/lib/searchgasm/active_record.rb +0 -8
  33. data/lib/searchgasm/helpers/control_types.rb +0 -57
  34. data/lib/searchgasm/helpers.rb +0 -9
  35. data/lib/searchgasm/search.rb +0 -7
@@ -9,7 +9,7 @@ module Searchgasm
9
9
  klass.class_eval do
10
10
  alias_method_chain :initialize, :conditions
11
11
  alias_method_chain :conditions=, :conditions
12
- alias_method_chain :include, :conditions
12
+ alias_method_chain :joins, :conditions
13
13
  alias_method_chain :sanitize, :conditions
14
14
  end
15
15
  end
@@ -33,7 +33,6 @@ module Searchgasm
33
33
  # now you can create the rest of your search and your "scope" will get merged into your final SQL.
34
34
  # What this does is determine if the value a hash or a conditions object, if not it sets it up as a scope.
35
35
  def conditions_with_conditions=(values)
36
-
37
36
  case values
38
37
  when Searchgasm::Conditions::Base
39
38
  @conditions = values
@@ -42,13 +41,12 @@ module Searchgasm
42
41
  end
43
42
  end
44
43
 
45
- # Tells searchgasm was relationships to include during the search. This is based on what conditions you set.
44
+ # Tells searchgasm what relationships to join during the search. This is based on what conditions you set.
46
45
  #
47
46
  # <b>Be careful!</b>
48
47
  # ActiveRecord associations can be an SQL train wreck. Make sure you think about what you are searching and that you aren't joining a table with a million records.
49
- def include_with_conditions
50
- includes = [include_without_conditions, conditions.includes].flatten.compact.uniq
51
- includes.blank? ? nil : (includes.size == 1 ? includes.first : includes)
48
+ def joins_with_conditions
49
+ merge_joins(joins_without_conditions, conditions.joins)
52
50
  end
53
51
 
54
52
  def sanitize_with_conditions(searching = true) # :nodoc:
@@ -59,14 +57,6 @@ module Searchgasm
59
57
  end
60
58
  find_options
61
59
  end
62
-
63
- def scope # :nodoc:
64
- conditions.scope
65
- end
66
-
67
- def scope=(value) # :nodoc:
68
- conditions.scope = value
69
- end
70
60
  end
71
61
  end
72
62
  end
@@ -18,18 +18,19 @@ module Searchgasm
18
18
  module Ordering
19
19
  def self.included(klass)
20
20
  klass.class_eval do
21
- alias_method_chain :include, :ordering
21
+ alias_method_chain :joins, :ordering
22
22
  alias_method_chain :order=, :ordering
23
23
  end
24
24
  end
25
25
 
26
- def include_with_ordering # :nodoc:
27
- includes = [include_without_ordering, order_by_includes].flatten.compact.uniq
28
- includes.blank? ? nil : (includes.size == 1 ? includes.first : includes)
26
+ def joins_with_ordering # :nodoc:
27
+ merge_joins(joins_without_ordering, order_by_joins)
29
28
  end
30
29
 
31
30
  def order_with_ordering=(value) # :nodoc
32
31
  @order_by = nil
32
+ @order_as = nil
33
+ self.order_by_joins.clear
33
34
  self.order_without_ordering = value
34
35
  end
35
36
 
@@ -45,8 +46,7 @@ module Searchgasm
45
46
 
46
47
  # Determines how the search is being ordered: as DESC or ASC
47
48
  def order_as
48
- return "ASC" if order.blank?
49
- order =~ /ASC$/i ? "ASC" : "DESC"
49
+ @order_as ||= (order.blank? || order =~ /ASC$/i) ? "ASC" : "DESC"
50
50
  end
51
51
 
52
52
  # Sets how the results will be ordered: ASC or DESC
@@ -55,12 +55,12 @@ module Searchgasm
55
55
  raise(ArgumentError, "order_as only accepts a string as ASC or DESC") unless ["ASC", "DESC"].include?(value)
56
56
 
57
57
  if order.blank?
58
- self.order = order_by_to_order(order_by, value)
58
+ @order = order_by_to_order(order_by, value)
59
59
  else
60
- self.order.gsub!(/(ASC|DESC)/i, value)
60
+ @order.gsub!(/(ASC|DESC)/i, value)
61
61
  end
62
62
 
63
- value
63
+ @order_as = value
64
64
  end
65
65
 
66
66
  # Determines by what columns the search is being ordered. This is nifty in that is reverse engineers the order SQL to determine this, only
@@ -84,9 +84,9 @@ module Searchgasm
84
84
  part
85
85
  end
86
86
  end.compact
87
- order_parts.size <= 1 ? order_parts.first : order_parts
87
+ @order_by = order_parts.size <= 1 ? order_parts.first : order_parts
88
88
  else
89
- klass.primary_key
89
+ @order_by = klass.primary_key
90
90
  end
91
91
  end
92
92
 
@@ -99,22 +99,23 @@ module Searchgasm
99
99
  # order_by = :id # => users.id ASC
100
100
  # order_by = [:id, name] # => users.id ASC, user.name ASC
101
101
  # order_by = [:id, {:user_group => :name}] # => users.id ASC, user_groups.name ASC
102
- def order_by=(value)
102
+ def order_by=(value)
103
+ self.order_by_joins.clear
103
104
  @order_by = get_order_by_value(value)
104
- @order = order_by_to_order(@order_by, order_as) # use @order so @order_by doesnt get reset
105
+ @order = order_by_to_order(@order_by, order_as)
105
106
  @order_by
106
107
  end
107
108
 
108
- # Returns the includes neccessary for the "order" statement so that we don't get an SQL error
109
- def order_by_includes
110
- @order_by_includes ||= []
111
- @order_by_includes.compact!
112
- @order_by_includes.uniq!
113
- @order_by_includes
109
+ # Returns the joins neccessary for the "order" statement so that we don't get an SQL error
110
+ def order_by_joins
111
+ @order_by_joins ||= []
112
+ @order_by_joins.compact!
113
+ @order_by_joins.uniq!
114
+ @order_by_joins
114
115
  end
115
116
 
116
117
  private
117
- def order_by_to_order(order_by, order_as, alt_klass = nil, new_includes = [])
118
+ def order_by_to_order(order_by, order_as, alt_klass = nil, new_joins = [])
118
119
  k = alt_klass || klass
119
120
  table_name = k.table_name
120
121
  sql_parts = []
@@ -127,23 +128,23 @@ module Searchgasm
127
128
  key = order_by.keys.first
128
129
  reflection = k.reflect_on_association(key.to_sym)
129
130
  value = order_by.values.first
130
- new_includes << key.to_sym
131
- sql_parts << order_by_to_order(value, order_as, reflection.klass, new_includes) # using eval, better performance, protection makes sure nothing fishy goes on here
131
+ new_joins << key.to_sym
132
+ sql_parts << order_by_to_order(value, order_as, reflection.klass, new_joins)
132
133
  when Symbol, String
133
- new_include = build_order_by_includes(new_includes)
134
- self.order_by_includes << new_include if new_include
134
+ new_join = build_order_by_joins(new_joins)
135
+ self.order_by_joins << new_join if new_join
135
136
  sql_parts << "#{quote_table_name(table_name)}.#{quote_column_name(order_by)} #{order_as}"
136
137
  end
137
138
 
138
139
  sql_parts.join(", ")
139
140
  end
140
141
 
141
- def build_order_by_includes(includes)
142
- return includes.first if includes.size <= 1
143
- includes = includes.dup
142
+ def build_order_by_joins(joins)
143
+ return joins.first if joins.size <= 1
144
+ joins = joins.dup
144
145
 
145
- key = includes.shift
146
- {key => build_order_by_includes(includes)}
146
+ key = joins.shift
147
+ {key => build_order_by_joins(joins)}
147
148
  end
148
149
 
149
150
  def get_order_by_value(value)
@@ -15,38 +15,46 @@ module Searchgasm
15
15
 
16
16
  def limit_with_pagination=(value) # :nodoc:
17
17
  r_value = self.limit_without_pagination = value
18
- self.page = @page unless @page.nil? # retry page now that the limit has changed
18
+ @page_count = nil
19
+ if @set_page
20
+ self.page = (@queued_page || @page) # retry setting page
21
+ else
22
+ @page = nil # the memoized page is invalid, so reset it
23
+ end
19
24
  r_value
20
25
  end
21
26
 
22
27
  def offset_with_pagination=(value) #:nodoc
23
28
  r_value = self.offset_without_pagination = value
24
- @page = nil
29
+ @set_page = @queued_page = @page = nil
25
30
  r_value
26
31
  end
27
32
 
28
33
  # The current page that the search is on
29
34
  def page
30
- return 1 if offset.blank? || limit.blank?
31
- (offset.to_f / limit).floor + 1
35
+ @page ||= (offset.blank? || limit.blank?) ? 1 : (offset.to_f / limit).floor + 1
32
36
  end
33
37
  alias_method :current_page, :page
34
38
 
35
39
  # Lets you change the page for the next search
36
40
  def page=(value)
37
- # Have to use @offset, since self.offset= resets @page
41
+ @set_page = true
42
+
38
43
  if value.blank?
39
44
  value = nil
40
45
  @page = value
41
- return @offset = value
46
+ return @offset = @page
42
47
  end
43
48
 
44
49
  v = value.to_i
45
- @page = v
46
50
 
47
51
  if limit.blank?
52
+ @queued_page = v
53
+ @page = 1
48
54
  @offset = nil
49
55
  else
56
+ @queued_page = nil
57
+ @page = v
50
58
  v -= 1 unless v == 0
51
59
  @offset = v * limit
52
60
  end
@@ -55,9 +63,7 @@ module Searchgasm
55
63
 
56
64
  # The total number of pages in your next search
57
65
  def page_count
58
- return 1 if per_page.blank? || per_page <= 0
59
- # Letting AR caching kick in with the count query
60
- (count / per_page.to_f).ceil
66
+ @page_count ||= (per_page.blank? || per_page <= 0) ? 1 : (count / per_page.to_f).ceil
61
67
  end
62
68
  alias_method :page_total, :page_count
63
69
 
@@ -9,30 +9,32 @@ module Searchgasm
9
9
  SEARCH_METHODS = [:all, :find, :first]
10
10
  CALCULATION_METHODS = [:average, :calculate, :count, :maximum, :minimum, :sum]
11
11
 
12
- # Setup methods for searching
13
- SEARCH_METHODS.each do |method|
14
- class_eval <<-"end_eval", __FILE__, __LINE__
15
- def #{method}(*args)
16
- options = args.extract_options!
17
- klass.send(:with_scope, :find => options) do
18
- args << (self.class < Searchgasm::Conditions::Base ? {:conditions => sanitize} : sanitize)
19
- klass.#{method}(*args)
20
- end
21
- end
22
- end_eval
12
+ def self.included(klass)
13
+ klass.class_eval do
14
+ attr_accessor :scope
15
+ end
23
16
  end
24
-
25
- # Setup methods for calculating
26
- CALCULATION_METHODS.each do |method|
17
+
18
+ (SEARCH_METHODS + CALCULATION_METHODS).each do |method|
27
19
  class_eval <<-"end_eval", __FILE__, __LINE__
28
20
  def #{method}(*args)
21
+ find_options = {}
29
22
  options = args.extract_options!
30
- klass.send(:with_scope, :find => options) do
31
- find_options = (self.class < Searchgasm::Conditions::Base ? {:conditions => sanitize} : sanitize(false))
32
- [:select, :limit, :offset].each { |option| find_options.delete(option) }
33
- args << find_options
34
- klass.#{method}(*args)
23
+ with_scopes = [scope, (self.class < Searchgasm::Conditions::Base ? {:conditions => sanitize} : sanitize(#{SEARCH_METHODS.include?(method)})), options].compact
24
+ with_scopes.each do |with_scope|
25
+ klass.send(:with_scope, :find => find_options) do
26
+ klass.send(:with_scope, :find => with_scope) do
27
+ find_options = klass.send(:scope, :find)
28
+ end
29
+ end
30
+ end
31
+
32
+ if self.class < Searchgasm::Search::Base
33
+ (find_options.symbolize_keys.keys - #{SEARCH_METHODS.include?(method) ? "Search::Base::AR_FIND_OPTIONS" : "Search::Base::AR_CALCULATIONS_OPTIONS"}).each { |option| find_options.delete(option) }
35
34
  end
35
+
36
+ args << find_options
37
+ klass.#{method}(*args)
36
38
  end
37
39
  end_eval
38
40
  end
@@ -27,6 +27,24 @@ module Searchgasm
27
27
 
28
28
  [conditions_str, *conditions_subs]
29
29
  end
30
+
31
+ def merge_joins(*joins)
32
+ joins.delete_if { |join| join.blank? }
33
+ return if joins.blank?
34
+ return joins.first if joins.size == 1
35
+
36
+ new_joins = []
37
+ joins.each do |join|
38
+ case join
39
+ when Array
40
+ new_joins += join
41
+ else
42
+ new_joins << join
43
+ end
44
+ end
45
+
46
+ new_joins.compact.uniq
47
+ end
30
48
  end
31
49
  end
32
50
  end
@@ -67,7 +67,7 @@ module Searchgasm
67
67
 
68
68
  MAJOR = 1
69
69
  MINOR = 1
70
- TINY = 1
70
+ TINY = 2
71
71
 
72
72
  # The current version as a Version instance
73
73
  CURRENT = new(MAJOR, MINOR, TINY)
data/lib/searchgasm.rb CHANGED
@@ -39,6 +39,8 @@ require "searchgasm/condition/ends_with"
39
39
  require "searchgasm/condition/equals"
40
40
  require "searchgasm/condition/greater_than"
41
41
  require "searchgasm/condition/greater_than_or_equal_to"
42
+ require "searchgasm/condition/is_blank"
43
+ require "searchgasm/condition/is_nil"
42
44
  require "searchgasm/condition/keywords"
43
45
  require "searchgasm/condition/less_than"
44
46
  require "searchgasm/condition/less_than_or_equal_to"
@@ -74,7 +76,7 @@ module Searchgasm
74
76
  include Protection
75
77
  end
76
78
 
77
- [:begins_with, :child_of, :contains, :descendant_of, :does_not_equal, :ends_with, :equals, :greater_than, :greater_than_or_equal_to, :inclusive_descendant_of, :keywords, :less_than, :less_than_or_equal_to, :sibling_of].each do |condition|
79
+ [:begins_with, :child_of, :contains, :descendant_of, :does_not_equal, :ends_with, :equals, :greater_than, :greater_than_or_equal_to, :inclusive_descendant_of, :is_blank, :is_nil, :keywords, :less_than, :less_than_or_equal_to, :sibling_of].each do |condition|
78
80
  Base.register_condition("Searchgasm::Condition::#{condition.to_s.camelize}".constantize)
79
81
  end
80
82
  end
data/searchgasm.gemspec CHANGED
@@ -1,18 +1,18 @@
1
1
 
2
- # Gem::Specification for Searchgasm-1.1.1
2
+ # Gem::Specification for Searchgasm-1.1.2
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.1.1
8
+ version: 1.1.2
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-09-19 00:00:00 -04:00
15
+ date: 2008-09-22 00:00:00 -04:00
16
16
  default_executable:
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
@@ -55,7 +55,6 @@ extra_rdoc_files:
55
55
  - CHANGELOG.rdoc
56
56
  - lib/searchgasm/active_record/associations.rb
57
57
  - lib/searchgasm/active_record/base.rb
58
- - lib/searchgasm/active_record.rb
59
58
  - lib/searchgasm/condition/base.rb
60
59
  - lib/searchgasm/condition/begins_with.rb
61
60
  - lib/searchgasm/condition/child_of.rb
@@ -67,6 +66,8 @@ extra_rdoc_files:
67
66
  - lib/searchgasm/condition/greater_than.rb
68
67
  - lib/searchgasm/condition/greater_than_or_equal_to.rb
69
68
  - lib/searchgasm/condition/inclusive_descendant_of.rb
69
+ - lib/searchgasm/condition/is_blank.rb
70
+ - lib/searchgasm/condition/is_nil.rb
70
71
  - lib/searchgasm/condition/keywords.rb
71
72
  - lib/searchgasm/condition/less_than.rb
72
73
  - lib/searchgasm/condition/less_than_or_equal_to.rb
@@ -82,16 +83,13 @@ extra_rdoc_files:
82
83
  - lib/searchgasm/helpers/control_types/remote_links.rb
83
84
  - lib/searchgasm/helpers/control_types/remote_select.rb
84
85
  - lib/searchgasm/helpers/control_types/select.rb
85
- - lib/searchgasm/helpers/control_types.rb
86
86
  - lib/searchgasm/helpers/form.rb
87
87
  - lib/searchgasm/helpers/utilities.rb
88
- - lib/searchgasm/helpers.rb
89
88
  - lib/searchgasm/search/base.rb
90
89
  - lib/searchgasm/search/conditions.rb
91
90
  - lib/searchgasm/search/ordering.rb
92
91
  - lib/searchgasm/search/pagination.rb
93
92
  - lib/searchgasm/search/protection.rb
94
- - lib/searchgasm/search.rb
95
93
  - lib/searchgasm/shared/searching.rb
96
94
  - lib/searchgasm/shared/utilities.rb
97
95
  - lib/searchgasm/shared/virtual_classes.rb
@@ -104,7 +102,6 @@ files:
104
102
  - init.rb
105
103
  - lib/searchgasm/active_record/associations.rb
106
104
  - lib/searchgasm/active_record/base.rb
107
- - lib/searchgasm/active_record.rb
108
105
  - lib/searchgasm/condition/base.rb
109
106
  - lib/searchgasm/condition/begins_with.rb
110
107
  - lib/searchgasm/condition/child_of.rb
@@ -116,6 +113,8 @@ files:
116
113
  - lib/searchgasm/condition/greater_than.rb
117
114
  - lib/searchgasm/condition/greater_than_or_equal_to.rb
118
115
  - lib/searchgasm/condition/inclusive_descendant_of.rb
116
+ - lib/searchgasm/condition/is_blank.rb
117
+ - lib/searchgasm/condition/is_nil.rb
119
118
  - lib/searchgasm/condition/keywords.rb
120
119
  - lib/searchgasm/condition/less_than.rb
121
120
  - lib/searchgasm/condition/less_than_or_equal_to.rb
@@ -131,16 +130,13 @@ files:
131
130
  - lib/searchgasm/helpers/control_types/remote_links.rb
132
131
  - lib/searchgasm/helpers/control_types/remote_select.rb
133
132
  - lib/searchgasm/helpers/control_types/select.rb
134
- - lib/searchgasm/helpers/control_types.rb
135
133
  - lib/searchgasm/helpers/form.rb
136
134
  - lib/searchgasm/helpers/utilities.rb
137
- - lib/searchgasm/helpers.rb
138
135
  - lib/searchgasm/search/base.rb
139
136
  - lib/searchgasm/search/conditions.rb
140
137
  - lib/searchgasm/search/ordering.rb
141
138
  - lib/searchgasm/search/pagination.rb
142
139
  - lib/searchgasm/search/protection.rb
143
- - lib/searchgasm/search.rb
144
140
  - lib/searchgasm/shared/searching.rb
145
141
  - lib/searchgasm/shared/utilities.rb
146
142
  - lib/searchgasm/shared/virtual_classes.rb
@@ -16,10 +16,10 @@ class TestActiveRecordAssociations < Test::Unit::TestCase
16
16
  search = Account.find(1).users.build_search
17
17
  assert_kind_of Searchgasm::Search::Base, search
18
18
  assert_equal User, search.klass
19
- assert_equal "\"users\".account_id = 1", search.conditions.sql
19
+ assert_equal({:conditions => "\"users\".account_id = 1"}, search.scope)
20
20
 
21
21
  search.conditions.first_name_contains = "Ben"
22
- assert_equal({:conditions => ["(\"users\".\"first_name\" LIKE ?) AND (\"users\".account_id = 1)", "%Ben%"]}, search.sanitize)
22
+ assert_equal({:conditions => ["\"users\".\"first_name\" LIKE ?", "%Ben%"]}, search.sanitize)
23
23
  end
24
24
 
25
25
  def test_searching
@@ -49,10 +49,10 @@ class TestConditionBase < Test::Unit::TestCase
49
49
 
50
50
  def test_ignore_blanks?
51
51
  condition = Searchgasm::Condition::Equals.new(Account, Account.columns_hash["id"])
52
- assert !condition.ignore_blanks?
52
+ assert !condition.class.ignore_blanks?
53
53
 
54
54
  condition = Searchgasm::Condition::Keywords.new(Account, Account.columns_hash["name"])
55
- assert condition.ignore_blanks?
55
+ assert condition.class.ignore_blanks?
56
56
  end
57
57
 
58
58
  def test_value
@@ -73,6 +73,54 @@ class TestConditionTypes < Test::Unit::TestCase
73
73
  condition.value = User.find(1)
74
74
  assert_equal condition.sanitize, ["(\"users\".\"id\" = ?) OR (\"users\".\"id\" = ? OR \"users\".\"id\" = ?)", 1, 2, 3]
75
75
 
76
+ condition = Searchgasm::Condition::IsBlank.new(Account, Account.columns_hash["id"])
77
+ condition.value = true
78
+ assert_equal condition.sanitize, "\"accounts\".\"id\" is NULL or \"accounts\".\"id\" = ''"
79
+
80
+ condition = Searchgasm::Condition::IsBlank.new(Account, Account.columns_hash["id"])
81
+ condition.value = false
82
+ assert_equal condition.sanitize, "\"accounts\".\"id\" is NOT NULL and \"accounts\".\"id\" != ''"
83
+
84
+ condition = Searchgasm::Condition::IsBlank.new(Account, Account.columns_hash["id"])
85
+ condition.value = "true"
86
+ assert_equal condition.sanitize, "\"accounts\".\"id\" is NULL or \"accounts\".\"id\" = ''"
87
+
88
+ condition = Searchgasm::Condition::IsBlank.new(Account, Account.columns_hash["id"])
89
+ condition.value = "false"
90
+ assert_equal condition.sanitize, "\"accounts\".\"id\" is NOT NULL and \"accounts\".\"id\" != ''"
91
+
92
+ condition = Searchgasm::Condition::IsBlank.new(Account, Account.columns_hash["id"])
93
+ condition.value = nil
94
+ assert_equal condition.sanitize, nil
95
+
96
+ condition = Searchgasm::Condition::IsBlank.new(Account, Account.columns_hash["id"])
97
+ condition.value = ""
98
+ assert_equal condition.sanitize, nil
99
+
100
+ condition = Searchgasm::Condition::IsNil.new(Account, Account.columns_hash["id"])
101
+ condition.value = true
102
+ assert_equal condition.sanitize, "\"accounts\".\"id\" is NULL"
103
+
104
+ condition = Searchgasm::Condition::IsNil.new(Account, Account.columns_hash["id"])
105
+ condition.value = false
106
+ assert_equal condition.sanitize, "\"accounts\".\"id\" is NOT NULL"
107
+
108
+ condition = Searchgasm::Condition::IsNil.new(Account, Account.columns_hash["id"])
109
+ condition.value = "true"
110
+ assert_equal condition.sanitize, "\"accounts\".\"id\" is NULL"
111
+
112
+ condition = Searchgasm::Condition::IsNil.new(Account, Account.columns_hash["id"])
113
+ condition.value = "false"
114
+ assert_equal condition.sanitize, "\"accounts\".\"id\" is NOT NULL"
115
+
116
+ condition = Searchgasm::Condition::IsNil.new(Account, Account.columns_hash["id"])
117
+ condition.value = nil
118
+ assert_equal condition.sanitize, nil
119
+
120
+ condition = Searchgasm::Condition::IsNil.new(Account, Account.columns_hash["id"])
121
+ condition.value = ""
122
+ assert_equal condition.sanitize, nil
123
+
76
124
  condition = Searchgasm::Condition::Keywords.new(Account, Account.columns_hash["name"])
77
125
  condition.value = "freedom yeah, freedom YEAH right"
78
126
  assert_equal condition.sanitize, ["\"accounts\".\"name\" LIKE ? AND \"accounts\".\"name\" LIKE ? AND \"accounts\".\"name\" LIKE ?", "%freedom%", "%yeah%", "%right%"]
@@ -71,18 +71,18 @@ class TestConditionsBase < Test::Unit::TestCase
71
71
  assert_equal conditions.users.last_name_begins_with, "Ben"
72
72
  end
73
73
 
74
- def test_includes
74
+ def test_joins
75
75
  conditions = Account.new_conditions
76
- assert_equal conditions.includes, nil
76
+ assert_equal conditions.joins, nil
77
77
 
78
78
  conditions.name_like = "Binary"
79
- assert_equal conditions.includes, nil
79
+ assert_equal conditions.joins, nil
80
80
 
81
81
  conditions.users.first_name_like = "Ben"
82
- assert_equal conditions.includes, :users
82
+ assert_equal conditions.joins, :users
83
83
 
84
84
  conditions.users.orders.description_like = "apple"
85
- assert_equal conditions.includes, {:users => :orders}
85
+ assert_equal conditions.joins, {:users => :orders}
86
86
  end
87
87
 
88
88
  def test_objects
@@ -109,20 +109,20 @@ class TestSearchBase < Test::Unit::TestCase
109
109
  assert_equal search.lock, true
110
110
  end
111
111
 
112
- def test_include
112
+ def test_joins
113
113
  search = Account.new_search
114
- assert_equal nil, search.include
114
+ assert_equal nil, search.joins
115
115
  search.conditions.name_contains = "Binary"
116
- assert_equal nil, search.include
116
+ assert_equal nil, search.joins
117
117
  search.conditions.users.first_name_contains = "Ben"
118
- assert_equal(:users, search.include)
118
+ assert_equal(:users, search.joins)
119
119
  search.conditions.users.orders.id_gt = 2
120
- assert_equal({:users => :orders}, search.include)
120
+ assert_equal({:users => :orders}, search.joins)
121
121
  search.conditions.users.reset_orders!
122
- assert_equal(:users, search.include)
122
+ assert_equal(:users, search.joins)
123
123
  search.conditions.users.orders.id_gt = 2
124
124
  search.conditions.reset_users!
125
- assert_equal nil, search.include
125
+ assert_equal nil, search.joins
126
126
  end
127
127
 
128
128
  def test_limit
@@ -151,7 +151,7 @@ class TestSearchBase < Test::Unit::TestCase
151
151
  search.conditions.users.id_greater_than = 2
152
152
  search.page = 3
153
153
  search.readonly = true
154
- assert_equal({:include => :users, :offset => 4, :readonly => true, :conditions => ["(\"accounts\".\"name\" LIKE ?) AND (\"users\".\"id\" > ?)", "%Binary%", 2], :limit => 2 }, search.sanitize)
154
+ assert_equal({:joins => :users, :group => "\"accounts\".\"id\"", :offset => 4, :readonly => true, :conditions => ["(\"accounts\".\"name\" LIKE ?) AND (\"users\".\"id\" > ?)", "%Binary%", 2], :limit => 2 }, search.sanitize)
155
155
  end
156
156
 
157
157
  def test_scope
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.1.1
4
+ version: 1.1.2
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-09-19 00:00:00 -04:00
12
+ date: 2008-09-22 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -52,7 +52,6 @@ extra_rdoc_files:
52
52
  - CHANGELOG.rdoc
53
53
  - lib/searchgasm/active_record/associations.rb
54
54
  - lib/searchgasm/active_record/base.rb
55
- - lib/searchgasm/active_record.rb
56
55
  - lib/searchgasm/condition/base.rb
57
56
  - lib/searchgasm/condition/begins_with.rb
58
57
  - lib/searchgasm/condition/child_of.rb
@@ -64,6 +63,8 @@ extra_rdoc_files:
64
63
  - lib/searchgasm/condition/greater_than.rb
65
64
  - lib/searchgasm/condition/greater_than_or_equal_to.rb
66
65
  - lib/searchgasm/condition/inclusive_descendant_of.rb
66
+ - lib/searchgasm/condition/is_blank.rb
67
+ - lib/searchgasm/condition/is_nil.rb
67
68
  - lib/searchgasm/condition/keywords.rb
68
69
  - lib/searchgasm/condition/less_than.rb
69
70
  - lib/searchgasm/condition/less_than_or_equal_to.rb
@@ -79,16 +80,13 @@ extra_rdoc_files:
79
80
  - lib/searchgasm/helpers/control_types/remote_links.rb
80
81
  - lib/searchgasm/helpers/control_types/remote_select.rb
81
82
  - lib/searchgasm/helpers/control_types/select.rb
82
- - lib/searchgasm/helpers/control_types.rb
83
83
  - lib/searchgasm/helpers/form.rb
84
84
  - lib/searchgasm/helpers/utilities.rb
85
- - lib/searchgasm/helpers.rb
86
85
  - lib/searchgasm/search/base.rb
87
86
  - lib/searchgasm/search/conditions.rb
88
87
  - lib/searchgasm/search/ordering.rb
89
88
  - lib/searchgasm/search/pagination.rb
90
89
  - lib/searchgasm/search/protection.rb
91
- - lib/searchgasm/search.rb
92
90
  - lib/searchgasm/shared/searching.rb
93
91
  - lib/searchgasm/shared/utilities.rb
94
92
  - lib/searchgasm/shared/virtual_classes.rb
@@ -101,7 +99,6 @@ files:
101
99
  - init.rb
102
100
  - lib/searchgasm/active_record/associations.rb
103
101
  - lib/searchgasm/active_record/base.rb
104
- - lib/searchgasm/active_record.rb
105
102
  - lib/searchgasm/condition/base.rb
106
103
  - lib/searchgasm/condition/begins_with.rb
107
104
  - lib/searchgasm/condition/child_of.rb
@@ -113,6 +110,8 @@ files:
113
110
  - lib/searchgasm/condition/greater_than.rb
114
111
  - lib/searchgasm/condition/greater_than_or_equal_to.rb
115
112
  - lib/searchgasm/condition/inclusive_descendant_of.rb
113
+ - lib/searchgasm/condition/is_blank.rb
114
+ - lib/searchgasm/condition/is_nil.rb
116
115
  - lib/searchgasm/condition/keywords.rb
117
116
  - lib/searchgasm/condition/less_than.rb
118
117
  - lib/searchgasm/condition/less_than_or_equal_to.rb
@@ -128,16 +127,13 @@ files:
128
127
  - lib/searchgasm/helpers/control_types/remote_links.rb
129
128
  - lib/searchgasm/helpers/control_types/remote_select.rb
130
129
  - lib/searchgasm/helpers/control_types/select.rb
131
- - lib/searchgasm/helpers/control_types.rb
132
130
  - lib/searchgasm/helpers/form.rb
133
131
  - lib/searchgasm/helpers/utilities.rb
134
- - lib/searchgasm/helpers.rb
135
132
  - lib/searchgasm/search/base.rb
136
133
  - lib/searchgasm/search/conditions.rb
137
134
  - lib/searchgasm/search/ordering.rb
138
135
  - lib/searchgasm/search/pagination.rb
139
136
  - lib/searchgasm/search/protection.rb
140
- - lib/searchgasm/search.rb
141
137
  - lib/searchgasm/shared/searching.rb
142
138
  - lib/searchgasm/shared/utilities.rb
143
139
  - lib/searchgasm/shared/virtual_classes.rb