searchgasm 0.9.8 → 0.9.9
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2 -0
- data/README.rdoc +196 -191
- data/lib/searchgasm/condition/begins_with.rb +1 -1
- data/lib/searchgasm/helpers/form_helper.rb +1 -1
- data/lib/searchgasm/search/base.rb +2 -1
- data/lib/searchgasm/version.rb +1 -1
- data/searchgasm.gemspec +2 -2
- data/test/test_search_base.rb +17 -6
- data/test/test_search_pagination.rb +16 -0
- metadata +1 -1
data/CHANGELOG
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
v0.9.9. Fixed setting per_page to nil, false, or ''. This is done to "show all" results.
|
2
|
+
|
1
3
|
v0.9.8. Fixed order_by helper bug when determing the text with arrays. Should use the first value instead of last. Added in per_page config option.
|
2
4
|
|
3
5
|
v0.9.7. Complete class restructure, much more organized, added in documentation, added in helpers for using searchgasm in a rails app, updated readme with link to documentation as well as a live example, some bug fixes, more tests
|
data/README.rdoc
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Searchgasm is orgasmic. Maybe not orgasmic, but you will get aroused. So go grab a towel and let's dive in.
|
4
4
|
|
5
|
-
<b>Searchgasm's inspiration comes right from ActiveRecord. ActiveRecord lets you create objects that represent a record in the database, so why can't you create objects that represent searching the database? Now you can
|
5
|
+
<b>Searchgasm's inspiration comes right from ActiveRecord. ActiveRecord lets you create objects that represent a record in the database, so why can't you create objects that represent searching the database? Now you can! It's searching, ordering, and pagination all in one.</b>
|
6
6
|
|
7
7
|
== Under the hood
|
8
8
|
|
@@ -16,21 +16,16 @@ I'm a big fan of understanding what I'm using, so here's a quick explanation: Th
|
|
16
16
|
|
17
17
|
== Install and use
|
18
18
|
|
19
|
-
|
19
|
+
sudo gem install searchgasm
|
20
20
|
|
21
|
-
For rails
|
21
|
+
For rails
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
For rails < 2.1
|
27
|
-
|
28
|
-
# environment.rb
|
29
|
-
require "searchgasm"
|
23
|
+
$ cd vendor/plugins
|
24
|
+
$ sudo gem unpack searchgasm
|
30
25
|
|
31
26
|
Or as a plugin
|
32
27
|
|
33
|
-
|
28
|
+
script/plugin install git://github.com/binarylogic/searchgasm.git
|
34
29
|
|
35
30
|
Now try out some of the examples below:
|
36
31
|
|
@@ -40,90 +35,100 @@ Now try out some of the examples below:
|
|
40
35
|
|
41
36
|
Using Searchgasm in rails is the best part, because rails has all kinds of nifty methods to make dealing with ActiveRecord objects quick and easy, especially with forms. So let's take advantage of them! That's the idea behind this plugin. Searchgasm is searching, ordering, and pagination all rolled into one simple plugin. Take all of that pagination and searching cruft out of your models and let Searchgasm handle it. Check it out:
|
42
37
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
Now your view.
|
38
|
+
# app/controllers/users_controller.rb
|
39
|
+
def index
|
40
|
+
@search = User.new_search(params[:search])
|
41
|
+
@users, @users_count = @search.all, @search.count
|
42
|
+
end
|
43
|
+
|
44
|
+
Now your view. Things to note in this view:
|
45
|
+
|
46
|
+
1. Passing a search object right into form\_for and fields\_for
|
47
|
+
2. The built in conditions for each column and how you can traverse the relationships and set conditions on them
|
48
|
+
3. The order_by helper
|
49
|
+
4. The page and per_page helpers
|
50
|
+
5. All of your search logic is in 1 spot: your view. Nice and DRY.
|
51
|
+
|
52
|
+
Your view:
|
53
|
+
|
54
|
+
# app/views/users/index.html.haml
|
55
|
+
- form_for @search do |f|
|
56
|
+
- f.fields_for @search.conditions do |users|
|
57
|
+
= users.text_field :first_name_contains
|
58
|
+
= users.calendar_date_select :created_after # nice rails plugin for replacing date_select
|
59
|
+
- users.fields_for users.object.orders do |orders|
|
60
|
+
= orders.select :total_gt, (1..100)
|
61
|
+
= f.submit "Search"
|
62
|
+
|
63
|
+
%table
|
64
|
+
%tr
|
65
|
+
%th= order_by :first_name
|
66
|
+
%th= order_by :last_name
|
67
|
+
%th= order_by :email
|
68
|
+
- @users.each do |user|
|
69
|
+
%tr
|
70
|
+
%td= user.first_name
|
71
|
+
%td= user.last_name
|
72
|
+
%td= user.email
|
73
|
+
|
74
|
+
Per page:
|
75
|
+
= per_page
|
76
|
+
Page:
|
77
|
+
= pages
|
50
78
|
|
51
|
-
|
52
|
-
- form_for @search do |f|
|
53
|
-
- f.fields_for @search.conditions do |users|
|
54
|
-
= users.text_field :first_name_contains
|
55
|
-
= users.calendar_date_select :created_after # nice rails plugin for replacing date_select
|
56
|
-
- users.fields_for users.object.orders do |orders|
|
57
|
-
= orders.select :total_gt, (1..100)
|
58
|
-
= f.submit "Search"
|
59
|
-
|
60
|
-
%table
|
61
|
-
%tr
|
62
|
-
%th= order_by :first_name
|
63
|
-
%th= order_by :last_name
|
64
|
-
%th= order_by :email
|
65
|
-
- @users.each do |user|
|
66
|
-
%tr
|
67
|
-
%td= user.first_name
|
68
|
-
%td= user.last_name
|
69
|
-
%td= user.email
|
70
|
-
|
71
|
-
Per page:
|
72
|
-
= per_page
|
73
|
-
Page:
|
74
|
-
= page
|
79
|
+
<b>See this example live: http://searchgasm_example.binarylogic.com</b>
|
75
80
|
|
76
|
-
|
81
|
+
You're probably saying, this is great, but I want to do all of this via AJAX. No problem. Check out the {live tutorial}(http://searchgasm_example.binarylogic.com/orders) based on this example, there is a link for an {AJAX example}(http://searchgasm_example.binarylogic.com/orders).
|
77
82
|
|
78
|
-
|
83
|
+
This is really just the tip of the iceberg. See below for more examples or {check out the documentation}[http://searchgasm.rubyforge.org] for options and explanations.
|
79
84
|
|
80
85
|
== Simple Searching Example
|
81
86
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
87
|
+
User.all(
|
88
|
+
:conditions => {
|
89
|
+
:first_name_contains => "Ben", # first_name like '%Ben%'
|
90
|
+
:email_ends_with => "binarylogic.com" # email like '%binarylogic.com'
|
91
|
+
},
|
92
|
+
:per_page => 20 # limit 20
|
93
|
+
:page => 3 # offset 40, which starts us on page 3
|
94
|
+
)
|
90
95
|
|
91
96
|
Instead of using the "all" method you could use any search method: first, find(:all), find(:first), count, sum, average, etc, just like ActiveRecord
|
92
97
|
|
93
98
|
== Exhaustive Example w/ Object Based Searching (great for form_for or fields_for)
|
94
99
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
100
|
+
# Instantiate
|
101
|
+
@search = User.new_search(
|
102
|
+
:conditions => {
|
103
|
+
:first_name_contains => "Ben",
|
104
|
+
:age_gt => 18,
|
105
|
+
:orders => {:total_lt => 100}
|
106
|
+
},
|
107
|
+
:per_page => 20,
|
108
|
+
:page => 2,
|
109
|
+
:order_by => {:orders => :total},
|
110
|
+
:order_as => "DESC"
|
111
|
+
)
|
112
|
+
|
113
|
+
# Set local conditions
|
114
|
+
@search.conditions.email_ends_with = "binarylogic.com"
|
115
|
+
|
116
|
+
# Set conditions on relationships
|
117
|
+
@search.conditions.oders.line_items.created_after = Time.now # can traverse through all relationships
|
118
|
+
|
119
|
+
# Set options
|
120
|
+
@search.per_page = 50 # overrides the 20 set above
|
121
|
+
@search.order_by = [:first_name, {:user_group => :name}] # order by first name and then by the user group's name it belongs to
|
122
|
+
@search.order_as = "ASC"
|
123
|
+
|
124
|
+
# Set ANY of the ActiveRecord options
|
125
|
+
@search.group = "last_name"
|
126
|
+
@search.readonly = true
|
127
|
+
# ... see ActiveRecord documentation
|
128
|
+
|
129
|
+
# Return results just like ActiveRecord
|
130
|
+
@search.all
|
131
|
+
@search.first
|
127
132
|
|
128
133
|
Take the @search object and pass it right into form\_for or fields\_for (see above).
|
129
134
|
|
@@ -131,100 +136,100 @@ Take the @search object and pass it right into form\_for or fields\_for (see abo
|
|
131
136
|
|
132
137
|
Using the object from above:
|
133
138
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
139
|
+
@search.average('id')
|
140
|
+
@search.count
|
141
|
+
@search.maximum('id')
|
142
|
+
@search.minimum('id')
|
143
|
+
@search.sum('id')
|
144
|
+
@search.calculate(:sum, 'id')
|
145
|
+
# ...any of the above calculations, see ActiveRecord documentation on calculations
|
141
146
|
|
142
147
|
Or do it from your model:
|
143
148
|
|
144
|
-
|
145
|
-
|
146
|
-
|
149
|
+
User.count(:conditions => {:first_name_contains => "Ben"})
|
150
|
+
User.sum('id', :conditions => {:first_name_contains => "Ben"})
|
151
|
+
# ... all other calcualtions, etc.
|
147
152
|
|
148
153
|
== Different ways to search, take your pick
|
149
154
|
|
150
155
|
Any of the options used in the above example can be used in these, but for the sake of brevity I am only using a few:
|
151
156
|
|
152
|
-
|
157
|
+
User.all(:conditions => {:age_gt => 18}, :per_page => 20)
|
153
158
|
|
154
|
-
|
159
|
+
User.first(:conditions => {:age_gt => 18}, :per_page => 20)
|
155
160
|
|
156
|
-
|
161
|
+
User.find(:all, :conditions => {::age_gt => 18}, :per_page => 20)
|
157
162
|
|
158
|
-
|
163
|
+
User.find(:first, :conditions => {::age_gt => 18}, :per_page => 20)
|
159
164
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
165
|
+
search = User.new_search(:conditions => {:age_gt => 18}) # build_search is an alias
|
166
|
+
search.conditions.first_name_contains = "Ben"
|
167
|
+
search.per_page = 20
|
168
|
+
search.all
|
164
169
|
|
165
170
|
If you want to use Searchgasm directly:
|
166
171
|
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
172
|
+
search = Searchgasm::Search::Base.new(User, :conditions => {:age_gt => 18})
|
173
|
+
search.conditions.first_name_contains = "Ben"
|
174
|
+
search.per_page = 20
|
175
|
+
search.all
|
171
176
|
|
172
177
|
== Search with conditions only
|
173
178
|
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
179
|
+
conditions = User.new_conditions(:age_gt => 18)
|
180
|
+
conditions.first_name_contains = "Ben"
|
181
|
+
conditions.all
|
182
|
+
# ... all operations above are available
|
178
183
|
|
179
184
|
Pass a conditions object right into ActiveRecord:
|
180
185
|
|
181
|
-
|
186
|
+
User.all(:conditions => conditions)
|
182
187
|
|
183
188
|
Again, if you want to use Searchgasm directly:
|
184
189
|
|
185
|
-
|
186
|
-
|
187
|
-
|
190
|
+
conditions = Searchgasm::Conditions::Base.new(User, :age_gt => 18)
|
191
|
+
conditions.first_name_contains = "Ben"
|
192
|
+
conditions.all
|
188
193
|
|
189
194
|
Now pass the conditions object right into form\_for or fields\_for (see above for example).
|
190
195
|
|
191
196
|
== Scoped searching
|
192
197
|
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
+
@current_user.orders.find(:all, :conditions => {:total_lte => 500})
|
199
|
+
@current_user.orders.count(:conditions => {:total_lte => 500})
|
200
|
+
@current_user.orders.sum('total', :conditions => {:total_lte => 500})
|
201
|
+
|
202
|
+
search = @current_user.orders.build_search('total', :conditions => {:total_lte => 500})
|
198
203
|
|
199
204
|
== Searching trees
|
200
205
|
|
201
206
|
For tree data structures you get a few nifty methods. Let's assume Users is a tree data structure.
|
202
207
|
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
208
|
+
# Child of
|
209
|
+
User.all(:conditions => {:child_of => User.roots.first})
|
210
|
+
User.all(:conditions => {:child_of => User.roots.first.id})
|
211
|
+
|
212
|
+
# Sibling of
|
213
|
+
User.all(:conditions => {:sibling_of => User.roots.first})
|
214
|
+
User.all(:conditions => {:sibling_of => User.roots.first.id})
|
215
|
+
|
216
|
+
# Descendant of (includes all recursive children: children, grand children, great grand children, etc)
|
217
|
+
User.all(:conditions => {:descendant_of => User.roots.first})
|
218
|
+
User.all(:conditions => {:descendant_of => User.roots.first.id})
|
219
|
+
|
220
|
+
# Inclusive descendant_of. Same as above but includes the root
|
221
|
+
User.all(:conditions => {:inclusive_descendant_of => User.roots.first})
|
222
|
+
User.all(:conditions => {:inclusive_descendant_of => User.roots.first.id})
|
223
|
+
|
219
224
|
|
220
225
|
== Available anywhere (relationships & scopes)
|
221
226
|
|
222
227
|
Not only can you use searchgasm when searching, but you can use it when setting up relationships or scopes. Anywhere you specify conditions in ActiveRecord.
|
223
228
|
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
229
|
+
class User < ActiveRecord::Base
|
230
|
+
has_many :expensive_pending_orders, :conditions => {:total_greater_than => 1_000_000, :state => :pending}, :per_page => 20
|
231
|
+
named_scope :sexy, :conditions => {:first_name => "Ben", email_ends_with => "binarylogic.com"}, :per_page => 20
|
232
|
+
end
|
228
233
|
|
229
234
|
== Always use protection...against SQL injections
|
230
235
|
|
@@ -232,16 +237,16 @@ If there is one thing we all know, it's to always use protection against SQL inj
|
|
232
237
|
|
233
238
|
=== Protected from SQL injections
|
234
239
|
|
235
|
-
|
236
|
-
|
240
|
+
search = Account.new_search(params[:search])
|
241
|
+
conditions = Account.new_conditions(params[:conditions])
|
237
242
|
|
238
243
|
=== *NOT* protected from SQL injections
|
239
244
|
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
+
accounts = Account.find(params[:search])
|
246
|
+
accounts = Account.all(params[:search])
|
247
|
+
account = Account.first(params[:search])
|
248
|
+
search = Account.new_search!(params[:search])
|
249
|
+
conditions = Account.new_conditions!(params[:conditions])
|
245
250
|
|
246
251
|
Lesson learned: use new\_search and new\_conditions when passing in params as *ANY* of the options.
|
247
252
|
|
@@ -249,30 +254,30 @@ Lesson learned: use new\_search and new\_conditions when passing in params as *A
|
|
249
254
|
|
250
255
|
Depending on the type, each column comes preloaded with a bunch of nifty conditions:
|
251
256
|
|
252
|
-
|
253
|
-
|
257
|
+
all columns
|
258
|
+
=> :equals, :does_not_equal
|
254
259
|
|
255
|
-
|
256
|
-
|
260
|
+
:string, :text
|
261
|
+
=> :begins_with, :contains, :keywords, :ends_with
|
257
262
|
|
258
|
-
|
259
|
-
|
263
|
+
:integer, :float, :decimal,:datetime, :timestamp, :time, :date
|
264
|
+
=> :greater_than, :greater_than_or_equal_to, :less_than, :less_than_or_equal_to
|
260
265
|
|
261
|
-
|
262
|
-
|
266
|
+
tree data structures (see above "searching trees")
|
267
|
+
=> :child_of, :sibling_of, :descendant_of, :inclusive_descendant_of
|
263
268
|
|
264
269
|
Some of these conditions come with aliases, so you have your choice how to call the conditions. For example you can use "greater\_than" or "gt":
|
265
270
|
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
271
|
+
:equals => :is
|
272
|
+
:does_not_equal => :is_not, :not
|
273
|
+
:begins_with => :starts_with, :bw, :start
|
274
|
+
:contains => :like, :has
|
275
|
+
:ends_with => :ew, :ends, :end
|
276
|
+
:greater_than => :gt, :after
|
277
|
+
:greater_than_or_equal_to => :at_least, :gte
|
278
|
+
:keywords => :kwords, :kw
|
279
|
+
:less_than => :lt, :before
|
280
|
+
:less_than_or_equal_to => :at_most, :lte
|
276
281
|
|
277
282
|
For more information on each condition see Searchgasm::Condition. Each condition has it's own class and the source is pretty simple and self explanatory.
|
278
283
|
|
@@ -286,38 +291,38 @@ I didn't include this function because its MySQL specific, and it's probably rar
|
|
286
291
|
|
287
292
|
I want to use it, so let's add it:
|
288
293
|
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
end
|
299
|
-
|
300
|
-
# Only do this if you want aliases for your condition
|
301
|
-
def aliases_for_column(column)
|
302
|
-
["#{column.name}_sounds", "#{column.name}_similar_to"]
|
303
|
-
end
|
304
|
-
end
|
305
|
-
|
306
|
-
# You can return an array or a string. NOT a hash, because all of these conditions
|
307
|
-
# need to eventually get merged together. The array or string can be anything you would put in
|
308
|
-
# the :conditions option for ActiveRecord::Base.find()
|
309
|
-
def to_conditions(value)
|
310
|
-
["#{quoted_table_name}.#{quoted_column_name} SOUNDS LIKE ?", value]
|
311
|
-
end
|
294
|
+
# config/initializers/searchgasm.rb
|
295
|
+
# Actual function for MySQL databases only
|
296
|
+
class SoundsLike < Searchgasm::Condition::Base
|
297
|
+
class << self
|
298
|
+
# I pass you the column, you tell me what you want the method to be called.
|
299
|
+
# If you don't want to add this condition for that column, return nil
|
300
|
+
# It defaults to "#{column.name}_sounds_like". So if thats what you want you don't even need to do this.
|
301
|
+
def name_for_column(column)
|
302
|
+
super
|
312
303
|
end
|
313
304
|
|
314
|
-
|
305
|
+
# Only do this if you want aliases for your condition
|
306
|
+
def aliases_for_column(column)
|
307
|
+
["#{column.name}_sounds", "#{column.name}_similar_to"]
|
308
|
+
end
|
309
|
+
end
|
310
|
+
|
311
|
+
# You can return an array or a string. NOT a hash, because all of these conditions
|
312
|
+
# need to eventually get merged together. The array or string can be anything you would put in
|
313
|
+
# the :conditions option for ActiveRecord::Base.find()
|
314
|
+
def to_conditions(value)
|
315
|
+
["#{quoted_table_name}.#{quoted_column_name} SOUNDS LIKE ?", value]
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
319
|
+
Searchgasm::Conditions::Base.register_condition(SoundsLike)
|
315
320
|
|
316
321
|
Now test it out:
|
317
322
|
|
318
|
-
|
319
|
-
|
320
|
-
|
323
|
+
search = User.new_search
|
324
|
+
search.conditions.first_name_sounds_like = "Ben"
|
325
|
+
search.all # will return any user that has a first name that sounds like "Ben"
|
321
326
|
|
322
327
|
Pretty nifty, huh? You can create any condition ultimately creating any SQL you want. The sky is the limit. For more information see Searchgasm::Condition::Base
|
323
328
|
|
@@ -84,7 +84,7 @@ module Searchgasm
|
|
84
84
|
return unless search_object.is_a?(Search::Base)
|
85
85
|
name = args.first
|
86
86
|
options = args.extract_options!
|
87
|
-
(options.delete(:hidden_fields) || Config.hidden_fields).each do |option|
|
87
|
+
[(options.delete(:hidden_fields) || Config.hidden_fields)].flatten.each do |option|
|
88
88
|
concat(hidden_field(name, option, :object => search_object, :value => (option == :order_by ? searchgasm_order_by_value(search_object.order_by) : search_object.send(option))))
|
89
89
|
end
|
90
90
|
args << options
|
data/lib/searchgasm/version.rb
CHANGED
data/searchgasm.gemspec
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
|
2
|
-
# Gem::Specification for Searchgasm-0.9.
|
2
|
+
# Gem::Specification for Searchgasm-0.9.9
|
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: 0.9.
|
8
|
+
version: 0.9.9
|
9
9
|
platform: ruby
|
10
10
|
authors:
|
11
11
|
- Ben Johnson of Binary Logic
|
data/test/test_search_base.rb
CHANGED
@@ -48,16 +48,27 @@ class TestSearchBase < Test::Unit::TestCase
|
|
48
48
|
assert_equal search.per_page, 20
|
49
49
|
assert_equal search.page, 5
|
50
50
|
assert_equal search.offset, 80
|
51
|
+
search.limit = nil
|
52
|
+
assert_equal nil, search.limit
|
53
|
+
assert_equal nil, search.per_page
|
54
|
+
assert_equal 1, search.page
|
55
|
+
assert_equal nil, search.offset
|
51
56
|
|
52
57
|
search.offset = 50
|
53
|
-
assert_equal search.offset
|
54
|
-
assert_equal search.page
|
58
|
+
assert_equal 50, search.offset
|
59
|
+
assert_equal 1, search.page
|
60
|
+
search.limit = 50
|
61
|
+
assert_equal 2, search.page
|
62
|
+
search.offset = nil
|
63
|
+
assert_equal 0, search.offset
|
64
|
+
assert_equal 1, search.page
|
55
65
|
|
56
66
|
search.per_page = 2
|
57
|
-
assert_equal search.per_page
|
58
|
-
assert_equal search.limit
|
59
|
-
|
60
|
-
assert_equal search.
|
67
|
+
assert_equal 2, search.per_page
|
68
|
+
assert_equal 2, search.limit
|
69
|
+
search.offset = 50
|
70
|
+
assert_equal 26, search.page
|
71
|
+
assert_equal 50, search.offset
|
61
72
|
|
62
73
|
search.order = "name ASC"
|
63
74
|
assert_equal search.order, "name ASC"
|
@@ -42,6 +42,22 @@ class TestSearchPagination < Test::Unit::TestCase
|
|
42
42
|
assert_equal 1, search.page
|
43
43
|
end
|
44
44
|
|
45
|
+
def test_per_page
|
46
|
+
search = Searchgasm::Search::Base.new(Account)
|
47
|
+
search.per_page = 10
|
48
|
+
assert_equal 10, search.per_page
|
49
|
+
search.per_page = ""
|
50
|
+
assert_equal nil, search.per_page
|
51
|
+
search.per_page = 40
|
52
|
+
assert_equal 40, search.per_page
|
53
|
+
search.per_page = nil
|
54
|
+
assert_equal nil, search.per_page
|
55
|
+
search.per_page = 60
|
56
|
+
assert_equal 60, search.per_page
|
57
|
+
search.per_page = false
|
58
|
+
assert_equal nil, search.per_page
|
59
|
+
end
|
60
|
+
|
45
61
|
def test_next_page
|
46
62
|
|
47
63
|
end
|