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.
- data/CHANGELOG.rdoc +10 -1
- data/Manifest +2 -2
- data/README.rdoc +2 -17
- data/Rakefile +1 -1
- data/lib/searchgasm/active_record/associations.rb +0 -20
- data/lib/searchgasm/active_record/base.rb +16 -44
- data/lib/searchgasm/conditions/base.rb +5 -4
- data/lib/searchgasm/core_ext/hash.rb +13 -0
- data/lib/searchgasm/helpers/control_types/link.rb +8 -10
- data/lib/searchgasm/helpers/control_types/links.rb +4 -4
- data/lib/searchgasm/helpers/control_types/select.rb +4 -9
- data/lib/searchgasm/helpers/utilities.rb +55 -31
- data/lib/searchgasm/search/base.rb +17 -11
- data/lib/searchgasm/search/conditions.rb +14 -3
- data/lib/searchgasm/search/ordering.rb +16 -16
- data/lib/searchgasm/search/searching.rb +32 -0
- data/lib/searchgasm/version.rb +2 -2
- data/lib/searchgasm.rb +2 -1
- data/searchgasm.gemspec +9 -6
- data/test/fixtures/user_groups.yml +13 -0
- data/test/test_active_record_associations.rb +56 -36
- data/test/test_active_record_base.rb +46 -56
- data/test/test_condition_base.rb +43 -20
- data/test/test_condition_types.rb +0 -11
- data/test/test_conditions_base.rb +113 -120
- data/test/test_conditions_protection.rb +6 -17
- data/test/test_config.rb +2 -11
- data/test/test_helper.rb +38 -7
- data/test/test_search_base.rb +7 -18
- data/test/test_search_conditions.rb +26 -14
- data/test/test_search_ordering.rb +0 -11
- data/test/test_search_pagination.rb +0 -11
- data/test/test_search_protection.rb +0 -11
- metadata +8 -5
- data/lib/searchgasm/shared/searching.rb +0 -43
- data/test/text_config.rb +0 -1
@@ -1,39 +1,130 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
2
|
|
3
3
|
class TestConditionsBase < 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_register_conditions
|
16
5
|
Searchgasm::Conditions::Base.register_condition(Searchgasm::Condition::Keywords)
|
17
6
|
assert [Searchgasm::Condition::Keywords], Searchgasm::Conditions::Base.conditions
|
18
7
|
|
19
8
|
Searchgasm::Conditions::Base.register_condition(Searchgasm::Condition::Contains)
|
20
9
|
assert [Searchgasm::Condition::Keywords, Searchgasm::Condition::Contains], Searchgasm::Conditions::Base.conditions
|
21
|
-
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_association_names
|
13
|
+
assert_equal ["account", "parent", "orders", "user_groups", "children"], Searchgasm::Cache::UserConditions.association_names
|
14
|
+
assert_equal ["admin", "orders", "users"], Searchgasm::Cache::AccountConditions.association_names
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_condition_names
|
18
|
+
# This is tested thoroughly through the tests
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_needed
|
22
|
+
assert !Searchgasm::Conditions::Base.needed?(User, {})
|
23
|
+
assert !Searchgasm::Conditions::Base.needed?(User, {:first_name => "Ben"})
|
24
|
+
assert Searchgasm::Conditions::Base.needed?(User, {:first_name_contains => "Awesome"})
|
22
25
|
end
|
23
26
|
|
24
27
|
def test_initialize
|
25
|
-
conditions =
|
28
|
+
conditions = Searchgasm::Cache::AccountConditions.new(:name_contains => "Binary")
|
26
29
|
assert_equal conditions.klass, Account
|
27
30
|
assert_equal conditions.name_contains, "Binary"
|
28
31
|
end
|
29
32
|
|
30
|
-
def
|
31
|
-
|
33
|
+
def test_any
|
34
|
+
conditions = Searchgasm::Cache::AccountConditions.new
|
35
|
+
assert !conditions.any?
|
36
|
+
|
37
|
+
conditions = Searchgasm::Cache::AccountConditions.new(:any => true)
|
38
|
+
assert conditions.any?
|
39
|
+
conditions.any = "false"
|
40
|
+
assert !conditions.any?
|
41
|
+
|
42
|
+
conditions = Searchgasm::Cache::AccountConditions.new
|
43
|
+
conditions.name_contains = "Binary"
|
44
|
+
assert_equal ["\"accounts\".\"name\" LIKE ?", "%Binary%"], conditions.sanitize
|
45
|
+
conditions.id = 1
|
46
|
+
assert_equal ["(\"accounts\".\"name\" LIKE ?) AND (\"accounts\".\"id\" = 1)", "%Binary%"], conditions.sanitize
|
47
|
+
conditions.any = true
|
48
|
+
assert_equal ["(\"accounts\".\"name\" LIKE ?) OR (\"accounts\".\"id\" = 1)", "%Binary%"], conditions.sanitize
|
49
|
+
conditions.any = false
|
50
|
+
assert_equal ["(\"accounts\".\"name\" LIKE ?) AND (\"accounts\".\"id\" = 1)", "%Binary%"], conditions.sanitize
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_auto_joins
|
54
|
+
conditions = Searchgasm::Cache::AccountConditions.new
|
55
|
+
assert_equal conditions.auto_joins, nil
|
56
|
+
|
57
|
+
conditions.name_like = "Binary"
|
58
|
+
assert_equal conditions.auto_joins, nil
|
59
|
+
|
60
|
+
conditions.users.first_name_like = "Ben"
|
61
|
+
assert_equal conditions.auto_joins, :users
|
62
|
+
|
63
|
+
conditions.users.orders.description_like = "apple"
|
64
|
+
assert_equal conditions.auto_joins, {:users => :orders}
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_inspect
|
68
|
+
conditions = Searchgasm::Cache::AccountConditions.new
|
69
|
+
assert_nothing_raised { conditions.inspect }
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_sanitize
|
73
|
+
conditions = Searchgasm::Cache::AccountConditions.new
|
74
|
+
conditions.name_contains = "Binary"
|
75
|
+
conditions.id_gt = 5
|
76
|
+
now = Time.now
|
77
|
+
conditions.created_after = now
|
78
|
+
assert_equal conditions.sanitize, ["(\"accounts\".\"name\" LIKE ?) AND (\"accounts\".\"id\" > ?) AND (\"accounts\".\"created_at\" > ?)", "%Binary%", 5, now]
|
79
|
+
|
80
|
+
# test out associations
|
81
|
+
conditions.users.first_name_like = "Ben"
|
82
|
+
conditions.users.id_gt = 10
|
83
|
+
conditions.users.orders.total_lt = 500
|
84
|
+
assert_equal conditions.sanitize, ["(\"accounts\".\"name\" LIKE ?) AND (\"accounts\".\"id\" > ?) AND (\"accounts\".\"created_at\" > ?) AND ((\"users\".\"first_name\" LIKE ?) AND (\"users\".\"id\" > ?) AND (\"orders\".\"total\" < ?))", "%Binary%", 5, now, "%Ben%", 10, 500]
|
85
|
+
|
86
|
+
# test that raw sql is returned
|
87
|
+
conditions.conditions = "awesome"
|
88
|
+
assert_equal "awesome", conditions.sanitize
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_conditions
|
92
|
+
conditions = Searchgasm::Cache::AccountConditions.new
|
93
|
+
now = Time.now
|
94
|
+
v = {:name_contains => "Binary", :created_at_greater_than => now}
|
95
|
+
conditions.conditions = v
|
96
|
+
assert_equal v, conditions.conditions
|
97
|
+
|
98
|
+
sql = "id in (1,2,3,4)"
|
99
|
+
conditions.conditions = sql
|
100
|
+
assert_equal sql, conditions.conditions
|
101
|
+
assert_equal [], conditions.send(:objects)
|
102
|
+
|
103
|
+
v2 = {:id_less_than => 5, :name_begins_with => "Beginning of string"}
|
104
|
+
conditions.conditions = v2
|
105
|
+
assert_equal v2, conditions.conditions
|
106
|
+
|
107
|
+
v = {:name_contains => "Binary", :created_at_greater_than => now}
|
108
|
+
conditions.conditions = v
|
109
|
+
assert_equal v2.merge(v), conditions.conditions
|
110
|
+
|
111
|
+
sql2 = "id > 5 and name = 'Test'"
|
112
|
+
conditions.conditions = sql2
|
113
|
+
assert_equal sql2, conditions.conditions
|
114
|
+
assert_equal [], conditions.send(:objects)
|
115
|
+
|
116
|
+
conditions.name_contains = "awesome"
|
117
|
+
assert_equal({:name_contains => "awesome"}, conditions.conditions)
|
118
|
+
|
119
|
+
conditions.conditions = {:id_gt => "", :name_starts_with => "Ben"}
|
120
|
+
assert_equal({:name_contains => "awesome", :name_begins_with => "Ben"}, conditions.conditions)
|
32
121
|
end
|
33
122
|
|
123
|
+
# Other general usage tests, need to clean these up
|
124
|
+
|
34
125
|
def test_setting_conditions
|
35
126
|
[Account, User, Order].each do |klass|
|
36
|
-
conditions = klass.
|
127
|
+
conditions = "Searchgasm::Cache::#{klass}Conditions".constantize.new
|
37
128
|
conditions.class.condition_names.each do |condition_name|
|
38
129
|
conditions.send("#{condition_name}=", 1)
|
39
130
|
assert_equal 1, conditions.send(condition_name)
|
@@ -43,13 +134,13 @@ class TestConditionsBase < Test::Unit::TestCase
|
|
43
134
|
|
44
135
|
def test_accessible_protected_conditions
|
45
136
|
Account.conditions_accessible << :name_contains
|
46
|
-
conditions =
|
137
|
+
conditions = Searchgasm::Cache::AccountConditions.new
|
47
138
|
conditions.conditions = {:created_after => Time.now, :name_contains => "Binary"}
|
48
139
|
assert({:name_contains => "Binary"}, conditions.conditions)
|
49
140
|
Account.send(:write_inheritable_attribute, :conditions_accessible, nil)
|
50
141
|
|
51
142
|
Account.conditions_protected << :name_contains
|
52
|
-
conditions =
|
143
|
+
conditions = Searchgasm::Cache::AccountConditions.new
|
53
144
|
now = Time.now
|
54
145
|
conditions.conditions = {:created_after => now, :name_contains => "Binary"}
|
55
146
|
assert({:created_after => now}, conditions.conditions)
|
@@ -57,36 +148,22 @@ class TestConditionsBase < Test::Unit::TestCase
|
|
57
148
|
end
|
58
149
|
|
59
150
|
def test_assert_valid_values
|
60
|
-
conditions =
|
151
|
+
conditions = Searchgasm::Cache::UserConditions.new
|
61
152
|
assert_raise(ArgumentError) { conditions.conditions = {:unknown => "blah"} }
|
62
153
|
assert_nothing_raised { conditions.conditions = {:first_name => "blah"} }
|
63
154
|
assert_nothing_raised { conditions.conditions = {:first_name_contains => "blah"} }
|
64
155
|
end
|
65
156
|
|
66
157
|
def test_setting_associations
|
67
|
-
conditions =
|
158
|
+
conditions = Searchgasm::Cache::AccountConditions.new(:users => {:first_name_like => "Ben"})
|
68
159
|
assert_equal conditions.users.first_name_like, "Ben"
|
69
160
|
|
70
161
|
conditions.users.last_name_begins_with = "Ben"
|
71
162
|
assert_equal conditions.users.last_name_begins_with, "Ben"
|
72
163
|
end
|
73
164
|
|
74
|
-
def test_joins
|
75
|
-
conditions = Account.new_conditions
|
76
|
-
assert_equal conditions.joins, nil
|
77
|
-
|
78
|
-
conditions.name_like = "Binary"
|
79
|
-
assert_equal conditions.joins, nil
|
80
|
-
|
81
|
-
conditions.users.first_name_like = "Ben"
|
82
|
-
assert_equal conditions.joins, :users
|
83
|
-
|
84
|
-
conditions.users.orders.description_like = "apple"
|
85
|
-
assert_equal conditions.joins, {:users => :orders}
|
86
|
-
end
|
87
|
-
|
88
165
|
def test_objects
|
89
|
-
conditions =
|
166
|
+
conditions = Searchgasm::Cache::AccountConditions.new
|
90
167
|
assert_equal conditions.send(:objects), []
|
91
168
|
|
92
169
|
conditions.name_contains = "Binary"
|
@@ -97,7 +174,7 @@ class TestConditionsBase < Test::Unit::TestCase
|
|
97
174
|
end
|
98
175
|
|
99
176
|
def test_reset
|
100
|
-
conditions =
|
177
|
+
conditions = Searchgasm::Cache::AccountConditions.new
|
101
178
|
|
102
179
|
conditions.name_contains = "Binary"
|
103
180
|
assert_equal 1, conditions.send(:objects).size
|
@@ -121,88 +198,4 @@ class TestConditionsBase < Test::Unit::TestCase
|
|
121
198
|
conditions.reset_users!
|
122
199
|
assert_equal [], conditions.send(:objects)
|
123
200
|
end
|
124
|
-
|
125
|
-
def test_sanitize
|
126
|
-
conditions = Account.new_conditions
|
127
|
-
conditions.name_contains = "Binary"
|
128
|
-
conditions.id_gt = 5
|
129
|
-
now = Time.now
|
130
|
-
conditions.created_after = now
|
131
|
-
assert_equal conditions.sanitize, ["(\"accounts\".\"name\" LIKE ?) AND (\"accounts\".\"id\" > ?) AND (\"accounts\".\"created_at\" > ?)", "%Binary%", 5, now]
|
132
|
-
|
133
|
-
# test out associations
|
134
|
-
conditions.users.first_name_like = "Ben"
|
135
|
-
conditions.users.id_gt = 10
|
136
|
-
conditions.users.orders.total_lt = 500
|
137
|
-
assert_equal conditions.sanitize, ["(\"accounts\".\"name\" LIKE ?) AND (\"accounts\".\"id\" > ?) AND (\"accounts\".\"created_at\" > ?) AND ((\"users\".\"first_name\" LIKE ?) AND (\"users\".\"id\" > ?) AND (\"orders\".\"total\" < ?))", "%Binary%", 5, now, "%Ben%", 10, 500]
|
138
|
-
end
|
139
|
-
|
140
|
-
def test_conditions
|
141
|
-
conditions = Account.new_conditions!
|
142
|
-
now = Time.now
|
143
|
-
v = {:name_contains => "Binary", :created_at_greater_than => now}
|
144
|
-
conditions.conditions = v
|
145
|
-
assert_equal v, conditions.conditions
|
146
|
-
|
147
|
-
sql = "id in (1,2,3,4)"
|
148
|
-
conditions.conditions = sql
|
149
|
-
assert_equal sql, conditions.conditions
|
150
|
-
|
151
|
-
v2 = {:id_less_than => 5, :name_begins_with => "Beginning of string"}
|
152
|
-
conditions.conditions = v2
|
153
|
-
assert_equal v2, conditions.conditions
|
154
|
-
|
155
|
-
v = {:name_contains => "Binary", :created_at_greater_than => now}
|
156
|
-
conditions.conditions = v
|
157
|
-
assert_equal v2.merge(v), conditions.conditions
|
158
|
-
|
159
|
-
sql2 = "id > 5 and name = 'Test'"
|
160
|
-
conditions.conditions = sql2
|
161
|
-
assert_equal sql2, conditions.conditions
|
162
|
-
|
163
|
-
conditions.name_contains = "awesome"
|
164
|
-
assert_equal({:name_contains => "awesome"}, conditions.conditions)
|
165
|
-
end
|
166
|
-
|
167
|
-
def test_searching
|
168
|
-
conditions = Account.new_conditions
|
169
|
-
conditions.name_contains = "Binary"
|
170
|
-
assert_equal Account.find(1, 3), conditions.all
|
171
|
-
assert_equal Account.find(1, 3), conditions.find(:all)
|
172
|
-
assert_equal Account.find(1), conditions.first
|
173
|
-
assert_equal Account.find(1), conditions.find(:first)
|
174
|
-
assert_equal 2, conditions.average('id')
|
175
|
-
assert_equal 2, conditions.calculate(:avg, 'id')
|
176
|
-
assert_equal 3, conditions.calculate(:max, 'id')
|
177
|
-
assert_equal 2, conditions.count
|
178
|
-
assert_equal 3, conditions.maximum('id')
|
179
|
-
assert_equal 1, conditions.minimum('id')
|
180
|
-
assert_equal 4, conditions.sum('id')
|
181
|
-
end
|
182
|
-
|
183
|
-
def test_any
|
184
|
-
conditions = Account.new_conditions
|
185
|
-
conditions.name_contains = "Binary"
|
186
|
-
assert_equal Account.find(1, 3), conditions.all
|
187
|
-
conditions.id = 1
|
188
|
-
assert_equal [Account.find(1)], conditions.all
|
189
|
-
conditions.any = true
|
190
|
-
assert_equal Account.find(1, 3), conditions.all
|
191
|
-
conditions.any = false
|
192
|
-
assert_equal [Account.find(1)], conditions.all
|
193
|
-
end
|
194
|
-
|
195
|
-
def test_ignoring_blanks
|
196
|
-
conditions = Account.new_conditions(:name => "", :created_after => nil)
|
197
|
-
assert_equal(nil, conditions.conditions)
|
198
|
-
conditions.name = ""
|
199
|
-
assert_equal({:name_equals => ""}, conditions.conditions)
|
200
|
-
conditions.created_after = ""
|
201
|
-
assert_equal({:name_equals => ""}, conditions.conditions)
|
202
|
-
end
|
203
|
-
|
204
|
-
def test_inspect
|
205
|
-
conditions = Account.new_conditions
|
206
|
-
assert_nothing_raised { conditions.inspect }
|
207
|
-
end
|
208
201
|
end
|
@@ -1,27 +1,16 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
2
|
|
3
3
|
class TestConditionsProtection < 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_protection
|
16
|
-
assert_raise(ArgumentError) { Account.
|
17
|
-
assert_nothing_raised { Account.
|
5
|
+
assert_raise(ArgumentError) { Account.new_search(:conditions => "(DELETE FROM users)") }
|
6
|
+
assert_nothing_raised { Account.new_search!(:conditions => "(DELETE FROM users)") }
|
18
7
|
|
19
8
|
account = Account.first
|
20
9
|
|
21
|
-
assert_raise(ArgumentError) { account.users.
|
22
|
-
assert_nothing_raised { account.users.
|
10
|
+
assert_raise(ArgumentError) { account.users.new_search(:conditions => "(DELETE FROM users)") }
|
11
|
+
assert_nothing_raised { account.users.new_search!(:conditions => "(DELETE FROM users)") }
|
23
12
|
|
24
|
-
|
25
|
-
|
13
|
+
search = Account.new_search
|
14
|
+
assert_raise(ArgumentError) { search.conditions = "(DELETE FROM users)" }
|
26
15
|
end
|
27
16
|
end
|
data/test/test_config.rb
CHANGED
@@ -1,17 +1,6 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
2
|
|
3
3
|
class TestConfig < 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_per_page
|
16
5
|
Searchgasm::Config.per_page = 1
|
17
6
|
|
@@ -31,4 +20,6 @@ class TestConfig < Test::Unit::TestCase
|
|
31
20
|
assert User.new_search.all.size > 1
|
32
21
|
assert User.new_search(:per_page => 1).all.size == 1
|
33
22
|
end
|
23
|
+
|
24
|
+
# test that config options do not mess up regular AR searches
|
34
25
|
end
|
data/test/test_helper.rb
CHANGED
@@ -14,11 +14,15 @@ class Account < ActiveRecord::Base
|
|
14
14
|
has_many :orders, :through => :users
|
15
15
|
end
|
16
16
|
|
17
|
+
class UserGroup < ActiveRecord::Base
|
18
|
+
has_and_belongs_to_many :users
|
19
|
+
end
|
20
|
+
|
17
21
|
class User < ActiveRecord::Base
|
18
22
|
acts_as_tree
|
19
23
|
belongs_to :account
|
20
24
|
has_many :orders, :dependent => :destroy
|
21
|
-
|
25
|
+
has_and_belongs_to_many :user_groups
|
22
26
|
end
|
23
27
|
|
24
28
|
class Order < ActiveRecord::Base
|
@@ -26,11 +30,6 @@ class Order < ActiveRecord::Base
|
|
26
30
|
end
|
27
31
|
|
28
32
|
class Test::Unit::TestCase
|
29
|
-
def self.fixtures(*fixtures)
|
30
|
-
@fixtures ||= []
|
31
|
-
@fixtures += [fixtures].flatten
|
32
|
-
end
|
33
|
-
|
34
33
|
def setup_db
|
35
34
|
ActiveRecord::Schema.define(:version => 1) do
|
36
35
|
create_table :accounts do |t|
|
@@ -40,6 +39,17 @@ class Test::Unit::TestCase
|
|
40
39
|
t.boolean :active
|
41
40
|
end
|
42
41
|
|
42
|
+
create_table :user_groups do |t|
|
43
|
+
t.datetime :created_at
|
44
|
+
t.datetime :updated_at
|
45
|
+
t.string :name
|
46
|
+
end
|
47
|
+
|
48
|
+
create_table :user_groups_users, :id => false do |t|
|
49
|
+
t.integer :user_group_id
|
50
|
+
t.integer :user_id
|
51
|
+
end
|
52
|
+
|
43
53
|
create_table :users do |t|
|
44
54
|
t.datetime :created_at
|
45
55
|
t.datetime :updated_at
|
@@ -63,7 +73,8 @@ class Test::Unit::TestCase
|
|
63
73
|
end
|
64
74
|
|
65
75
|
def load_fixtures
|
66
|
-
|
76
|
+
fixtures = [:accounts, :orders, :users, :user_groups]
|
77
|
+
fixtures.each do |fixture|
|
67
78
|
records = YAML.load(File.read(File.dirname(__FILE__) + "/fixtures/#{fixture.to_s}.yml"))
|
68
79
|
records.each do |name, attributes|
|
69
80
|
record = fixture.to_s.singularize.classify.constantize.new
|
@@ -71,6 +82,17 @@ class Test::Unit::TestCase
|
|
71
82
|
record.save!
|
72
83
|
end
|
73
84
|
end
|
85
|
+
|
86
|
+
# Not sure why I have to do this, but sick of dealing with it
|
87
|
+
UserGroup.all.each do |user_group|
|
88
|
+
user_ids = user_group.user_ids.uniq!
|
89
|
+
user_group.users.clear
|
90
|
+
user_group.user_ids = user_ids
|
91
|
+
user_group.save!
|
92
|
+
end
|
93
|
+
|
94
|
+
# Create the cached virtual classes
|
95
|
+
fixtures.each { |fixture| fixture.to_s.classify.constantize.new_search }
|
74
96
|
end
|
75
97
|
|
76
98
|
def teardown_db
|
@@ -78,4 +100,13 @@ class Test::Unit::TestCase
|
|
78
100
|
ActiveRecord::Base.connection.drop_table(table)
|
79
101
|
end
|
80
102
|
end
|
103
|
+
|
104
|
+
def setup
|
105
|
+
setup_db
|
106
|
+
load_fixtures
|
107
|
+
end
|
108
|
+
|
109
|
+
def teardown
|
110
|
+
teardown_db
|
111
|
+
end
|
81
112
|
end
|
data/test/test_search_base.rb
CHANGED
@@ -1,17 +1,6 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
2
|
|
3
3
|
class TestSearchBase < 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_needed
|
16
5
|
assert Searchgasm::Search::Base.needed?(Account, :page => 2, :conditions => {:name => "Ben"})
|
17
6
|
assert !Searchgasm::Search::Base.needed?(Account, :conditions => {:name => "Ben"})
|
@@ -109,20 +98,20 @@ class TestSearchBase < Test::Unit::TestCase
|
|
109
98
|
assert_equal search.lock, true
|
110
99
|
end
|
111
100
|
|
112
|
-
def
|
101
|
+
def test_auto_joins
|
113
102
|
search = Account.new_search
|
114
|
-
assert_equal nil, search.
|
103
|
+
assert_equal nil, search.auto_joins
|
115
104
|
search.conditions.name_contains = "Binary"
|
116
|
-
assert_equal nil, search.
|
105
|
+
assert_equal nil, search.auto_joins
|
117
106
|
search.conditions.users.first_name_contains = "Ben"
|
118
|
-
assert_equal(:users, search.
|
107
|
+
assert_equal(:users, search.auto_joins)
|
119
108
|
search.conditions.users.orders.id_gt = 2
|
120
|
-
assert_equal({:users => :orders}, search.
|
109
|
+
assert_equal({:users => :orders}, search.auto_joins)
|
121
110
|
search.conditions.users.reset_orders!
|
122
|
-
assert_equal(:users, search.
|
111
|
+
assert_equal(:users, search.auto_joins)
|
123
112
|
search.conditions.users.orders.id_gt = 2
|
124
113
|
search.conditions.reset_users!
|
125
|
-
assert_equal nil, search.
|
114
|
+
assert_equal nil, search.auto_joins
|
126
115
|
end
|
127
116
|
|
128
117
|
def test_limit
|
@@ -1,17 +1,6 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
2
|
|
3
3
|
class TestSearchConditions < 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_conditions
|
16
5
|
search = Account.new_search
|
17
6
|
assert_kind_of Searchgasm::Conditions::Base, search.conditions
|
@@ -19,9 +8,32 @@ class TestSearchConditions < Test::Unit::TestCase
|
|
19
8
|
|
20
9
|
search.conditions = {:name_like => "Binary"}
|
21
10
|
assert_kind_of Searchgasm::Conditions::Base, search.conditions
|
11
|
+
|
12
|
+
search = Account.new_search(:conditions => {:name_like => "Ben"})
|
13
|
+
assert_equal({:name_contains => "Ben"}, search.conditions.conditions)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_auto_joins
|
17
|
+
search = Account.new_search
|
18
|
+
search.conditions = {:name_like => "Binary"}
|
19
|
+
assert_equal nil, search.auto_joins
|
20
|
+
search.conditions.users.first_name_like = "Ben"
|
21
|
+
assert_equal :users, search.auto_joins
|
22
|
+
search.conditions.reset_users!
|
23
|
+
assert_equal nil, search.auto_joins
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_joins
|
27
|
+
search = Account.new_search
|
28
|
+
search.conditions = {:id_lte => 2, :users => {:first_name_like => "Ben"}}
|
29
|
+
assert_equal :users, search.joins
|
30
|
+
assert_equal [Account.find(1)], search.all
|
31
|
+
search.conditions.any = true
|
32
|
+
assert_equal " LEFT OUTER JOIN \"users\" ON users.account_id = accounts.id ", search.joins
|
33
|
+
assert_equal Account.find(1, 2), search.all
|
34
|
+
end
|
22
35
|
|
23
|
-
|
24
|
-
|
25
|
-
assert_equal conditions, search.conditions
|
36
|
+
def test_sanitize
|
37
|
+
# This is tested in test_search_base
|
26
38
|
end
|
27
39
|
end
|
@@ -1,17 +1,6 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
2
|
|
3
3
|
class TestSearchOrdering < 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_order_as
|
16
5
|
search = Account.new_search
|
17
6
|
assert_equal nil, search.order
|
@@ -1,17 +1,6 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
2
|
|
3
3
|
class TestSearchPagination < 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_limit
|
16
5
|
search = Account.new_search
|
17
6
|
search.limit = 10
|
@@ -1,17 +1,6 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
2
|
|
3
3
|
class TestSearchProtection < 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_protection
|
16
5
|
assert_raise(ArgumentError) { Account.build_search(:conditions => "(DELETE FROM users)", :page => 2, :per_page => 15) }
|
17
6
|
Searchgasm::Search::Base::VULNERABLE_FIND_OPTIONS.each { |option| assert_raise(ArgumentError) { Account.build_search(option => "(DELETE FROM users)") } }
|
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.
|
4
|
+
version: 1.2.0
|
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-
|
12
|
+
date: 2008-09-24 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -31,6 +31,9 @@ dependencies:
|
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: "0"
|
34
|
+
- - "="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 2.1.0
|
34
37
|
version:
|
35
38
|
- !ruby/object:Gem::Dependency
|
36
39
|
name: echoe
|
@@ -87,7 +90,7 @@ extra_rdoc_files:
|
|
87
90
|
- lib/searchgasm/search/ordering.rb
|
88
91
|
- lib/searchgasm/search/pagination.rb
|
89
92
|
- lib/searchgasm/search/protection.rb
|
90
|
-
- lib/searchgasm/
|
93
|
+
- lib/searchgasm/search/searching.rb
|
91
94
|
- lib/searchgasm/shared/utilities.rb
|
92
95
|
- lib/searchgasm/shared/virtual_classes.rb
|
93
96
|
- lib/searchgasm/version.rb
|
@@ -134,7 +137,7 @@ files:
|
|
134
137
|
- lib/searchgasm/search/ordering.rb
|
135
138
|
- lib/searchgasm/search/pagination.rb
|
136
139
|
- lib/searchgasm/search/protection.rb
|
137
|
-
- lib/searchgasm/
|
140
|
+
- lib/searchgasm/search/searching.rb
|
138
141
|
- lib/searchgasm/shared/utilities.rb
|
139
142
|
- lib/searchgasm/shared/virtual_classes.rb
|
140
143
|
- lib/searchgasm/version.rb
|
@@ -145,6 +148,7 @@ files:
|
|
145
148
|
- README.rdoc
|
146
149
|
- test/fixtures/accounts.yml
|
147
150
|
- test/fixtures/orders.yml
|
151
|
+
- test/fixtures/user_groups.yml
|
148
152
|
- test/fixtures/users.yml
|
149
153
|
- test/libs/acts_as_tree.rb
|
150
154
|
- test/libs/rexml_fix.rb
|
@@ -161,7 +165,6 @@ files:
|
|
161
165
|
- test/test_search_ordering.rb
|
162
166
|
- test/test_search_pagination.rb
|
163
167
|
- test/test_search_protection.rb
|
164
|
-
- test/text_config.rb
|
165
168
|
- searchgasm.gemspec
|
166
169
|
has_rdoc: true
|
167
170
|
homepage: http://github.com/binarylogic/searchgasm
|