searchgasm 0.9.9 → 0.9.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +3 -1
 - data/Manifest +5 -1
 - data/README.rdoc +47 -38
 - data/lib/searchgasm/config.rb +15 -1
 - data/lib/searchgasm/helpers/search_helper.rb +16 -2
 - data/lib/searchgasm/search/base.rb +0 -5
 - data/lib/searchgasm/search/pagination.rb +4 -4
 - data/lib/searchgasm/search/protection.rb +13 -0
 - data/lib/searchgasm/version.rb +1 -1
 - data/lib/searchgasm.rb +1 -1
 - data/searchgasm.gemspec +12 -5
 - data/test/test_active_record_base.rb +1 -1
 - data/test/test_condition_base.rb +61 -0
 - data/test/{test_condition.rb → test_condition_types.rb} +1 -48
 - data/test/test_conditions_base.rb +0 -10
 - data/test/test_conditions_protection.rb +24 -0
 - data/test/test_search_base.rb +1 -14
 - data/test/test_search_conditions.rb +27 -0
 - data/test/text_config.rb +1 -0
 - metadata +11 -4
 
    
        data/CHANGELOG
    CHANGED
    
    | 
         @@ -1,10 +1,12 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            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.
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       1 
3 
     | 
    
         
             
            v0.9.9. Fixed setting per_page to nil, false, or ''. This is done to "show all" results.
         
     | 
| 
       2 
4 
     | 
    
         | 
| 
       3 
5 
     | 
    
         
             
            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.
         
     | 
| 
       4 
6 
     | 
    
         | 
| 
       5 
7 
     | 
    
         
             
            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
         
     | 
| 
       6 
8 
     | 
    
         | 
| 
       7 
     | 
    
         
            -
            v0.9.6.  
     | 
| 
      
 9 
     | 
    
         
            +
            v0.9.6. Fixed bug when instantiating with nil options
         
     | 
| 
       8 
10 
     | 
    
         | 
| 
       9 
11 
     | 
    
         
             
            v0.9.5. Enhanced searching with conditions only. Updated read me to include example on adding your own conditions.
         
     | 
| 
       10 
12 
     | 
    
         | 
    
        data/Manifest
    CHANGED
    
    | 
         @@ -44,10 +44,14 @@ test/libs/acts_as_tree.rb 
     | 
|
| 
       44 
44 
     | 
    
         
             
            test/libs/rexml_fix.rb
         
     | 
| 
       45 
45 
     | 
    
         
             
            test/test_active_record_associations.rb
         
     | 
| 
       46 
46 
     | 
    
         
             
            test/test_active_record_base.rb
         
     | 
| 
       47 
     | 
    
         
            -
            test/ 
     | 
| 
      
 47 
     | 
    
         
            +
            test/test_condition_base.rb
         
     | 
| 
      
 48 
     | 
    
         
            +
            test/test_condition_types.rb
         
     | 
| 
       48 
49 
     | 
    
         
             
            test/test_conditions_base.rb
         
     | 
| 
      
 50 
     | 
    
         
            +
            test/test_conditions_protection.rb
         
     | 
| 
       49 
51 
     | 
    
         
             
            test/test_helper.rb
         
     | 
| 
       50 
52 
     | 
    
         
             
            test/test_search_base.rb
         
     | 
| 
      
 53 
     | 
    
         
            +
            test/test_search_conditions.rb
         
     | 
| 
       51 
54 
     | 
    
         
             
            test/test_search_ordering.rb
         
     | 
| 
       52 
55 
     | 
    
         
             
            test/test_search_pagination.rb
         
     | 
| 
       53 
56 
     | 
    
         
             
            test/test_search_protection.rb
         
     | 
| 
      
 57 
     | 
    
         
            +
            test/text_config.rb
         
     | 
    
        data/README.rdoc
    CHANGED
    
    | 
         @@ -4,11 +4,7 @@ Searchgasm is orgasmic. Maybe not orgasmic, but you will get aroused. So go grab 
     | 
|
| 
       4 
4 
     | 
    
         | 
| 
       5 
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 
     | 
    
         
            -
            ==  
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
            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.
         
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
            == Quicklinks
         
     | 
| 
      
 7 
     | 
    
         
            +
            == Helpful links
         
     | 
| 
       12 
8 
     | 
    
         | 
| 
       13 
9 
     | 
    
         
             
            *	<b>Documentation:</b> http://searchgasm.rubyforge.org
         
     | 
| 
       14 
10 
     | 
    
         
             
            *	<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: 
     | 
|
| 
       31 
27 
     | 
    
         | 
| 
       32 
28 
     | 
    
         
             
            <b>For all examples, let's assume the following relationships: User => Orders => Line Items</b>
         
     | 
| 
       33 
29 
     | 
    
         | 
| 
       34 
     | 
    
         
            -
            ==  
     | 
| 
      
 30 
     | 
    
         
            +
            == Simple Searching Example
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
              User.all(
         
     | 
| 
      
 33 
     | 
    
         
            +
                :conditions => {
         
     | 
| 
      
 34 
     | 
    
         
            +
                  :first_name_contains => "Ben",          # first_name like '%Ben%'
         
     | 
| 
      
 35 
     | 
    
         
            +
                  :email_ends_with => "binarylogic.com"   # email like '%binarylogic.com'
         
     | 
| 
      
 36 
     | 
    
         
            +
                },
         
     | 
| 
      
 37 
     | 
    
         
            +
                :per_page => 20,                        # limit 20
         
     | 
| 
      
 38 
     | 
    
         
            +
                :page => 3,                             # offset 40, which starts us on page 3
         
     | 
| 
      
 39 
     | 
    
         
            +
                :order_as => "ASC",
         
     | 
| 
      
 40 
     | 
    
         
            +
                :order_by => {:user_group => :name}     # order user_groups.name ASC
         
     | 
| 
      
 41 
     | 
    
         
            +
              )
         
     | 
| 
      
 42 
     | 
    
         
            +
              
         
     | 
| 
      
 43 
     | 
    
         
            +
            same as above, but object based
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
              search = User.new_search
         
     | 
| 
      
 46 
     | 
    
         
            +
              search.conditions.first_name_contains = "Ben"
         
     | 
| 
      
 47 
     | 
    
         
            +
              search.conditions.email_ends_with = "binarylogic.com"
         
     | 
| 
      
 48 
     | 
    
         
            +
              search.per_page = 20
         
     | 
| 
      
 49 
     | 
    
         
            +
              search.page = 3
         
     | 
| 
      
 50 
     | 
    
         
            +
              search.order_as = "ASC"
         
     | 
| 
      
 51 
     | 
    
         
            +
              search.order_by = {:user_group => :name}
         
     | 
| 
      
 52 
     | 
    
         
            +
              search.all
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
            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.
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
            == The beauty of searchgasm, integration into rails
         
     | 
| 
       35 
57 
     | 
    
         | 
| 
       36 
58 
     | 
    
         
             
            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:
         
     | 
| 
       37 
