filterrific 5.2.3 → 5.2.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,153 +1,136 @@
1
- require 'spec_helper'
2
- require 'filterrific/param_set'
1
+ require "spec_helper"
2
+ require "filterrific/param_set"
3
3
 
4
4
  module Filterrific
5
+ # Container for test data
6
+ class TestData
7
+ def self.filterrific_available_filters
8
+ %w[
9
+ filter_almost_int
10
+ filter_array_int
11
+ filter_array_string
12
+ filter_hash
13
+ filter_hyphen
14
+ filter_int
15
+ filter_negative_int
16
+ filter_proc
17
+ filter_string
18
+ filter_zero
19
+ ]
20
+ end
5
21
 
6
- describe ParamSet do
7
-
8
- # Container for test data
9
- class TestData
10
-
11
- def self.filterrific_available_filters
12
- %w[
13
- filter_almost_int
14
- filter_array_int
15
- filter_array_string
16
- filter_hash
17
- filter_hyphen
18
- filter_int
19
- filter_negative_int
20
- filter_proc
21
- filter_string
22
- filter_zero
23
- ]
24
- end
25
-
26
- def self.filterrific_default_filter_params
27
- { 'filter_int' => 42 }
28
- end
29
-
30
- def self.filterrific_params
31
- {
32
- 'filter_almost_int' => '042',
33
- 'filter_array_int' => %w[1 2 3],
34
- 'filter_array_string' => %w[one two three],
35
- 'filter_hash' => { a: 1, b: 2 },
36
- 'filter_hyphen' => '-',
37
- 'filter_int' => '42',
38
- 'filter_negative_int' => '-42',
39
- 'filter_proc' => lambda { 1 + 1 },
40
- 'filter_string' => 'forty-two',
41
- 'filter_zero' => '0',
42
- }
43
- end
44
-
45
- def self.filterrific_params_after_conditioning
46
- {
47
- 'filter_almost_int' => '042',
48
- 'filter_array_int' => [1, 2, 3],
49
- 'filter_array_string' => %w[one two three],
50
- 'filter_hash' => OpenStruct.new(a: 1, b: 2),
51
- 'filter_hyphen' => '-',
52
- 'filter_int' => 42,
53
- 'filter_negative_int' => -42,
54
- 'filter_proc' => 2,
55
- 'filter_string' => 'forty-two',
56
- 'filter_zero' => 0,
57
- }
58
- end
22
+ def self.filterrific_default_filter_params
23
+ {"filter_int" => 42}
24
+ end
59
25
 
60
- def self.filterrific_params_as_hash
61
- {
62
- 'filter_almost_int' => '042',
63
- 'filter_array_int' => [1, 2, 3],
64
- 'filter_array_string' => %w[one two three],
65
- 'filter_hash' => { a: 1, b: 2 },
66
- 'filter_hyphen' => '-',
67
- 'filter_int' => 42,
68
- 'filter_negative_int' => -42,
69
- 'filter_proc' => 2,
70
- 'filter_string' => 'forty-two',
71
- 'filter_zero' => 0,
72
- }
73
- end
26
+ def self.filterrific_params
27
+ {
28
+ "filter_almost_int" => "042",
29
+ "filter_array_int" => %w[1 2 3],
30
+ "filter_array_string" => %w[one two three],
31
+ "filter_hash" => {a: 1, b: 2},
32
+ "filter_hyphen" => "-",
33
+ "filter_int" => "42",
34
+ "filter_negative_int" => "-42",
35
+ "filter_proc" => lambda { 1 + 1 },
36
+ "filter_string" => "forty-two",
37
+ "filter_zero" => "0"
38
+ }
39
+ end
74
40
 
41
+ def self.filterrific_params_after_conditioning
42
+ {
43
+ "filter_almost_int" => "042",
44
+ "filter_array_int" => [1, 2, 3],
45
+ "filter_array_string" => %w[one two three],
46
+ "filter_hash" => OpenStruct.new(a: 1, b: 2),
47
+ "filter_hyphen" => "-",
48
+ "filter_int" => 42,
49
+ "filter_negative_int" => -42,
50
+ "filter_proc" => 2,
51
+ "filter_string" => "forty-two",
52
+ "filter_zero" => 0
53
+ }
75
54
  end
76
55
 
77
- # Simulates a class that would include the filterrific directive
78
- class ModelClass
56
+ def self.filterrific_params_as_hash
57
+ {
58
+ "filter_almost_int" => "042",
59
+ "filter_array_int" => [1, 2, 3],
60
+ "filter_array_string" => %w[one two three],
61
+ "filter_hash" => {a: 1, b: 2},
62
+ "filter_hyphen" => "-",
63
+ "filter_int" => 42,
64
+ "filter_negative_int" => -42,
65
+ "filter_proc" => 2,
66
+ "filter_string" => "forty-two",
67
+ "filter_zero" => 0
68
+ }
69
+ end
70
+ end
79
71
 
80
- def self.filterrific_default_filter_params
81
- TestData.filterrific_default_filter_params
82
- end
83
- def self.filterrific_available_filters
84
- TestData.filterrific_available_filters
85
- end
72
+ # Simulates a class that would include the filterrific directive
73
+ class ModelClass
74
+ def self.filterrific_default_filter_params
75
+ TestData.filterrific_default_filter_params
76
+ end
86
77
 
78
+ def self.filterrific_available_filters
79
+ TestData.filterrific_available_filters
87
80
  end
81
+ end
88
82
 
89
- let(:filterrific_param_set){
90
- Kernel::silence_warnings {
83
+ describe ParamSet do
84
+ let(:filterrific_param_set) {
85
+ Kernel.silence_warnings {
91
86
  Filterrific::ParamSet.new(ModelClass, TestData.filterrific_params)
92
87
  }
93
88
  }
94
89
 
95
90
  describe "initialization" do
96
-
97
91
  it "assigns resource class" do
98
92
  filterrific_param_set.model_class.must_equal(ModelClass)
99
93
  end
100
94
 
101
95
  describe "dynamic filter_name attr_accessors" do
102
-
103
96
  TestData.filterrific_available_filters.each do |filter_name|
104
-
105
- it "defines a getter for '#{ filter_name }'" do
97
+ it "defines a getter for '#{filter_name}'" do
106
98
  filterrific_param_set.must_respond_to(filter_name)
107
99
  end
108
100
 
109
- it "defines a setter for '#{ filter_name }'" do
110
- filterrific_param_set.must_respond_to("#{ filter_name }=")
101
+ it "defines a setter for '#{filter_name}'" do
102
+ filterrific_param_set.must_respond_to("#{filter_name}=")
111
103
  end
112
-
113
104
  end
114
105
 
115
106
  TestData.filterrific_params.keys.each do |key|
116
-
117
- it "assigns conditioned param to '#{ key }' attr" do
107
+ it "assigns conditioned param to '#{key}' attr" do
118
108
  filterrific_param_set.send(key).must_equal(TestData.filterrific_params_after_conditioning[key])
119
109
  end
120
-
121
110
  end
122
-
123
111
  end
124
-
125
112
  end
126
113
 
127
- describe 'find' do
128
- it 'responds to #find' do
114
+ describe "find" do
115
+ it "responds to #find" do
129
116
  filterrific_param_set.must_respond_to(:find)
130
117
  end
131
118
  end
132
119
 
133
120
  describe "to_hash" do
134
-
135
121
  it "returns all filterrific_params as hash" do
136
122
  filterrific_param_set.to_hash.must_equal(
137
123
  TestData.filterrific_params_as_hash
138
124
  )
139
125
  end
140
-
141
126
  end
142
127
 
143
128
  describe "to_json" do
144
-
145
129
  it "returns all filterrific_params as json string" do
146
130
  filterrific_param_set.to_json.must_equal(
147
131
  TestData.filterrific_params_as_hash.to_json
148
132
  )
149
133
  end
150
-
151
134
  end
152
135
 
153
136
  describe "#select_options" do
@@ -175,26 +158,23 @@ module Filterrific
175
158
  end
176
159
 
177
160
  describe "#condition_filterrific_params" do
178
-
179
161
  [
180
- [{ a_proc: lambda { 1 + 1 } }, { a_proc: 2 }],
181
- [{ an_array: [1, 'a'] }, { an_array: [1, 'a'] }],
182
- [{ a_hash: { 'a' => 1, 'b' => 2 } }, { a_hash: OpenStruct.new({ 'a' => 1, 'b' => 2 }) }],
183
- [{ a_string_that_looks_like_int: '123' }, { a_string_that_looks_like_int: 123 }],
184
- [{ a_string_that_looks_like_a_negative_int: '-123' }, { a_string_that_looks_like_a_negative_int: -123 }],
185
- [{ a_string_that_almost_looks_like_int: '0123' }, { a_string_that_almost_looks_like_int: '0123' }],
186
- [{ an_array_with_almost_int: ['0123', '123'] }, { an_array_with_almost_int: ['0123', 123] }],
187
- [{ a_string: 'abc' }, { a_string: 'abc' }],
162
+ [{a_proc: lambda { 1 + 1 }}, {a_proc: 2}],
163
+ [{an_array: [1, "a"]}, {an_array: [1, "a"]}],
164
+ [{a_hash: {"a" => 1, "b" => 2}}, {a_hash: OpenStruct.new({"a" => 1, "b" => 2})}],
165
+ [{a_string_that_looks_like_int: "123"}, {a_string_that_looks_like_int: 123}],
166
+ [{a_string_that_looks_like_a_negative_int: "-123"}, {a_string_that_looks_like_a_negative_int: -123}],
167
+ [{a_string_that_almost_looks_like_int: "0123"}, {a_string_that_almost_looks_like_int: "0123"}],
168
+ [{an_array_with_almost_int: ["0123", "123"]}, {an_array_with_almost_int: ["0123", 123]}],
169
+ [{a_string: "abc"}, {a_string: "abc"}]
188
170
  ].each do |test_params, xpect|
189
- it "Handles #{ test_params.inspect }" do
171
+ it "Handles #{test_params.inspect}" do
190
172
  filterrific_param_set.send(
191
173
  :condition_filterrific_params,
192
174
  test_params
193
175
  ).must_equal(xpect)
194
176
  end
195
177
  end
196
-
197
178
  end
198
-
199
179
  end
200
180
  end
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe Filterrific do
4
4
  end
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  ENV["RAILS_ENV"] = "test"
2
- require 'bundler/setup'
3
- require 'minitest/autorun'
4
- require 'rails'
5
- require 'filterrific'
2
+ require "bundler/setup"
3
+ require "minitest/autorun"
4
+ require "rails"
5
+ require "filterrific"
6
6
 
7
- #MiniTest::Unit.autorun
7
+ # MiniTest::Unit.autorun
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: filterrific
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.2.3
4
+ version: 5.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jo Hund
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-18 00:00:00.000000000 Z
11
+ date: 2023-01-30 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Filterrific is a Rails Engine plugin that makes it easy to filter, search,
14
14
  and sort your ActiveRecord lists.
@@ -22,7 +22,7 @@ files:
22
22
  - README.md
23
23
  - Rakefile
24
24
  - app/assets/images/filterrific/filterrific-spinner.gif
25
- - app/assets/javascripts/filterrific/filterrific-jquery.js
25
+ - app/assets/javascripts/filterrific/filterrific.js
26
26
  - bin/rails
27
27
  - doc/Overview diagram.graffle/data.plist
28
28
  - doc/Overview diagram.graffle/image1.tiff
@@ -1,118 +0,0 @@
1
- /**
2
- * Javascript behaviors for Filterrific.
3
- * http://filterrific.clearcove.ca
4
- *
5
- * Requires jQuery 1.7.0 or later.
6
- *
7
- * Released under the MIT license
8
- *
9
- */
10
-
11
-
12
-
13
- // Create global Filterrific namespace
14
- if (typeof Filterrific === 'undefined') {
15
- var Filterrific = {};
16
- }
17
-
18
-
19
-
20
- // Define function to submit Filterrific filter form
21
- Filterrific.submitFilterForm = function(){
22
- var form = $(this).parents("form"),
23
- url = form.attr("action");
24
- // send before event
25
- $(form).trigger('loadingFilterrificResults');
26
- // turn on spinner
27
- $('.filterrific_spinner').show();
28
-
29
- // Abort previous ajax request
30
- if (Filterrific.lastRequest && Filterrific.lastRequest.readyState != 4) {
31
- Filterrific.lastRequest.abort();
32
- }
33
-
34
- // Submit ajax request
35
- Filterrific.lastRequest = $.ajax({
36
- url: url,
37
- data: form.serialize(),
38
- type: 'GET',
39
- dataType: 'script'
40
- }).done(function( msg ) {
41
- // send after event
42
- $(form).trigger('loadedFilterrificResults');
43
- $('.filterrific_spinner').hide();
44
- });
45
- };
46
-
47
-
48
-
49
- //
50
- // Embed jquery.observe_field.js to observe Filterrific filter inputs
51
- //
52
- // Copied from https://github.com/splendeo/jquery.observe_field
53
- // Wrap in immediately invoked function for compatibility with other js libraries
54
- //
55
- (function($) {
56
-
57
- $.fn.filterrific_observe_field = function(frequency, callback) {
58
- frequency = frequency * 1000; // translate to milliseconds
59
- return this.each(function(){
60
- var $this = $(this);
61
- var prev = $this.val();
62
- var check = function() {
63
- if(removed()){ // if removed clear the interval and don't fire the callback
64
- if(ti) clearInterval(ti);
65
- return;
66
- }
67
- var val = $this.val();
68
- if(prev != val){
69
- prev = val;
70
- $this.map(callback); // invokes the callback on $this
71
- }
72
- };
73
- var removed = function() {
74
- return $this.closest('html').length == 0
75
- };
76
- var reset = function() {
77
- if(ti){
78
- clearInterval(ti);
79
- ti = setInterval(check, frequency);
80
- }
81
- };
82
- check();
83
- var ti = setInterval(check, frequency); // invoke check periodically
84
- // reset counter after user interaction
85
- $this.bind('keyup click mousemove', reset); //mousemove is for selects
86
- });
87
- };
88
- })(jQuery);
89
-
90
-
91
- Filterrific.init = function() {
92
- // Add change event handler to all Filterrific filter inputs.
93
- $('#filterrific_filter').on(
94
- "change",
95
- ":input",
96
- Filterrific.submitFilterForm
97
- );
98
-
99
- // Add periodic observer to selected inputs.
100
- // Use this for text fields you want to observe for change, e.g., a search input.
101
- $(".filterrific-periodically-observed").filterrific_observe_field(
102
- 0.5,
103
- Filterrific.submitFilterForm
104
- );
105
- };
106
-
107
-
108
- // Initialize event observers on document ready and turbolinks page:load
109
- jQuery(document).on('turbolinks:load', function() {
110
- // Prevent double initilisation. With turbolinks 5 this function
111
- // will be called twice: on 'ready' and 'turbolinks:load'
112
- jQuery(document).off('ready page:load')
113
- Filterrific.init();
114
- });
115
-
116
- jQuery(document).on('ready page:load', function() {
117
- Filterrific.init();
118
- });