searchgasm 0.9.6 → 0.9.7

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 (66) hide show
  1. data/CHANGELOG +2 -0
  2. data/Manifest +34 -21
  3. data/{README.mdown → README.rdoc} +96 -63
  4. data/Rakefile +1 -1
  5. data/examples/README.rdoc +4 -0
  6. data/lib/searchgasm/active_record/associations.rb +40 -42
  7. data/lib/searchgasm/active_record/base.rb +75 -61
  8. data/lib/searchgasm/condition/base.rb +127 -0
  9. data/lib/searchgasm/condition/begins_with.rb +20 -0
  10. data/lib/searchgasm/condition/child_of.rb +11 -0
  11. data/lib/searchgasm/condition/contains.rb +20 -0
  12. data/lib/searchgasm/condition/descendant_of.rb +24 -0
  13. data/lib/searchgasm/condition/does_not_equal.rb +28 -0
  14. data/lib/searchgasm/condition/ends_with.rb +20 -0
  15. data/lib/searchgasm/condition/equals.rb +20 -0
  16. data/lib/searchgasm/condition/greater_than.rb +25 -0
  17. data/lib/searchgasm/condition/greater_than_or_equal_to.rb +20 -0
  18. data/lib/searchgasm/condition/inclusive_descendant_of.rb +13 -0
  19. data/lib/searchgasm/condition/keywords.rb +33 -0
  20. data/lib/searchgasm/condition/less_than.rb +25 -0
  21. data/lib/searchgasm/condition/less_than_or_equal_to.rb +20 -0
  22. data/lib/searchgasm/condition/sibling_of.rb +16 -0
  23. data/lib/searchgasm/condition/tree.rb +16 -0
  24. data/lib/searchgasm/conditions/base.rb +221 -0
  25. data/lib/searchgasm/conditions/protection.rb +30 -0
  26. data/lib/searchgasm/config.rb +137 -0
  27. data/lib/searchgasm/helpers/form_helper.rb +159 -0
  28. data/lib/searchgasm/helpers/search_helper.rb +178 -0
  29. data/lib/searchgasm/helpers/utilities_helper.rb +125 -0
  30. data/lib/searchgasm/search/base.rb +73 -179
  31. data/lib/searchgasm/search/conditions.rb +42 -166
  32. data/lib/searchgasm/search/ordering.rb +149 -0
  33. data/lib/searchgasm/search/pagination.rb +69 -0
  34. data/lib/searchgasm/search/protection.rb +61 -0
  35. data/lib/searchgasm/utilities.rb +30 -0
  36. data/lib/searchgasm/version.rb +44 -47
  37. data/lib/searchgasm.rb +57 -21
  38. data/searchgasm.gemspec +71 -46
  39. data/test/test_active_record_associations.rb +1 -1
  40. data/test/test_active_record_base.rb +4 -4
  41. data/test/test_condition.rb +143 -0
  42. data/test/{test_searchgasm_conditions.rb → test_conditions_base.rb} +43 -33
  43. data/test/test_search_base.rb +189 -0
  44. data/test/test_search_ordering.rb +91 -0
  45. data/test/test_search_pagination.rb +56 -0
  46. data/test/test_search_protection.rb +35 -0
  47. metadata +70 -45
  48. data/lib/searchgasm/search/condition.rb +0 -105
  49. data/lib/searchgasm/search/condition_types/begins_with_condition.rb +0 -26
  50. data/lib/searchgasm/search/condition_types/child_of_condition.rb +0 -17
  51. data/lib/searchgasm/search/condition_types/contains_condition.rb +0 -26
  52. data/lib/searchgasm/search/condition_types/descendant_of_condition.rb +0 -30
  53. data/lib/searchgasm/search/condition_types/does_not_equal_condition.rb +0 -34
  54. data/lib/searchgasm/search/condition_types/ends_with_condition.rb +0 -26
  55. data/lib/searchgasm/search/condition_types/equals_condition.rb +0 -26
  56. data/lib/searchgasm/search/condition_types/greater_than_condition.rb +0 -31
  57. data/lib/searchgasm/search/condition_types/greater_than_or_equal_to_condition.rb +0 -26
  58. data/lib/searchgasm/search/condition_types/inclusive_descendant_of_condition.rb +0 -19
  59. data/lib/searchgasm/search/condition_types/keywords_condition.rb +0 -39
  60. data/lib/searchgasm/search/condition_types/less_than_condition.rb +0 -31
  61. data/lib/searchgasm/search/condition_types/less_than_or_equal_to_condition.rb +0 -26
  62. data/lib/searchgasm/search/condition_types/sibling_of_condition.rb +0 -22
  63. data/lib/searchgasm/search/condition_types/tree_condition.rb +0 -20
  64. data/lib/searchgasm/search/utilities.rb +0 -34
  65. data/test/test_searchgasm_base.rb +0 -185
  66. data/test/test_searchgasm_condition_types.rb +0 -143
