searchgasm 1.1.3 → 1.2.0

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.
@@ -18,20 +18,20 @@ module Searchgasm
18
18
  module Ordering
19
19
  def self.included(klass)
20
20
  klass.class_eval do
21
- alias_method_chain :joins, :ordering
21
+ alias_method_chain :auto_joins, :ordering
22
22
  alias_method_chain :order=, :ordering
23
23
  end
24
24
  end
25
25
 
26
- def joins_with_ordering # :nodoc:
27
- @memoized_joins ||= merge_joins(joins_without_ordering, order_by_joins)
26
+ def auto_joins_with_ordering # :nodoc:
27
+ @memoized_auto_joins ||= merge_joins(auto_joins_without_ordering, order_by_auto_joins)
28
28
  end
29
29
 
30
30
  def order_with_ordering=(value) # :nodoc
31
31
  @order_by = nil
32
32
  @order_as = nil
33
- self.order_by_joins.clear
34
- @memoized_joins = nil
33
+ self.order_by_auto_joins.clear
34
+ @memoized_auto_joins = nil
35
35
  self.order_without_ordering = value
36
36
  end
37
37
 
@@ -101,19 +101,19 @@ module Searchgasm
101
101
  # order_by = [:id, name] # => users.id ASC, user.name ASC
102
102
  # order_by = [:id, {:user_group => :name}] # => users.id ASC, user_groups.name ASC
103
103
  def order_by=(value)
104
- self.order_by_joins.clear
105
- @memoized_joins = nil
104
+ self.order_by_auto_joins.clear
105
+ @memoized_auto_joins = nil
106
106
  @order_by = get_order_by_value(value)
107
107
  @order = order_by_to_order(@order_by, order_as)
108
108
  @order_by
109
109
  end
110
110
 
111
111
  # Returns the joins neccessary for the "order" statement so that we don't get an SQL error
112
- def order_by_joins
113
- @order_by_joins ||= []
114
- @order_by_joins.compact!
115
- @order_by_joins.uniq!
116
- @order_by_joins
112
+ def order_by_auto_joins
113
+ @order_by_auto_joins ||= []
114
+ @order_by_auto_joins.compact!
115
+ @order_by_auto_joins.uniq!
116
+ @order_by_auto_joins
117
117
  end
118
118
 
119
119
  private
@@ -133,20 +133,20 @@ module Searchgasm
133
133
  new_joins << key.to_sym
134
134
  sql_parts << order_by_to_order(value, order_as, reflection.klass, new_joins)
135
135
  when Symbol, String
136
- new_join = build_order_by_joins(new_joins)
137
- self.order_by_joins << new_join if new_join
136
+ new_join = build_order_by_auto_joins(new_joins)
137
+ self.order_by_auto_joins << new_join if new_join
138
138
  sql_parts << "#{quote_table_name(table_name)}.#{quote_column_name(order_by)} #{order_as}"
139
139
  end
140
140
 
141
141
  sql_parts.join(", ")
142
142
  end
143
143
 
144
- def build_order_by_joins(joins)
144
+ def build_order_by_auto_joins(joins)
145
145
  return joins.first if joins.size <= 1
146
146
  joins = joins.dup
147
147
 
148
148
  key = joins.shift
149
- {key => build_order_by_joins(joins)}
149
+ {key => build_order_by_auto_joins(joins)}
150
150
  end
151
151
 
152
152
  def get_order_by_value(value)
