Skip to content
Browse files

Updated searchgasm

  • Loading branch information...
1 parent 5622daa commit 6a50ab0c7635372e66865610f742acb68d8a3e76 @binarylogic committed Sep 8, 2008
Showing with 235 additions and 134 deletions.
  1. +2 −2 config/environments/development.rb
  2. +3 −1 vendor/plugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/CHANGELOG
  3. 0 vendor/plugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/MIT-LICENSE
  4. +5 −1 vendor/plugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/Manifest
  5. +47 −38 vendor/plugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/README.rdoc
  6. 0 vendor/plugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/Rakefile
  7. 0 vendor/plugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/examples/README.rdoc
  8. 0 vendor/plugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/init.rb
  9. +1 −1 vendor/plugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/lib/searchgasm.rb
  10. 0 vendor/plugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/lib/searchgasm/active_record/associations.rb
  11. 0 vendor/plugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/lib/searchgasm/active_record/base.rb
  12. 0 vendor/plugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/lib/searchgasm/condition/base.rb
  13. 0 vendor/plugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/lib/searchgasm/condition/begins_with.rb
  14. 0 vendor/plugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/lib/searchgasm/condition/child_of.rb
  15. 0 vendor/plugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/lib/searchgasm/condition/contains.rb
  16. 0 vendor/plugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/lib/searchgasm/condition/descendant_of.rb
  17. 0 vendor/plugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/lib/searchgasm/condition/does_not_equal.rb
  18. 0 vendor/plugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/lib/searchgasm/condition/ends_with.rb
  19. 0 vendor/plugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/lib/searchgasm/condition/equals.rb
  20. 0 vendor/plugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/lib/searchgasm/condition/greater_than.rb
  21. 0 ...ugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/lib/searchgasm/condition/greater_than_or_equal_to.rb
  22. 0 ...lugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/lib/searchgasm/condition/inclusive_descendant_of.rb
  23. 0 vendor/plugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/lib/searchgasm/condition/keywords.rb
  24. 0 vendor/plugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/lib/searchgasm/condition/less_than.rb
  25. 0 .../plugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/lib/searchgasm/condition/less_than_or_equal_to.rb
  26. 0 vendor/plugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/lib/searchgasm/condition/sibling_of.rb
  27. 0 vendor/plugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/lib/searchgasm/condition/tree.rb
  28. 0 vendor/plugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/lib/searchgasm/conditions/base.rb
  29. 0 vendor/plugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/lib/searchgasm/conditions/protection.rb
  30. +15 −1 vendor/plugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/lib/searchgasm/config.rb
  31. 0 vendor/plugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/lib/searchgasm/helpers/form_helper.rb
  32. +16 −2 vendor/plugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/lib/searchgasm/helpers/search_helper.rb
  33. 0 vendor/plugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/lib/searchgasm/helpers/utilities_helper.rb
  34. +0 −5 vendor/plugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/lib/searchgasm/search/base.rb
  35. 0 vendor/plugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/lib/searchgasm/search/conditions.rb
  36. 0 vendor/plugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/lib/searchgasm/search/ordering.rb
  37. +4 −4 vendor/plugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/lib/searchgasm/search/pagination.rb
  38. +13 −0 vendor/plugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/lib/searchgasm/search/protection.rb
  39. 0 vendor/plugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/lib/searchgasm/utilities.rb
  40. +1 −1 vendor/plugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/lib/searchgasm/version.rb
  41. +12 −5 vendor/plugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/searchgasm.gemspec
  42. 0 vendor/plugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/test/fixtures/accounts.yml
  43. 0 vendor/plugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/test/fixtures/orders.yml
  44. 0 vendor/plugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/test/fixtures/users.yml
  45. 0 vendor/plugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/test/libs/acts_as_tree.rb
  46. 0 vendor/plugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/test/libs/rexml_fix.rb
  47. 0 vendor/plugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/test/test_active_record_associations.rb
  48. +1 −1 vendor/plugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/test/test_active_record_base.rb
  49. +61 −0 vendor/plugins/searchgasm-0.9.10/test/test_condition_base.rb
  50. +1 −48 ...lugins/{searchgasm-0.9.9/test/test_condition.rb → searchgasm-0.9.10/test/test_condition_types.rb}
  51. +0 −10 vendor/plugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/test/test_conditions_base.rb
  52. +24 −0 vendor/plugins/searchgasm-0.9.10/test/test_conditions_protection.rb
  53. 0 vendor/plugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/test/test_helper.rb
  54. +1 −14 vendor/plugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/test/test_search_base.rb
  55. +27 −0 vendor/plugins/searchgasm-0.9.10/test/test_search_conditions.rb
  56. 0 vendor/plugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/test/test_search_ordering.rb
  57. 0 vendor/plugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/test/test_search_pagination.rb
  58. 0 vendor/plugins/{searchgasm-0.9.9 → searchgasm-0.9.10}/test/test_search_protection.rb
  59. +1 −0 vendor/plugins/searchgasm-0.9.10/test/text_config.rb