@@ -0,0 +1,189 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
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
+ def test_needed
16
+ assert Searchgasm::Search::Base.needed?(Account, :page => 2, :conditions => {:name => "Ben"})
17
+ assert !Searchgasm::Search::Base.needed?(Account, :conditions => {:name => "Ben"})
18
+ assert Searchgasm::Search::Base.needed?(Account, :limit => 2, :conditions => {:name_contains => "Ben"})
19
+ assert !Searchgasm::Search::Base.needed?(Account, :limit => 2)
20
+ assert Searchgasm::Search::Base.needed?(Account, :per_page => 2)
21
+ end
22
+
23
+ def test_initialize
24
+ assert_nothing_raised { Searchgasm::Search::Base.new(Account) }
25
+ search = Searchgasm::Search::Base.new(Account, :conditions => {:name_like => "binary"}, :page => 2, :limit => 10, :readonly => true)
26
+ assert_equal Account, search.klass
27
+ assert_equal "binary", search.conditions.name_like
28
+ assert_equal 2, search.page
29
+ assert_equal 10, search.limit
30
+ assert_equal true, search.readonly
31
+ end
32
+
33
+ def test_setting_first_level_options
34
+ search = Searchgasm::Search::Base.new(Account)
35
+
36
+ search.include = :users
37
+ assert_equal :users, search.include
38
+
39
+ search.joins = "test"
40
+ assert_equal "test", search.joins
41
+
42
+ search.page = 5
43
+ assert_equal 1, search.page # haven't set a limit yet
44
+ assert_equal nil, search.offset
45
+
46
+ search.limit = 20
47
+ assert_equal search.limit, 20
48
+ assert_equal search.per_page, 20
49
+ assert_equal search.page, 5
50
+ assert_equal search.offset, 80
51
+
52
+ search.offset = 50
53
+ assert_equal search.offset, 50
54
+ assert_equal search.page, 3
55
+
56
+ search.per_page = 2
57
+ assert_equal search.per_page, 2
58
+ assert_equal search.limit, 2
59
+ assert_equal search.page, 26
60
+ assert_equal search.offset, 50
61
+
62
+ search.order = "name ASC"
63
+ assert_equal search.order, "name ASC"
64
+
65
+ search.select = "name"
66
+ assert_equal search.select, "name"
67
+
68
+ search.readonly = true
69
+ assert_equal search.readonly, true
70
+
71
+ search.group = "name"
72
+ assert_equal search.group, "name"
73
+
74
+ search.from = "accounts"
75
+ assert_equal search.from, "accounts"
76
+
77
+ search.lock = true
78
+ assert_equal search.lock, true
79
+ end
80
+
81
+ def test_conditions
82
+ search = Searchgasm::Search::Base.new(Account)
83
+ assert_kind_of Searchgasm::Conditions::Base, search.conditions
84
+ assert_equal search.conditions.klass, Account
85
+
86
+ search.conditions = {:name_like => "Binary"}
87
+ assert_kind_of Searchgasm::Conditions::Base, search.conditions
88
+
89
+ conditions = Searchgasm::Conditions::Base.new(Account, :id_greater_than => 8)
90
+ search.conditions = conditions
91
+ assert_equal conditions, search.conditions
92
+ end
93
+
94
+ def test_include
95
+ search = Searchgasm::Search::Base.new(Account)
96
+ assert_equal nil, search.include
97
+ search.conditions.name_contains = "Binary"
98
+ assert_equal nil, search.include
99
+ search.conditions.users.first_name_contains = "Ben"
100
+ assert_equal(:users, search.include)
101
+ search.conditions.users.orders.id_gt = 2
102
+ assert_equal({:users => :orders}, search.include)
103
+ search.conditions.users.reset_orders!
104
+ assert_equal(:users, search.include)
105
+ search.conditions.users.orders.id_gt = 2
106
+ search.conditions.reset_users!
107
+ assert_equal nil, search.include
108
+ end
109
+
110
+ def test_limit
111
+ search = Searchgasm::Search::Base.new(Account)
112
+ search.limit = 10
113
+ assert_equal 10, search.limit
114
+ search.page = 2
115
+ assert_equal 10, search.offset
116
+ search.limit = 25
117
+ assert_equal 25, search.offset
118
+ assert_equal 2, search.page
119
+ search.page = 5
120
+ assert_equal 5, search.page
121
+ assert_equal 25, search.limit
122
+ search.limit = 3
123
+ assert_equal 12, search.offset
124
+ end
125
+
126
+ def test_options
127
+ end
128
+
129
+ def test_sanitize
130
+ search = Searchgasm::Search::Base.new(Account)
131
+ search.per_page = 2
132
+ search.conditions.name_like = "Binary"
133
+ search.conditions.users.id_greater_than = 2
134
+ search.page = 3
135
+ search.readonly = true
136
+ assert_equal({:include => :users, :offset => 4, :readonly => true, :conditions => ["(\"accounts\".\"name\" LIKE ?) AND (\"users\".\"id\" > ?)", "%Binary%", 2], :limit => 2 }, search.sanitize(:all))
137
+ assert_equal({:include => :users, :readonly => true, :conditions => ["(\"accounts\".\"name\" LIKE ?) AND (\"users\".\"id\" > ?)", "%Binary%", 2] }, search.sanitize(:count))
138
+ end
139
+
140
+ def test_scope
141
+ search = Searchgasm::Search::Base.new(Account)
142
+ search.conditions = "some scope"
143
+ assert_equal "some scope", search.conditions.scope
144
+ search.conditions = nil
145
+ assert_equal nil, search.conditions.scope
146
+ search.conditions = "some scope"
147
+ assert_equal "some scope", search.conditions.scope
148
+ search.conditions = "some scope2"
149
+ assert_equal "some scope2", search.conditions.scope
150
+ end
151
+
152
+ def test_searching
153
+ search = Searchgasm::Search::Base.new(Account)
154
+ search.conditions.name_like = "Binary"
155
+ assert_equal search.all, [Account.find(1), Account.find(3)]
156
+ assert_equal search.find(:all), [Account.find(1), Account.find(3)]
157
+ assert_equal search.first, Account.find(1)
158
+ assert_equal search.find(:first), Account.find(1)
159
+
160
+ search.per_page = 20
161
+ search.page = 2
162
+
163
+ assert_equal [], search.all
164
+ assert_equal [], search.find(:all)
165
+ assert_equal nil, search.first
166
+ assert_equal nil, search.find(:first)
167
+
168
+ search.per_page = 0
169
+ search.page = nil
170
+ search.conditions.users.first_name_contains = "Ben"
171
+ search.conditions.users.orders.description_keywords = "products, &*ap#ple $%^&*"
172
+ assert_equal [Account.find(1)], search.all
173
+ assert_equal [Account.find(1)], search.find(:all)
174
+ assert_equal Account.find(1), search.first
175
+ assert_equal Account.find(1), search.find(:first)
176
+ end
177
+
178
+ def test_calculations
179
+ search = Searchgasm::Search::Base.new(Account)
180
+ search.conditions.name_like = "Binary"
181
+ assert_equal 2, search.average('id')
182
+ assert_equal 2, search.calculate(:avg, 'id')
183
+ assert_equal 3, search.calculate(:max, 'id')
184
+ assert_equal 2, search.count
185
+ assert_equal 3, search.maximum('id')
186
+ assert_equal 1, search.minimum('id')
187
+ assert_equal 4, search.sum('id')
188
+ end
189
+ end
@@ -0,0 +1,91 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
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
+ def test_order_as
16
+ search = Searchgasm::Search::Base.new(Account)
17
+ assert_equal nil, search.order
18
+ assert_equal "ASC", search.order_as
19
+ assert search.asc?
20
+
21
+ search.order_as = "DESC"
22
+ assert_equal "DESC", search.order_as
23
+ assert search.desc?
24
+ assert_equal "\"accounts\".\"id\" DESC", search.order
25
+
26
+ search.order = "id ASC"
27
+ assert_equal "ASC", search.order_as
28
+ assert search.asc?
29
+ assert_equal "id ASC", search.order
30
+
31
+ search.order = "id DESC"
32
+ assert_equal "DESC", search.order_as
33
+ assert search.desc?
34
+ assert_equal "id DESC", search.order
35
+
36
+ search.order_by = "name"
37
+ assert_equal "DESC", search.order_as
38
+ assert search.desc?
39
+ assert_equal "\"accounts\".\"name\" DESC", search.order
40
+ end
41
+
42
+ def test_order_by
43
+ search = Searchgasm::Search::Base.new(Account)
44
+ assert_equal nil, search.order
45
+ assert_equal "id", search.order_by
46
+
47
+ search.order_by = "first_name"
48
+ assert_equal "first_name", search.order_by
49
+ assert_equal "\"accounts\".\"first_name\" ASC", search.order
50
+
51
+ search.order_by = "last_name"
52
+ assert_equal "last_name", search.order_by
53
+ assert_equal "\"accounts\".\"last_name\" ASC", search.order
54
+
55
+ search.order_by = ["first_name", "last_name"]
56
+ assert_equal ["first_name", "last_name"], search.order_by
57
+ assert_equal "\"accounts\".\"first_name\" ASC, \"accounts\".\"last_name\" ASC", search.order
58
+
59
+ search.order = "created_at DESC"
60
+ assert_equal "created_at", search.order_by
61
+ assert_equal "created_at DESC", search.order
62
+
63
+ search.order = "\"users\".updated_at ASC"
64
+ assert_equal({"users" => "updated_at"}, search.order_by)
65
+ assert_equal "\"users\".updated_at ASC", search.order
66
+
67
+ search.order = "`users`.first_name DESC"
68
+ assert_equal({"users" => "first_name"}, search.order_by)
69
+ assert_equal "`users`.first_name DESC", search.order
70
+
71
+ search.order = "`accounts`.name DESC"
72
+ assert_equal "name", search.order_by
73
+ assert_equal "`accounts`.name DESC", search.order
74
+
75
+ search.order = "accounts.name DESC"
76
+ assert_equal "name", search.order_by
77
+ assert_equal "accounts.name DESC", search.order
78
+
79
+ search.order = "`users`.first_name DESC, name DESC, `accounts`.id DESC"
80
+ assert_equal [{"users" => "first_name"}, "name", "id"], search.order_by
81
+ assert_equal "`users`.first_name DESC, name DESC, `accounts`.id DESC", search.order
82
+
83
+ search.order = "`users`.first_name DESC, `line_items`.id DESC, `accounts`.id DESC"
84
+ assert_equal [{"users" => "first_name"}, "id"], search.order_by
85
+ assert_equal "`users`.first_name DESC, `line_items`.id DESC, `accounts`.id DESC", search.order
86
+
87
+ search.order = "`line_items`.id DESC"
88
+ assert_equal nil, search.order_by
89
+ assert_equal "`line_items`.id DESC", search.order
90
+ end
91
+ end
@@ -0,0 +1,56 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
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
+ def test_limit
16
+ search = Searchgasm::Search::Base.new(Account)
17
+ search.limit = 10
18
+ assert_equal 10, search.limit
19
+ search.page = 2
20
+ assert_equal 10, search.offset
21
+ search.limit = 25
22
+ assert_equal 25, search.offset
23
+ assert_equal 2, search.page
24
+ search.page = 5
25
+ assert_equal 5, search.page
26
+ assert_equal 25, search.limit
27
+ search.limit = 3
28
+ assert_equal 12, search.offset
29
+ end
30
+
31
+ def test_page
32
+ search = Searchgasm::Search::Base.new(Account)
33
+ search.page = 2
34
+ assert_equal 1, search.page
35
+ search.per_page = 20
36
+ assert_equal 2, search.page
37
+ search.limit = 0
38
+ assert_equal 1, search.page
39
+ search.per_page = 20
40
+ assert_equal 2, search.page
41
+ search.limit = nil
42
+ assert_equal 1, search.page
43
+ end
44
+
45
+ def test_next_page
46
+
47
+ end
48
+
49
+ def test_prev_page
50
+
51
+ end
52
+
53
+ def test_page_count
54
+
55
+ end
56
+ end
@@ -0,0 +1,35 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
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
+ def test_protection
16
+ assert_raise(ArgumentError) { Account.build_search(:conditions => "(DELETE FROM users)", :page => 2, :per_page => 15) }
17
+ Searchgasm::Search::Base::VULNERABLE_OPTIONS.each { |option| assert_raise(ArgumentError) { Account.build_search(option => "(DELETE FROM users)") } }
18
+
19
+ assert_nothing_raised { Account.build_search!(:conditions => "(DELETE FROM users)", :page => 2, :per_page => 15) }
20
+ Searchgasm::Search::Base::VULNERABLE_OPTIONS.each { |option| assert_nothing_raised { Account.build_search!(option => "(DELETE FROM users)") } }
21
+
22
+ account = Account.first
23
+
24
+ assert_raise(ArgumentError) { account.users.build_search(:conditions => "(DELETE FROM users)", :page => 2, :per_page => 15) }
25
+ Searchgasm::Search::Base::VULNERABLE_OPTIONS.each { |option| assert_raise(ArgumentError) { account.users.build_search(option => "(DELETE FROM users)") } }
26
+
27
+ assert_nothing_raised { account.users.build_search!(:conditions => "(DELETE FROM users)", :page => 2, :per_page => 15) }
28
+ Searchgasm::Search::Base::VULNERABLE_OPTIONS.each { |option| assert_nothing_raised { account.users.build_search!(option => "(DELETE FROM users)") } }
29
+
30
+ assert_raise(ArgumentError) { Account.build_search(:order_by => "unknown_column") }
31
+ assert_nothing_raised { Account.build_search!(:order_by => "unknown_column") }
32
+ assert_raise(ArgumentError) { Account.build_search(:order_by => ["name", "unknown_column"]) }
33
+ assert_nothing_raised { Account.build_search!(:order_by => ["name", "unknown_column"]) }
34
+ end
35
+ end
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: 0.9.6
4
+ version: 0.9.7
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-03 00:00:00 -04:00
12
+ date: 2008-09-06 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -52,58 +52,77 @@ extra_rdoc_files:
52
52
  - CHANGELOG
