action_param_caching 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -0
- data/lib/action_param_caching/action_config.rb +1 -1
- data/lib/action_param_caching/version.rb +1 -1
- data/spec/action_config_spec.rb +25 -23
- data/spec/rails/action_controller_spec.rb +4 -1
- 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: af2efb7d4b2e8e93e987c154450467fc5a6cd033
|
4
|
+
data.tar.gz: 54c135c51ef4f9675ef95972ebfdee17179dc605
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33378ceee82abfb723d4a21cba13eb61adb0a40946107b20d7314506d45e55e7d048231de2fe381e1e022f86b02655c7fe38bc67a02fc4e6dbafaa3894c88ad9
|
7
|
+
data.tar.gz: e79cae2094f1ae7845b356489854ba459c187e7f85081e90b7bdff8e67f836e5fc3a9a31db371cd8367f54512e349772404299ca29efd4a688e67e13b7fb1cf1
|
data/.travis.yml
ADDED
@@ -15,7 +15,7 @@ module ActionParamCaching
|
|
15
15
|
|
16
16
|
def initialize(controller_path, action, valid_params = [], filter_starting_with = nil)
|
17
17
|
@action = action
|
18
|
-
if valid_params
|
18
|
+
if valid_params and !valid_params.empty?
|
19
19
|
@valid_params = valid_params
|
20
20
|
@valid_params << :controller << :action << :format
|
21
21
|
end
|
data/spec/action_config_spec.rb
CHANGED
@@ -4,21 +4,21 @@ module ActionParamCaching
|
|
4
4
|
describe ActionConfig do
|
5
5
|
context "in order to track the cache configuration of an action" do
|
6
6
|
it "is initialized with valid params, an action, and a prefix filter" do
|
7
|
-
cache_config = ActionParamCaching::ActionConfig.new(:index,[:id, :name, :amount], '_')
|
7
|
+
cache_config = ActionParamCaching::ActionConfig.new("some_controller", :index,[:id, :name, :amount], '_')
|
8
8
|
cache_config.action.should == :index
|
9
|
-
cache_config.valid_params.should == [:id, :name, :amount]
|
9
|
+
cache_config.valid_params.should == [:id, :name, :amount, :controller, :action, :format]
|
10
10
|
cache_config.filter_starting_with.should == '_'
|
11
11
|
end
|
12
12
|
|
13
13
|
it "sets the correct default values for valid params and prefix filters" do
|
14
|
-
cache_config = ActionParamCaching::ActionConfig.new(:index)
|
14
|
+
cache_config = ActionParamCaching::ActionConfig.new("some_controller", :index)
|
15
15
|
cache_config.action.should == :index
|
16
|
-
cache_config.valid_params.should ==
|
17
|
-
cache_config.filter_starting_with.should
|
16
|
+
cache_config.valid_params.should == nil
|
17
|
+
cache_config.filter_starting_with.should == '_'
|
18
18
|
end
|
19
19
|
|
20
20
|
it "tracks if a cache has been configured" do
|
21
|
-
cache_config = ActionParamCaching::ActionConfig.new(:index)
|
21
|
+
cache_config = ActionParamCaching::ActionConfig.new("some_controller", :index)
|
22
22
|
cache_config.did_config_cache.should be_false
|
23
23
|
cache_config.did_config_cache = true
|
24
24
|
cache_config.did_config_cache.should be_true
|
@@ -27,55 +27,57 @@ module ActionParamCaching
|
|
27
27
|
|
28
28
|
context "when generating action cache arguments" do
|
29
29
|
it "has an if condition when you specify valid params" do
|
30
|
-
cache_config = ActionParamCaching::ActionConfig.new(:index,[:id, :name, :amount], '_')
|
30
|
+
cache_config = ActionParamCaching::ActionConfig.new("some_controller", :index,[:id, :name, :amount], '_')
|
31
31
|
cache_args = cache_config.cache_args
|
32
32
|
cache_args[:if].should be
|
33
33
|
end
|
34
34
|
|
35
35
|
it "does not have an if condition if you don't specify valid params" do
|
36
|
-
cache_config = ActionParamCaching::ActionConfig.new(
|
36
|
+
cache_config = ActionParamCaching::ActionConfig.new("some_controller",:index)
|
37
37
|
cache_args = cache_config.cache_args
|
38
38
|
cache_args[:if].should be_nil
|
39
39
|
end
|
40
40
|
|
41
41
|
it "has a the correct cache path when stripping params with a prefix" do
|
42
|
-
cache_config = ActionParamCaching::ActionConfig.new(:index,[:id, :name, :amount], '_')
|
43
|
-
|
44
|
-
|
45
|
-
cache_config.stubs(:params).returns( {:_remove_me => true} )
|
42
|
+
cache_config = ActionParamCaching::ActionConfig.new("some_controller", :index,[:id, :name, :amount], '_')
|
43
|
+
request = mock
|
44
|
+
request.stubs(:params).returns( {:_remove_me => true, :controller => "some_controller", :action => :index, :format => 'json'} )
|
46
45
|
cache_args = cache_config.cache_args
|
47
46
|
proc = cache_args[:cache_path]
|
48
|
-
proc.call(
|
47
|
+
proc.call(request).should == {:controller => "some_controller", :action => :index, :format => 'json'}.to_query
|
49
48
|
end
|
50
49
|
|
51
50
|
it "has a the correct cache path under normal conditions" do
|
52
|
-
cache_config = ActionParamCaching::ActionConfig.new(:index,[:id, :name, :amount])
|
51
|
+
cache_config = ActionParamCaching::ActionConfig.new("some_controller", :index,[:id, :name, :amount])
|
53
52
|
cache_args = cache_config.cache_args
|
54
|
-
|
53
|
+
request = mock
|
54
|
+
request.stubs(:params).returns( {:_remove_me => false, :controller => "some_controller", :action => :index, :format => 'json'} )
|
55
55
|
proc = cache_args[:cache_path]
|
56
|
-
proc.call(
|
56
|
+
proc.call(request).should == {:controller => "some_controller", :action => :index, :format => 'json'}.to_query
|
57
57
|
end
|
58
58
|
|
59
59
|
it "does not have a if argument if the valid params are empty" do
|
60
|
-
cache_config = ActionParamCaching::ActionConfig.new(:index)
|
60
|
+
cache_config = ActionParamCaching::ActionConfig.new("some_controller", :index)
|
61
61
|
cache_args = cache_config.cache_args
|
62
62
|
cache_args[:if].should be_nil
|
63
63
|
end
|
64
64
|
|
65
65
|
it "does have an if argument that returns true if the params are a subset of the valid params" do
|
66
|
-
cache_config = ActionParamCaching::ActionConfig.new(:index,[:id, :name, :amount])
|
66
|
+
cache_config = ActionParamCaching::ActionConfig.new("some_controller", :index,[:id, :name, :amount])
|
67
67
|
cache_args = cache_config.cache_args
|
68
|
-
|
68
|
+
request = mock
|
69
|
+
request.stubs(:params).returns( {:id => 23, :name => "test", :controller => "some_controller", :action => :index, :format => 'json'} )
|
69
70
|
proc = cache_args[:if]
|
70
|
-
proc.call.should be_true
|
71
|
+
proc.call(request).should be_true
|
71
72
|
end
|
72
73
|
|
73
74
|
it "does have an if argument that returns false if the params are not a subset of the valid params" do
|
74
|
-
cache_config = ActionParamCaching::ActionConfig.new(:index,[:id, :name, :amount])
|
75
|
+
cache_config = ActionParamCaching::ActionConfig.new("some_controller", :index,[:id, :name, :amount])
|
75
76
|
cache_args = cache_config.cache_args
|
76
|
-
|
77
|
+
request = mock
|
78
|
+
request.stubs(:params).returns( {:id => 23, :name => "test", :not => "valid", :controller => "some_controller", :action => :index, :format => 'json'} )
|
77
79
|
proc = cache_args[:if]
|
78
|
-
proc.call.should be_false
|
80
|
+
proc.call(request).should be_false
|
79
81
|
end
|
80
82
|
end
|
81
83
|
end
|
@@ -4,6 +4,9 @@ class TestController
|
|
4
4
|
extend ActionParamCaching::Rails::ActionController
|
5
5
|
def self.caches_action(action, args)
|
6
6
|
end
|
7
|
+
def self.controller_path
|
8
|
+
"some_controller"
|
9
|
+
end
|
7
10
|
end
|
8
11
|
|
9
12
|
module ActionParamCaching
|
@@ -20,7 +23,7 @@ module ActionParamCaching
|
|
20
23
|
|
21
24
|
it "provided a means to set a set or subset or params to cache on" do
|
22
25
|
TestController.cache_with_params :on => [:test2], :with_set_or_subset => [:param1, :param2]
|
23
|
-
TestController.action_cache_configs[:test2].valid_params.should == [:param1, :param2]
|
26
|
+
TestController.action_cache_configs[:test2].valid_params.should == [:param1, :param2, :controller, :action, :format]
|
24
27
|
end
|
25
28
|
|
26
29
|
it "provides a means to filter params that have a prefix" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: action_param_caching
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- cparratto
|
@@ -102,6 +102,7 @@ extensions: []
|
|
102
102
|
extra_rdoc_files: []
|
103
103
|
files:
|
104
104
|
- .gitignore
|
105
|
+
- .travis.yml
|
105
106
|
- Gemfile
|
106
107
|
- LICENSE.txt
|
107
108
|
- README.md
|