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 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!</b>
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
- sudo gem install searchgasm
19
+ sudo gem install searchgasm
20
20
 
21
- For rails > 2.1
21
+ For rails
22
22
 
23
- # environment.rb
24
- config.gem "searchgasm"
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
- script/plugin install git://github.com/binarylogic/searchgasm.git
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
- # app/controllers/users_controller.rb
44
- def index
45
- @search = User.new_search(params[:search])
46
- @users, @users_count = @search.all, @search.count
47
- end
48
-
49
- Now your view. Notice you can use your search object <b>just like</b> an ActiveRecord object.
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
- # app/views/users/index.html.haml
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
- Nice and simple. 2 lines in your controller, no "cruft" in your models, pagination as simple as calling the "page" and "per_page" helpers, ordering as simple as calling "order_by", and all searching conditions in 1 spot: your form. For documentation on helpers see Searchgasm::Helpers::FormHelper and Searchgasm::Helpers::SearchHelper.
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
- <b>See this example live: http://searchgasm_example.binarylogic.com</b>
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
- User.all(
83
- :conditions => {
84
- :first_name_contains => "Ben", # first_name like '%Ben%'
85
- :email_ends_with => "binarylogic.com" # email like '%binarylogic.com'
86
- },
87
- :per_page => 20 # limit 20
88
- :page => 3 # offset 40, which starts us on page 3
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
- # Instantiate
96
- @search = User.new_search(
97
- :conditions => {
98
- :first_name_contains => "Ben",
99
- :age_gt => 18,
100
- :orders => {:total_lt => 100}
101
- },
102
- :per_page => 20,
103
- :page => 2,
104
- :order_by => {:orders => :total},
105
- :order_as => "DESC"
106
- )
107
-
108
- # Set local conditions
109
- @search.conditions.email_ends_with = "binarylogic.com"
110
-
111
- # Set conditions on relationships
112
- @search.conditions.oders.line_items.created_after = Time.now # can traverse through all relationships
113
-
114
- # Set options
115
- @search.per_page = 50 # overrides the 20 set above
116
- @search.order_by = [:first_name, {:user_group => :name}] # order by first name and then by the user group's name it belongs to
117
- @search.order_as = "ASC"
118
-
119
- # Set ANY of the ActiveRecord options
120
- @search.group = "last_name"
121
- @search.readonly = true
122
- # ... see ActiveRecord documentation
123
-
124
- # Return results just like ActiveRecord
125
- @search.all
126
- @search.first
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
- @search.average('id')
135
- @search.count
136
- @search.maximum('id')
137
- @search.minimum('id')
138
- @search.sum('id')
139
- @search.calculate(:sum, 'id')
140
- # ...any of the above calculations, see ActiveRecord documentation on calculations
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
- User.count(:conditions => {:first_name_contains => "Ben"})
145
- User.sum('id', :conditions => {:first_name_contains => "Ben"})
146
- # ... all other calcualtions, etc.
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
- User.all(:conditions => {:age_gt => 18}, :per_page => 20)
157
+ User.all(:conditions => {:age_gt => 18}, :per_page => 20)
153
158
 
154
- User.first(:conditions => {:age_gt => 18}, :per_page => 20)
159
+ User.first(:conditions => {:age_gt => 18}, :per_page => 20)
155
160
 
156
- User.find(:all, :conditions => {::age_gt => 18}, :per_page => 20)
161
+ User.find(:all, :conditions => {::age_gt => 18}, :per_page => 20)
157
162
 
158
- User.find(:first, :conditions => {::age_gt => 18}, :per_page => 20)
163
+ User.find(:first, :conditions => {::age_gt => 18}, :per_page => 20)
159
164
 
160
- search = User.new_search(:conditions => {:age_gt => 18}) # build_search is an alias
161
- search.conditions.first_name_contains = "Ben"
162
- search.per_page = 20
163
- search.all
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
- search = Searchgasm::Search::Base.new(User, :conditions => {:age_gt => 18})
168
- search.conditions.first_name_contains = "Ben"
169
- search.per_page = 20
170
- search.all
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
- conditions = User.new_conditions(:age_gt => 18)
175
- conditions.first_name_contains = "Ben"
176
- conditions.all
177
- # ... all operations above are available
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
- User.all(:conditions => conditions)
186
+ User.all(:conditions => conditions)
182
187
 
183
188
  Again, if you want to use Searchgasm directly:
184
189
 
185
- conditions = Searchgasm::Conditions::Base.new(User, :age_gt => 18)
186
- conditions.first_name_contains = "Ben"
187
- conditions.all
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
- @current_user.orders.find(:all, :conditions => {:total_lte => 500})
194
- @current_user.orders.count(:conditions => {:total_lte => 500})
195
- @current_user.orders.sum('total', :conditions => {:total_lte => 500})
196
-
197
- search = @current_user.orders.build_search('total', :conditions => {:total_lte => 500})
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
- # Child of
204
- User.all(:conditions => {:child_of => User.roots.first})
205
- User.all(:conditions => {:child_of => User.roots.first.id})
206
-
207
- # Sibling of
208
- User.all(:conditions => {:sibling_of => User.roots.first})
209
- User.all(:conditions => {:sibling_of => User.roots.first.id})
210
-
211
- # Descendant of (includes all recursive children: children, grand children, great grand children, etc)
212
- User.all(:conditions => {:descendant_of => User.roots.first})
213
- User.all(:conditions => {:descendant_of => User.roots.first.id})
214
-
215
- # Inclusive descendant_of. Same as above but includes the root
216
- User.all(:conditions => {:inclusive_descendant_of => User.roots.first})
217
- User.all(:conditions => {:inclusive_descendant_of => User.roots.first.id})
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
- class User < ActiveRecord::Base
225
- has_many :expensive_pending_orders, :conditions => {:total_greater_than => 1_000_000, :state => :pending}, :per_page => 20
226
- named_scope :sexy, :conditions => {:first_name => "Ben", email_ends_with => "binarylogic.com"}, :per_page => 20
227
- end
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
- search = Account.new_search(params[:search])
236
- conditions = Account.new_conditions(params[:conditions])
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
- accounts = Account.find(params[:search])
241
- accounts = Account.all(params[:search])
242
- account = Account.first(params[:search])
243
- search = Account.new_search!(params[:search])
244
- conditions = Account.new_conditions!(params[:conditions])
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
- all columns
253
- => :equals, :does_not_equal
257
+ all columns
258
+ => :equals, :does_not_equal
254
259
 
255
- :string, :text
256
- => :begins_with, :contains, :keywords, :ends_with
260
+ :string, :text
261
+ => :begins_with, :contains, :keywords, :ends_with
257
262
 
258
- :integer, :float, :decimal,:datetime, :timestamp, :time, :date
259
- => :greater_than, :greater_than_or_equal_to, :less_than, :less_than_or_equal_to
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
- tree data structures (see above "searching trees")
262
- => :child_of, :sibling_of, :descendant_of, :inclusive_descendant_of
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
- :equals; => :is
267
- :does_not_equal => :is_not, :not
268
- :begins_with => :starts_with, :bw, :start
269
- :contains => :like, :has
270
- :ends_with => :ew, :ends, :end
271
- :greater_than => :gt, :after
272
- :greater_than_or_equal_to => :at_least, :gte
273
- :keywords => :kwords, :kw
274
- :less_than => :lt, :before
275
- :less_than_or_equal_to => :at_most, :lte
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
- # config/initializers/searchgasm.rb
290
- # Actual function for MySQL databases only
291
- class SoundsLike < Searchgasm::Condition::Base
292
- class << self
293
- # I pass you the column, you tell me what you want the method to be called.
294
- # If you don't want to add this condition for that column, return nil
295
- # It defaults to "#{column.name}_sounds_like". So if thats what you want you don't even need to do this.
296
- def name_for_column(column)
297
- super
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
- Searchgasm::Conditions::Base.register_condition(SoundsLike)
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
- search = User.new_search
319
- search.conditions.first_name_sounds_like = "Ben"
320
- search.all # will return any user that has a first name that sounds like "Ben"
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
 
@@ -8,7 +8,7 @@ module Searchgasm
8
8
  end
9
9
 
10
10
  def aliases_for_column(column)
11
- ["#{column.name}_bw", "#{column.name}_starts_with", "#{column.name}_start"]
11
+ ["#{column.name}_bw", "#{column.name}_sw", "#{column.name}_starts_with", "#{column.name}_start"]
12
12
  end
13
13
  end
14
14
 
@@ -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
@@ -50,10 +50,11 @@ module Searchgasm #:nodoc:
50
50
  end
51
51
 
52
52
  def limit
53
- @limit ||= Config.per_page
53
+ @set_limit ? @limit : Config.per_page
54
54
  end
55
55
 
56
56
  def limit=(value)
57
+ @set_limit = true
57
58
  @limit = value.blank? || value == 0 ? nil : value.to_i
58
59
  end
59
60
 
@@ -67,7 +67,7 @@ module Searchgasm
67
67
 
68
68
  MAJOR = 0
69
69
  MINOR = 9
70
- TINY = 8
70
+ TINY = 9
71
71
 
72
72
  # The current version as a Version instance
73
73
  CURRENT = new(MAJOR, MINOR, TINY)
data/searchgasm.gemspec CHANGED
@@ -1,11 +1,11 @@
1
1
 
2
- # Gem::Specification for Searchgasm-0.9.8
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
8
+ version: 0.9.9
9
9
  platform: ruby
10
10
  authors:
11
11
  - Ben Johnson of Binary Logic
@@ -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, 50
54
- assert_equal search.page, 3
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, 2
58
- assert_equal search.limit, 2
59
- assert_equal search.page, 26
60
- assert_equal search.offset, 50
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
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.8
4
+ version: 0.9.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Johnson of Binary Logic