53
53
  - lib/searchgasm/active_record/associations.rb
54
54
  - lib/searchgasm/active_record/base.rb
55
+ - lib/searchgasm/condition/base.rb
56
+ - lib/searchgasm/condition/begins_with.rb
57
+ - lib/searchgasm/condition/child_of.rb
58
+ - lib/searchgasm/condition/contains.rb
59
+ - lib/searchgasm/condition/descendant_of.rb
60
+ - lib/searchgasm/condition/does_not_equal.rb
61
+ - lib/searchgasm/condition/ends_with.rb
62
+ - lib/searchgasm/condition/equals.rb
63
+ - lib/searchgasm/condition/greater_than.rb
64
+ - lib/searchgasm/condition/greater_than_or_equal_to.rb
65
+ - lib/searchgasm/condition/inclusive_descendant_of.rb
66
+ - lib/searchgasm/condition/keywords.rb
67
+ - lib/searchgasm/condition/less_than.rb
68
+ - lib/searchgasm/condition/less_than_or_equal_to.rb
69
+ - lib/searchgasm/condition/sibling_of.rb
70
+ - lib/searchgasm/condition/tree.rb
71
+ - lib/searchgasm/conditions/base.rb
72
+ - lib/searchgasm/conditions/protection.rb
73
+ - lib/searchgasm/config.rb
74
+ - lib/searchgasm/helpers/form_helper.rb
75
+ - lib/searchgasm/helpers/search_helper.rb
76
+ - lib/searchgasm/helpers/utilities_helper.rb
55
77
  - lib/searchgasm/search/base.rb
