flip 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -27,7 +27,7 @@ module Flip
27
27
  end
28
28
 
29
29
  def self.cookies= cookies
30
- @@cookies = cookies
30
+ @cookies = cookies
31
31
  end
32
32
 
33
33
  def cookie_name(definition)
@@ -38,16 +38,22 @@ module Flip
38
38
  private
39
39
 
40
40
  def cookies
41
- @@cookies || raise("Cookies not loaded")
41
+ self.class.instance_variable_get(:@cookies) || {}
42
42
  end
43
43
 
44
44
  # Include in ApplicationController to push cookies into CookieStrategy.
45
+ # Users before_filter and after_filter rather than around_filter to
46
+ # avoid pointlessly adding to stack depth.
45
47
  module Loader
46
48
  extend ActiveSupport::Concern
47
- included { around_filter :cookie_feature_strategy }
48
- def cookie_feature_strategy
49
+ included do
50
+ before_filter :flip_cookie_strategy_before
51
+ after_filter :flip_cookie_strategy_after
52
+ end
53
+ def flip_cookie_strategy_before
49
54
  CookieStrategy.cookies = cookies
50
- yield
55
+ end
56
+ def flip_cookie_strategy_after
51
57
  CookieStrategy.cookies = nil
52
58
  end
53
59
  end
@@ -1,3 +1,3 @@
1
1
  module Flip
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -2,7 +2,8 @@ require "spec_helper"
2
2
 
3
3
  class ControllerWithoutCookieStrategy; end
4
4
  class ControllerWithCookieStrategy
5
- def self.around_filter(_); end
5
+ def self.before_filter(_); end
6
+ def self.after_filter(_); end
6
7
  def cookies; []; end
7
8
  include Flip::CookieStrategy::Loader
8
9
  end
@@ -73,33 +74,39 @@ end
73
74
 
74
75
  describe Flip::CookieStrategy::Loader do
75
76
 
76
- it "adds around_filter when included in controller" do
77
+ it "adds filters when included in controller" do
77
78
  ControllerWithoutCookieStrategy.tap do |klass|
78
- klass.should_receive(:around_filter).with(:cookie_feature_strategy)
79
+ klass.should_receive(:before_filter).with(:flip_cookie_strategy_before)
80
+ klass.should_receive(:after_filter).with(:flip_cookie_strategy_after)
79
81
  klass.send :include, Flip::CookieStrategy::Loader
80
82
  end
81
83
  end
82
84
 
83
- describe "#cookie_feature_strategy as around_filter" do
84
-
85
+ describe "filter methods" do
85
86
  let(:strategy) { Flip::CookieStrategy.new }
86
87
  let(:controller) { ControllerWithCookieStrategy.new }
87
-
88
- it "yields to block" do
89
- run = false
90
- ControllerWithCookieStrategy.new.cookie_feature_strategy { run = true }
91
- run.should be_true
88
+ describe "#flip_cookie_strategy_before" do
89
+ it "passes controller cookies to CookieStrategy" do
90
+ controller.should_receive(:cookies).and_return(strategy.cookie_name(:test) => "true")
91
+ expect {
92
+ controller.flip_cookie_strategy_before
93
+ }.to change {
94
+ [ strategy.knows?(:test), strategy.on?(:test) ]
95
+ }.from([false, false]).to([true, true])
96
+ end
92
97
  end
93
-
94
- it "passes controller cookies to Flip::CookieStrategy" do
95
- controller.should_receive(:cookies).and_return(strategy.cookie_name(:test) => "true")
96
- results = []
97
- controller.cookie_feature_strategy {
98
- results << strategy.on?(:test)
99
- results << strategy.on?(:different)
100
- }
101
- results.should == [ true, false ]
98
+ describe "#flip_cookie_strategy_after" do
99
+ before do
100
+ Flip::CookieStrategy.cookies = { strategy.cookie_name(:test) => "true" }
101
+ end
102
+ it "passes controller cookies to CookieStrategy" do
103
+ expect {
104
+ controller.flip_cookie_strategy_after
105
+ }.to change {
106
+ [ strategy.knows?(:test), strategy.on?(:test) ]
107
+ }.from([true, true]).to([false, false])
108
+ end
102
109
  end
103
-
104
110
  end
111
+
105
112
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-11-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &70134752968140 !ruby/object:Gem::Requirement
16
+ requirement: &70214336000200 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70134752968140
24
+ version_requirements: *70214336000200
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: i18n
27
- requirement: &70134752967220 !ruby/object:Gem::Requirement
27
+ requirement: &70214335999180 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70134752967220
35
+ version_requirements: *70214335999180
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &70134752966320 !ruby/object:Gem::Requirement
38
+ requirement: &70214335997480 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '2.5'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70134752966320
46
+ version_requirements: *70214335997480
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rake
49
- requirement: &70134752965900 !ruby/object:Gem::Requirement
49
+ requirement: &70214335996600 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70134752965900
57
+ version_requirements: *70214335996600
58
58
  description: Declarative API for specifying features, switchable in declaration, database
59
59
  and cookies.
60
60
  email: