filterrific 2.0.1 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/lib/filterrific/action_controller_extension.rb +5 -4
- data/lib/filterrific/version.rb +1 -1
- data/spec/filterrific/action_controller_extension_spec.rb +106 -0
- data/spec/filterrific/action_view_extension_spec.rb +12 -7
- data/spec/filterrific/active_record_extension_spec.rb +6 -2
- data/spec/filterrific/param_set_spec.rb +12 -2
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22973115fb8e2d33a1d7e745f9fa8ec4e1fdb2f4
|
4
|
+
data.tar.gz: f08ad266412fa07cae094360180a0a02ec2e2ddd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0bbf1cebbbd731472e6cdf21e20b42c1134df780bb00bf12c37f49af828f101c47c77a9e9f1efcf5bfbbfa7f04fd667e4c3c751a6c1bdb14a251ca73f1563a0
|
7
|
+
data.tar.gz: b93b3eff9d9b1f278237d65ecaaaeef9a5897bd53acd78c0d86426aed9bbdd95a9b5640684a5fd44a356d56af4ab9da26547ca6162e92b1d3a6e3e3085f6ae11
|
data/CHANGELOG.md
CHANGED
@@ -37,7 +37,7 @@ module Filterrific
|
|
37
37
|
redirect_to url_for({}) and return false # works with `or return` in calling action.
|
38
38
|
end
|
39
39
|
|
40
|
-
f_params = compute_filterrific_params(model_class, f_params, opts)
|
40
|
+
f_params = compute_filterrific_params(model_class, f_params, opts, pi)
|
41
41
|
|
42
42
|
filterrific = Filterrific::ParamSet.new(model_class, f_params)
|
43
43
|
filterrific.select_options = opts['select_options']
|
@@ -55,14 +55,15 @@ module Filterrific
|
|
55
55
|
# @param model_class [ActiveRecord::Base]
|
56
56
|
# @param filterrific_params [Hash]
|
57
57
|
# @param opts [Hash]
|
58
|
-
|
58
|
+
# @param persistence_id [String]
|
59
|
+
def compute_filterrific_params(model_class, filterrific_params, opts, persistence_id)
|
59
60
|
r = (
|
60
61
|
filterrific_params.presence || # start with passed in params
|
61
|
-
session[
|
62
|
+
session[persistence_id].presence || # then try session persisted params
|
62
63
|
opts['default_filter_params'] || # then use passed in opts
|
63
64
|
model_class.filterrific_default_filter_params # finally use model_class defaults
|
64
65
|
).stringify_keys
|
65
|
-
r.slice!(opts['available_filters'].map(&:to_s)) if opts['available_filters']
|
66
|
+
r.slice!(*opts['available_filters'].map(&:to_s)) if opts['available_filters']
|
66
67
|
r
|
67
68
|
end
|
68
69
|
|
data/lib/filterrific/version.rb
CHANGED
@@ -0,0 +1,106 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'filterrific/action_controller_extension'
|
3
|
+
|
4
|
+
module Filterrific
|
5
|
+
|
6
|
+
class TestController
|
7
|
+
include ActionControllerExtension
|
8
|
+
def action_name; 'index'; end
|
9
|
+
def controller_name; 'test_controller'; end
|
10
|
+
def session
|
11
|
+
{
|
12
|
+
'test_controller#index' => {
|
13
|
+
'filter1' => '1_from_session',
|
14
|
+
'filter2' => '2_from_session',
|
15
|
+
}
|
16
|
+
}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class TestModelClass
|
21
|
+
def self.filterrific_available_filters; %w[filter1 filter2]; end
|
22
|
+
def self.filterrific_default_filter_params
|
23
|
+
{ 'filter1' => '1_from_model_defaults' }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe ActionControllerExtension do
|
28
|
+
|
29
|
+
describe '#initialize_filterrific' do
|
30
|
+
|
31
|
+
it 'returns a Filterrific::ParamSet' do
|
32
|
+
TestController.new.send(
|
33
|
+
:initialize_filterrific,
|
34
|
+
TestModelClass,
|
35
|
+
{ 'filter1' => 1, 'filter2' => 2 },
|
36
|
+
).must_be_instance_of(ParamSet)
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '#compute_default_persistence_id' do
|
42
|
+
|
43
|
+
it 'computes the default persistence id from controller_name and action_name' do
|
44
|
+
TestController.new.send(
|
45
|
+
:compute_default_persistence_id
|
46
|
+
).must_equal('test_controller#index')
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '#compute_filterrific_params' do
|
52
|
+
|
53
|
+
it 'uses filterrific_params if given' do
|
54
|
+
TestController.new.send(
|
55
|
+
:compute_filterrific_params,
|
56
|
+
TestModelClass,
|
57
|
+
{ 'filter1' => 1, 'filter2' => 2 },
|
58
|
+
{ },
|
59
|
+
'test_controller#index'
|
60
|
+
).must_equal({ 'filter1' => 1, 'filter2' => 2 })
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'uses session if filterrific_params are blank' do
|
64
|
+
TestController.new.send(
|
65
|
+
:compute_filterrific_params,
|
66
|
+
TestModelClass,
|
67
|
+
{},
|
68
|
+
{ },
|
69
|
+
'test_controller#index',
|
70
|
+
).must_equal({ 'filter1' => '1_from_session', 'filter2' => '2_from_session' })
|
71
|
+
end
|
72
|
+
|
73
|
+
it "uses opts['default_filter_params'] if session is blank" do
|
74
|
+
TestController.new.send(
|
75
|
+
:compute_filterrific_params,
|
76
|
+
TestModelClass,
|
77
|
+
{},
|
78
|
+
{ 'default_filter_params' => { 'filter1' => '1_from_opts' } },
|
79
|
+
'non existent persistence id to skip session',
|
80
|
+
).must_equal({ 'filter1' => '1_from_opts' })
|
81
|
+
end
|
82
|
+
|
83
|
+
it "uses model default_filter_params if opts is blank" do
|
84
|
+
TestController.new.send(
|
85
|
+
:compute_filterrific_params,
|
86
|
+
TestModelClass,
|
87
|
+
{},
|
88
|
+
{ },
|
89
|
+
'non existent persistence id to skip session',
|
90
|
+
).must_equal({ 'filter1' => '1_from_model_defaults' })
|
91
|
+
end
|
92
|
+
|
93
|
+
it "limits filter params to opts['available_filters']" do
|
94
|
+
TestController.new.send(
|
95
|
+
:compute_filterrific_params,
|
96
|
+
TestModelClass,
|
97
|
+
{ 'filter1' => 1, 'filter2' => 2 },
|
98
|
+
{ 'available_filters' => %w[filter1] },
|
99
|
+
'test_controller#index'
|
100
|
+
).must_equal({ 'filter1' => 1 })
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
end
|
@@ -9,15 +9,20 @@ module Filterrific
|
|
9
9
|
|
10
10
|
describe ActionViewExtension do
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
ViewContext.new.must_respond_to(:render_filterrific_spinner)
|
15
|
-
end
|
12
|
+
it 'responds to #form_for_filterrific' do
|
13
|
+
ViewContext.new.must_respond_to(:form_for_filterrific)
|
16
14
|
end
|
17
15
|
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
it 'responds to #render_filterrific_spinner' do
|
17
|
+
ViewContext.new.must_respond_to(:render_filterrific_spinner)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'responds to #filterrific_sorting_link' do
|
21
|
+
ViewContext.new.must_respond_to(:filterrific_sorting_link)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'responds to #reset_filterrific_url' do
|
25
|
+
ViewContext.new.must_respond_to(:reset_filterrific_url)
|
21
26
|
end
|
22
27
|
|
23
28
|
end
|
@@ -45,11 +45,15 @@ module Filterrific
|
|
45
45
|
describe "Filterrific initialization" do
|
46
46
|
|
47
47
|
it "initializes filterrific_available_filters" do
|
48
|
-
filterrific_class.filterrific_available_filters.must_equal(
|
48
|
+
filterrific_class.filterrific_available_filters.must_equal(
|
49
|
+
TestData.filterrific_available_filters
|
50
|
+
)
|
49
51
|
end
|
50
52
|
|
51
53
|
it "initializes filterrific_default_filter_params" do
|
52
|
-
filterrific_class.filterrific_default_filter_params.must_equal(
|
54
|
+
filterrific_class.filterrific_default_filter_params.must_equal(
|
55
|
+
TestData.filterrific_default_filter_params
|
56
|
+
)
|
53
57
|
end
|
54
58
|
|
55
59
|
it "raises when no filter_names are given" do
|
@@ -92,10 +92,18 @@ module Filterrific
|
|
92
92
|
|
93
93
|
end
|
94
94
|
|
95
|
+
describe 'find' do
|
96
|
+
it 'responds to #find' do
|
97
|
+
filterrific_param_set.must_respond_to(:find)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
95
101
|
describe "to_hash" do
|
96
102
|
|
97
103
|
it "returns all filterrific_params as hash" do
|
98
|
-
filterrific_param_set.to_hash.must_equal(
|
104
|
+
filterrific_param_set.to_hash.must_equal(
|
105
|
+
TestData.filterrific_params_after_sanitizing
|
106
|
+
)
|
99
107
|
end
|
100
108
|
|
101
109
|
end
|
@@ -103,7 +111,9 @@ module Filterrific
|
|
103
111
|
describe "to_json" do
|
104
112
|
|
105
113
|
it "returns all filterrific_params as json string" do
|
106
|
-
filterrific_param_set.to_json.must_equal(
|
114
|
+
filterrific_param_set.to_json.must_equal(
|
115
|
+
TestData.filterrific_params_after_sanitizing.to_json
|
116
|
+
)
|
107
117
|
end
|
108
118
|
|
109
119
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: filterrific
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jo Hund
|
@@ -109,6 +109,7 @@ files:
|
|
109
109
|
- lib/filterrific/engine.rb
|
110
110
|
- lib/filterrific/param_set.rb
|
111
111
|
- lib/filterrific/version.rb
|
112
|
+
- spec/filterrific/action_controller_extension_spec.rb
|
112
113
|
- spec/filterrific/action_view_extension_spec.rb
|
113
114
|
- spec/filterrific/active_record_extension_spec.rb
|
114
115
|
- spec/filterrific/param_set_spec.rb
|