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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 11a56a1d6587f1b007103d3f23906fe5cda61466
4
- data.tar.gz: 7f33fc8e000fe7f7969cc6b8dfd057e6364c0518
3
+ metadata.gz: 22973115fb8e2d33a1d7e745f9fa8ec4e1fdb2f4
4
+ data.tar.gz: f08ad266412fa07cae094360180a0a02ec2e2ddd
5
5
  SHA512:
6
- metadata.gz: 812ea2580b378e23db574823a3fa561d116773392698a7b5fa51e3bbbc90a7053fe000dc98622e15666d85b6e81a11e4560b08d578e7449e84a3d1de50a2728e
7
- data.tar.gz: df6c4d694d297697fd3befc2702af6b65094a0631e457f22732cc44e216fb5c98b29c520a1ca23e754917675f46cca349d69ec6bb87f76ababed04791797bd8d
6
+ metadata.gz: e0bbf1cebbbd731472e6cdf21e20b42c1134df780bb00bf12c37f49af828f101c47c77a9e9f1efcf5bfbbfa7f04fd667e4c3c751a6c1bdb14a251ca73f1563a0
7
+ data.tar.gz: b93b3eff9d9b1f278237d65ecaaaeef9a5897bd53acd78c0d86426aed9bbdd95a9b5640684a5fd44a356d56af4ab9da26547ca6162e92b1d3a6e3e3085f6ae11
@@ -39,6 +39,13 @@
39
39
  },
40
40
  )
41
41
 
42
+ ### 2.0.2
43
+
44
+ * Fixed bugs in ActionControllerExtension
45
+ * Improved test coverage
46
+
47
+
48
+
42
49
  ### 2.0.1
43
50
 
44
51
  * Fixed regression with Rails 3.2 (doesn't support `#deep_stringify_keys`)
@@ -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
- def compute_filterrific_params(model_class, filterrific_params, opts)
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[pi].presence || # then try session persisted params
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
 
@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  module Filterrific
4
- VERSION = "2.0.1"
4
+ VERSION = "2.0.2"
5
5
  end
@@ -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
- describe '#render_filterrific_spinner' do
13
- it "renders filterrific spinner" do
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
- describe '#filterrific_sorting_link' do
19
- it 'changes sorting on new column' do
20
- end
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(TestData.filterrific_available_filters)
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(TestData.filterrific_default_filter_params)
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(TestData.filterrific_params_after_sanitizing)
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(TestData.filterrific_params_after_sanitizing.to_json)
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.1
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