split_cacheable 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/split_cacheable/version.rb +1 -1
- data/lib/split_cacheable.rb +4 -1
- data/spec/cacheable_spec.rb +20 -10
- data/spec/spec_helper.rb +7 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 514a9d878ce909f2c3de0c556c52caf32804cc75
|
4
|
+
data.tar.gz: 0ddd41fcdb78e194904ab73a07cd69c7d83ee66d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f781f6ea770b92cfdc324e6683f56eb849bb17df545c9ee1f19b65d19aff7baae0d349333afcb5306e8f3be11ac16320fed8ca2e7ecac77ad620a116360b4e0e
|
7
|
+
data.tar.gz: 4e1510714732bc8d7c5a240acbfc418323a89854e9d098085fcbe89d1a6ed59aaee0e12505470fba6fc0db8f72b09fba3e4fec5513af3c6f979b26c86b6c912d
|
data/lib/split_cacheable.rb
CHANGED
@@ -80,10 +80,13 @@ module Split
|
|
80
80
|
when 0
|
81
81
|
return [DEFAULT_KEY]
|
82
82
|
when 1
|
83
|
+
test_variations[0].unshift(DEFAULT_KEY)
|
83
84
|
return test_variations[0]
|
84
85
|
else
|
85
86
|
first_test = test_variations.shift
|
86
|
-
|
87
|
+
all_variations = first_test.product(*test_variations).map{|a| a.join("/")}
|
88
|
+
all_variations.unshift(DEFAULT_KEY)
|
89
|
+
return all_variations
|
87
90
|
end
|
88
91
|
end
|
89
92
|
end
|
data/spec/cacheable_spec.rb
CHANGED
@@ -1,29 +1,39 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Split::Cacheable do
|
4
|
-
ALL_VARIATIONS = ["test_1/old/test_2/left", "test_1/old/test_2/right", "test_1/new/test_2/left", "test_1/new/test_2/right"]
|
4
|
+
ALL_VARIATIONS = [Split::Cacheable::Adapter::DEFAULT_KEY, "test_1/old/test_2/left", "test_1/old/test_2/right", "test_1/new/test_2/left", "test_1/new/test_2/right"]
|
5
5
|
|
6
6
|
it "should return the default variation if there is no request" do
|
7
|
-
Split::Cacheable::Adapter.new(TestControllerWithoutRequest.new, :index).get_current_variations.
|
7
|
+
expect(Split::Cacheable::Adapter.new(TestControllerWithoutRequest.new, :index).get_current_variations).to eql Split::Cacheable::Adapter::DEFAULT_KEY
|
8
8
|
end
|
9
9
|
|
10
10
|
it "should return a possible active variation if the controller has a request" do
|
11
|
-
ALL_VARIATIONS.
|
11
|
+
expect(ALL_VARIATIONS).to include(Split::Cacheable::Adapter.new(TestControllerWithRequest.new, :index).get_current_variations)
|
12
12
|
end
|
13
13
|
|
14
14
|
it "should return all active tests for a controller/action combination" do
|
15
|
-
Split::Cacheable::Adapter.new(TestControllerWithRequest.new, :index).active_tests.
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should return all possible variations of the cachekey" do
|
19
|
-
Split::Cacheable::Adapter.new(TestControllerWithoutRequest.new, :index).get_all_possible_variations.should eql ALL_VARIATIONS
|
15
|
+
expect(Split::Cacheable::Adapter.new(TestControllerWithRequest.new, :index).active_tests).to eql [{:only=>[:index], :except=>[], :test_name=>:test_1}, {:only=>[], :except=>[:show], :test_name=>:test_2}]
|
20
16
|
end
|
21
17
|
|
22
18
|
it "should disregard tests that don't pass the :if Proc" do
|
23
19
|
controller = TestControllerWithRequestAndProc.new
|
24
|
-
Split::Cacheable::Adapter.new(controller, :index).get_current_variations.
|
20
|
+
expect(Split::Cacheable::Adapter.new(controller, :index).get_current_variations).to eql Split::Cacheable::Adapter::DEFAULT_KEY
|
25
21
|
|
26
22
|
controller.instance_variable_set("@mobile_device", true)
|
27
|
-
ALL_VARIATIONS.
|
23
|
+
expect(ALL_VARIATIONS).to include(Split::Cacheable::Adapter.new(TestControllerWithRequest.new, :index).get_current_variations)
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "get_all_possible_variations method" do
|
27
|
+
it "should return all possible variations of the cachekey" do
|
28
|
+
expect(Split::Cacheable::Adapter.new(TestControllerWithoutRequest.new, :index).get_all_possible_variations).to eql ALL_VARIATIONS
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should return the default key when there are no variations" do
|
32
|
+
expect(Split::Cacheable::Adapter.new(TestControllerWithNoVariations.new, :index).get_all_possible_variations).to eql [Split::Cacheable::Adapter::DEFAULT_KEY]
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should return one test plus the default key when there is one test" do
|
36
|
+
expect(Split::Cacheable::Adapter.new(TestControllerWithOneVariation.new, :index).get_all_possible_variations).to eql [Split::Cacheable::Adapter::DEFAULT_KEY, "test_1/old", "test_1/new"]
|
37
|
+
end
|
28
38
|
end
|
29
39
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -47,6 +47,13 @@ class TestControllerWithoutRequest
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
+
class TestControllerWithNoVariations < TestControllerWithoutRequest
|
51
|
+
end
|
52
|
+
|
53
|
+
class TestControllerWithOneVariation < TestControllerWithoutRequest
|
54
|
+
cacheable_ab_test :test_1, :only => :index
|
55
|
+
end
|
56
|
+
|
50
57
|
class TestControllerWithRequest < TestControllerWithoutRequest
|
51
58
|
cacheable_ab_test :test_1, :only => :index
|
52
59
|
cacheable_ab_test :test_2, :except => :show
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: split_cacheable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Schwartz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: split
|
@@ -136,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
136
|
version: '0'
|
137
137
|
requirements: []
|
138
138
|
rubyforge_project:
|
139
|
-
rubygems_version: 2.
|
139
|
+
rubygems_version: 2.0.14
|
140
140
|
signing_key:
|
141
141
|
specification_version: 4
|
142
142
|
summary: We use action caching in Rails 3 to cache both our standard and mobile site.
|