56
- - lib/searchgasm/search/condition.rb
57
- - lib/searchgasm/search/condition_types/begins_with_condition.rb
58
- - lib/searchgasm/search/condition_types/child_of_condition.rb
59
- - lib/searchgasm/search/condition_types/contains_condition.rb
60
- - lib/searchgasm/search/condition_types/descendant_of_condition.rb
61
- - lib/searchgasm/search/condition_types/does_not_equal_condition.rb
62
- - lib/searchgasm/search/condition_types/ends_with_condition.rb
63
- - lib/searchgasm/search/condition_types/equals_condition.rb
64
- - lib/searchgasm/search/condition_types/greater_than_condition.rb
65
- - lib/searchgasm/search/condition_types/greater_than_or_equal_to_condition.rb
66
- - lib/searchgasm/search/condition_types/inclusive_descendant_of_condition.rb
67
- - lib/searchgasm/search/condition_types/keywords_condition.rb
68
- - lib/searchgasm/search/condition_types/less_than_condition.rb
69
- - lib/searchgasm/search/condition_types/less_than_or_equal_to_condition.rb
70
- - lib/searchgasm/search/condition_types/sibling_of_condition.rb
71
- - lib/searchgasm/search/condition_types/tree_condition.rb
72
78
  - lib/searchgasm/search/conditions.rb