View
4 config/environments/development.rb
@@ -16,5 +16,5 @@
# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = false
-config.plugin_paths += ["../../Ruby Libs"]
-config.plugins = ["calendar_date_select", "searchgasm-0.9.9"]
+#config.plugin_paths += ["../../Ruby Libs"]
+#config.plugins = ["calendar_date_select", "searchgasm-0.9.9"]
View
4 vendor/plugins/searchgasm-0.9.9/CHANGELOG → vendor/plugins/searchgasm-0.9.10/CHANGELOG
@@ -1,10 +1,12 @@
+v0.9.10. Hardened more tests, fixed bug with setting the per_page configuration to only take effect on protected searches, thus staying out of the way of normal searching.
+
v0.9.9. Fixed setting per_page to nil, false, or ''. This is done to "show all" results.
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.
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
-v0.9.6. Fix bug when instantiating with nil options
+v0.9.6. Fixed bug when instantiating with nil options
v0.9.5. Enhanced searching with conditions only. Updated read me to include example on adding your own conditions.
View
0 vendor/plugins/searchgasm-0.9.9/MIT-LICENSE → vendor/plugins/searchgasm-0.9.10/MIT-LICENSE
File renamed without changes.
View
6 vendor/plugins/searchgasm-0.9.9/Manifest → vendor/plugins/searchgasm-0.9.10/Manifest
@@ -44,10 +44,14 @@ test/libs/acts_as_tree.rb
test/libs/rexml_fix.rb
test/test_active_record_associations.rb
test/test_active_record_base.rb
-test/test_condition.rb
+test/test_condition_base.rb
+test/test_condition_types.rb
test/test_conditions_base.rb
+test/test_conditions_protection.rb
test/test_helper.rb
test/test_search_base.rb
+test/test_search_conditions.rb
test/test_search_ordering.rb
test/test_search_pagination.rb
test/test_search_protection.rb
+test/text_config.rb
View
85 vendor/plugins/searchgasm-0.9.9/README.rdoc → vendor/plugins/searchgasm-0.9.10/README.rdoc
@@ -4,11 +4,7 @@ Searchgasm is orgasmic. Maybe not orgasmic, but you will get aroused. So go grab
<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>
-== Under the hood
-
-I'm a big fan of understanding what I'm using, so here's a quick explanation: The design behind this plugin is pretty simple. The search object "sanitizes" down into the options passed into ActiveRecord::Base.find(). It serves as a transparent filter between you and ActiveRecord::Base.find(). This filter provides "enhancements" that get translated into options that ActiveRecord::Base.find() can understand. It doesn't dig into the ActiveRecord internals, it only uses what is publicly available. It jumps in and helps out <em>only</em> when needed, otherwise it sits back and lets ActiveRecord do all of the work. Between that and the extensive tests, this is a solid and fast plugin.
-
-== Quicklinks
+== Helpful links
* <b>Documentation:</b> http://searchgasm.rubyforge.org
* <b>Easy pagination, ordering, and searching tutorial:</b> http://www.binarylogic.com/2008/9/7/tutorial-pagination-ordering-and-searching-with-searchgasm
@@ -31,7 +27,33 @@ Now try out some of the examples below:
<b>For all examples, let's assume the following relationships: User => Orders => Line Items</b>
-== The beauty of searchgasm
+== Simple Searching Example
+
+ User.all(
+ :conditions => {
+ :first_name_contains => "Ben", # first_name like '%Ben%'
+ :email_ends_with => "binarylogic.com" # email like '%binarylogic.com'
+ },
+ :per_page => 20, # limit 20
+ :page => 3, # offset 40, which starts us on page 3
+ :order_as => "ASC",
+ :order_by => {:user_group => :name} # order user_groups.name ASC
+ )
+
+same as above, but object based
+
+ search = User.new_search
+ search.conditions.first_name_contains = "Ben"
+ search.conditions.email_ends_with = "binarylogic.com"
+ search.per_page = 20
+ search.page = 3
+ search.order_as = "ASC"
+ search.order_by = {:user_group => :name}
+ search.all
+
+In both examples, instead of using the "all" method you could use any search method: first, find(:all), find(:first), count, sum, average, etc, just like ActiveRecord.
+
+== The beauty of searchgasm, integration into rails
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:
@@ -76,28 +98,11 @@ Your view:
Page:
= pages
-<b>See this example live: http://searchgasm_example.binarylogic.com</b>
-
-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).
-
-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.
-
-== Simple Searching Example
-
- User.all(
- :conditions => {
- :first_name_contains => "Ben", # first_name like '%Ben%'
- :email_ends_with => "binarylogic.com" # email like '%binarylogic.com'
- },
- :per_page => 20 # limit 20
- :page => 3 # offset 40, which starts us on page 3
- )
-
-Instead of using the "all" method you could use any search method: first, find(:all), find(:first), count, sum, average, etc, just like ActiveRecord
+<b>{See my tutorial on this example}(http://www.binarylogic.com/2008/9/7/tutorial-pagination-ordering-and-searching-with-searchgasm)</b>
== Exhaustive Example w/ Object Based Searching (great for form_for or fields_for)
- # Instantiate
+ # Start a new search
@search = User.new_search(
:conditions => {
:first_name_contains => "Ben",
@@ -158,9 +163,9 @@ Any of the options used in the above example can be used in these, but for the s
User.first(:conditions => {:age_gt => 18}, :per_page => 20)
- User.find(:all, :conditions => {::age_gt => 18}, :per_page => 20)
+ User.find(:all, :conditions => {:age_gt => 18}, :per_page => 20)
- User.find(:first, :conditions => {::age_gt => 18}, :per_page => 20)
+ User.find(:first, :conditions => {:age_gt => 18}, :per_page => 20)
search = User.new_search(:conditions => {:age_gt => 18}) # build_search is an alias
search.conditions.first_name_contains = "Ben"
@@ -176,6 +181,8 @@ If you want to use Searchgasm directly:
== Search with conditions only
+Don't need pagination, ordering, or any of the other options? Search with conditions only.
+
conditions = User.new_conditions(:age_gt => 18)
conditions.first_name_contains = "Ben"
conditions.all
@@ -191,8 +198,6 @@ Again, if you want to use Searchgasm directly:
conditions.first_name_contains = "Ben"
conditions.all
-Now pass the conditions object right into form\_for or fields\_for (see above for example).
-
== Scoped searching
@current_user.orders.find(:all, :conditions => {:total_lte => 500})
@@ -268,16 +273,16 @@ Depending on the type, each column comes preloaded with a bunch of nifty conditi
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":
- :equals => :is
- :does_not_equal => :is_not, :not
- :begins_with => :starts_with, :bw, :start
- :contains => :like, :has
- :ends_with => :ew, :ends, :end
- :greater_than => :gt, :after
+ :equals => :is
+ :does_not_equal => :is_not, :not
+ :begins_with => :starts_with, :sw, :bw, :start
+ :contains => :like, :has
+ :ends_with => :ew, :ends, :end
+ :greater_than => :gt, :after
:greater_than_or_equal_to => :at_least, :gte
- :keywords => :kwords, :kw
- :less_than => :lt, :before
- :less_than_or_equal_to => :at_most, :lte
+ :keywords => :kwords, :kw
+ :less_than => :lt, :before
+ :less_than_or_equal_to => :at_most, :lte
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.
@@ -326,6 +331,10 @@ Now test it out:
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
+== Under the hood
+
+I'm a big fan of understanding what I'm using, so here's a quick explanation: The design behind this plugin is pretty simple. The search object "sanitizes" down into the options passed into ActiveRecord::Base.find(). It serves as a transparent filter between you and ActiveRecord::Base.find(). This filter provides "enhancements" that get translated into options that ActiveRecord::Base.find() can understand. It doesn't dig into the ActiveRecord internals, it only uses what is publicly available. It jumps in and helps out <em>only</em> when needed, otherwise it sits back and lets ActiveRecord do all of the work. Between that and the extensive tests, this is a solid and fast plugin.
+
== Reporting problems / bugs
http://binarylogic.lighthouseapp.com/projects/16601-searchgasm
View
0 vendor/plugins/searchgasm-0.9.9/Rakefile → vendor/plugins/searchgasm-0.9.10/Rakefile
File renamed without changes.
View
0 ...ins/searchgasm-0.9.9/examples/README.rdoc → ...ns/searchgasm-0.9.10/examples/README.rdoc
File renamed without changes.
View
0 vendor/plugins/searchgasm-0.9.9/init.rb → vendor/plugins/searchgasm-0.9.10/init.rb
File renamed without changes.
View
2 ...lugins/searchgasm-0.9.9/lib/searchgasm.rb → ...ugins/searchgasm-0.9.10/lib/searchgasm.rb
@@ -50,8 +50,8 @@ module Search
class Base
include Conditions
include Ordering
- include Pagination
include Protection
+ include Pagination
end
end
View
0 .../searchgasm/active_record/associations.rb → .../searchgasm/active_record/associations.rb
File renamed without changes.
View
0 ....9.9/lib/searchgasm/active_record/base.rb → ...9.10/lib/searchgasm/active_record/base.rb
File renamed without changes.
View
0 ...sm-0.9.9/lib/searchgasm/condition/base.rb → ...m-0.9.10/lib/searchgasm/condition/base.rb
File renamed without changes.
View
0 ...9/lib/searchgasm/condition/begins_with.rb → ...0/lib/searchgasm/condition/begins_with.rb
File renamed without changes.
View
0 ....9.9/lib/searchgasm/condition/child_of.rb → ...9.10/lib/searchgasm/condition/child_of.rb
File renamed without changes.
View
0 ....9.9/lib/searchgasm/condition/contains.rb → ...9.10/lib/searchgasm/condition/contains.rb
File renamed without changes.
View
0 ...lib/searchgasm/condition/descendant_of.rb → ...lib/searchgasm/condition/descendant_of.rb
File renamed without changes.
View
0 ...ib/searchgasm/condition/does_not_equal.rb → ...ib/searchgasm/condition/does_not_equal.rb
File renamed without changes.
View
0 ...9.9/lib/searchgasm/condition/ends_with.rb → ....10/lib/searchgasm/condition/ends_with.rb
File renamed without changes.
View
0 ...-0.9.9/lib/searchgasm/condition/equals.rb → ...0.9.10/lib/searchgasm/condition/equals.rb
File renamed without changes.
View
0 .../lib/searchgasm/condition/greater_than.rb → .../lib/searchgasm/condition/greater_than.rb
File renamed without changes.
View
0 ...asm/condition/greater_than_or_equal_to.rb → ...asm/condition/greater_than_or_equal_to.rb
File renamed without changes.
View
0 ...gasm/condition/inclusive_descendant_of.rb → ...gasm/condition/inclusive_descendant_of.rb
File renamed without changes.
View
0 ....9.9/lib/searchgasm/condition/keywords.rb → ...9.10/lib/searchgasm/condition/keywords.rb
File renamed without changes.
View
0 ...9.9/lib/searchgasm/condition/less_than.rb → ....10/lib/searchgasm/condition/less_than.rb
File renamed without changes.
View
0 ...chgasm/condition/less_than_or_equal_to.rb → ...chgasm/condition/less_than_or_equal_to.rb
File renamed without changes.
View
0 ....9/lib/searchgasm/condition/sibling_of.rb → ...10/lib/searchgasm/condition/sibling_of.rb
File renamed without changes.
View
0 ...sm-0.9.9/lib/searchgasm/condition/tree.rb → ...m-0.9.10/lib/searchgasm/condition/tree.rb
File renamed without changes.
View
0 ...m-0.9.9/lib/searchgasm/conditions/base.rb → ...-0.9.10/lib/searchgasm/conditions/base.rb
File renamed without changes.
View
0 ...9/lib/searchgasm/conditions/protection.rb → ...0/lib/searchgasm/conditions/protection.rb
File renamed without changes.
View
16 ...searchgasm-0.9.9/lib/searchgasm/config.rb → ...earchgasm-0.9.10/lib/searchgasm/config.rb
@@ -43,6 +43,19 @@ def desc_indicator=(value)
@desc_indicator = value
end
+ def pages_text # :nodoc:
+ @set_pages_text ? @pages_text : "Page %p"
+ end
+
+ # The default value for the :text options in the pages helper.
+ #
+ # * <tt>Default:</tt> "Page %p"
+ # * <tt>Accepts:</tt> "Your string %p": where %p is replaced by the page number, or a block: Proc.new { |p| "Page #{p}" }
+ def pages_text=(value)
+ @set_pages_text = true
+ @pages_text
+ end
+
def pages_type # :nodoc:
@pages_type ||= :select
end
@@ -59,7 +72,8 @@ def per_page # :nodoc:
@per_page
end
- # The default for per page.
+ # The default for per page. This is only applicaple for protected searches. Meaning you start the search with new_search or new_conditions.
+ # The reason for this not to disturb regular queries such as Whatever.find(:all). You would not expect that to be limited.
#
# * <tt>Default:</tt> nil, nil means "show all"
# * <tt>Accepts:</tt> Any value in your per_page choices
View
0 ...9.9/lib/searchgasm/helpers/form_helper.rb → ....10/lib/searchgasm/helpers/form_helper.rb
File renamed without changes.
View
18 ...9/lib/searchgasm/helpers/search_helper.rb → ...0/lib/searchgasm/helpers/search_helper.rb
@@ -73,6 +73,7 @@ def order_by(column_name, options = {}, &block)
# === Options
# * <tt>:type</tt> -- default: :select, pass :links as an alternative to have flickr like pagination
# * <tt>:remote</tt> -- default: false, if true requests will be AJAX
+ # * <tt>:text</tt> -- default: "1", "2", etc, if you want to change the text to say "Page 1", "Page 2", etc. Set this to: "Page %p". I will replace %p with the page #. Or pass a block and I will pass you the page number: Proc.new { |p| "Page #{p}" }
#
# === Advanced Options
# * <tt>:action</tt> -- this is automatically determined for you based on the type. For a :select type, its :onchange. For a :links type, its :onclick. You shouldn't have to use this option unless you are doing something out of the norm. The point of this option is to return a URL that will include this.value or not
@@ -85,6 +86,19 @@ def pages(options = {})
add_searchgasm_helper_defaults!(options, :page)
return "" if options[:search_obj].page_count <= 1
+ page_range = (1..options[:search_obj].page_count)
+ options[:text] = Config.pages_text unless options.has_key?(:text)
+
+ choices = nil
+ case options[:text]
+ when String
+ choices = page_range.collect { |p| [options[:text].gsub(/%p/, p.to_s), p] }
+ when Proc
+ choices = page_range.collect { |p| [yield(p), p] }
+ else
+ choices = page_range
+ end
+
if block_given?
yield options
else
@@ -94,7 +108,7 @@ def pages(options = {})
options[:html][options[:action]] ||= ""
options[:html][options[:action]] += ";"
options[:html][options[:action]] += options[:url]
- select(:search, :page, (1..options[:search_obj].page_count), {}, options[:html])
+ select(options[:params_scope], :page, choices, {:selected => options[:search_obj].page}, options[:html])
else
# HTML for links
end
@@ -153,7 +167,7 @@ def per_page(options = {})
options[:html][options[:action]] ||= ""
options[:html][options[:action]] += ";"
options[:html][options[:action]] += options[:url]
- select(:search, :per_page, options[:choices], {}, options[:html])
+ select(options[:params_scope], :per_page, options[:choices], {:selected => options[:search_obj].per_page}, options[:html])
end
end
end
View
0 ...ib/searchgasm/helpers/utilities_helper.rb → ...ib/searchgasm/helpers/utilities_helper.rb
File renamed without changes.
View
5 ...hgasm-0.9.9/lib/searchgasm/search/base.rb → ...gasm-0.9.10/lib/searchgasm/search/base.rb
@@ -49,12 +49,7 @@ def inspect
"#<#{klass} #{options_as_nice_string}>"
end
- def limit
- @set_limit ? @limit : Config.per_page
- end
-
def limit=(value)
- @set_limit = true
@limit = value.blank? || value == 0 ? nil : value.to_i
end
View
0 ...0.9.9/lib/searchgasm/search/conditions.rb → ....9.10/lib/searchgasm/search/conditions.rb
File renamed without changes.
View
0 ...m-0.9.9/lib/searchgasm/search/ordering.rb → ...-0.9.10/lib/searchgasm/search/ordering.rb
File renamed without changes.
View
8 ...0.9.9/lib/searchgasm/search/pagination.rb → ....9.10/lib/searchgasm/search/pagination.rb
@@ -11,15 +11,15 @@ def self.included(klass)
end
def limit_with_pagination=(value)
- self.limit_without_pagination = value
+ r_value = self.limit_without_pagination = value
self.page = @page unless @page.nil? # retry page now that the limit has changed
- limit
+ r_value
end
def offset_with_pagination=(value)
- self.offset_without_pagination = value
+ r_value = self.offset_without_pagination = value
@page = nil
- offset
+ r_value
end
def page
View
13 ...0.9.9/lib/searchgasm/search/protection.rb → ....9.10/lib/searchgasm/search/protection.rb
@@ -10,10 +10,22 @@ module Protection
def self.included(klass)
klass.class_eval do
attr_reader :protect
+ alias_method_chain :limit, :protection
+ alias_method_chain :limit=, :protection
alias_method_chain :options=, :protection
end
end
+ def limit_with_protection
+ return Config.per_page if protected? && !@set_limit
+ limit_without_protection
+ end
+
+ def limit_with_protection=(value)
+ @set_limit = true
+ self.limit_without_protection = value
+ end
+
def options_with_protection=(values)
return unless values.is_a?(Hash)
self.protect = values.delete(:protect) if values.has_key?(:protect) # make sure we do this first
@@ -29,6 +41,7 @@ def protect=(value)
def protect?
protect == true
end
+ alias_method :protected?, :protect?
private
def order_by_safe?(order_by, alt_klass = nil)
View
0 ...rchgasm-0.9.9/lib/searchgasm/utilities.rb → ...chgasm-0.9.10/lib/searchgasm/utilities.rb
File renamed without changes.
View
2 ...earchgasm-0.9.9/lib/searchgasm/version.rb → ...archgasm-0.9.10/lib/searchgasm/version.rb
@@ -67,7 +67,7 @@ def to_a
MAJOR = 0
MINOR = 9
- TINY = 9
+ TINY = 10
# The current version as a Version instance
CURRENT = new(MAJOR, MINOR, TINY)
View
17 ...ugins/searchgasm-0.9.9/searchgasm.gemspec → ...gins/searchgasm-0.9.10/searchgasm.gemspec
@@ -1,18 +1,18 @@
-# Gem::Specification for Searchgasm-0.9.9
+# Gem::Specification for Searchgasm-0.9.10
# Originally generated by Echoe
--- !ruby/object:Gem::Specification
name: searchgasm
version: !ruby/object:Gem::Version
- version: 0.9.9
+ version: 0.9.10
platform: ruby
authors:
- Ben Johnson of Binary Logic
autorequire:
bindir: bin
-date: 2008-09-07 00:00:00 -04:00
+date: 2008-09-08 00:00:00 -04:00
default_executable:
dependencies:
- !ruby/object:Gem::Dependency
@@ -133,13 +133,17 @@ files:
- test/libs/rexml_fix.rb
- test/test_active_record_associations.rb
- test/test_active_record_base.rb
-- test/test_condition.rb
+- test/test_condition_base.rb
+- test/test_condition_types.rb
- test/test_conditions_base.rb
+- test/test_conditions_protection.rb
- test/test_helper.rb
- test/test_search_base.rb
+- test/test_search_conditions.rb
- test/test_search_ordering.rb
- test/test_search_pagination.rb
- test/test_search_protection.rb
+- test/text_config.rb
- searchgasm.gemspec
has_rdoc: true
homepage: http://github.com/binarylogic/searchgasm
@@ -174,10 +178,13 @@ summary: Orgasmic ActiveRecord searching
test_files:
- test/test_active_record_associations.rb
- test/test_active_record_base.rb
-- test/test_condition.rb
+- test/test_condition_base.rb
+- test/test_condition_types.rb
- test/test_conditions_base.rb
+- test/test_conditions_protection.rb
- test/test_helper.rb
- test/test_search_base.rb
+- test/test_search_conditions.rb
- test/test_search_ordering.rb
- test/test_search_pagination.rb
- test/test_search_protection.rb
View
0 ...archgasm-0.9.9/test/fixtures/accounts.yml → ...rchgasm-0.9.10/test/fixtures/accounts.yml
File renamed without changes.
View
0 ...searchgasm-0.9.9/test/fixtures/orders.yml → ...earchgasm-0.9.10/test/fixtures/orders.yml
File renamed without changes.
View
0 .../searchgasm-0.9.9/test/fixtures/users.yml → ...searchgasm-0.9.10/test/fixtures/users.yml
File renamed without changes.
View
0 ...earchgasm-0.9.9/test/libs/acts_as_tree.rb → ...archgasm-0.9.10/test/libs/acts_as_tree.rb
File renamed without changes.
View
0 ...s/searchgasm-0.9.9/test/libs/rexml_fix.rb → .../searchgasm-0.9.10/test/libs/rexml_fix.rb
File renamed without changes.
View
0 ...9/test/test_active_record_associations.rb → ...0/test/test_active_record_associations.rb
File renamed without changes.
View
2 ...asm-0.9.9/test/test_active_record_base.rb → ...sm-0.9.10/test/test_active_record_base.rb
@@ -35,7 +35,7 @@ def test_valid_find_options
def test_build_search
search = Account.new_search
assert_kind_of Searchgasm::Search::Base, search
-
+
search = Account.build_search(:conditions => {:name_keywords => "awesome"}, :page => 2, :per_page => 15)
assert_kind_of Searchgasm::Search::Base, search
assert_equal Account, search.klass
View
61 vendor/plugins/searchgasm-0.9.10/test/test_condition_base.rb
@@ -0,0 +1,61 @@
+require File.dirname(__FILE__) + '/test_helper.rb'
+
+class TestConditionBase < Test::Unit::TestCase
+ fixtures :accounts, :users, :orders
+
+ def setup
+ setup_db
+ load_fixtures
+ end
+
+ def teardown
+ teardown_db
+ end
+
+ def test_condition_name
+ assert_equal "equals", Searchgasm::Condition::Equals.condition_name
+ assert_equal "keywords", Searchgasm::Condition::Keywords.condition_name
+ assert_equal "greater_than_or_equal_to", Searchgasm::Condition::GreaterThanOrEqualTo.condition_name
+ end
+
+ def test_string_column
+
+ end
+
+ def test_comparable_column
+
+ end
+
+ def test_initialize
+ condition = Searchgasm::Condition::Keywords.new(Account, Account.columns_hash["name"])
+ assert_equal condition.klass, Account
+ assert_equal condition.column, Account.columns_hash["name"]
+
+ condition = Searchgasm::Condition::GreaterThan.new(Account, "id")
+ assert_equal condition.column, Account.columns_hash["id"]
+ end
+
+ def test_explicitly_set_value
+ condition = Searchgasm::Condition::Equals.new(Account, Account.columns_hash["name"])
+ assert !condition.explicitly_set_value?
+ condition.value = nil
+ assert condition.explicitly_set_value?
+
+ condition = Searchgasm::Condition::Keywords.new(Account, Account.columns_hash["name"])
+ assert !condition.explicitly_set_value?
+ condition.value = nil
+ assert !condition.explicitly_set_value?
+ end
+
+ def test_ignore_blanks?
+ condition = Searchgasm::Condition::Equals.new(Account, Account.columns_hash["id"])
+ assert !condition.ignore_blanks?
+
+ condition = Searchgasm::Condition::Keywords.new(Account, Account.columns_hash["name"])
+ assert condition.ignore_blanks?
+ end
+
+ def test_value
+
+ end
+end
View
49 ...s/searchgasm-0.9.9/test/test_condition.rb → ...hgasm-0.9.10/test/test_condition_types.rb
@@ -1,6 +1,6 @@
require File.dirname(__FILE__) + '/test_helper.rb'
-class TestCondition < Test::Unit::TestCase
+class TestConditionTypes < Test::Unit::TestCase
fixtures :accounts, :users, :orders
def setup
@@ -11,49 +11,6 @@ def setup
def teardown
teardown_db
end
-
- def test_condition_name
- assert_equal "equals", Searchgasm::Condition::Equals.condition_name
- assert_equal "keywords", Searchgasm::Condition::Keywords.condition_name
- assert_equal "greater_than_or_equal_to", Searchgasm::Condition::GreaterThanOrEqualTo.condition_name
- end
-
- def test_string_column
-
- end
-
- def test_comparable_column
-
- end
-
- def test_initialize
- condition = Searchgasm::Condition::Keywords.new(Account, Account.columns_hash["name"])
- assert_equal condition.klass, Account
- assert_equal condition.column, Account.columns_hash["name"]
-
- condition = Searchgasm::Condition::GreaterThan.new(Account, "id")
- assert_equal condition.column, Account.columns_hash["id"]
- end
-
- def test_explicitly_set_value
- condition = Searchgasm::Condition::Equals.new(Account, Account.columns_hash["name"])
- assert !condition.explicitly_set_value?
- condition.value = nil
- assert condition.explicitly_set_value?
-
- condition = Searchgasm::Condition::Keywords.new(Account, Account.columns_hash["name"])
- assert !condition.explicitly_set_value?
- condition.value = nil
- assert !condition.explicitly_set_value?
- end
-
- def test_ignore_blanks?
- condition = Searchgasm::Condition::Equals.new(Account, Account.columns_hash["id"])
- assert !condition.ignore_blanks?
-
- condition = Searchgasm::Condition::Keywords.new(Account, Account.columns_hash["name"])
- assert condition.ignore_blanks?
- end
def test_sanitize
condition = Searchgasm::Condition::BeginsWith.new(Account, Account.columns_hash["name"])
@@ -136,8 +93,4 @@ def test_sanitize
condition.value = User.find(2)
assert_equal condition.sanitize, ["(\"users\".\"id\" != ?) AND (\"users\".\"parent_id\" = ?)", 2, 1]
end
-
- def test_value
-
- end
end
View
10 ...chgasm-0.9.9/test/test_conditions_base.rb → ...hgasm-0.9.10/test/test_conditions_base.rb
@@ -165,14 +165,4 @@ def test_searching
assert_equal 1, conditions.minimum('id')
assert_equal 4, conditions.sum('id')
end
-
- def test_protection
- assert_raise(ArgumentError) { Account.new_conditions("(DELETE FROM users)") }
- assert_nothing_raised { Account.build_conditions!("(DELETE FROM users)") }
-
- account = Account.first
-
- assert_raise(ArgumentError) { account.users.build_conditions("(DELETE FROM users)") }
- assert_nothing_raised { account.users.build_conditions!("(DELETE FROM users)") }
- end
end
View
24 vendor/plugins/searchgasm-0.9.10/test/test_conditions_protection.rb
@@ -0,0 +1,24 @@
+require File.dirname(__FILE__) + '/test_helper.rb'
+
+class TestConditionsProtection < Test::Unit::TestCase
+ fixtures :accounts, :users, :orders
+
+ def setup
+ setup_db
+ load_fixtures
+ end
+
+ def teardown
+ teardown_db
+ end
+
+ def test_protection
+ assert_raise(ArgumentError) { Account.new_conditions("(DELETE FROM users)") }
+ assert_nothing_raised { Account.build_conditions!("(DELETE FROM users)") }
+
+ account = Account.first
+
+ assert_raise(ArgumentError) { account.users.build_conditions("(DELETE FROM users)") }
+ assert_nothing_raised { account.users.build_conditions!("(DELETE FROM users)") }
+ end
+end
View
0 ...gins/searchgasm-0.9.9/test/test_helper.rb → ...ins/searchgasm-0.9.10/test/test_helper.rb
File renamed without changes.
View
15 ...searchgasm-0.9.9/test/test_search_base.rb → ...earchgasm-0.9.10/test/test_search_base.rb
@@ -40,7 +40,7 @@ def test_setting_first_level_options
assert_equal "test", search.joins
search.page = 5
- assert_equal 1, search.page # haven't set a limit yet
+ assert_equal 1, search.page
assert_equal nil, search.offset
search.limit = 20
@@ -89,19 +89,6 @@ def test_setting_first_level_options
assert_equal search.lock, true
end
- def test_conditions
- search = Searchgasm::Search::Base.new(Account)
- assert_kind_of Searchgasm::Conditions::Base, search.conditions
- assert_equal search.conditions.klass, Account
-
- search.conditions = {:name_like => "Binary"}
- assert_kind_of Searchgasm::Conditions::Base, search.conditions
-
- conditions = Searchgasm::Conditions::Base.new(Account, :id_greater_than => 8)
- search.conditions = conditions
- assert_equal conditions, search.conditions
- end
-
def test_include
search = Searchgasm::Search::Base.new(Account)
assert_equal nil, search.include
View
27 vendor/plugins/searchgasm-0.9.10/test/test_search_conditions.rb
@@ -0,0 +1,27 @@
+require File.dirname(__FILE__) + '/test_helper.rb'
+
+class TestSearchConditions < Test::Unit::TestCase
+ fixtures :accounts, :users, :orders
+
+ def setup
+ setup_db
+ load_fixtures
+ end
+
+ def teardown
+ teardown_db
+ end
+
+ def test_conditions
+ search = Searchgasm::Search::Base.new(Account)
+ assert_kind_of Searchgasm::Conditions::Base, search.conditions
+ assert_equal search.conditions.klass, Account
+
+ search.conditions = {:name_like => "Binary"}
+ assert_kind_of Searchgasm::Conditions::Base, search.conditions
+
+ conditions = Searchgasm::Conditions::Base.new(Account, :id_greater_than => 8)
+ search.conditions = conditions
+ assert_equal conditions, search.conditions
+ end
+end
View
0 ...chgasm-0.9.9/test/test_search_ordering.rb → ...hgasm-0.9.10/test/test_search_ordering.rb
File renamed without changes.
View
0 ...gasm-0.9.9/test/test_search_pagination.rb → ...asm-0.9.10/test/test_search_pagination.rb
File renamed without changes.
View
0 ...gasm-0.9.9/test/test_search_protection.rb → ...asm-0.9.10/test/test_search_protection.rb
File renamed without changes.
View
1 vendor/plugins/searchgasm-0.9.10/test/text_config.rb
@@ -0,0 +1 @@
+# need to test that setting config doesn't mess up regular searches, only protected ones, etc

0 comments on commit 6a50ab0

Please sign in to comment.
Something went wrong with that request. Please try again.