From 1831e6dfabd28f86716a3dfe17333dbd75d9a380 Mon Sep 17 00:00:00 2001 From: ferdinand Date: Mon, 29 Jun 2015 10:59:15 +0530 Subject: [PATCH 01/33] Update patch version for ruby --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8fcf8ad..c363748 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,5 +5,5 @@ script: "bundle exec rake test" rvm: - 1.9.3 - 2.0.0 - - 2.1.2 - - 2.2.0 + - 2.1.6 + - 2.2.2 From 4a217cccc072fac27817eaceada938a3db4a8c21 Mon Sep 17 00:00:00 2001 From: hachpai Date: Wed, 15 Jul 2015 16:35:37 +0200 Subject: [PATCH 02/33] Scope with arity 0 and enum requests compatible --- lib/filterrific/active_record_extension.rb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/filterrific/active_record_extension.rb b/lib/filterrific/active_record_extension.rb index 34abfe3..936bd65 100644 --- a/lib/filterrific/active_record_extension.rb +++ b/lib/filterrific/active_record_extension.rb @@ -65,11 +65,14 @@ def filterrific_find(filterrific_param_set) # Apply filterrific params filterrific_available_filters.each do |filter_name| filter_param = filterrific_param_set.send(filter_name) - next if filter_param.blank? # skip blank filter_params - ar_rel = ar_rel.send(filter_name, filter_param) - end - - ar_rel + next if filter_param.blank? # skip blank filter_params + begin + ar_rel = ar_rel.send(filter_name, filter_param) + rescue ArgumentError #if we have a scope with arity 0 or enum query, we can perform the request without the parameter + ar_rel = ar_rel.send(filter_name) if (filter_param == 1) + end + end + ar_rel end protected From adf5fe2f7459ac9614356cd5c53e981e540f21fe Mon Sep 17 00:00:00 2001 From: Ferdinand Rosario Date: Tue, 1 Dec 2015 10:37:52 +0530 Subject: [PATCH 03/33] update patch and readme --- .travis.yml | 4 ++-- README.md | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index c363748..f3b3208 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,5 +5,5 @@ script: "bundle exec rake test" rvm: - 1.9.3 - 2.0.0 - - 2.1.6 - - 2.2.2 + - 2.1.7 + - 2.2.3 diff --git a/README.md b/README.md index b8962c7..882b0ef 100644 --- a/README.md +++ b/README.md @@ -28,10 +28,10 @@ Every commit to Filterrific is automatically tested against the following scenar | Rails version | Ruby environments | Database adapters | Build status | |---------------|--------------------------------|------------------------------------|--------------| -| Rails 4.2 | MRI 1.9.3, 2.0.0, 2.1.2, 2.2.0 | mysql, mysql2, postgresql, sqlite3 |[![Build Status](https://travis-ci.org/jhund/filterrific_demo.svg?branch=rails-4.2)](https://travis-ci.org/jhund/filterrific_demo)| -| Rails 4.1 | MRI 1.9.3, 2.0.0, 2.1.2, 2.2.0 | mysql, mysql2, postgresql, sqlite3 |[![Build Status](https://travis-ci.org/jhund/filterrific_demo.svg?branch=rails-4.1)](https://travis-ci.org/jhund/filterrific_demo)| -| Rails 4.0 | MRI 1.9.3, 2.0.0, 2.1.2, 2.2.0 | mysql, mysql2, postgresql, sqlite3 |[![Build Status](https://travis-ci.org/jhund/filterrific_demo.svg?branch=rails-4.0)](https://travis-ci.org/jhund/filterrific_demo)| -| Rails 3.2 | MRI 1.9.3, 2.0.0, 2.1.2 | mysql, mysql2, postgresql, sqlite3 |[![Build Status](https://travis-ci.org/jhund/filterrific_demo.svg?branch=rails-3.2)](https://travis-ci.org/jhund/filterrific_demo)| +| Rails 4.2 | MRI 1.9.3, 2.0.0, 2.1.7, 2.2.3 | mysql, mysql2, postgresql, sqlite3 |[![Build Status](https://travis-ci.org/jhund/filterrific_demo.svg?branch=rails-4.2)](https://travis-ci.org/jhund/filterrific_demo)| +| Rails 4.1 | MRI 1.9.3, 2.0.0, 2.1.7, 2.2.3 | mysql, mysql2, postgresql, sqlite3 |[![Build Status](https://travis-ci.org/jhund/filterrific_demo.svg?branch=rails-4.1)](https://travis-ci.org/jhund/filterrific_demo)| +| Rails 4.0 | MRI 1.9.3, 2.0.0, 2.1.7, 2.2.3 | mysql, mysql2, postgresql, sqlite3 |[![Build Status](https://travis-ci.org/jhund/filterrific_demo.svg?branch=rails-4.0)](https://travis-ci.org/jhund/filterrific_demo)| +| Rails 3.2 | MRI 1.9.3, 2.0.0, 2.1.7 | mysql, mysql2, postgresql, sqlite3 |[![Build Status](https://travis-ci.org/jhund/filterrific_demo.svg?branch=rails-3.2)](https://travis-ci.org/jhund/filterrific_demo)| Filterrific version 1.x should work on older versions of Rails and Ruby, however the 1.x branch is not supported any more. From 730e4b9856508ac303c94b517689870e15e3538b Mon Sep 17 00:00:00 2001 From: Oleg Antonyan Date: Tue, 12 Apr 2016 16:04:21 +0200 Subject: [PATCH 04/33] Turbolinks 5 compatibility --- app/assets/javascripts/filterrific/filterrific-jquery.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/filterrific/filterrific-jquery.js b/app/assets/javascripts/filterrific/filterrific-jquery.js index b5e6268..1e4ef76 100644 --- a/app/assets/javascripts/filterrific/filterrific-jquery.js +++ b/app/assets/javascripts/filterrific/filterrific-jquery.js @@ -80,7 +80,7 @@ Filterrific.submitFilterForm = function(){ // Initialize event observers on document ready and turbolinks page:load -jQuery(document).on('ready page:load', function() { +jQuery(document).on('ready page:load turbolinks:load', function() { // Add change event handler to all Filterrific filter inputs. $('#filterrific_filter').on( "change", From 5965ffca258081afa312d8be719a11389dfca9d7 Mon Sep 17 00:00:00 2001 From: Oleg Antonyan Date: Tue, 12 Apr 2016 16:24:14 +0200 Subject: [PATCH 05/33] prevent double initialization --- app/assets/javascripts/filterrific/filterrific-jquery.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/assets/javascripts/filterrific/filterrific-jquery.js b/app/assets/javascripts/filterrific/filterrific-jquery.js index 1e4ef76..5ee47dc 100644 --- a/app/assets/javascripts/filterrific/filterrific-jquery.js +++ b/app/assets/javascripts/filterrific/filterrific-jquery.js @@ -81,6 +81,13 @@ Filterrific.submitFilterForm = function(){ // Initialize event observers on document ready and turbolinks page:load jQuery(document).on('ready page:load turbolinks:load', function() { + + // Prevent double initilisation. With turbolinks 5 this function + // will be called twice: on read and turbolinks:load + if(Filterrific.initialized) { + return; + } + // Add change event handler to all Filterrific filter inputs. $('#filterrific_filter').on( "change", @@ -94,4 +101,6 @@ jQuery(document).on('ready page:load turbolinks:load', function() { 0.5, Filterrific.submitFilterForm ); + + Filterrific.initialized = true }); From 286d3ce097dd5d73306ed4b34d310cee5f1d3e70 Mon Sep 17 00:00:00 2001 From: Oleg Antonyan Date: Tue, 12 Apr 2016 16:26:19 +0200 Subject: [PATCH 06/33] spelling --- app/assets/javascripts/filterrific/filterrific-jquery.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/filterrific/filterrific-jquery.js b/app/assets/javascripts/filterrific/filterrific-jquery.js index 5ee47dc..819a9be 100644 --- a/app/assets/javascripts/filterrific/filterrific-jquery.js +++ b/app/assets/javascripts/filterrific/filterrific-jquery.js @@ -83,7 +83,7 @@ Filterrific.submitFilterForm = function(){ jQuery(document).on('ready page:load turbolinks:load', function() { // Prevent double initilisation. With turbolinks 5 this function - // will be called twice: on read and turbolinks:load + // will be called twice: on 'ready' and 'turbolinks:load' if(Filterrific.initialized) { return; } From 08bd20edaf21a57bde18fcbf013b64db0884b3e7 Mon Sep 17 00:00:00 2001 From: Oleg Antonyan Date: Tue, 12 Apr 2016 16:44:44 +0200 Subject: [PATCH 07/33] fix double init --- .../filterrific/filterrific-jquery.js | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/app/assets/javascripts/filterrific/filterrific-jquery.js b/app/assets/javascripts/filterrific/filterrific-jquery.js index 819a9be..610f0ea 100644 --- a/app/assets/javascripts/filterrific/filterrific-jquery.js +++ b/app/assets/javascripts/filterrific/filterrific-jquery.js @@ -78,16 +78,7 @@ Filterrific.submitFilterForm = function(){ })(jQuery); - -// Initialize event observers on document ready and turbolinks page:load -jQuery(document).on('ready page:load turbolinks:load', function() { - - // Prevent double initilisation. With turbolinks 5 this function - // will be called twice: on 'ready' and 'turbolinks:load' - if(Filterrific.initialized) { - return; - } - +Filterrific.init = function() { // Add change event handler to all Filterrific filter inputs. $('#filterrific_filter').on( "change", @@ -101,6 +92,17 @@ jQuery(document).on('ready page:load turbolinks:load', function() { 0.5, Filterrific.submitFilterForm ); +}; + + +// Initialize event observers on document ready and turbolinks page:load +jQuery(document).on('turbolinks:load', function() { + // Prevent double initilisation. With turbolinks 5 this function + // will be called twice: on 'ready' and 'turbolinks:load' + jQuery(document).off('ready page:load') + Filterrific.init(); +}); - Filterrific.initialized = true +jQuery(document).on('ready page:load', function() { + Filterrific.init(); }); From 968d95fe0b62b48bf4a2a5581930bb4e7e7bb466 Mon Sep 17 00:00:00 2001 From: Geraint White Date: Mon, 9 May 2016 16:15:32 +0100 Subject: [PATCH 08/33] Don't parse a hypen (-) as an int, also allow 0 --- lib/filterrific/param_set.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/filterrific/param_set.rb b/lib/filterrific/param_set.rb index f2ed7c3..48c37da 100644 --- a/lib/filterrific/param_set.rb +++ b/lib/filterrific/param_set.rb @@ -82,12 +82,12 @@ def condition_filterrific_params(fp) fp[key] = val.call when val.is_a?(Array) # type cast integers in the array - fp[key] = fp[key].map { |e| e =~ /\A[1-9\-]\d*\z/ ? e.to_i : e } + fp[key] = fp[key].map { |e| e =~ /\A-?\d+\z/ ? e.to_i : e } when val.is_a?(Hash) # type cast Hash to OpenStruct so that nested params render correctly # in the form fp[key] = OpenStruct.new(fp[key]) - when val =~ /\A[1-9\-]\d*\z/ + when val =~ /\A-?\d+\z/ # type cast integer fp[key] = fp[key].to_i end From f27f173feda0ef8e032c88b060a68266b136460b Mon Sep 17 00:00:00 2001 From: Scott Kolodziej Date: Thu, 23 Jun 2016 21:46:53 -0500 Subject: [PATCH 09/33] Change array join to safe_join MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit join concatenates array elements to create a string with the optional specified separator. Unfortunately, the resulting string is assumed not HTML-safe, and so Rails escapes it to be safe. Rails offers a better alternative, safe_join, that will concatenate elements while retaining each element’s HTML-safety and returning an HTML-safe string. --- lib/filterrific/action_view_extension.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/filterrific/action_view_extension.rb b/lib/filterrific/action_view_extension.rb index 124b2c9..519ca1e 100644 --- a/lib/filterrific/action_view_extension.rb +++ b/lib/filterrific/action_view_extension.rb @@ -106,17 +106,17 @@ def filterrific_sorting_link_reverse_order(filterrific, new_sort_key, opts) else ['asc', opts[:descending_indicator]] end - new_sorting = [new_sort_key, new_sort_direction].join('_') - css_classes = [ + new_sorting = safe_join([new_sort_key, new_sort_direction], '_') + css_classes = safe_join([ opts[:active_column_class], opts[:html_attrs].delete(:class) - ].compact.join(' ') + ].compact, ' ') new_filterrific_params = filterrific.to_hash .with_indifferent_access .merge(opts[:sorting_scope_name] => new_sorting) url_for_attrs = opts[:url_for_attrs].merge(:filterrific => new_filterrific_params) link_to( - [opts[:label], opts[:current_sort_direction_indicator]].join(' '), + safe_join([opts[:label], opts[:current_sort_direction_indicator]], ' '), url_for(url_for_attrs), opts[:html_attrs].reverse_merge(:class => css_classes, :method => :get, :remote => true) ) @@ -129,11 +129,11 @@ def filterrific_sorting_link_reverse_order(filterrific, new_sort_key, opts) # @return [String] an HTML fragment def filterrific_sorting_link_new_column(filterrific, new_sort_key, opts) new_sort_direction = opts[:default_sort_direction] - new_sorting = [new_sort_key, new_sort_direction].join('_') - css_classes = [ + new_sorting = safe_join([new_sort_key, new_sort_direction], '_') + css_classes = safe_join([ opts[:inactive_column_class], opts[:html_attrs].delete(:class) - ].compact.join(' ') + ].compact, ' ') new_filterrific_params = filterrific.to_hash .with_indifferent_access .merge(opts[:sorting_scope_name] => new_sorting) From ee985619503dd23226d167590e5605c2108d1c11 Mon Sep 17 00:00:00 2001 From: Oleg Antonyan Date: Mon, 22 Aug 2016 06:14:29 +0200 Subject: [PATCH 10/33] fix stringify_keys! on params deprication warning in rails 5 --- lib/filterrific/param_set.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/filterrific/param_set.rb b/lib/filterrific/param_set.rb index f2ed7c3..872e626 100644 --- a/lib/filterrific/param_set.rb +++ b/lib/filterrific/param_set.rb @@ -28,7 +28,11 @@ def initialize(a_model_class, filterrific_params = {}) # Persistence, baby. By the time you submit changes to one filter, all the others # will be already initialized with the defaults. filterrific_params = model_class.filterrific_default_filter_params if filterrific_params.blank? - filterrific_params.stringify_keys! + if defined?(ActionController::Parameters) && filterrific_params.is_a?(ActionController::Parameters) + filterrific_params = filterrific_params.permit(model_class.filterrific_available_filters).to_h.stringify_keys + else + filterrific_params.stringify_keys! + end filterrific_params = condition_filterrific_params(filterrific_params) define_and_assign_attr_accessors_for_each_filter(filterrific_params) end From 3ddcee12b0a8c8e64fd5404e64952bd1c368c262 Mon Sep 17 00:00:00 2001 From: Rodrigo Argumedo Date: Fri, 14 Oct 2016 19:51:23 -0500 Subject: [PATCH 11/33] Add Ruby 2.3.1 into Travis CI --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index f3b3208..cbef4de 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,3 +7,4 @@ rvm: - 2.0.0 - 2.1.7 - 2.2.3 + - 2.3.1 From 25860a1b0f3a039d7a3e117f9f107cad95502280 Mon Sep 17 00:00:00 2001 From: Jo Hund Date: Sun, 6 Nov 2016 16:53:09 -0800 Subject: [PATCH 12/33] Updated to Ruby 2.2.2 in CI test matrix --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8fcf8ad..6ba7e34 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,4 +6,4 @@ rvm: - 1.9.3 - 2.0.0 - 2.1.2 - - 2.2.0 + - 2.2.2 From ad02e47cb140f3a34c501c5f2964e13ac0045071 Mon Sep 17 00:00:00 2001 From: Jo Hund Date: Sun, 6 Nov 2016 16:53:40 -0800 Subject: [PATCH 13/33] Removed unused l_var and simplified code --- lib/filterrific/action_view_extension.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/filterrific/action_view_extension.rb b/lib/filterrific/action_view_extension.rb index 124b2c9..ed23723 100644 --- a/lib/filterrific/action_view_extension.rb +++ b/lib/filterrific/action_view_extension.rb @@ -101,11 +101,7 @@ def filterrific_sorting_link(filterrific, sort_key, opts = {}) # @return [String] an HTML fragment def filterrific_sorting_link_reverse_order(filterrific, new_sort_key, opts) # current sort column, toggle search_direction - new_sort_direction, current_sort_direction_indicator = if 'asc' == opts[:current_sort_direction] - ['desc', opts[:ascending_indicator]] - else - ['asc', opts[:descending_indicator]] - end + new_sort_direction = 'asc' == opts[:current_sort_direction] ? 'desc' : 'asc' new_sorting = [new_sort_key, new_sort_direction].join('_') css_classes = [ opts[:active_column_class], From 73c5ad67cc196011c748eded20590d8f269c8002 Mon Sep 17 00:00:00 2001 From: Jo Hund Date: Sun, 6 Nov 2016 16:54:18 -0800 Subject: [PATCH 14/33] Add to assets.precompile only prior to Rails 5 --- lib/filterrific/engine.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/filterrific/engine.rb b/lib/filterrific/engine.rb index 832a897..fd73bf4 100644 --- a/lib/filterrific/engine.rb +++ b/lib/filterrific/engine.rb @@ -28,8 +28,12 @@ class Engine < ::Rails::Engine extend Filterrific::ActiveRecordExtension end - initializer "filterrific" do |app| - app.config.assets.precompile += %w(filterrific-spinner.gif) + # sprockets-rails 3 tracks down the calls to `font_path` and `image_path` + # and automatically precompiles the referenced assets. + unless Rails::VERSION::MAJOR < 5 + initializer "filterrific.assets.precompile" do |app| + app.config.assets.precompile += %w(filterrific/filterrific-spinner.gif) + end end end From 58e1376718e8d267606a5e14fce18cb86d75fe2c Mon Sep 17 00:00:00 2001 From: Jo Hund Date: Sun, 6 Nov 2016 16:55:07 -0800 Subject: [PATCH 15/33] Name spaced test code in specs to silence warnings --- .../action_controller_extension_spec.rb | 36 ++--- .../filterrific/action_view_extension_spec.rb | 8 +- .../active_record_extension_spec.rb | 28 ++-- spec/filterrific/param_set_spec.rb | 142 ++++++++++-------- 4 files changed, 112 insertions(+), 102 deletions(-) diff --git a/spec/filterrific/action_controller_extension_spec.rb b/spec/filterrific/action_controller_extension_spec.rb index 4d2363f..d263735 100644 --- a/spec/filterrific/action_controller_extension_spec.rb +++ b/spec/filterrific/action_controller_extension_spec.rb @@ -3,28 +3,28 @@ module Filterrific - class TestController - include ActionControllerExtension - def action_name; 'index'; end - def controller_name; 'test_controller'; end - def session - { - 'test_controller#index' => { - 'filter1' => '1_from_session', - 'filter2' => '2_from_session', + describe ActionControllerExtension do + + class TestController + include ActionControllerExtension + def action_name; 'index'; end + def controller_name; 'test_controller'; end + def session + { + 'test_controller#index' => { + 'filter1' => '1_from_session', + 'filter2' => '2_from_session', + } } - } + end end - end - class TestModelClass - def self.filterrific_available_filters; %w[filter1 filter2]; end - def self.filterrific_default_filter_params - { 'filter1' => '1_from_model_defaults' } + class TestModelClass + def self.filterrific_available_filters; %w[filter1 filter2]; end + def self.filterrific_default_filter_params + { 'filter1' => '1_from_model_defaults' } + end end - end - - describe ActionControllerExtension do describe '#initialize_filterrific' do diff --git a/spec/filterrific/action_view_extension_spec.rb b/spec/filterrific/action_view_extension_spec.rb index 4db3cc1..93d8193 100644 --- a/spec/filterrific/action_view_extension_spec.rb +++ b/spec/filterrific/action_view_extension_spec.rb @@ -3,12 +3,12 @@ module Filterrific - class ViewContext - include ActionViewExtension - end - describe ActionViewExtension do + class ViewContext + include ActionViewExtension + end + it 'responds to #form_for_filterrific' do ViewContext.new.must_respond_to(:form_for_filterrific) end diff --git a/spec/filterrific/active_record_extension_spec.rb b/spec/filterrific/active_record_extension_spec.rb index 85d2abd..af8082e 100644 --- a/spec/filterrific/active_record_extension_spec.rb +++ b/spec/filterrific/active_record_extension_spec.rb @@ -6,26 +6,26 @@ module Filterrific - # Container for test data - class TestData + describe ActiveRecordExtension do - def self.filterrific_available_filters - %w[search_query sorted_by with_country_id] - end + # Container for test data + class TestDataARES - def self.filterrific_default_filter_params - { 'sorted_by' => 'name_asc' } - end + def self.filterrific_available_filters + %w[search_query sorted_by with_country_id] + end - end + def self.filterrific_default_filter_params + { 'sorted_by' => 'name_asc' } + end - describe ActiveRecordExtension do + end let(:filterrific_class){ Class.new(ActiveRecord::Base) do filterrific( - available_filters: TestData.filterrific_available_filters, - default_filter_params: TestData.filterrific_default_filter_params + available_filters: TestDataARES.filterrific_available_filters, + default_filter_params: TestDataARES.filterrific_default_filter_params ) end } @@ -46,13 +46,13 @@ def self.filterrific_default_filter_params it "initializes filterrific_available_filters" do filterrific_class.filterrific_available_filters.must_equal( - TestData.filterrific_available_filters + TestDataARES.filterrific_available_filters ) end it "initializes filterrific_default_filter_params" do filterrific_class.filterrific_default_filter_params.must_equal( - TestData.filterrific_default_filter_params + TestDataARES.filterrific_default_filter_params ) end diff --git a/spec/filterrific/param_set_spec.rb b/spec/filterrific/param_set_spec.rb index 49cf70f..84a763c 100644 --- a/spec/filterrific/param_set_spec.rb +++ b/spec/filterrific/param_set_spec.rb @@ -3,83 +3,93 @@ module Filterrific - # Container for test data - class TestData - - def self.filterrific_available_filters - %w[ - filter_almost_int - filter_array_int - filter_array_string - filter_hash - filter_int - filter_negative_int - filter_proc - filter_string - ] - end - - def self.filterrific_default_filter_params - { 'filter_int' => 42 } - end + describe ParamSet do - def self.filterrific_params - { - 'filter_almost_int' => '042', - 'filter_array_int' => %w[1 2 3], - 'filter_array_string' => %w[one two three], - 'filter_hash' => { a: 1, b: 2 }, - 'filter_int' => '42', - 'filter_negative_int' => '-42', - 'filter_proc' => lambda { 1 + 1 }, - 'filter_string' => 'forty-two', - } - end + # Container for test data + class TestData + + def self.filterrific_available_filters + %w[ + filter_almost_int + filter_array_int + filter_array_string + filter_hash + filter_hyphen + filter_int + filter_negative_int + filter_proc + filter_string + filter_zero + ] + end - def self.filterrific_params_after_conditioning - { - 'filter_almost_int' => '042', - 'filter_array_int' => [1, 2, 3], - 'filter_array_string' => %w[one two three], - 'filter_hash' => OpenStruct.new(a: 1, b: 2), - 'filter_int' => 42, - 'filter_negative_int' => -42, - 'filter_proc' => 2, - 'filter_string' => 'forty-two', - } - end + def self.filterrific_default_filter_params + { 'filter_int' => 42 } + end - def self.filterrific_params_as_hash - { - 'filter_almost_int' => '042', - 'filter_array_int' => [1, 2, 3], - 'filter_array_string' => %w[one two three], - 'filter_hash' => { a: 1, b: 2 }, - 'filter_int' => 42, - 'filter_negative_int' => -42, - 'filter_proc' => 2, - 'filter_string' => 'forty-two', - } - end + def self.filterrific_params + { + 'filter_almost_int' => '042', + 'filter_array_int' => %w[1 2 3], + 'filter_array_string' => %w[one two three], + 'filter_hash' => { a: 1, b: 2 }, + 'filter_hyphen' => '-', + 'filter_int' => '42', + 'filter_negative_int' => '-42', + 'filter_proc' => lambda { 1 + 1 }, + 'filter_string' => 'forty-two', + 'filter_zero' => '0', + } + end - end + def self.filterrific_params_after_conditioning + { + 'filter_almost_int' => '042', + 'filter_array_int' => [1, 2, 3], + 'filter_array_string' => %w[one two three], + 'filter_hash' => OpenStruct.new(a: 1, b: 2), + 'filter_hyphen' => '-', + 'filter_int' => 42, + 'filter_negative_int' => -42, + 'filter_proc' => 2, + 'filter_string' => 'forty-two', + 'filter_zero' => 0, + } + end - # Simulates a class that would include the filterrific directive - class ModelClass + def self.filterrific_params_as_hash + { + 'filter_almost_int' => '042', + 'filter_array_int' => [1, 2, 3], + 'filter_array_string' => %w[one two three], + 'filter_hash' => { a: 1, b: 2 }, + 'filter_hyphen' => '-', + 'filter_int' => 42, + 'filter_negative_int' => -42, + 'filter_proc' => 2, + 'filter_string' => 'forty-two', + 'filter_zero' => 0, + } + end - def self.filterrific_default_filter_params - TestData.filterrific_default_filter_params - end - def self.filterrific_available_filters - TestData.filterrific_available_filters end - end + # Simulates a class that would include the filterrific directive + class ModelClass - describe ParamSet do + def self.filterrific_default_filter_params + TestData.filterrific_default_filter_params + end + def self.filterrific_available_filters + TestData.filterrific_available_filters + end + + end let(:filterrific_param_set){ - Filterrific::ParamSet.new(ModelClass, TestData.filterrific_params) + Kernel::silence_warnings { + Filterrific::ParamSet.new(ModelClass, TestData.filterrific_params) + } } describe "initialization" do From 4af0c91694c8247f62c13617e9da31f4f73b64c3 Mon Sep 17 00:00:00 2001 From: Jo Hund Date: Sun, 6 Nov 2016 16:55:33 -0800 Subject: [PATCH 16/33] Added asset initializer to make filterrific-spinner available under Rails 5 --- config/initializers/assets.rb | 1 + 1 file changed, 1 insertion(+) create mode 100644 config/initializers/assets.rb diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb new file mode 100644 index 0000000..488e928 --- /dev/null +++ b/config/initializers/assets.rb @@ -0,0 +1 @@ +Rails.application.config.assets.precompile += %w( filterrific/filterrific-spinner.gif ) From 3424bb540d9e006dd12093fb1e12bbb4b4077274 Mon Sep 17 00:00:00 2001 From: Jo Hund Date: Sun, 6 Nov 2016 17:34:22 -0800 Subject: [PATCH 17/33] Cosmetic changes, documentation updates --- .travis.yml | 5 ----- README.md | 17 +++++++++-------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index b2fe3f0..cbef4de 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,11 +5,6 @@ script: "bundle exec rake test" rvm: - 1.9.3 - 2.0.0 -<<<<<<< HEAD - - 2.1.2 - - 2.2.2 -======= - 2.1.7 - 2.2.3 - 2.3.1 ->>>>>>> a1f25839f8dcc62c29b92f1f0a1bc642278413c4 diff --git a/README.md b/README.md index 882b0ef..a9f18c4 100644 --- a/README.md +++ b/README.md @@ -26,12 +26,13 @@ or with bundler in your Gemfile: Every commit to Filterrific is automatically tested against the following scenarios: -| Rails version | Ruby environments | Database adapters | Build status | -|---------------|--------------------------------|------------------------------------|--------------| -| Rails 4.2 | MRI 1.9.3, 2.0.0, 2.1.7, 2.2.3 | mysql, mysql2, postgresql, sqlite3 |[![Build Status](https://travis-ci.org/jhund/filterrific_demo.svg?branch=rails-4.2)](https://travis-ci.org/jhund/filterrific_demo)| -| Rails 4.1 | MRI 1.9.3, 2.0.0, 2.1.7, 2.2.3 | mysql, mysql2, postgresql, sqlite3 |[![Build Status](https://travis-ci.org/jhund/filterrific_demo.svg?branch=rails-4.1)](https://travis-ci.org/jhund/filterrific_demo)| -| Rails 4.0 | MRI 1.9.3, 2.0.0, 2.1.7, 2.2.3 | mysql, mysql2, postgresql, sqlite3 |[![Build Status](https://travis-ci.org/jhund/filterrific_demo.svg?branch=rails-4.0)](https://travis-ci.org/jhund/filterrific_demo)| -| Rails 3.2 | MRI 1.9.3, 2.0.0, 2.1.7 | mysql, mysql2, postgresql, sqlite3 |[![Build Status](https://travis-ci.org/jhund/filterrific_demo.svg?branch=rails-3.2)](https://travis-ci.org/jhund/filterrific_demo)| +| Rails version | Ruby environments | Database adapters | Build status | +|---------------|---------------------------------------|------------------------------------|--------------| +| Rails 5.x | MRI 1.9.3, 2.0.0, 2.1.7, 2.2.3, 2.3.1 | mysql2, postgresql, sqlite3 |[![Build Status](https://travis-ci.org/jhund/filterrific_demo.svg?branch=rails-5.x)](https://travis-ci.org/jhund/filterrific_demo)| +| Rails 4.2 | MRI 1.9.3, 2.0.0, 2.1.7, 2.2.3, 2.3.1 | mysql, mysql2, postgresql, sqlite3 |[![Build Status](https://travis-ci.org/jhund/filterrific_demo.svg?branch=rails-4.2)](https://travis-ci.org/jhund/filterrific_demo)| +| Rails 4.1 | MRI 1.9.3, 2.0.0, 2.1.7, 2.2.3, 2.3.1 | mysql, mysql2, postgresql, sqlite3 |[![Build Status](https://travis-ci.org/jhund/filterrific_demo.svg?branch=rails-4.1)](https://travis-ci.org/jhund/filterrific_demo)| +| Rails 4.0 | MRI 1.9.3, 2.0.0, 2.1.7, 2.2.3, 2.3.1 | mysql, mysql2, postgresql, sqlite3 |[![Build Status](https://travis-ci.org/jhund/filterrific_demo.svg?branch=rails-4.0)](https://travis-ci.org/jhund/filterrific_demo)| +| Rails 3.2 | MRI 1.9.3, 2.0.0, 2.1.7 | mysql, mysql2, postgresql, sqlite3 |[![Build Status](https://travis-ci.org/jhund/filterrific_demo.svg?branch=rails-3.2)](https://travis-ci.org/jhund/filterrific_demo)| Filterrific version 1.x should work on older versions of Rails and Ruby, however the 1.x branch is not supported any more. @@ -43,7 +44,7 @@ Please post questions related to usage at [StackOverflow](http://stackoverflow.c If you think you've found a bug, or have a feature request, then create an issue here on Github. You'll make my job easier if you follow these guidelines: -* Please keep in mind that I do this in my spare time. I appreciate it if you first do everything you can on your own: read the detailed filterrific documentation, look for similar issues on StackOverflow, search the internets, etc. +* Please keep in mind that I do this in my spare time. I appreciate it if you first do everything you can on your own: read the detailed filterrific documentation, look for similar issues on StackOverflow, search the internets, etc. To you this software is free as in `beer`, to me it's free as in `baby`. * If you're stuck, give me sufficient context so that I have a chance to identify the issue: * what version of filterrific are you using? (look in your `Gemfile.lock`) * what version of Rails are you using? (look in your `Gemfile.lock`) @@ -75,4 +76,4 @@ If you think you've found a bug, or have a feature request, then create an issue ### Copyright -Copyright (c) 2010 - 2015 Jo Hund. See [(MIT) LICENSE](https://github.com/jhund/filterrific/blob/master/MIT-LICENSE) for details. +Copyright (c) 2010 - 2016 Jo Hund. See [(MIT) LICENSE](https://github.com/jhund/filterrific/blob/master/MIT-LICENSE) for details. From b520aaa369094925d34bc09b2b74389ea4c2b827 Mon Sep 17 00:00:00 2001 From: Jo Hund Date: Sun, 6 Nov 2016 17:34:53 -0800 Subject: [PATCH 18/33] Refactored and improved regex for casting string params to integer --- lib/filterrific/param_set.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/filterrific/param_set.rb b/lib/filterrific/param_set.rb index 5c4e527..14ee0e4 100644 --- a/lib/filterrific/param_set.rb +++ b/lib/filterrific/param_set.rb @@ -86,12 +86,12 @@ def condition_filterrific_params(fp) fp[key] = val.call when val.is_a?(Array) # type cast integers in the array - fp[key] = fp[key].map { |e| e =~ /\A-?\d+\z/ ? e.to_i : e } + fp[key] = fp[key].map { |e| e =~ integer_detector_regex ? e.to_i : e } when val.is_a?(Hash) # type cast Hash to OpenStruct so that nested params render correctly # in the form fp[key] = OpenStruct.new(fp[key]) - when val =~ /\A-?\d+\z/ + when val =~ integer_detector_regex # type cast integer fp[key] = fp[key].to_i end @@ -99,6 +99,11 @@ def condition_filterrific_params(fp) fp end + # Regex to detect if str represents and int + def integer_detector_regex + /\A-?([1-9]\d*|0)\z/ + end + # Defines attr accessors for each available_filter on self and assigns # values based on fp. # @param fp [Hash] filterrific_params with stringified keys From 74b0b47a8e5dd56e771a48d3725b99debfa33655 Mon Sep 17 00:00:00 2001 From: Jo Hund Date: Sun, 6 Nov 2016 17:51:49 -0800 Subject: [PATCH 19/33] Updated changelog --- CHANGELOG.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b0d1797..f4e3446 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ +## 2.1.0 + +* Updated filterrific for Rails 5 compatibility: + * Turbolinks compatibility (thanks @olegantonyan) + * Updated to Ruby 2.2.2 in CI test matrix + * Added Ruby 2.3.1 to CI test matrix (thanks @rodrigoargumedo) + * Fixed #stringify_keys deprecation warning (thanks @olegantonyan) +* When generating sorting headers, allow usage of HTML (e.g., for icons) using #safe_join (thanks @ScottKolo) +* Improved param casting to Int: hyphens and zeros (thanks @grit96) + + ### 2.0.5 * Feature: Allow disabling of session persistence by passing `false` as From 0c18426932477ebb2a2fc0cb1c89ca7e83ff80a6 Mon Sep 17 00:00:00 2001 From: Jo Hund Date: Sun, 6 Nov 2016 17:52:08 -0800 Subject: [PATCH 20/33] Bump to 2.1.0 --- lib/filterrific/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/filterrific/version.rb b/lib/filterrific/version.rb index 929aa22..2db5b2b 100644 --- a/lib/filterrific/version.rb +++ b/lib/filterrific/version.rb @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- module Filterrific - VERSION = "2.0.5" + VERSION = "2.1.0" end From 8cacc0652036c05d127034d299757344101d4d79 Mon Sep 17 00:00:00 2001 From: Jo Hund Date: Sun, 6 Nov 2016 18:25:49 -0800 Subject: [PATCH 21/33] Tweaked CI test matrix to test older Ruby versions only up to Rails 4.2 --- .travis.yml | 11 +++++++++++ Gemfile-Rails-4.2 | 5 +++++ 2 files changed, 16 insertions(+) create mode 100644 Gemfile-Rails-4.2 diff --git a/.travis.yml b/.travis.yml index cbef4de..1a55c08 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,3 +8,14 @@ rvm: - 2.1.7 - 2.2.3 - 2.3.1 +gemfile: + - Gemfile + - Gemfile-Rails-4.2 +matrix: + exclude: + - rvm: 1.9.3 + gemfile: Gemfile + - rvm: 2.0.0 + gemfile: Gemfile + - rvm: 2.1.7 + gemfile: Gemfile diff --git a/Gemfile-Rails-4.2 b/Gemfile-Rails-4.2 new file mode 100644 index 0000000..040f85a --- /dev/null +++ b/Gemfile-Rails-4.2 @@ -0,0 +1,5 @@ +source "https://rubygems.org" + +gem 'rails', '~> 4.2' + +gemspec From d2c2810860b5a5631cfb306505a3318c254d2274 Mon Sep 17 00:00:00 2001 From: Jo Hund Date: Sun, 6 Nov 2016 18:57:54 -0800 Subject: [PATCH 22/33] Further tweaked CI test matrix --- .travis.yml | 5 ++++- Gemfile-Rails-3.2 | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 Gemfile-Rails-3.2 diff --git a/.travis.yml b/.travis.yml index 1a55c08..933c3e3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,10 +9,13 @@ rvm: - 2.2.3 - 2.3.1 gemfile: - - Gemfile + - Gemfile-Rails-3.2 - Gemfile-Rails-4.2 + - Gemfile matrix: exclude: + - rvm: 1.9.3 + gemfile: Gemfile-Rails-4.2 - rvm: 1.9.3 gemfile: Gemfile - rvm: 2.0.0 diff --git a/Gemfile-Rails-3.2 b/Gemfile-Rails-3.2 new file mode 100644 index 0000000..e5180a7 --- /dev/null +++ b/Gemfile-Rails-3.2 @@ -0,0 +1,5 @@ +source "https://rubygems.org" + +gem 'rails', '~> 3.2' + +gemspec From b03c3fbb620274055a0c77bbef34243d69206353 Mon Sep 17 00:00:00 2001 From: Jo Hund Date: Sun, 6 Nov 2016 19:54:59 -0800 Subject: [PATCH 23/33] Changed how Gem dependencies are handled for the various Rails version tests: Use Gemfile instead of .gemspect --- .travis.yml | 10 +++++++--- Gemfile | 7 ++++++- Gemfile-Rails-3.2 | 5 ----- Gemfile-Rails-3.x | 8 ++++++++ Gemfile-Rails-4.2 | 5 ----- Gemfile-Rails-4.x | 8 ++++++++ filterrific.gemspec | 7 ------- 7 files changed, 29 insertions(+), 21 deletions(-) delete mode 100644 Gemfile-Rails-3.2 create mode 100644 Gemfile-Rails-3.x delete mode 100644 Gemfile-Rails-4.2 create mode 100644 Gemfile-Rails-4.x diff --git a/.travis.yml b/.travis.yml index 933c3e3..0a8b2fb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,13 +9,17 @@ rvm: - 2.2.3 - 2.3.1 gemfile: - - Gemfile-Rails-3.2 - - Gemfile-Rails-4.2 + - Gemfile-Rails-3.x + - Gemfile-Rails-4.x - Gemfile matrix: exclude: + - rvm: 2.2.3 + gemfile: Gemfile-Rails-3.x + - rvm: 2.3.1 + gemfile: Gemfile-Rails-3.x - rvm: 1.9.3 - gemfile: Gemfile-Rails-4.2 + gemfile: Gemfile-Rails-4.x - rvm: 1.9.3 gemfile: Gemfile - rvm: 2.0.0 diff --git a/Gemfile b/Gemfile index b4e2a20..a56ae23 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,8 @@ source "https://rubygems.org" -gemspec +gem 'rails' + +group :development, :test do + gem 'gem-release' + gem 'wwtd' # to simulate travis locally +end diff --git a/Gemfile-Rails-3.2 b/Gemfile-Rails-3.2 deleted file mode 100644 index e5180a7..0000000 --- a/Gemfile-Rails-3.2 +++ /dev/null @@ -1,5 +0,0 @@ -source "https://rubygems.org" - -gem 'rails', '~> 3.2' - -gemspec diff --git a/Gemfile-Rails-3.x b/Gemfile-Rails-3.x new file mode 100644 index 0000000..45bb301 --- /dev/null +++ b/Gemfile-Rails-3.x @@ -0,0 +1,8 @@ +source "https://rubygems.org" + +gem 'rails', '3.1.0' + +group :development, :test do + gem 'gem-release' + gem 'wwtd' # to simulate travis locally +end diff --git a/Gemfile-Rails-4.2 b/Gemfile-Rails-4.2 deleted file mode 100644 index 040f85a..0000000 --- a/Gemfile-Rails-4.2 +++ /dev/null @@ -1,5 +0,0 @@ -source "https://rubygems.org" - -gem 'rails', '~> 4.2' - -gemspec diff --git a/Gemfile-Rails-4.x b/Gemfile-Rails-4.x new file mode 100644 index 0000000..8c0047a --- /dev/null +++ b/Gemfile-Rails-4.x @@ -0,0 +1,8 @@ +source "https://rubygems.org" + +gem 'rails', '~> 4.2' + +group :development, :test do + gem 'gem-release' + gem 'wwtd' # to simulate travis locally +end diff --git a/filterrific.gemspec b/filterrific.gemspec index a96f134..d07d2f9 100644 --- a/filterrific.gemspec +++ b/filterrific.gemspec @@ -23,11 +23,4 @@ Gem::Specification.new do |gem| 'README*', '{app,bin,doc,lib,spec}/**/*' ] - - gem.add_dependency 'rails', ['>= 3.1.0'] - - gem.add_development_dependency 'bundler', ['>= 1.6.1'] - gem.add_development_dependency 'gem-release', ['>= 0.7.3'] - gem.add_development_dependency 'rake', ['>= 10.3.2'] - gem.add_development_dependency 'wwtd', ['>= 0.5.5'] # to simulate travis locally end From 78ec0e9020faaa3e221d80ffbb4996f3ce359c9a Mon Sep 17 00:00:00 2001 From: Jo Hund Date: Sun, 6 Nov 2016 20:09:04 -0800 Subject: [PATCH 24/33] =?UTF-8?q?Removed=20testing=20for=20Ruby=201.9.3.?= =?UTF-8?q?=20It=20should=20still=20work,=20however=20we=E2=80=99re=20not?= =?UTF-8?q?=20testing=20for=20it=20any=20more.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .travis.yml | 10 ---------- Gemfile-Rails-3.x | 8 -------- README.md | 16 +++++++++------- 3 files changed, 9 insertions(+), 25 deletions(-) delete mode 100644 Gemfile-Rails-3.x diff --git a/.travis.yml b/.travis.yml index 0a8b2fb..cc7ce78 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,25 +3,15 @@ language: ruby script: "bundle exec rake test" rvm: - - 1.9.3 - 2.0.0 - 2.1.7 - 2.2.3 - 2.3.1 gemfile: - - Gemfile-Rails-3.x - Gemfile-Rails-4.x - Gemfile matrix: exclude: - - rvm: 2.2.3 - gemfile: Gemfile-Rails-3.x - - rvm: 2.3.1 - gemfile: Gemfile-Rails-3.x - - rvm: 1.9.3 - gemfile: Gemfile-Rails-4.x - - rvm: 1.9.3 - gemfile: Gemfile - rvm: 2.0.0 gemfile: Gemfile - rvm: 2.1.7 diff --git a/Gemfile-Rails-3.x b/Gemfile-Rails-3.x deleted file mode 100644 index 45bb301..0000000 --- a/Gemfile-Rails-3.x +++ /dev/null @@ -1,8 +0,0 @@ -source "https://rubygems.org" - -gem 'rails', '3.1.0' - -group :development, :test do - gem 'gem-release' - gem 'wwtd' # to simulate travis locally -end diff --git a/README.md b/README.md index a9f18c4..de39252 100644 --- a/README.md +++ b/README.md @@ -26,17 +26,19 @@ or with bundler in your Gemfile: Every commit to Filterrific is automatically tested against the following scenarios: -| Rails version | Ruby environments | Database adapters | Build status | -|---------------|---------------------------------------|------------------------------------|--------------| -| Rails 5.x | MRI 1.9.3, 2.0.0, 2.1.7, 2.2.3, 2.3.1 | mysql2, postgresql, sqlite3 |[![Build Status](https://travis-ci.org/jhund/filterrific_demo.svg?branch=rails-5.x)](https://travis-ci.org/jhund/filterrific_demo)| -| Rails 4.2 | MRI 1.9.3, 2.0.0, 2.1.7, 2.2.3, 2.3.1 | mysql, mysql2, postgresql, sqlite3 |[![Build Status](https://travis-ci.org/jhund/filterrific_demo.svg?branch=rails-4.2)](https://travis-ci.org/jhund/filterrific_demo)| -| Rails 4.1 | MRI 1.9.3, 2.0.0, 2.1.7, 2.2.3, 2.3.1 | mysql, mysql2, postgresql, sqlite3 |[![Build Status](https://travis-ci.org/jhund/filterrific_demo.svg?branch=rails-4.1)](https://travis-ci.org/jhund/filterrific_demo)| -| Rails 4.0 | MRI 1.9.3, 2.0.0, 2.1.7, 2.2.3, 2.3.1 | mysql, mysql2, postgresql, sqlite3 |[![Build Status](https://travis-ci.org/jhund/filterrific_demo.svg?branch=rails-4.0)](https://travis-ci.org/jhund/filterrific_demo)| -| Rails 3.2 | MRI 1.9.3, 2.0.0, 2.1.7 | mysql, mysql2, postgresql, sqlite3 |[![Build Status](https://travis-ci.org/jhund/filterrific_demo.svg?branch=rails-3.2)](https://travis-ci.org/jhund/filterrific_demo)| +| Rails version | Ruby environments | Database adapters | Build status | +|---------------|--------------------------------|------------------------------------|--------------| +| Rails 5.x | MRI 2.0.0, 2.1.7, 2.2.3, 2.3.1 | mysql2, postgresql, sqlite3 |[![Build Status](https://travis-ci.org/jhund/filterrific_demo.svg?branch=rails-5.x)](https://travis-ci.org/jhund/filterrific_demo)| +| Rails 4.2 | MRI 2.0.0, 2.1.7, 2.2.3, 2.3.1 | mysql, mysql2, postgresql, sqlite3 |[![Build Status](https://travis-ci.org/jhund/filterrific_demo.svg?branch=rails-4.2)](https://travis-ci.org/jhund/filterrific_demo)| +| Rails 4.1 | MRI 2.0.0, 2.1.7, 2.2.3, 2.3.1 | mysql, mysql2, postgresql, sqlite3 |[![Build Status](https://travis-ci.org/jhund/filterrific_demo.svg?branch=rails-4.1)](https://travis-ci.org/jhund/filterrific_demo)| +| Rails 4.0 | MRI 2.0.0, 2.1.7, 2.2.3, 2.3.1 | mysql, mysql2, postgresql, sqlite3 |[![Build Status](https://travis-ci.org/jhund/filterrific_demo.svg?branch=rails-4.0)](https://travis-ci.org/jhund/filterrific_demo)| +| Rails 3.2 | MRI 2.0.0, 2.1.7 | mysql, mysql2, postgresql, sqlite3 |[![Build Status](https://travis-ci.org/jhund/filterrific_demo.svg?branch=rails-3.2)](https://travis-ci.org/jhund/filterrific_demo)| Filterrific version 1.x should work on older versions of Rails and Ruby, however the 1.x branch is not supported any more. +Filterrific up to version 2.1.0 should work on Ruby 1.9.3, however we're not testing it any more. Time to move on to a more current version of Ruby. + ### Guidelines for submitting issues From 6507aa680e20069b2533ee449c4735414ed95f5b Mon Sep 17 00:00:00 2001 From: Jo Hund Date: Thu, 10 Nov 2016 16:57:09 -0800 Subject: [PATCH 25/33] Updated readme, cosmetic code change --- README.md | 4 ++-- config/initializers/assets.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index de39252..151a371 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ Every commit to Filterrific is automatically tested against the following scenar | Rails version | Ruby environments | Database adapters | Build status | |---------------|--------------------------------|------------------------------------|--------------| -| Rails 5.x | MRI 2.0.0, 2.1.7, 2.2.3, 2.3.1 | mysql2, postgresql, sqlite3 |[![Build Status](https://travis-ci.org/jhund/filterrific_demo.svg?branch=rails-5.x)](https://travis-ci.org/jhund/filterrific_demo)| +| Rails 5.x | MRI 2.0.0, 2.1.7, 2.2.3, 2.3.1 | mysql2, postgresql |[![Build Status](https://travis-ci.org/jhund/filterrific_demo.svg?branch=rails-5.x)](https://travis-ci.org/jhund/filterrific_demo)| | Rails 4.2 | MRI 2.0.0, 2.1.7, 2.2.3, 2.3.1 | mysql, mysql2, postgresql, sqlite3 |[![Build Status](https://travis-ci.org/jhund/filterrific_demo.svg?branch=rails-4.2)](https://travis-ci.org/jhund/filterrific_demo)| | Rails 4.1 | MRI 2.0.0, 2.1.7, 2.2.3, 2.3.1 | mysql, mysql2, postgresql, sqlite3 |[![Build Status](https://travis-ci.org/jhund/filterrific_demo.svg?branch=rails-4.1)](https://travis-ci.org/jhund/filterrific_demo)| | Rails 4.0 | MRI 2.0.0, 2.1.7, 2.2.3, 2.3.1 | mysql, mysql2, postgresql, sqlite3 |[![Build Status](https://travis-ci.org/jhund/filterrific_demo.svg?branch=rails-4.0)](https://travis-ci.org/jhund/filterrific_demo)| @@ -46,7 +46,7 @@ Please post questions related to usage at [StackOverflow](http://stackoverflow.c If you think you've found a bug, or have a feature request, then create an issue here on Github. You'll make my job easier if you follow these guidelines: -* Please keep in mind that I do this in my spare time. I appreciate it if you first do everything you can on your own: read the detailed filterrific documentation, look for similar issues on StackOverflow, search the internets, etc. To you this software is free as in `beer`, to me it's free as in `baby`. +* Please keep in mind that I do this in my spare time. To you this software is free as in `beer`, to me it's free as in `baby`. I appreciate it if you first do everything you can on your own: read the detailed [Filterrific documentation](http://filterrific.clearcove.ca), look for similar issues on [StackOverflow](http://stackoverflow.com/questions/tagged/filterrific), search the internets, etc. * If you're stuck, give me sufficient context so that I have a chance to identify the issue: * what version of filterrific are you using? (look in your `Gemfile.lock`) * what version of Rails are you using? (look in your `Gemfile.lock`) diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index 488e928..f3f1a04 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -1 +1 @@ -Rails.application.config.assets.precompile += %w( filterrific/filterrific-spinner.gif ) +Rails.application.config.assets.precompile += %w(filterrific/filterrific-spinner.gif) From 8e2c176ce937576c5b04664041d646e5db14e697 Mon Sep 17 00:00:00 2001 From: Jo Hund Date: Fri, 11 Nov 2016 10:43:18 -0800 Subject: [PATCH 26/33] Reverted asset initialization back to working state for versions prior to Rails5 --- lib/filterrific/engine.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/filterrific/engine.rb b/lib/filterrific/engine.rb index fd73bf4..88baccc 100644 --- a/lib/filterrific/engine.rb +++ b/lib/filterrific/engine.rb @@ -31,8 +31,8 @@ class Engine < ::Rails::Engine # sprockets-rails 3 tracks down the calls to `font_path` and `image_path` # and automatically precompiles the referenced assets. unless Rails::VERSION::MAJOR < 5 - initializer "filterrific.assets.precompile" do |app| - app.config.assets.precompile += %w(filterrific/filterrific-spinner.gif) + initializer "filterrific" do |app| + app.config.assets.precompile += %w(filterrific-spinner.gif) end end From bb5953b592e67c3e7dad1c43d4b0ffc2eea7e7ef Mon Sep 17 00:00:00 2001 From: Jo Hund Date: Fri, 11 Nov 2016 10:44:06 -0800 Subject: [PATCH 27/33] Updated Changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f4e3446..f390c33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +### 2.1.1 + +* Reverted asset initialization back to working state for versions prior to Rails5. + ## 2.1.0 * Updated filterrific for Rails 5 compatibility: From 4458c0504719cde3a1dbf7523aa95eac0fe366ee Mon Sep 17 00:00:00 2001 From: Jo Hund Date: Fri, 11 Nov 2016 10:44:22 -0800 Subject: [PATCH 28/33] Bump to 2.1.1 --- lib/filterrific/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/filterrific/version.rb b/lib/filterrific/version.rb index 2db5b2b..5b0a546 100644 --- a/lib/filterrific/version.rb +++ b/lib/filterrific/version.rb @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- module Filterrific - VERSION = "2.1.0" + VERSION = "2.1.1" end From ec3d308c4cb60fa77620f9c39c519a4285f0b655 Mon Sep 17 00:00:00 2001 From: Jo Hund Date: Fri, 11 Nov 2016 12:18:47 -0800 Subject: [PATCH 29/33] Removed older way of initializing assets, relying on config/initializers/assets.rb for all versions of Rails. --- CHANGELOG.md | 4 ++++ lib/filterrific/engine.rb | 8 -------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f390c33..4f9d799 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +### 2.1.2 + +* Removed older way of initializing assets, relying on config/initializers/assets.rb for all versions of Rails. + ### 2.1.1 * Reverted asset initialization back to working state for versions prior to Rails5. diff --git a/lib/filterrific/engine.rb b/lib/filterrific/engine.rb index 88baccc..dba729a 100644 --- a/lib/filterrific/engine.rb +++ b/lib/filterrific/engine.rb @@ -28,13 +28,5 @@ class Engine < ::Rails::Engine extend Filterrific::ActiveRecordExtension end - # sprockets-rails 3 tracks down the calls to `font_path` and `image_path` - # and automatically precompiles the referenced assets. - unless Rails::VERSION::MAJOR < 5 - initializer "filterrific" do |app| - app.config.assets.precompile += %w(filterrific-spinner.gif) - end - end - end end From d48c91bf672639987b32f44dc95ad3a3b505f482 Mon Sep 17 00:00:00 2001 From: Jo Hund Date: Fri, 11 Nov 2016 12:19:15 -0800 Subject: [PATCH 30/33] Bump to 2.1.2 --- lib/filterrific/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/filterrific/version.rb b/lib/filterrific/version.rb index 5b0a546..2d46ba6 100644 --- a/lib/filterrific/version.rb +++ b/lib/filterrific/version.rb @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- module Filterrific - VERSION = "2.1.1" + VERSION = "2.1.2" end From 5564769304d24b98c5d5a07292c2f190f4b5aa96 Mon Sep 17 00:00:00 2001 From: Jo Hund Date: Fri, 11 Nov 2016 16:02:42 -0800 Subject: [PATCH 31/33] Updated Readme, dropped support and testing for Rails 3.x --- README.md | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 151a371..9915761 100644 --- a/README.md +++ b/README.md @@ -29,16 +29,11 @@ Every commit to Filterrific is automatically tested against the following scenar | Rails version | Ruby environments | Database adapters | Build status | |---------------|--------------------------------|------------------------------------|--------------| | Rails 5.x | MRI 2.0.0, 2.1.7, 2.2.3, 2.3.1 | mysql2, postgresql |[![Build Status](https://travis-ci.org/jhund/filterrific_demo.svg?branch=rails-5.x)](https://travis-ci.org/jhund/filterrific_demo)| -| Rails 4.2 | MRI 2.0.0, 2.1.7, 2.2.3, 2.3.1 | mysql, mysql2, postgresql, sqlite3 |[![Build Status](https://travis-ci.org/jhund/filterrific_demo.svg?branch=rails-4.2)](https://travis-ci.org/jhund/filterrific_demo)| -| Rails 4.1 | MRI 2.0.0, 2.1.7, 2.2.3, 2.3.1 | mysql, mysql2, postgresql, sqlite3 |[![Build Status](https://travis-ci.org/jhund/filterrific_demo.svg?branch=rails-4.1)](https://travis-ci.org/jhund/filterrific_demo)| -| Rails 4.0 | MRI 2.0.0, 2.1.7, 2.2.3, 2.3.1 | mysql, mysql2, postgresql, sqlite3 |[![Build Status](https://travis-ci.org/jhund/filterrific_demo.svg?branch=rails-4.0)](https://travis-ci.org/jhund/filterrific_demo)| -| Rails 3.2 | MRI 2.0.0, 2.1.7 | mysql, mysql2, postgresql, sqlite3 |[![Build Status](https://travis-ci.org/jhund/filterrific_demo.svg?branch=rails-3.2)](https://travis-ci.org/jhund/filterrific_demo)| +| Rails 4.x | MRI 2.0.0, 2.1.7, 2.2.3, 2.3.1 | mysql2, postgresql |[![Build Status](https://travis-ci.org/jhund/filterrific_demo.svg?branch=rails-4.x)](https://travis-ci.org/jhund/filterrific_demo)| -Filterrific version 1.x should work on older versions of Rails and Ruby, however -the 1.x branch is not supported any more. - -Filterrific up to version 2.1.0 should work on Ruby 1.9.3, however we're not testing it any more. Time to move on to a more current version of Ruby. +Filterrific up to version 2.1.x should work on Rails 3.2 and Ruby 1.9.3. I stopped testing it though as it became too cumbersome to manage gem dependencies. +Filterrific version 1.x should work on versions prior to Rails 3.2 and older Rubies, however the 1.x branch is not supported any more. ### Guidelines for submitting issues From 41ad41f930bec41e8e208d73451dd279f5a47bc9 Mon Sep 17 00:00:00 2001 From: hachpai Date: Mon, 30 Jan 2017 16:51:29 +0100 Subject: [PATCH 32/33] v2 --- lib/filterrific/active_record_extension.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/filterrific/active_record_extension.rb b/lib/filterrific/active_record_extension.rb index 34abfe3..6a20c90 100644 --- a/lib/filterrific/active_record_extension.rb +++ b/lib/filterrific/active_record_extension.rb @@ -66,9 +66,12 @@ def filterrific_find(filterrific_param_set) filterrific_available_filters.each do |filter_name| filter_param = filterrific_param_set.send(filter_name) next if filter_param.blank? # skip blank filter_params - ar_rel = ar_rel.send(filter_name, filter_param) + begin + ar_rel = ar_rel.send(filter_name, filter_param) + rescue ArgumentError #if we have a scope with arity 0 or enum query, we can perform the request without the parameter + ar_rel = ar_rel.send(filter_name) if (filter_param == 1) + end end - ar_rel end From 49af5fc2fc9b60069429e2c714551779fb7eb469 Mon Sep 17 00:00:00 2001 From: hachpai Date: Mon, 30 Jan 2017 16:57:15 +0100 Subject: [PATCH 33/33] v2.1 --- lib/filterrific/active_record_extension.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/filterrific/active_record_extension.rb b/lib/filterrific/active_record_extension.rb index 34abfe3..6a20c90 100644 --- a/lib/filterrific/active_record_extension.rb +++ b/lib/filterrific/active_record_extension.rb @@ -66,9 +66,12 @@ def filterrific_find(filterrific_param_set) filterrific_available_filters.each do |filter_name| filter_param = filterrific_param_set.send(filter_name) next if filter_param.blank? # skip blank filter_params - ar_rel = ar_rel.send(filter_name, filter_param) + begin + ar_rel = ar_rel.send(filter_name, filter_param) + rescue ArgumentError #if we have a scope with arity 0 or enum query, we can perform the request without the parameter + ar_rel = ar_rel.send(filter_name) if (filter_param == 1) + end end - ar_rel end