73
- - lib/searchgasm/search/utilities.rb
79
+ - lib/searchgasm/search/ordering.rb
80
+ - lib/searchgasm/search/pagination.rb
81
+ - lib/searchgasm/search/protection.rb
82
+ - lib/searchgasm/utilities.rb
74
83
  - lib/searchgasm/version.rb
75
84
  - lib/searchgasm.rb
76
- - README.mdown
85
+ - README.rdoc
77
86
  files:
78
87
  - CHANGELOG
88
+ - examples/README.rdoc
79
89
  - init.rb
80
90
  - lib/searchgasm/active_record/associations.rb
81
91
  - lib/searchgasm/active_record/base.rb
92
+ - lib/searchgasm/condition/base.rb
93
+ - lib/searchgasm/condition/begins_with.rb
94
+ - lib/searchgasm/condition/child_of.rb
95
+ - lib/searchgasm/condition/contains.rb
96
+ - lib/searchgasm/condition/descendant_of.rb
97
+ - lib/searchgasm/condition/does_not_equal.rb
98
+ - lib/searchgasm/condition/ends_with.rb
99
+ - lib/searchgasm/condition/equals.rb
100
+ - lib/searchgasm/condition/greater_than.rb
101
+ - lib/searchgasm/condition/greater_than_or_equal_to.rb
102
+ - lib/searchgasm/condition/inclusive_descendant_of.rb
103
+ - lib/searchgasm/condition/keywords.rb
104
+ - lib/searchgasm/condition/less_than.rb
105
+ - lib/searchgasm/condition/less_than_or_equal_to.rb
106
+ - lib/searchgasm/condition/sibling_of.rb
107
+ - lib/searchgasm/condition/tree.rb
108
+ - lib/searchgasm/conditions/base.rb
109
+ - lib/searchgasm/conditions/protection.rb
110
+ - lib/searchgasm/config.rb
111
+ - lib/searchgasm/helpers/form_helper.rb
112
+ - lib/searchgasm/helpers/search_helper.rb
113
+ - lib/searchgasm/helpers/utilities_helper.rb
82
114
  - lib/searchgasm/search/base.rb