59 
     | 
    
         | 
| 
         @@ -76,28 +98,11 @@ Your view: 
     | 
|
| 
       76 
98 
     | 
    
         
             
              Page:
         
     | 
| 
       77 
99 
     | 
    
         
             
              = pages
         
     | 
| 
       78 
100 
     | 
    
         | 
| 
       79 
     | 
    
         
            -
            <b>See this example 
     | 
| 
       80 
     | 
    
         
            -
             
     | 
| 
       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).
         
     | 
| 
       82 
     | 
    
         
            -
             
     | 
| 
       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.
         
     | 
| 
       84 
     | 
    
         
            -
             
     | 
| 
       85 
     | 
    
         
            -
            == Simple Searching Example
         
     | 
| 
       86 
     | 
    
         
            -
             
     | 
| 
       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 
     | 
    
         
            -
              )
         
     | 
| 
       95 
     | 
    
         
            -
             
     | 
| 
       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
         
     | 
| 
      
 101 
     | 
    
         
            +
            <b>{See my tutorial on this example}(http://www.binarylogic.com/2008/9/7/tutorial-pagination-ordering-and-searching-with-searchgasm)</b>
         
     | 
| 
       97 
102 
     | 
    
         | 
| 
       98 
103 
     | 
    
         
             
            == Exhaustive Example w/ Object Based Searching (great for form_for or fields_for)
         
     | 
| 
       99 
104 
     | 
    
         | 
| 
       100 
     | 
    
         
            -
              #  
     | 
| 
      
 105 
     | 
    
         
            +
              # Start a new search
         
     | 
| 
       101 
106 
     | 
    
         
             
              @search = User.new_search(
         
     | 
| 
       102 
107 
     | 
    
         
             
                :conditions => {
         
     | 
| 
       103 
108 
     | 
    
         
             
                  :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 
     | 
|
| 
       158 
163 
     | 
    
         | 
| 
       159 
164 
     | 
    
         
             
              User.first(:conditions => {:age_gt => 18}, :per_page => 20)
         
     | 
| 
       160 
165 
     | 
    
         | 
| 
       161 
     | 
    
         
            -
              User.find(:all, :conditions => { 
     | 
| 
      
 166 
     | 
    
         
            +
              User.find(:all, :conditions => {:age_gt => 18}, :per_page => 20)
         
     | 
| 
       162 
167 
     | 
    
         | 
| 
       163 
     | 
    
         
            -
              User.find(:first, :conditions => { 
     | 
| 
      
 168 
     | 
    
         
            +
              User.find(:first, :conditions => {:age_gt => 18}, :per_page => 20)
         
     | 
| 
       164 
169 
     | 
    
         | 
| 
       165 
170 
     | 
    
         
             
              search = User.new_search(:conditions => {:age_gt => 18})  # build_search is an alias
         
     | 
| 
       166 
171 
     | 
    
         
             
              search.conditions.first_name_contains = "Ben"
         
     | 
| 
         @@ -176,6 +181,8 @@ If you want to use Searchgasm directly: 
     | 
|
| 
       176 
181 
     | 
    
         | 
| 
       177 
182 
     | 
    
         
             
            == Search with conditions only
         
     | 
| 
       178 
183 
     | 
    
         | 
| 
      
 184 
     | 
    
         
            +
            Don't need pagination, ordering, or any of the other options? Search with conditions only.
         
     | 
| 
      
 185 
     | 
    
         
            +
             
     | 
| 
       179 
186 
     | 
    
         
             
              conditions = User.new_conditions(:age_gt => 18)
         
     | 
| 
       180 
187 
     | 
    
         
             
              conditions.first_name_contains = "Ben"
         
     | 
| 
       181 
188 
     | 
    
         
             
              conditions.all
         
     | 
| 
         @@ -191,8 +198,6 @@ Again, if you want to use Searchgasm directly: 
     | 
|
| 
       191 
198 
     | 
    
         
             
              conditions.first_name_contains = "Ben"
         
     | 
| 
       192 
199 
     | 
    
         
             
              conditions.all
         
     | 
| 
       193 
200 
     | 
    
         | 
| 
       194 
     | 
    
         
            -
            Now pass the conditions object right into form\_for or fields\_for (see above for example).
         
     | 
| 
       195 
     | 
    
         
            -
             
     | 
| 
       196 
201 
     | 
    
         
             
            == Scoped searching
         
     | 
| 
       197 
202 
     | 
    
         | 
| 
       198 
203 
     | 
    
         
             
              @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 
     | 
|
| 
       268 
273 
     | 
    
         | 
| 
       269 
274 
     | 
    
         
             
            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":
         
     | 
| 
       270 
275 
     | 
    
         | 
| 
       271 
     | 
    
         
            -
              :equals 
     | 
| 
       272 
     | 
    
         
            -
              :does_not_equal 
     | 
| 
       273 
     | 
    
         
            -
              :begins_with 
     | 
| 
       274 
     | 
    
         
            -
              :contains 
     | 
| 
       275 
     | 
    
         
            -
              :ends_with 
     | 
| 
       276 
     | 
    
         
            -
              :greater_than 
     | 
| 
      
 276 
     | 
    
         
            +
              :equals                     => :is
         
     | 
| 
      
 277 
     | 
    
         
            +
              :does_not_equal             => :is_not, :not
         
     | 
| 
      
 278 
     | 
    
         
            +
              :begins_with                => :starts_with, :sw, :bw, :start
         
     | 
| 
      
 279 
     | 
    
         
            +
              :contains                   => :like, :has
         
     | 
| 
      
 280 
     | 
    
         
            +
              :ends_with                  => :ew, :ends, :end
         
     | 
| 
      
 281 
     | 
    
         
            +
              :greater_than               => :gt, :after
         
     | 
| 
       277 
282 
     | 
    
         
             
              :greater_than_or_equal_to   => :at_least, :gte
         
     | 
| 
       278 
     | 
    
         
            -
              :keywords 
     | 
| 
       279 
     | 
    
         
            -
              :less_than 
     | 
| 
       280 
     | 
    
         
            -
              :less_than_or_equal_to 
     | 
| 
      
 283 
     | 
    
         
            +
              :keywords                   => :kwords, :kw
         
     | 
| 
      
 284 
     | 
    
         
            +
              :less_than                  => :lt, :before
         
     | 
| 
      
 285 
     | 
    
         
            +
              :less_than_or_equal_to      => :at_most, :lte
         
     | 
| 
       281 
286 
     | 
    
         | 
| 
       282 
287 
     | 
    
         
             
            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.
         
     | 
| 
       283 
288 
     | 
    
         | 
| 
         @@ -326,6 +331,10 @@ Now test it out: 
     | 
|
| 
       326 
331 
     | 
    
         | 
| 
       327 
332 
     | 
    
         
             
            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
         
     | 
| 
       328 
333 
     | 
    
         | 
| 
      
 334 
     | 
    
         
            +
            == Under the hood
         
     | 
| 
      
 335 
     | 
    
         
            +
             
     | 
| 
      
 336 
     | 
    
         
            +
            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.
         
     | 
| 
      
 337 
     | 
    
         
            +
             
     | 
| 
       329 
338 
     | 
    
         
             
            == Reporting problems / bugs
         
     | 
| 
       330 
339 
     | 
    
         | 
| 
       331 
340 
     | 
    
         
             
            http://binarylogic.lighthouseapp.com/projects/16601-searchgasm
         
     | 
    
        data/lib/searchgasm/config.rb
    CHANGED
    
    | 
         @@ -43,6 +43,19 @@ module Searchgasm 
     | 
|
| 
       43 
43 
     | 
    
         
             
                    @desc_indicator = value
         
     | 
| 
       44 
44 
     | 
    
         
             
                  end
         
     | 
| 
       45 
45 
     | 
    
         | 
| 
      
 46 
     | 
    
         
            +
                  def pages_text # :nodoc:
         
     | 
| 
      
 47 
     | 
    
         
            +
                    @set_pages_text ? @pages_text : "Page %p"
         
     | 
| 
      
 48 
     | 
    
         
            +
                  end
         
     | 
| 
      
 49 
     | 
    
         
            +
                  
         
     | 
| 
      
 50 
     | 
    
         
            +
                  # The default value for the :text options in the pages helper.
         
     | 
| 
      
 51 
     | 
    
         
            +
                  #
         
     | 
| 
      
 52 
     | 
    
         
            +
                  # * <tt>Default:</tt> "Page %p"
         
     | 
| 
      
 53 
     | 
    
         
            +
                  # * <tt>Accepts:</tt> "Your string %p": where %p is replaced by the page number, or a block: Proc.new { |p| "Page #{p}" }
         
     | 
| 
      
 54 
     | 
    
         
            +
                  def pages_text=(value)
         
     | 
| 
      
 55 
     | 
    
         
            +
                    @set_pages_text = true
         
     | 
| 
      
 56 
     | 
    
         
            +
                    @pages_text
         
     | 
| 
      
 57 
     | 
    
         
            +
                  end
         
     | 
| 
      
 58 
     | 
    
         
            +
                  
         
     | 
| 
       46 
59 
     | 
    
         
             
                  def pages_type # :nodoc:
         
     | 
| 
       47 
60 
     | 
    
         
             
                    @pages_type ||= :select
         
     | 
| 
       48 
61 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -59,7 +72,8 @@ module Searchgasm 
     | 
|
| 
       59 
72 
     | 
    
         
             
                    @per_page
         
     | 
| 
       60 
73 
     | 
    
         
             
                  end
         
     | 
| 
       61 
74 
     | 
    
         | 
| 
       62 
     | 
    
         
            -
                  # The default for per page.
         
     | 
| 
      
 75 
     | 
    
         
            +
                  # The default for per page. This is only applicaple for protected searches. Meaning you start the search with new_search or new_conditions.
         
     | 
| 
      
 76 
     | 
    
         
            +
                  # The reason for this not to disturb regular queries such as Whatever.find(:all). You would not expect that to be limited.
         
     | 
| 
       63 
77 
     | 
    
         
             
                  #
         
     | 
| 
       64 
78 
     | 
    
         
             
                  # * <tt>Default:</tt> nil, nil means "show all"
         
     | 
| 
       65 
79 
     | 
    
         
             
                  # * <tt>Accepts:</tt> Any value in your per_page choices
         
     | 
| 
         @@ -73,6 +73,7 @@ module Searchgasm 
     | 
|
| 
       73 
73 
     | 
    
         
             
                  # === Options
         
     | 
| 
       74 
74 
     | 
    
         
             
                  # * <tt>:type</tt> -- default: :select, pass :links as an alternative to have flickr like pagination
         
     | 
| 
       75 
75 
     | 
    
         
             
                  # * <tt>:remote</tt> -- default: false, if true requests will be AJAX
         
     | 
| 
      
 76 
     | 
    
         
            +
                  # * <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}" }
         
     | 
| 
       76 
77 
     | 
    
         
             
                  #
         
     | 
| 
       77 
78 
     | 
    
         
             
                  # === Advanced Options
         
     | 
| 
       78 
79 
     | 
    
         
             
                  # * <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 @@ module Searchgasm 
     | 
|
| 
       85 
86 
     | 
    
         
             
                    add_searchgasm_helper_defaults!(options, :page)
         
     | 
| 
       86 
87 
     | 
    
         
             
                    return "" if options[:search_obj].page_count <= 1
         
     | 
| 
       87 
88 
     | 
    
         | 
| 
      
 89 
     | 
    
         
            +
                    page_range = (1..options[:search_obj].page_count)
         
     | 
| 
      
 90 
     | 
    
         
            +
                    options[:text] = Config.pages_text unless options.has_key?(:text)
         
     | 
| 
      
 91 
     | 
    
         
            +
                    
         
     | 
| 
      
 92 
     | 
    
         
            +
                    choices = nil
         
     | 
| 
      
 93 
     | 
    
         
            +
                    case options[:text]
         
     | 
| 
      
 94 
     | 
    
         
            +
                    when String
         
     | 
| 
      
 95 
     | 
    
         
            +
                      choices = page_range.collect { |p| [options[:text].gsub(/%p/, p.to_s), p] }
         
     | 
| 
      
 96 
     | 
    
         
            +
                    when Proc
         
     | 
| 
      
 97 
     | 
    
         
            +
                      choices = page_range.collect { |p| [yield(p), p] }
         
     | 
| 
      
 98 
     | 
    
         
            +
                    else
         
     | 
| 
      
 99 
     | 
    
         
            +
                      choices = page_range
         
     | 
| 
      
 100 
     | 
    
         
            +
                    end
         
     | 
| 
      
 101 
     | 
    
         
            +
                    
         
     | 
| 
       88 
102 
     | 
    
         
             
                    if block_given?
         
     | 
| 
       89 
103 
     | 
    
         
             
                      yield options
         
     | 
| 
       90 
104 
     | 
    
         
             
                    else
         
     | 
| 
         @@ -94,7 +108,7 @@ module Searchgasm 
     | 
|
| 
       94 
108 
     | 
    
         
             
                        options[:html][options[:action]] ||= ""
         
     | 
| 
       95 
109 
     | 
    
         
             
                        options[:html][options[:action]] += ";"
         
     | 
| 
       96 
110 
     | 
    
         
             
                        options[:html][options[:action]] += options[:url]
         
     | 
| 
       97 
     | 
    
         
            -
                        select(: 
     | 
| 
      
 111 
     | 
    
         
            +
                        select(options[:params_scope], :page, choices, {:selected => options[:search_obj].page}, options[:html])
         
     | 
| 
       98 
112 
     | 
    
         
             
                      else
         
     | 
| 
       99 
113 
     | 
    
         
             
                        # HTML for links
         
     | 
| 
       100 
114 
     | 
    
         
             
                      end
         
     | 
| 
         @@ -153,7 +167,7 @@ module Searchgasm 
     | 
|
| 
       153 
167 
     | 
    
         
             
                        options[:html][options[:action]] ||= ""
         
     | 
| 
       154 
168 
     | 
    
         
             
                        options[:html][options[:action]] += ";"
         
     | 
| 
       155 
169 
     | 
    
         
             
                        options[:html][options[:action]] += options[:url]
         
     | 
| 
       156 
     | 
    
         
            -
                        select(: 
     | 
| 
      
 170 
     | 
    
         
            +
                        select(options[:params_scope], :per_page, options[:choices], {:selected => options[:search_obj].per_page}, options[:html])
         
     | 
| 
       157 
171 
     | 
    
         
             
                      end
         
     | 
| 
       158 
172 
     | 
    
         
             
                    end
         
     | 
| 
       159 
173 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -49,12 +49,7 @@ module Searchgasm #:nodoc: 
     | 
|
| 
       49 
49 
     | 
    
         
             
                    "#<#{klass} #{options_as_nice_string}>"
         
     | 
| 
       50 
50 
     | 
    
         
             
                  end
         
     | 
| 
       51 
51 
     | 
    
         | 
| 
       52 
     | 
    
         
            -
                  def limit
         
     | 
| 
       53 
     | 
    
         
            -
                    @set_limit ? @limit : Config.per_page
         
     | 
| 
       54 
     | 
    
         
            -
                  end
         
     | 
| 
       55 
     | 
    
         
            -
                  
         
     | 
| 
       56 
52 
     | 
    
         
             
                  def limit=(value)
         
     | 
| 
       57 
     | 
    
         
            -
                    @set_limit = true
         
     | 
| 
       58 
53 
     | 
    
         
             
                    @limit = value.blank? || value == 0 ? nil : value.to_i
         
     | 
| 
       59 
54 
     | 
    
         
             
                  end
         
     | 
| 
       60 
55 
     | 
    
         | 
| 
         @@ -11,15 +11,15 @@ module Searchgasm 
     | 
|
| 
       11 
11 
     | 
    
         
             
                  end
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
       13 
13 
     | 
    
         
             
                  def limit_with_pagination=(value)
         
     | 
| 
       14 
     | 
    
         
            -
                    self.limit_without_pagination = value
         
     | 
| 
      
 14 
     | 
    
         
            +
                    r_value = self.limit_without_pagination = value
         
     | 
| 
       15 
15 
     | 
    
         
             
                    self.page = @page unless @page.nil? # retry page now that the limit has changed
         
     | 
| 
       16 
     | 
    
         
            -
                     
     | 
| 
      
 16 
     | 
    
         
            +
                    r_value
         
     | 
| 
       17 
17 
     | 
    
         
             
                  end
         
     | 
| 
       18 
18 
     | 
    
         | 
| 
       19 
19 
     | 
    
         
             
                  def offset_with_pagination=(value)
         
     | 
| 
       20 
     | 
    
         
            -
                    self.offset_without_pagination = value
         
     | 
| 
      
 20 
     | 
    
         
            +
                    r_value = self.offset_without_pagination = value
         
     | 
| 
       21 
21 
     | 
    
         
             
                    @page = nil
         
     | 
| 
       22 
     | 
    
         
            -
                     
     | 
| 
      
 22 
     | 
    
         
            +
                    r_value
         
     | 
| 
       23 
23 
     | 
    
         
             
                  end
         
     | 
| 
       24 
24 
     | 
    
         | 
| 
       25 
25 
     | 
    
         
             
                  def page
         
     | 
| 
         @@ -10,10 +10,22 @@ module Searchgasm 
     | 
|
| 
       10 
10 
     | 
    
         
             
                  def self.included(klass)
         
     | 
| 
       11 
11 
     | 
    
         
             
                    klass.class_eval do
         
     | 
| 
       12 
12 
     | 
    
         
             
                      attr_reader :protect
         
     | 
| 
      
 13 
     | 
    
         
            +
                      alias_method_chain :limit, :protection
         
     | 
| 
      
 14 
     | 
    
         
            +
                      alias_method_chain :limit=, :protection
         
     | 
| 
       13 
15 
     | 
    
         
             
                      alias_method_chain :options=, :protection
         
     | 
| 
       14 
16 
     | 
    
         
             
                    end
         
     | 
| 
       15 
17 
     | 
    
         
             
                  end
         
     | 
| 
       16 
18 
     | 
    
         | 
| 
      
 19 
     | 
    
         
            +
                  def limit_with_protection
         
     | 
| 
      
 20 
     | 
    
         
            +
                    return Config.per_page if protected? && !@set_limit
         
     | 
| 
      
 21 
     | 
    
         
            +
                    limit_without_protection
         
     | 
| 
      
 22 
     | 
    
         
            +
                  end
         
     | 
| 
      
 23 
     | 
    
         
            +
                  
         
     | 
| 
      
 24 
     | 
    
         
            +
                  def limit_with_protection=(value)
         
     | 
| 
      
 25 
     | 
    
         
            +
                    @set_limit = true
         
     | 
| 
      
 26 
     | 
    
         
            +
                    self.limit_without_protection = value
         
     | 
| 
      
 27 
     | 
    
         
            +
                  end
         
     | 
| 
      
 28 
     | 
    
         
            +
                  
         
     | 
| 
       17 
29 
     | 
    
         
             
                  def options_with_protection=(values)
         
     | 
| 
       18 
30 
     | 
    
         
             
                    return unless values.is_a?(Hash)
         
     | 
| 
       19 
31 
     | 
    
         
             
                    self.protect = values.delete(:protect) if values.has_key?(:protect) # make sure we do this first
         
     | 
| 
         @@ -29,6 +41,7 @@ module Searchgasm 
     | 
|
| 
       29 
41 
     | 
    
         
             
                  def protect?
         
     | 
| 
       30 
42 
     | 
    
         
             
                    protect == true
         
     | 
| 
       31 
43 
     | 
    
         
             
                  end
         
     | 
| 
      
 44 
     | 
    
         
            +
                  alias_method :protected?, :protect?
         
     | 
| 
       32 
45 
     | 
    
         | 
| 
       33 
46 
     | 
    
         
             
                  private
         
     | 
| 
       34 
47 
     | 
    
         
             
                    def order_by_safe?(order_by, alt_klass = nil)
         
     | 
    
        data/lib/searchgasm/version.rb
    CHANGED
    
    
    
        data/lib/searchgasm.rb
    CHANGED
    
    
    
        data/searchgasm.gemspec
    CHANGED
    
    | 
         @@ -1,18 +1,18 @@ 
     | 
|
| 
       1 
1 
     | 
    
         | 
| 
       2 
     | 
    
         
            -
            # Gem::Specification for Searchgasm-0.9. 
     | 
| 
      
 2 
     | 
    
         
            +
            # Gem::Specification for Searchgasm-0.9.10
         
     | 
| 
       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.10
         
     | 
| 
       9 
9 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       10 
10 
     | 
    
         
             
            authors: 
         
     | 
| 
       11 
11 
     | 
    
         
             
            - Ben Johnson of Binary Logic
         
     | 
| 
       12 
12 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       13 
13 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       14 
14 
     | 
    
         | 
| 
       15 
     | 
    
         
            -
            date: 2008-09- 
     | 
| 
      
 15 
     | 
    
         
            +
            date: 2008-09-08 00:00:00 -04:00
         
     | 
| 
       16 
16 
     | 
    
         
             
            default_executable: 
         
     | 
| 
       17 
17 
     | 
    
         
             
            dependencies: 
         
     | 
| 
       18 
18 
     | 
    
         
             
            - !ruby/object:Gem::Dependency 
         
     | 
| 
         @@ -133,13 +133,17 @@ files: 
     | 
|
| 
       133 
133 
     | 
    
         
             
            - test/libs/rexml_fix.rb
         
     | 
| 
       134 
134 
     | 
    
         
             
            - test/test_active_record_associations.rb
         
     | 
| 
       135 
135 
     | 
    
         
             
            - test/test_active_record_base.rb
         
     | 
| 
       136 
     | 
    
         
            -
            - test/ 
     | 
| 
      
 136 
     | 
    
         
            +
            - test/test_condition_base.rb
         
     | 
| 
      
 137 
     | 
    
         
            +
            - test/test_condition_types.rb
         
     | 
| 
       137 
138 
     | 
    
         
             
            - test/test_conditions_base.rb
         
     | 
| 
      
 139 
     | 
    
         
            +
            - test/test_conditions_protection.rb
         
     | 
| 
       138 
140 
     | 
    
         
             
            - test/test_helper.rb
         
     | 
| 
       139 
141 
     | 
    
         
             
            - test/test_search_base.rb
         
     | 
| 
      
 142 
     | 
    
         
            +
            - test/test_search_conditions.rb
         
     | 
| 
       140 
143 
     | 
    
         
             
            - test/test_search_ordering.rb
         
     | 
| 
       141 
144 
     | 
    
         
             
            - test/test_search_pagination.rb
         
     | 
| 
       142 
145 
     | 
    
         
             
            - test/test_search_protection.rb
         
     | 
| 
      
 146 
     | 
    
         
            +
            - test/text_config.rb
         
     | 
| 
       143 
147 
     | 
    
         
             
            - searchgasm.gemspec
         
     | 
| 
       144 
148 
     | 
    
         
             
            has_rdoc: true
         
     | 
| 
       145 
149 
     | 
    
         
             
            homepage: http://github.com/binarylogic/searchgasm
         
     | 
| 
         @@ -174,10 +178,13 @@ summary: Orgasmic ActiveRecord searching 
     | 
|
| 
       174 
178 
     | 
    
         
             
            test_files: 
         
     | 
| 
       175 
179 
     | 
    
         
             
            - test/test_active_record_associations.rb
         
     | 
| 
       176 
180 
     | 
    
         
             
            - test/test_active_record_base.rb
         
     | 
| 
       177 
     | 
    
         
            -
            - test/ 
     | 
| 
      
 181 
     | 
    
         
            +
            - test/test_condition_base.rb
         
     | 
| 
      
 182 
     | 
    
         
            +
            - test/test_condition_types.rb
         
     | 
| 
       178 
183 
     | 
    
         
             
            - test/test_conditions_base.rb
         
     | 
| 
      
 184 
     | 
    
         
            +
            - test/test_conditions_protection.rb
         
     | 
| 
       179 
185 
     | 
    
         
             
            - test/test_helper.rb
         
     | 
| 
       180 
186 
     | 
    
         
             
            - test/test_search_base.rb
         
     | 
| 
      
 187 
     | 
    
         
            +
            - test/test_search_conditions.rb
         
     | 
| 
       181 
188 
     | 
    
         
             
            - test/test_search_ordering.rb
         
     | 
| 
       182 
189 
     | 
    
         
             
            - test/test_search_pagination.rb
         
     | 
| 
       183 
190 
     | 
    
         
             
            - test/test_search_protection.rb
         
     | 
| 
         @@ -35,7 +35,7 @@ class TestActiveRecordBase < Test::Unit::TestCase 
     | 
|
| 
       35 
35 
     | 
    
         
             
              def test_build_search
         
     | 
| 
       36 
36 
     | 
    
         
             
                search = Account.new_search
         
     | 
| 
       37 
37 
     | 
    
         
             
                assert_kind_of Searchgasm::Search::Base, search
         
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
      
 38 
     | 
    
         
            +
                    
         
     | 
| 
       39 
39 
     | 
    
         
             
                search = Account.build_search(:conditions => {:name_keywords => "awesome"}, :page => 2, :per_page => 15)
         
     | 
| 
       40 
40 
     | 
    
         
             
                assert_kind_of Searchgasm::Search::Base, search
         
     | 
| 
       41 
41 
     | 
    
         
             
                assert_equal Account, search.klass
         
     | 
| 
         @@ -0,0 +1,61 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require File.dirname(__FILE__) + '/test_helper.rb'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            class TestConditionBase < 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_condition_name
         
     | 
| 
      
 16 
     | 
    
         
            +
                assert_equal "equals", Searchgasm::Condition::Equals.condition_name
         
     | 
| 
      
 17 
     | 
    
         
            +
                assert_equal "keywords", Searchgasm::Condition::Keywords.condition_name
         
     | 
| 
      
 18 
     | 
    
         
            +
                assert_equal "greater_than_or_equal_to", Searchgasm::Condition::GreaterThanOrEqualTo.condition_name
         
     | 
| 
      
 19 
     | 
    
         
            +
              end
         
     | 
| 
      
 20 
     | 
    
         
            +
              
         
     | 
| 
      
 21 
     | 
    
         
            +
              def test_string_column
         
     | 
| 
      
 22 
     | 
    
         
            +
                
         
     | 
| 
      
 23 
     | 
    
         
            +
              end
         
     | 
| 
      
 24 
     | 
    
         
            +
              
         
     | 
| 
      
 25 
     | 
    
         
            +
              def test_comparable_column
         
     | 
| 
      
 26 
     | 
    
         
            +
                
         
     | 
| 
      
 27 
     | 
    
         
            +
              end
         
     | 
| 
      
 28 
     | 
    
         
            +
              
         
     | 
| 
      
 29 
     | 
    
         
            +
              def test_initialize
         
     | 
| 
      
 30 
     | 
    
         
            +
                condition = Searchgasm::Condition::Keywords.new(Account, Account.columns_hash["name"])
         
     | 
| 
      
 31 
     | 
    
         
            +
                assert_equal condition.klass, Account
         
     | 
| 
      
 32 
     | 
    
         
            +
                assert_equal condition.column, Account.columns_hash["name"]
         
     | 
| 
      
 33 
     | 
    
         
            +
                
         
     | 
| 
      
 34 
     | 
    
         
            +
                condition = Searchgasm::Condition::GreaterThan.new(Account, "id")
         
     | 
| 
      
 35 
     | 
    
         
            +
                assert_equal condition.column, Account.columns_hash["id"]
         
     | 
| 
      
 36 
     | 
    
         
            +
              end
         
     | 
| 
      
 37 
     | 
    
         
            +
              
         
     | 
| 
      
 38 
     | 
    
         
            +
              def test_explicitly_set_value
         
     | 
| 
      
 39 
     | 
    
         
            +
                condition = Searchgasm::Condition::Equals.new(Account, Account.columns_hash["name"])
         
     | 
| 
      
 40 
     | 
    
         
            +
                assert !condition.explicitly_set_value?
         
     | 
| 
      
 41 
     | 
    
         
            +
                condition.value = nil
         
     | 
| 
      
 42 
     | 
    
         
            +
                assert condition.explicitly_set_value?
         
     | 
| 
      
 43 
     | 
    
         
            +
                
         
     | 
| 
      
 44 
     | 
    
         
            +
                condition = Searchgasm::Condition::Keywords.new(Account, Account.columns_hash["name"])
         
     | 
| 
      
 45 
     | 
    
         
            +
                assert !condition.explicitly_set_value?
         
     | 
| 
      
 46 
     | 
    
         
            +
                condition.value = nil
         
     | 
| 
      
 47 
     | 
    
         
            +
                assert !condition.explicitly_set_value?
         
     | 
| 
      
 48 
     | 
    
         
            +
              end
         
     | 
| 
      
 49 
     | 
    
         
            +
              
         
     | 
| 
      
 50 
     | 
    
         
            +
              def test_ignore_blanks?
         
     | 
| 
      
 51 
     | 
    
         
            +
                condition = Searchgasm::Condition::Equals.new(Account, Account.columns_hash["id"])
         
     | 
| 
      
 52 
     | 
    
         
            +
                assert !condition.ignore_blanks?
         
     | 
| 
      
 53 
     | 
    
         
            +
                
         
     | 
| 
      
 54 
     | 
    
         
            +
                condition = Searchgasm::Condition::Keywords.new(Account, Account.columns_hash["name"])
         
     | 
| 
      
 55 
     | 
    
         
            +
                assert condition.ignore_blanks?
         
     | 
| 
      
 56 
     | 
    
         
            +
              end
         
     | 
| 
      
 57 
     | 
    
         
            +
              
         
     | 
| 
      
 58 
     | 
    
         
            +
              def test_value
         
     | 
| 
      
 59 
     | 
    
         
            +
                
         
     | 
| 
      
 60 
     | 
    
         
            +
              end
         
     | 
| 
      
 61 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -1,6 +1,6 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require File.dirname(__FILE__) + '/test_helper.rb'
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
            class  
     | 
| 
      
 3 
     | 
    
         
            +
            class TestConditionTypes < Test::Unit::TestCase
         
     | 
| 
       4 
4 
     | 
    
         
             
              fixtures :accounts, :users, :orders
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
6 
     | 
    
         
             
              def setup
         
     | 
| 
         @@ -11,49 +11,6 @@ class TestCondition < Test::Unit::TestCase 
     | 
|
| 
       11 
11 
     | 
    
         
             
              def teardown
         
     | 
| 
       12 
12 
     | 
    
         
             
                teardown_db
         
     | 
| 
       13 
13 
     | 
    
         
             
              end
         
     | 
| 
       14 
     | 
    
         
            -
              
         
     | 
| 
       15 
     | 
    
         
            -
              def test_condition_name
         
     | 
| 
       16 
     | 
    
         
            -
                assert_equal "equals", Searchgasm::Condition::Equals.condition_name
         
     | 
| 
       17 
     | 
    
         
            -
                assert_equal "keywords", Searchgasm::Condition::Keywords.condition_name
         
     | 
| 
       18 
     | 
    
         
            -
                assert_equal "greater_than_or_equal_to", Searchgasm::Condition::GreaterThanOrEqualTo.condition_name
         
     | 
| 
       19 
     | 
    
         
            -
              end
         
     | 
| 
       20 
     | 
    
         
            -
              
         
     | 
| 
       21 
     | 
    
         
            -
              def test_string_column
         
     | 
| 
       22 
     | 
    
         
            -
                
         
     | 
| 
       23 
     | 
    
         
            -
              end
         
     | 
| 
       24 
     | 
    
         
            -
              
         
     | 
| 
       25 
     | 
    
         
            -
              def test_comparable_column
         
     | 
| 
       26 
     | 
    
         
            -
                
         
     | 
| 
       27 
     | 
    
         
            -
              end
         
     | 
| 
       28 
     | 
    
         
            -
              
         
     | 
| 
       29 
     | 
    
         
            -
              def test_initialize
         
     | 
| 
       30 
     | 
    
         
            -
                condition = Searchgasm::Condition::Keywords.new(Account, Account.columns_hash["name"])
         
     | 
| 
       31 
     | 
    
         
            -
                assert_equal condition.klass, Account
         
     | 
| 
       32 
     | 
    
         
            -
                assert_equal condition.column, Account.columns_hash["name"]
         
     | 
| 
       33 
     | 
    
         
            -
                
         
     | 
| 
       34 
     | 
    
         
            -
                condition = Searchgasm::Condition::GreaterThan.new(Account, "id")
         
     | 
| 
       35 
     | 
    
         
            -
                assert_equal condition.column, Account.columns_hash["id"]
         
     | 
| 
       36 
     | 
    
         
            -
              end
         
     | 
| 
       37 
     | 
    
         
            -
              
         
     | 
| 
       38 
     | 
    
         
            -
              def test_explicitly_set_value
         
     | 
| 
       39 
     | 
    
         
            -
                condition = Searchgasm::Condition::Equals.new(Account, Account.columns_hash["name"])
         
     | 
| 
       40 
     | 
    
         
            -
                assert !condition.explicitly_set_value?
         
     | 
| 
       41 
     | 
    
         
            -
                condition.value = nil
         
     | 
| 
       42 
     | 
    
         
            -
                assert condition.explicitly_set_value?
         
     | 
| 
       43 
     | 
    
         
            -
                
         
     | 
| 
       44 
     | 
    
         
            -
                condition = Searchgasm::Condition::Keywords.new(Account, Account.columns_hash["name"])
         
     | 
| 
       45 
     | 
    
         
            -
                assert !condition.explicitly_set_value?
         
     | 
| 
       46 
     | 
    
         
            -
                condition.value = nil
         
     | 
| 
       47 
     | 
    
         
            -
                assert !condition.explicitly_set_value?
         
     | 
| 
       48 
     | 
    
         
            -
              end
         
     | 
| 
       49 
     | 
    
         
            -
              
         
     | 
| 
       50 
     | 
    
         
            -
              def test_ignore_blanks?
         
     | 
| 
       51 
     | 
    
         
            -
                condition = Searchgasm::Condition::Equals.new(Account, Account.columns_hash["id"])
         
     | 
| 
       52 
     | 
    
         
            -
                assert !condition.ignore_blanks?
         
     | 
| 
       53 
     | 
    
         
            -
                
         
     | 
| 
       54 
     | 
    
         
            -
                condition = Searchgasm::Condition::Keywords.new(Account, Account.columns_hash["name"])
         
     | 
| 
       55 
     | 
    
         
            -
                assert condition.ignore_blanks?
         
     | 
| 
       56 
     | 
    
         
            -
              end
         
     | 
| 
       57 
14 
     | 
    
         | 
| 
       58 
15 
     | 
    
         
             
              def test_sanitize
         
     | 
| 
       59 
16 
     | 
    
         
             
                condition = Searchgasm::Condition::BeginsWith.new(Account, Account.columns_hash["name"])
         
     | 
| 
         @@ -136,8 +93,4 @@ class TestCondition < Test::Unit::TestCase 
     | 
|
| 
       136 
93 
     | 
    
         
             
                condition.value = User.find(2)
         
     | 
| 
       137 
94 
     | 
    
         
             
                assert_equal condition.sanitize, ["(\"users\".\"id\" != ?) AND (\"users\".\"parent_id\" = ?)", 2, 1]
         
     | 
| 
       138 
95 
     | 
    
         
             
              end
         
     | 
| 
       139 
     | 
    
         
            -
              
         
     | 
| 
       140 
     | 
    
         
            -
              def test_value
         
     | 
| 
       141 
     | 
    
         
            -
                
         
     | 
| 
       142 
     | 
    
         
            -
              end
         
     | 
| 
       143 
96 
     | 
    
         
             
            end
         
     | 
| 
         @@ -165,14 +165,4 @@ class TestConditionsBase < Test::Unit::TestCase 
     | 
|
| 
       165 
165 
     | 
    
         
             
                assert_equal 1, conditions.minimum('id')
         
     | 
| 
       166 
166 
     | 
    
         
             
                assert_equal 4, conditions.sum('id')
         
     | 
| 
       167 
167 
     | 
    
         
             
              end
         
     | 
| 
       168 
     | 
    
         
            -
              
         
     | 
| 
       169 
     | 
    
         
            -
              def test_protection
         
     | 
| 
       170 
     | 
    
         
            -
                assert_raise(ArgumentError) { Account.new_conditions("(DELETE FROM users)") }
         
     | 
| 
       171 
     | 
    
         
            -
                assert_nothing_raised { Account.build_conditions!("(DELETE FROM users)") }
         
     | 
| 
       172 
     | 
    
         
            -
                
         
     | 
| 
       173 
     | 
    
         
            -
                account = Account.first
         
     | 
| 
       174 
     | 
    
         
            -
                
         
     | 
| 
       175 
     | 
    
         
            -
                assert_raise(ArgumentError) { account.users.build_conditions("(DELETE FROM users)") }
         
     | 
| 
       176 
     | 
    
         
            -
                assert_nothing_raised { account.users.build_conditions!("(DELETE FROM users)") }
         
     | 
| 
       177 
     | 
    
         
            -
              end
         
     | 
| 
       178 
168 
     | 
    
         
             
            end
         
     | 
| 
         @@ -0,0 +1,24 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require File.dirname(__FILE__) + '/test_helper.rb'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            class TestConditionsProtection < Test::Unit::TestCase
         
     | 
| 
      
 4 
     | 
    
         
            +
              fixtures :accounts, :users, :orders
         
     | 
| 
      
 5 
     | 
    
         
            +
              
         
     | 
| 
      
 6 
     | 
    
         
            +
              def setup
         
     | 
| 
      
 7 
     | 
    
         
            +
                setup_db
         
     | 
| 
      
 8 
     | 
    
         
            +
                load_fixtures
         
     | 
| 
      
 9 
     | 
    
         
            +
              end
         
     | 
| 
      
 10 
     | 
    
         
            +
              
         
     | 
| 
      
 11 
     | 
    
         
            +
              def teardown
         
     | 
| 
      
 12 
     | 
    
         
            +
                teardown_db
         
     | 
| 
      
 13 
     | 
    
         
            +
              end
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
              def test_protection
         
     | 
| 
      
 16 
     | 
    
         
            +
                assert_raise(ArgumentError) { Account.new_conditions("(DELETE FROM users)") }
         
     | 
| 
      
 17 
     | 
    
         
            +
                assert_nothing_raised { Account.build_conditions!("(DELETE FROM users)") }
         
     | 
| 
      
 18 
     | 
    
         
            +
                
         
     | 
| 
      
 19 
     | 
    
         
            +
                account = Account.first
         
     | 
| 
      
 20 
     | 
    
         
            +
                
         
     | 
| 
      
 21 
     | 
    
         
            +
                assert_raise(ArgumentError) { account.users.build_conditions("(DELETE FROM users)") }
         
     | 
| 
      
 22 
     | 
    
         
            +
                assert_nothing_raised { account.users.build_conditions!("(DELETE FROM users)") }
         
     | 
| 
      
 23 
     | 
    
         
            +
              end
         
     | 
| 
      
 24 
     | 
    
         
            +
            end
         
     | 
    
        data/test/test_search_base.rb
    CHANGED
    
    | 
         @@ -40,7 +40,7 @@ class TestSearchBase < Test::Unit::TestCase 
     | 
|
| 
       40 
40 
     | 
    
         
             
                assert_equal "test", search.joins
         
     | 
| 
       41 
41 
     | 
    
         | 
| 
       42 
42 
     | 
    
         
             
                search.page = 5
         
     | 
| 
       43 
     | 
    
         
            -
                assert_equal 1, search.page 
     | 
| 
      
 43 
     | 
    
         
            +
                assert_equal 1, search.page
         
     | 
| 
       44 
44 
     | 
    
         
             
                assert_equal nil, search.offset
         
     | 
| 
       45 
45 
     | 
    
         | 
| 
       46 
46 
     | 
    
         
             
                search.limit = 20
         
     | 
| 
         @@ -89,19 +89,6 @@ class TestSearchBase < Test::Unit::TestCase 
     | 
|
| 
       89 
89 
     | 
    
         
             
                assert_equal search.lock, true
         
     | 
| 
       90 
90 
     | 
    
         
             
              end
         
     | 
| 
       91 
91 
     | 
    
         | 
| 
       92 
     | 
    
         
            -
              def test_conditions
         
     | 
| 
       93 
     | 
    
         
            -
                search = Searchgasm::Search::Base.new(Account)
         
     | 
| 
       94 
     | 
    
         
            -
                assert_kind_of Searchgasm::Conditions::Base, search.conditions
         
     | 
| 
       95 
     | 
    
         
            -
                assert_equal search.conditions.klass, Account
         
     | 
| 
       96 
     | 
    
         
            -
              
         
     | 
| 
       97 
     | 
    
         
            -
                search.conditions = {:name_like => "Binary"}
         
     | 
| 
       98 
     | 
    
         
            -
                assert_kind_of Searchgasm::Conditions::Base, search.conditions
         
     | 
| 
       99 
     | 
    
         
            -
              
         
     | 
| 
       100 
     | 
    
         
            -
                conditions = Searchgasm::Conditions::Base.new(Account, :id_greater_than => 8)
         
     | 
| 
       101 
     | 
    
         
            -
                search.conditions = conditions
         
     | 
| 
       102 
     | 
    
         
            -
                assert_equal conditions, search.conditions
         
     | 
| 
       103 
     | 
    
         
            -
              end
         
     | 
| 
       104 
     | 
    
         
            -
             
     | 
| 
       105 
92 
     | 
    
         
             
              def test_include
         
     | 
| 
       106 
93 
     | 
    
         
             
                search = Searchgasm::Search::Base.new(Account)
         
     | 
| 
       107 
94 
     | 
    
         
             
                assert_equal nil, search.include
         
     | 
| 
         @@ -0,0 +1,27 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require File.dirname(__FILE__) + '/test_helper.rb'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            class TestSearchConditions < Test::Unit::TestCase
         
     | 
| 
      
 4 
     | 
    
         
            +
              fixtures :accounts, :users, :orders
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
              def setup
         
     | 
| 
      
 7 
     | 
    
         
            +
                setup_db
         
     | 
| 
      
 8 
     | 
    
         
            +
                load_fixtures
         
     | 
| 
      
 9 
     | 
    
         
            +
              end
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
              def teardown
         
     | 
| 
      
 12 
     | 
    
         
            +
                teardown_db
         
     | 
| 
      
 13 
     | 
    
         
            +
              end
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
              def test_conditions
         
     | 
| 
      
 16 
     | 
    
         
            +
                search = Searchgasm::Search::Base.new(Account)
         
     | 
| 
      
 17 
     | 
    
         
            +
                assert_kind_of Searchgasm::Conditions::Base, search.conditions
         
     | 
| 
      
 18 
     | 
    
         
            +
                assert_equal search.conditions.klass, Account
         
     | 
| 
      
 19 
     | 
    
         
            +
              
         
     | 
| 
      
 20 
     | 
    
         
            +
                search.conditions = {:name_like => "Binary"}
         
     | 
| 
      
 21 
     | 
    
         
            +
                assert_kind_of Searchgasm::Conditions::Base, search.conditions
         
     | 
| 
      
 22 
     | 
    
         
            +
              
         
     | 
| 
      
 23 
     | 
    
         
            +
                conditions = Searchgasm::Conditions::Base.new(Account, :id_greater_than => 8)
         
     | 
| 
      
 24 
     | 
    
         
            +
                search.conditions = conditions
         
     | 
| 
      
 25 
     | 
    
         
            +
                assert_equal conditions, search.conditions
         
     | 
| 
      
 26 
     | 
    
         
            +
              end
         
     | 
| 
      
 27 
     | 
    
         
            +
            end
         
     | 
    
        data/test/text_config.rb
    ADDED
    
    | 
         @@ -0,0 +1 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # need to test that setting config doesn't mess up regular searches, only protected ones, etc
         
     | 
    
        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. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.9.10
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors: 
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Ben Johnson of Binary Logic
         
     | 
| 
         @@ -9,7 +9,7 @@ autorequire: 
     | 
|
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
11 
     | 
    
         | 
| 
       12 
     | 
    
         
            -
            date: 2008-09- 
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2008-09-08 00:00:00 -04:00
         
     | 
| 
       13 
13 
     | 
    
         
             
            default_executable: 
         
     | 
| 
       14 
14 
     | 
    
         
             
            dependencies: 
         
     | 
| 
       15 
15 
     | 
    
         
             
            - !ruby/object:Gem::Dependency 
         
     | 
| 
         @@ -130,13 +130,17 @@ files: 
     | 
|
| 
       130 
130 
     | 
    
         
             
            - test/libs/rexml_fix.rb
         
     | 
| 
       131 
131 
     | 
    
         
             
            - test/test_active_record_associations.rb
         
     | 
| 
       132 
132 
     | 
    
         
             
            - test/test_active_record_base.rb
         
     | 
| 
       133 
     | 
    
         
            -
            - test/ 
     | 
| 
      
 133 
     | 
    
         
            +
            - test/test_condition_base.rb
         
     | 
| 
      
 134 
     | 
    
         
            +
            - test/test_condition_types.rb
         
     | 
| 
       134 
135 
     | 
    
         
             
            - test/test_conditions_base.rb
         
     | 
| 
      
 136 
     | 
    
         
            +
            - test/test_conditions_protection.rb
         
     | 
| 
       135 
137 
     | 
    
         
             
            - test/test_helper.rb
         
     | 
| 
       136 
138 
     | 
    
         
             
            - test/test_search_base.rb
         
     | 
| 
      
 139 
     | 
    
         
            +
            - test/test_search_conditions.rb
         
     | 
| 
       137 
140 
     | 
    
         
             
            - test/test_search_ordering.rb
         
     | 
| 
       138 
141 
     | 
    
         
             
            - test/test_search_pagination.rb
         
     | 
| 
       139 
142 
     | 
    
         
             
            - test/test_search_protection.rb
         
     | 
| 
      
 143 
     | 
    
         
            +
            - test/text_config.rb
         
     | 
| 
       140 
144 
     | 
    
         
             
            - searchgasm.gemspec
         
     | 
| 
       141 
145 
     | 
    
         
             
            has_rdoc: true
         
     | 
| 
       142 
146 
     | 
    
         
             
            homepage: http://github.com/binarylogic/searchgasm
         
     | 
| 
         @@ -172,10 +176,13 @@ summary: Orgasmic ActiveRecord searching 
     | 
|
| 
       172 
176 
     | 
    
         
             
            test_files: 
         
     | 
| 
       173 
177 
     | 
    
         
             
            - test/test_active_record_associations.rb
         
     | 
| 
       174 
178 
     | 
    
         
             
            - test/test_active_record_base.rb
         
     | 
| 
       175 
     | 
    
         
            -
            - test/ 
     | 
| 
      
 179 
     | 
    
         
            +
            - test/test_condition_base.rb
         
     | 
| 
      
 180 
     | 
    
         
            +
            - test/test_condition_types.rb
         
     | 
| 
       176 
181 
     | 
    
         
             
            - test/test_conditions_base.rb
         
     | 
| 
      
 182 
     | 
    
         
            +
            - test/test_conditions_protection.rb
         
     | 
| 
       177 
183 
     | 
    
         
             
            - test/test_helper.rb
         
     | 
| 
       178 
184 
     | 
    
         
             
            - test/test_search_base.rb
         
     | 
| 
      
 185 
     | 
    
         
            +
            - test/test_search_conditions.rb
         
     | 
| 
       179 
186 
     | 
    
         
             
            - test/test_search_ordering.rb
         
     | 
| 
       180 
187 
     | 
    
         
             
            - test/test_search_pagination.rb
         
     | 
| 
       181 
188 
     | 
    
         
             
            - test/test_search_protection.rb
         
     |