@@ -0,0 +1,32 @@
1
+ module Searchgasm
2
+ module Search
3
+ # = Searchgasm Searching
4
+ #
5
+ # Implements searching functionality for searchgasm. Searchgasm::Search::Base and Searchgasm::Conditions::Base can both search and include
6
+ # this module.
7
+ module Searching
8
+ # Use these methods just like you would in ActiveRecord
9
+ SEARCH_METHODS = [:all, :find, :first]
10
+ CALCULATION_METHODS = [:average, :calculate, :count, :maximum, :minimum, :sum]
11
+
12
+ def self.included(klass)
13
+ klass.class_eval do
14
+ attr_accessor :scope
15
+ end
16
+ end
17
+
18
+ (SEARCH_METHODS + CALCULATION_METHODS).each do |method|
19
+ class_eval <<-"end_eval", __FILE__, __LINE__
20
+ def #{method}(*args)
21
+ find_options = {}
22
+ options = args.extract_options! # can't pass options, your options are in the search
23
+ klass.send(:with_scope, :find => scope) do
24
+ args << sanitize(#{SEARCH_METHODS.include?(method)})
25
+ klass.#{method}(*args)
26
+ end
27
+ end
28
+ end_eval
29
+ end
30
+ end
31
+ end
32
+ end
@@ -66,8 +66,8 @@ module Searchgasm
66
66
  end
67
67
 
68
68
  MAJOR = 1
69
- MINOR = 1
70
- TINY = 3
69
+ MINOR = 2
70
+ TINY = 0
71
71
 
72
72
  # The current version as a Version instance
73
73
  CURRENT = new(MAJOR, MINOR, TINY)
data/lib/searchgasm.rb CHANGED
@@ -8,7 +8,6 @@ require "searchgasm/core_ext/hash"
8
8
 
9
9
  # Shared
10
10
  require "searchgasm/shared/utilities"
11
- require "searchgasm/shared/searching"
12
11
  require "searchgasm/shared/virtual_classes"
13
12
 
14
13
  # Base classes
@@ -23,6 +22,7 @@ require "searchgasm/active_record/associations"
23
22
  require "searchgasm/search/ordering"
24
23
  require "searchgasm/search/pagination"
25
24
  require "searchgasm/search/conditions"
25
+ require "searchgasm/search/searching"
26
26
  require "searchgasm/search/base"
27
27
  require "searchgasm/search/protection"
28
28
 
@@ -68,6 +68,7 @@ module Searchgasm
68
68
  include Ordering
69
69
  include Protection
70
70
  include Pagination
71
+ include Searching
71
72
  end
72
73
  end
73
74
 
data/searchgasm.gemspec CHANGED
@@ -1,18 +1,18 @@
1
1
 
2
- # Gem::Specification for Searchgasm-1.1.3
2
+ # Gem::Specification for Searchgasm-1.2.0
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.3
8
+ version: 1.2.0
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-23 00:00:00 -04:00
15
+ date: 2008-09-24 00:00:00 -04:00
16
16
  default_executable:
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
@@ -34,6 +34,9 @@ dependencies:
34
34
  - - ">="
35
35
  - !ruby/object:Gem::Version
36
36
  version: "0"
37
+ - - "="
38
+ - !ruby/object:Gem::Version
39
+ version: 2.1.0
37
40
  version:
38
41
  - !ruby/object:Gem::Dependency
39
42
  name: echoe
@@ -90,7 +93,7 @@ extra_rdoc_files:
90
93
  - lib/searchgasm/search/ordering.rb
91
94
  - lib/searchgasm/search/pagination.rb
92
95
  - lib/searchgasm/search/protection.rb
93
- - lib/searchgasm/shared/searching.rb
96
+ - lib/searchgasm/search/searching.rb
94
97
  - lib/searchgasm/shared/utilities.rb
95
98
  - lib/searchgasm/shared/virtual_classes.rb
96
99
  - lib/searchgasm/version.rb
@@ -137,7 +140,7 @@ files:
137
140
  - lib/searchgasm/search/ordering.rb
138
141
  - lib/searchgasm/search/pagination.rb
139
142
  - lib/searchgasm/search/protection.rb
140
- - lib/searchgasm/shared/searching.rb
143
+ - lib/searchgasm/search/searching.rb
141
144
  - lib/searchgasm/shared/utilities.rb
142
145
  - lib/searchgasm/shared/virtual_classes.rb
143
146
  - lib/searchgasm/version.rb
@@ -148,6 +151,7 @@ files:
148
151
  - README.rdoc
149
152
  - test/fixtures/accounts.yml
150
153
  - test/fixtures/orders.yml
154
+ - test/fixtures/user_groups.yml
151
155
  - test/fixtures/users.yml
152
156
  - test/libs/acts_as_tree.rb
153
157
  - test/libs/rexml_fix.rb
@@ -164,7 +168,6 @@ files:
164
168
  - test/test_search_ordering.rb
165
169
  - test/test_search_pagination.rb
166
170
  - test/test_search_protection.rb
167
- - test/text_config.rb
168
171
  - searchgasm.gemspec
169
172
  has_rdoc: true
170
173
  homepage: http://github.com/binarylogic/searchgasm
@@ -0,0 +1,13 @@
1
+ neco:
2
+ id: 1
3
+ name: NECO
4
+ user_ids:
5
+ - 1
6
+ - 2
7
+
8
+ johnsons:
9
+ id: 2
10
+ name: Johnsons
11
+ user_ids:
12
+ - 1
13
+ - 3
@@ -1,61 +1,81 @@
1
1
  require File.dirname(__FILE__) + '/test_helper.rb'
2
2
 
3
3
  class TestActiveRecordAssociations < Test::Unit::TestCase
4
- fixtures :accounts, :users, :orders
5
-
6
- def setup
7
- setup_db
8
- load_fixtures
9
- end
10
-
11
- def teardown
12
- teardown_db
13
- end
14
-
15
- def test_build_search
16
- search = Account.find(1).users.build_search
4
+ def test_has_many
5
+ search = Account.find(1).users.new_search
17
6
  assert_kind_of Searchgasm::Search::Base, search
18
7
  assert_equal User, search.klass
19
8
  assert_equal({:conditions => "\"users\".account_id = 1"}, search.scope)
20
9
 
10
+ assert_equal User.find(1, 3), search.all
11
+ assert_equal User.find(1), search.first
12
+ assert_equal 2, search.average("id")
13
+ assert_equal 2, search.count
14
+
21
15
  search.conditions.first_name_contains = "Ben"
22
- assert_equal({:conditions => ["\"users\".\"first_name\" LIKE ?", "%Ben%"]}, search.sanitize)
23
- end
24
-
25
- def test_searching
26
- assert_equal [User.find(1)], Account.find(1).users.all(:conditions => {:first_name_begins_with => "Ben"})
27
- assert_equal [User.find(1)], Account.find(1).users.find(:all, :conditions => {:first_name_begins_with => "Ben"})
28
- assert_equal User.find(1), Account.find(1).users.first(:conditions => {:first_name_begins_with => "Ben"})
29
- assert_equal User.find(1), Account.find(1).users.find(:first, :conditions => {:first_name_begins_with => "Ben"})
30
- assert_equal [], Account.find(1).users.all(:conditions => {:first_name_begins_with => "Ben"}, :per_page => 20, :page => 5)
31
16
 
32
- search = Account.find(1).users.new_search
33
- assert_equal User.find(1, 3), search.all
17
+ assert_equal [User.find(1)], search.all
34
18
  assert_equal User.find(1), search.first
35
- end
36
-
37
- def test_calculations
38
- assert_equal 1, Account.find(1).users.count(:conditions => {:first_name_begins_with => "Ben"})
39
- assert_equal 1, Account.find(1).users.sum("id", :conditions => {:first_name_begins_with => "Ben"})
40
- assert_equal 1, Account.find(1).users.average("id", :conditions => {:first_name_begins_with => "Ben"})
19
+ assert_equal 1, search.average("id")
20
+ assert_equal 1, search.count
21
+
22
+ assert_equal 2, Account.find(1).users.count
23
+ assert_equal 1, Account.find(1).users.all(:conditions => {:first_name_contains => "Ben"}).size
24
+ assert_equal 0, Account.find(1).users.all(:conditions => {:first_name_contains => "No one"}).size
25
+ assert_equal 1, Account.find(1).users.sum("id", :conditions => {:first_name_contains => "Ben"})
26
+ assert_equal 0, Account.find(1).users.sum("id", :conditions => {:first_name_contains => "No one"})
27
+ assert_equal 1, Account.find(1).users.average("id", :conditions => {:first_name_contains => "Ben"})
41
28
  end
42
29
 
43
30
  def test_has_many_through
31
+ search = Account.find(1).orders.new_search
32
+ assert_kind_of Searchgasm::Search::Base, search
33
+ assert_equal Order, search.klass
34
+ assert_equal({:joins => "INNER JOIN users ON orders.user_id = users.id ", :conditions => "(\"users\".account_id = 1)"}, search.scope)
35
+
36
+ assert_equal [Order.find(1)], search.all
37
+ assert_equal Order.find(1), search.first
38
+ assert_equal 1, search.average("id")
39
+ assert_equal 1, search.count
40
+
41
+ search.conditions.total_gt = 100
42
+
43
+ assert_equal [Order.find(1)], search.all
44
+ assert_equal Order.find(1), search.first
45
+ assert_equal 1, search.average("id")
46
+ assert_equal 1, search.count
47
+
44
48
  assert_equal 1, Account.find(1).orders.count
45
49
  assert_equal 1, Account.find(1).orders.all(:conditions => {:total_gt => 100}).size
46
50
  assert_equal 0, Account.find(1).orders.all(:conditions => {:total_gt => 1000}).size
47
51
  assert_equal 1, Account.find(1).orders.sum("id", :conditions => {:total_gt => 100})
48
52
  assert_equal 0, Account.find(1).orders.sum("id", :conditions => {:total_gt => 1000})
49
53
  assert_equal 1, Account.find(1).orders.average("id", :conditions => {:total_gt => 100})
50
-
51
- search = Account.find(1).orders.new_search
52
- assert_equal [Order.find(1)], search.all
53
- assert_equal Order.find(1), search.first
54
- assert_equal 1, search.average("id")
55
- assert_equal 1, search.count
56
54
  end
57
55
 
58
56
  def test_habtm
57
+ search = UserGroup.find(1).users.new_search
58
+ assert_kind_of Searchgasm::Search::Base, search
59
+ assert_equal User, search.klass
60
+ assert_equal({:conditions => "\"user_groups_users\".user_group_id = 1 ", :joins => "INNER JOIN \"user_groups_users\" ON \"users\".id = \"user_groups_users\".user_id"}, search.scope)
61
+
62
+ assert_equal User.find(1, 2), search.all
63
+ assert_equal User.find(1), search.first
64
+ assert_equal 1.5, search.average("id")
65
+ assert_equal 2, search.count
66
+
67
+ search.conditions.first_name_contains = "Ben"
68
+
69
+ assert_equal [User.find(1)], search.all
70
+ assert_equal User.find(1), search.first
71
+ assert_equal 1, search.average("id")
72
+ assert_equal 1, search.count
59
73
 
74
+ assert_equal 2, UserGroup.find(1).users.count
75
+ assert_equal 1, UserGroup.find(1).users.all(:conditions => {:first_name_contains => "Ben"}).size
76
+ assert_equal 0, UserGroup.find(1).users.all(:conditions => {:first_name_contains => "No one"}).size
77
+ assert_equal 1, UserGroup.find(1).users.sum("id", :conditions => {:first_name_contains => "Ben"})
78
+ assert_equal 0, UserGroup.find(1).users.sum("id", :conditions => {:first_name_contains => "No one"})
79
+ assert_equal 1, UserGroup.find(1).users.average("id", :conditions => {:first_name_contains => "Ben"})
60
80
  end
61
81
  end
@@ -1,67 +1,46 @@
1
1
  require File.dirname(__FILE__) + '/test_helper.rb'
2
2
 
3
3
  class TestActiveRecordBase < Test::Unit::TestCase
4
- fixtures :accounts, :users, :orders
5
-
6
- def setup
7
- setup_db
8
- load_fixtures
9
- end
10
-
11
- def teardown
12
- teardown_db
4
+ def test_standard_find
5
+ assert_equal [1,2,3], Account.all.map(&:id)
6
+ assert_equal 1, Account.first.id
7
+ assert_equal [1,2,3], Account.find(:all).map(&:id)
8
+ assert_equal [1], Account.find(:all, :conditions => {:name => "Binary Logic"}).map(&:id)
9
+ assert_equal [1], Account.find(:all, :conditions => ["name = ?", "Binary Logic"]).map(&:id)
10
+ assert_equal [1], Account.find(:all, :conditions => "name = 'Binary Logic'").map(&:id)
11
+ assert_equal 1, Account.find(:first).id
12
+ assert_equal [1,2,3], Account.find(:all, nil).map(&:id)
13
+ assert_equal [1,2,3], Account.find(:all, {}).map(&:id)
13
14
  end
14
15
 
15
- def test_standard_searches
16
- assert_nothing_raised { Account.all }
17
- assert_nothing_raised { Account.first }
18
- assert_nothing_raised { Account.find(:all) }
19
- assert_nothing_raised { Account.find(:all, :conditions => {:name => "Ben"}) }
20
- assert_nothing_raised { Account.find(:all, :conditions => ["name = ?", "Ben"]) }
21
- assert_nothing_raised { Account.find(:all, :conditions => "name = 'Ben'") }
22
- assert_nothing_raised { Account.find(:first) }
23
- assert_nothing_raised { Account.find(:all, nil) }
24
- assert_nothing_raised { Account.find(:all, {}) }
25
- assert_nothing_raised { Account.count({}) }
26
- assert_nothing_raised { Account.count(nil) }
27
- assert_nothing_raised { Account.sum("id") }
28
- assert_nothing_raised { Account.sum("id", {}) }
16
+ def test_standard_calculations
17
+ assert_equal 3, Account.count({})
18
+ assert_equal 3, Account.count(nil)
19
+ assert_equal 3, Account.count(:limit => 1)
20
+ assert_equal 0, Account.count(:limit => 10, :offset => 10)
21
+ assert_equal 6, Account.sum("id")
22
+ assert_equal 6, Account.sum("id", {})
23
+ assert_equal 2, Account.average("id")
24
+ assert_equal 3, Account.maximum("id")
25
+ assert_equal 1, Account.minimum("id")
29
26
  end
30
27
 
31
- def test_ar_options
28
+ def test_valid_ar_options
32
29
  assert_equal [ :conditions, :include, :joins, :limit, :offset, :order, :select, :readonly, :group, :from, :lock ], ActiveRecord::Base.valid_find_options
33
30
  assert_equal [:conditions, :joins, :order, :select, :group, :having, :distinct, :limit, :offset, :include, :from], ActiveRecord::Base.valid_calculations_options
34
31
  end
35
32
 
36
33
  def test_build_search
37
- search = Account.new_search
38
- assert_kind_of Searchgasm::Search::Base, search
39
-
40
- search = Account.build_search(:conditions => {:name_keywords => "awesome"}, :page => 2, :per_page => 15)
34
+ search = Account.new_search(:conditions => {:name_keywords => "awesome"}, :page => 2, :per_page => 15)
41
35
  assert_kind_of Searchgasm::Search::Base, search
36
+ assert_equal({}, search.scope)
42
37
  assert_equal Account, search.klass
43
38
  assert_equal "awesome", search.conditions.name_keywords
44
39
  assert_equal 2, search.page
45
40
  assert_equal 15, search.per_page
46
-
47
- search = Account.new_search(:conditions => {:name_keywords => "awesome"}, :page => 2, :per_page => 15)
48
- assert_equal Account, search.klass
49
41
  end
50
42
 
51
- def test_build_conditions
52
- search = Account.new_conditions
53
- assert_kind_of Searchgasm::Conditions::Base, search
54
-
55
- search = Account.build_conditions(:name_keywords => "awesome")
56
- assert_kind_of Searchgasm::Conditions::Base, search
57
- assert_equal Account, search.klass
58
- assert_equal "awesome", search.name_keywords
59
-
60
- search = Account.new_conditions(:name_keywords => "awesome")
61
- assert_equal Account, search.klass
62
- end
63
-
64
- def test_searching
43
+ def test_searchgasm_searching
65
44
  assert_equal Account.find(1, 3), Account.all(:conditions => {:name_contains => "Binary"})
66
45
  assert_equal [Account.find(1)], Account.all(:conditions => {:name_contains => "Binary", :users => {:first_name_starts_with => "Ben"}})
67
46
  assert_equal [], Account.all(:conditions => {:name_contains => "Binary", :users => {:first_name_starts_with => "Ben", :last_name => "Mills"}})
@@ -73,23 +52,34 @@ class TestActiveRecordBase < Test::Unit::TestCase
73
52
  assert_equal [], Account.all(:conditions => {:name_contains => "Binary"}, :page => 2, :per_page => 20)
74
53
  end
75
54
 
76
- def test_counting
55
+ def test_searchgasm_counting
77
56
  assert_equal 2, Account.count(:conditions => {:name_contains => "Binary"})
78
57
  assert_equal 1, Account.count(:conditions => {:name_contains => "Binary", :users => {:first_name_contains => "Ben"}})
58
+ assert_equal 1, Account.count(:conditions => {:name_contains => "Binary", :users => {:first_name_contains => "Ben"}}, :limit => 10, :offset => 10, :order_by => "id", :group => "id")
79
59
  end
80
60
 
81
61
  def test_scoping
82
- assert_equal nil, Account.send(:scope, :find)
62
+ assert_equal({:conditions => {:name => "Binary"}, :limit => 10, :readonly => true}, Account.send(:with_scope, :find => {:conditions => {:name => "Binary"}, :limit => 10, :readonly => true}) { Account.send(:scope, :find) })
63
+ assert_equal({:conditions => ["\"accounts\".\"name\" LIKE ?", "%Binary%"], :limit => 10, :offset => 20}, Account.send(:with_scope, :find => {:conditions => {:name_contains => "Binary"}, :per_page => 10, :page => 3}) { Account.send(:scope, :find) })
83
64
  end
84
65
 
85
- def test_count
86
- assert_equal 3, Account.count
87
- assert_equal 3, Account.count(:limit => 1)
88
- assert_equal 0, Account.count(:limit => 1, :offset => 1) # not sure why AR doesn't ignore offset like it does for limit
89
- search = Account.new_search
90
- assert_equal 3, search.count
91
- search.per_page = 10
92
- search.page = 10
93
- assert_equal 3, search.count
66
+ def test_accessible_conditions
67
+ Account.conditions_accessible :name_contains
68
+ assert_equal Set.new(["name_contains"]), Account.accessible_conditions
69
+ Account.conditions_accessible :id_gt
70
+ assert_equal Set.new(["id_gt", "name_contains"]), Account.accessible_conditions
71
+ Account.conditions_accessible :id_gt, :name_contains
72
+ assert_equal Set.new(["id_gt", "name_contains"]), Account.accessible_conditions
73
+ Account.send(:write_inheritable_attribute, :conditions_accessible, nil)
74
+ end
75
+
76
+ def test_protected_conditions
77
+ Account.conditions_protected :name_contains
78
+ assert_equal Set.new(["name_contains"]), Account.protected_conditions
79
+ Account.conditions_protected :id_gt
80
+ assert_equal Set.new(["id_gt", "name_contains"]), Account.protected_conditions
81
+ Account.conditions_protected :id_gt, :name_contains
82
+ assert_equal Set.new(["id_gt", "name_contains"]), Account.protected_conditions
83
+ Account.send(:write_inheritable_attribute, :conditions_protected, nil)
94
84
  end
95
85
  end
@@ -1,29 +1,42 @@
1
1
  require File.dirname(__FILE__) + '/test_helper.rb'
2
2
 
3
3
  class TestConditionBase < Test::Unit::TestCase
4
- fixtures :accounts, :users, :orders
4
+ def test_condition_name
5
+ assert_equal "equals", Searchgasm::Condition::Equals.condition_name
6
+ assert_equal "keywords", Searchgasm::Condition::Keywords.condition_name
7
+ assert_equal "greater_than_or_equal_to", Searchgasm::Condition::GreaterThanOrEqualTo.condition_name
8
+ end
5
9
 
6
- def setup
7
- setup_db
8
- load_fixtures
10
+ def test_name_for_column
11
+ assert_equal "id_equals", Searchgasm::Condition::Equals.name_for_column(Account.columns_hash["id"])
12
+ assert_equal nil, Searchgasm::Condition::Keywords.name_for_column(Account.columns_hash["id"])
9
13
  end
10
14
 
11
- def teardown
12
- teardown_db
15
+ def test_ignore_blanks?
16
+ assert !Searchgasm::Condition::Equals.ignore_blanks?
17
+ assert Searchgasm::Condition::Keywords.ignore_blanks?
13
18
  end
14
19
 
15
- def test_condition_name
16
- assert_equal "equals", Searchgasm::Condition::Equals.condition_name
17
- assert_equal "keywords", Searchgasm::Condition::Keywords.condition_name
18
- assert_equal "greater_than_or_equal_to", Searchgasm::Condition::GreaterThanOrEqualTo.condition_name
20
+ def test_type_cast_value?
21
+ assert Searchgasm::Condition::Equals.type_cast_value?
22
+ assert Searchgasm::Condition::Keywords.type_cast_value?
23
+ assert !Searchgasm::Condition::IsNil.type_cast_value?
24
+ assert !Searchgasm::Condition::IsBlank.type_cast_value?
19
25
  end
20
26
 
21
27
  def test_string_column
22
-
28
+ assert !Searchgasm::Condition::Base.string_column?(Account.columns_hash["id"])
29
+ assert Searchgasm::Condition::Base.string_column?(Account.columns_hash["name"])
30
+ assert !Searchgasm::Condition::Base.string_column?(Account.columns_hash["active"])
31
+ assert Searchgasm::Condition::Base.string_column?(User.columns_hash["bio"])
23
32
  end
24
33
 
25
34
  def test_comparable_column
26
-
35
+ assert Searchgasm::Condition::Base.comparable_column?(Account.columns_hash["id"])
36
+ assert !Searchgasm::Condition::Base.comparable_column?(Account.columns_hash["name"])
37
+ assert !Searchgasm::Condition::Base.comparable_column?(Account.columns_hash["active"])
38
+ assert !Searchgasm::Condition::Base.comparable_column?(User.columns_hash["bio"])
39
+ assert Searchgasm::Condition::Base.comparable_column?(Order.columns_hash["total"])
27
40
  end
28
41
 
29
42
  def test_initialize
@@ -35,19 +48,29 @@ class TestConditionBase < Test::Unit::TestCase
35
48
  assert_equal condition.column, Account.columns_hash["id"]
36
49
  end
37
50
 
38
- def test_ignore_blanks?
39
- condition = Searchgasm::Condition::Equals.new(Account, Account.columns_hash["id"])
40
- assert !condition.class.ignore_blanks?
41
-
51
+ def test_explicitly_set_value
42
52
  condition = Searchgasm::Condition::Keywords.new(Account, Account.columns_hash["name"])
43
- assert condition.class.ignore_blanks?
53
+ assert !condition.explicitly_set_value?
54
+ condition.value = "test"
55
+ assert condition.explicitly_set_value?
44
56
  end
45
57
 
46
- def test_value
58
+ def test_name
59
+ condition = Searchgasm::Condition::Keywords.new(Account, Account.columns_hash["name"])
60
+ assert_equal "name_keywords", condition.name
61
+
62
+ condition = Searchgasm::Condition::DescendantOf.new(User)
63
+ assert_equal "descendant_of", condition.name
47
64
 
65
+ condition = Searchgasm::Condition::DescendantOf.new(Account)
66
+ assert_equal nil, condition.name
48
67
  end
49
68
 
50
- def test_method_creation_in_scope
51
- # test ot make sure methods are not created across the board for all models
69
+ def test_sanitize
70
+ # This is tested thoroughly in test_condition_types
71
+ end
72
+
73
+ def test_value
74
+ # This is tested thoroughly in test_condition_types
52
75
  end
53
76
  end
@@ -1,17 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/test_helper.rb'
2
2
 
3
3
  class TestConditionTypes < Test::Unit::TestCase
4
- fixtures :accounts, :users, :orders
5
-
6
- def setup
7
- setup_db
8
- load_fixtures
9
- end
10
-
11
- def teardown
12
- teardown_db
13
- end
14
-
15
4
  def test_sanitize
16
5
  condition = Searchgasm::Condition::BeginsWith.new(Account, Account.columns_hash["name"])
17
6
  condition.value = "Binary"