83
- - lib/searchgasm/search/condition.rb
84
- - lib/searchgasm/search/condition_types/begins_with_condition.rb
85
- - lib/searchgasm/search/condition_types/child_of_condition.rb
86
- - lib/searchgasm/search/condition_types/contains_condition.rb
87
- - lib/searchgasm/search/condition_types/descendant_of_condition.rb
88
- - lib/searchgasm/search/condition_types/does_not_equal_condition.rb
89
- - lib/searchgasm/search/condition_types/ends_with_condition.rb
90
- - lib/searchgasm/search/condition_types/equals_condition.rb
91
- - lib/searchgasm/search/condition_types/greater_than_condition.rb
92
- - lib/searchgasm/search/condition_types/greater_than_or_equal_to_condition.rb
93
- - lib/searchgasm/search/condition_types/inclusive_descendant_of_condition.rb
94
- - lib/searchgasm/search/condition_types/keywords_condition.rb
95
- - lib/searchgasm/search/condition_types/less_than_condition.rb
96
- - lib/searchgasm/search/condition_types/less_than_or_equal_to_condition.rb
97
- - lib/searchgasm/search/condition_types/sibling_of_condition.rb
98
- - lib/searchgasm/search/condition_types/tree_condition.rb
99
115
  - lib/searchgasm/search/conditions.rb
100
- - lib/searchgasm/search/utilities.rb
116
+ - lib/searchgasm/search/ordering.rb
117
+ - lib/searchgasm/search/pagination.rb
118
+ - lib/searchgasm/search/protection.rb
119
+ - lib/searchgasm/utilities.rb
101
120
  - lib/searchgasm/version.rb
102
121
  - lib/searchgasm.rb
103
122
  - Manifest
104
123
  - MIT-LICENSE
105
124
  - Rakefile
106
- - README.mdown
125
+ - README.rdoc
107
126
  - test/fixtures/accounts.yml
108
127
  - test/fixtures/orders.yml
109
128
  - test/fixtures/users.yml
@@ -111,10 +130,13 @@ files:
111
130
  - test/libs/rexml_fix.rb
112
131
  - test/test_active_record_associations.rb
113
132
  - test/test_active_record_base.rb
133
+ - test/test_condition.rb
134
+ - test/test_conditions_base.rb
114
135
  - test/test_helper.rb
115
- - test/test_searchgasm_base.rb
116
- - test/test_searchgasm_condition_types.rb
117
- - test/test_searchgasm_conditions.rb
136
+ - test/test_search_base.rb
137
+ - test/test_search_ordering.rb
138
+ - test/test_search_pagination.rb
139
+ - test/test_search_protection.rb
118
140
  - searchgasm.gemspec
119
141
  has_rdoc: true
120
142
  homepage: http://github.com/binarylogic/searchgasm
@@ -125,7 +147,7 @@ rdoc_options:
125
147
  - --title
126
148
  - Searchgasm
127
149
  - --main
128
- - README.mdown
150
+ - README.rdoc
129
151
  require_paths:
130
152
  - lib
131
153
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -150,7 +172,10 @@ summary: Orgasmic ActiveRecord searching
150
172
  test_files:
151
173
  - test/test_active_record_associations.rb
152
174
  - test/test_active_record_base.rb
175
+ - test/test_condition.rb
176
+ - test/test_conditions_base.rb
153
177
  - test/test_helper.rb
154
- - test/test_searchgasm_base.rb
155
- - test/test_searchgasm_condition_types.rb
156
- - test/test_searchgasm_conditions.rb
178
+ - test/test_search_base.rb
179
+ - test/test_search_ordering.rb
180
+ - test/test_search_pagination.rb
181
+ - test/test_search_protection.rb
@@ -1,105 +0,0 @@
1
- module BinaryLogic
2
- module Searchgasm
3
- module Search
4
- class Condition
5
- include Utilities
6
-
7
- attr_accessor :column, :klass
8
- attr_reader :value
9
-
10
- class << self
11
- def condition_name
12
- name.split("::").last.scan(/(.*)Condition/)[0][0].underscore
13
- end
14
-
15
- def name_for_column(column)
16
- "#{column.name}_#{condition_name}"
17
- end
18
-
19
- def aliases_for_column(column)
20
- []
21
- end
22
-
23
- def name_for_klass(klass)
24
- nil
25
- end
26
-
27
- def aliases_for_klass(klass)
28
- []
29
- end
30
-
31
- def string_column?(column)
32
- [:string, :text].include?(column.type)
33
- end
34
-
35
- def comparable_column?(column)
36
- [:integer, :float, :decimal, :datetime, :timestamp, :time, :date].include?(column.type)
37
- end
38
- end
39
-
40
- def initialize(klass, column = nil)
41
- self.klass = klass
42
- self.column = column.is_a?(String) ? klass.columns_hash[column] : column
43
- end
44
-
45
- def explicitly_set_value=(value)
46
- @explicitly_set_value = value
47
- end
48
-
49
- # Need this if someone wants to actually use nil in a meaningful way
50
- def explicitly_set_value?
51
- @explicitly_set_value == true
52
- end
53
-
54
- def ignore_blanks?
55
- true
56
- end
57
-
58
- def name
59
- column ? self.class.name_for_column(column) : self.class.name_for_klass(klass)
60
- end
61
-
62
- def condition_name
63
- self.class.condition_name
64
- end
65
-
66
- def quote_column_name(column_name)
67
- klass.connection.quote_column_name(column_name)
68
- end
69
-
70
- def quoted_column_name
71
- quote_column_name(column.name)
72
- end
73
-
74
- def quote_table_name(table_name)
75
- klass.connection.quote_table_name(table_name)
76
- end
77
-
78
- def quoted_table_name
79
- quote_table_name(klass.table_name)
80
- end
81
-
82
- def sanitize(alt_value = nil)
83
- return unless explicitly_set_value?
84
- v = alt_value || value
85
- if v.is_a?(Array) && !["equals", "does_not_equal"].include?(condition_name)
86
- merge_conditions(*v.collect { |i| sanitize(i) })
87
- else
88
- v = v.utc if column && [:time, :timestamp, :datetime].include?(column.type) && klass.time_zone_aware_attributes && !klass.skip_time_zone_conversion_for_attributes.include?(column.name.to_sym)
89
- to_conditions(v)
90
- end
91
- end
92
-
93
- def value
94
- @value.is_a?(String) ? column.type_cast(@value) : @value
95
- end
96
-
97
- def value=(v)
98
- return if ignore_blanks? && v.blank?
99
- self.explicitly_set_value = true
100
- @value = v
101
- end
102
- end
103
- end
104
- end
105
- end
@@ -1,26 +0,0 @@
1
- module BinaryLogic
2
- module Searchgasm
3
- module Search
4
- module ConditionTypes
5
- class BeginsWithCondition < Condition
6
- class << self
7
- def name_for_column(column)
8
- return unless string_column?(column)
9
- super
10
- end
11
-
12
- def aliases_for_column(column)
13
- ["#{column.name}_bw", "#{column.name}_starts_with", "#{column.name}_start"]
14
- end
15
- end
16
-
17
- def to_conditions(value)
18
- ["#{quoted_table_name}.#{quoted_column_name} LIKE ?", "#{value}%"]
19
- end
20
- end
21
- end
22
-
23
- Conditions.register_condition(ConditionTypes::BeginsWithCondition)
24
- end
25
- end
26
- end
@@ -1,17 +0,0 @@
1
- module BinaryLogic
2
- module Searchgasm
3
- module Search
4
- module ConditionTypes
5
- class ChildOfCondition < TreeCondition
6
- def to_conditions(value)
7
- parent_association = klass.reflect_on_association(:parent)
8
- foreign_key_name = (parent_association && parent_association.options[:foreign_key]) || "parent_id"
9
- ["#{quoted_table_name}.#{quote_column_name(foreign_key_name)} = ?", (value.is_a?(klass) ? value.send(klass.primary_key) : value)]
10
- end
11
- end
12
- end
13
-
14
- Conditions.register_condition(ConditionTypes::ChildOfCondition)
15
- end
16
- end
17
- end