flip2 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/.rspec +1 -0
- data/.travis.yml +5 -0
- data/Gemfile +2 -0
- data/README.md +180 -0
- data/Rakefile +11 -0
- data/TODO +3 -0
- data/app/assets/stylesheets/flip.css +70 -0
- data/app/controllers/flip/features_controller.rb +47 -0
- data/app/controllers/flip/strategies_controller.rb +31 -0
- data/app/helpers/flip_helper.rb +9 -0
- data/app/views/flip/features/index.html.erb +62 -0
- data/config/routes.rb +14 -0
- data/flip.gemspec +27 -0
- data/lib/flip/abstract_strategy.rb +26 -0
- data/lib/flip/cacheable.rb +25 -0
- data/lib/flip/controller_filters.rb +25 -0
- data/lib/flip/cookie_strategy.rb +67 -0
- data/lib/flip/database_strategy.rb +46 -0
- data/lib/flip/declarable.rb +24 -0
- data/lib/flip/declaration_strategy.rb +20 -0
- data/lib/flip/definition.rb +21 -0
- data/lib/flip/engine.rb +9 -0
- data/lib/flip/facade.rb +18 -0
- data/lib/flip/feature_set.rb +57 -0
- data/lib/flip/forbidden.rb +7 -0
- data/lib/flip/version.rb +3 -0
- data/lib/flip2.rb +28 -0
- data/lib/generators/flip/install/install_generator.rb +9 -0
- data/lib/generators/flip/migration/USAGE +5 -0
- data/lib/generators/flip/migration/migration_generator.rb +22 -0
- data/lib/generators/flip/migration/templates/create_features.rb +11 -0
- data/lib/generators/flip/model/USAGE +8 -0
- data/lib/generators/flip/model/model_generator.rb +8 -0
- data/lib/generators/flip/model/templates/feature.rb +15 -0
- data/lib/generators/flip/routes/USAGE +7 -0
- data/lib/generators/flip/routes/routes_generator.rb +7 -0
- data/lib/generators/flip/views/USAGE +8 -0
- data/lib/generators/flip/views/templates/index.html.erb +54 -0
- data/lib/generators/flip/views/views_generator.rb +8 -0
- data/spec/abstract_strategy_spec.rb +11 -0
- data/spec/cacheable_spec.rb +49 -0
- data/spec/controller_filters_spec.rb +27 -0
- data/spec/cookie_strategy_spec.rb +112 -0
- data/spec/database_strategy_spec.rb +110 -0
- data/spec/declarable_spec.rb +32 -0
- data/spec/declaration_strategy_spec.rb +39 -0
- data/spec/definition_spec.rb +19 -0
- data/spec/feature_set_spec.rb +67 -0
- data/spec/flip_spec.rb +33 -0
- data/spec/spec_helper.rb +2 -0
- metadata +172 -0
@@ -0,0 +1,32 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Flip::Declarable do
|
4
|
+
|
5
|
+
let!(:model_class) do
|
6
|
+
Class.new do
|
7
|
+
extend Flip::Declarable
|
8
|
+
|
9
|
+
strategy Flip::DeclarationStrategy
|
10
|
+
default false
|
11
|
+
|
12
|
+
feature :one
|
13
|
+
feature :two, description: "Second one."
|
14
|
+
feature :three, default: true
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
subject { Flip::FeatureSet.instance }
|
19
|
+
|
20
|
+
describe "the .on? class method" do
|
21
|
+
context "with default set to false" do
|
22
|
+
it { should_not be_on(:one) }
|
23
|
+
it { should be_on(:three) }
|
24
|
+
end
|
25
|
+
context "with default set to true" do
|
26
|
+
before { model_class.send(:default, true) }
|
27
|
+
it { should be_on(:one) }
|
28
|
+
it { should be_on(:three) }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Flip::DeclarationStrategy do
|
4
|
+
|
5
|
+
def definition(default)
|
6
|
+
Flip::Definition.new :feature, default: default
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "#knows?" do
|
10
|
+
it "does not know definition with no default specified" do
|
11
|
+
subject.knows?(Flip::Definition.new :feature).should be false
|
12
|
+
end
|
13
|
+
it "does not know definition with default of nil" do
|
14
|
+
subject.knows?(definition(nil)).should be false
|
15
|
+
end
|
16
|
+
it "knows definition with default set to true" do
|
17
|
+
subject.knows?(definition(true)).should be true
|
18
|
+
end
|
19
|
+
it "knows definition with default set to false" do
|
20
|
+
subject.knows?(definition(false)).should be true
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#on? for Flip::Definition" do
|
25
|
+
subject { Flip::DeclarationStrategy.new.on? definition(default) }
|
26
|
+
[
|
27
|
+
{ default: true, result: true },
|
28
|
+
{ default: false, result: false },
|
29
|
+
{ default: proc { true }, result: true, name: "proc returning true" },
|
30
|
+
{ default: proc { false }, result: false, name: "proc returning false" },
|
31
|
+
].each do |parameters|
|
32
|
+
context "with default of #{parameters[:name] || parameters[:default]}" do
|
33
|
+
let(:default) { parameters[:default] }
|
34
|
+
it { should == parameters[:result] }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Flip::Definition do
|
4
|
+
|
5
|
+
subject { Flip::Definition.new :the_key, description: "The description" }
|
6
|
+
|
7
|
+
[:key, :name, :to_s].each do |method|
|
8
|
+
its(method) { should == :the_key }
|
9
|
+
end
|
10
|
+
|
11
|
+
its(:description) { should == "The description" }
|
12
|
+
its(:options) { should == { description: "The description" } }
|
13
|
+
|
14
|
+
context "without description specified" do
|
15
|
+
subject { Flip::Definition.new :the_key }
|
16
|
+
its(:description) { should == "The key." }
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
class NullStrategy < Flip::AbstractStrategy
|
4
|
+
def knows?(d); false; end
|
5
|
+
end
|
6
|
+
|
7
|
+
class TrueStrategy < Flip::AbstractStrategy
|
8
|
+
def knows?(d); true; end
|
9
|
+
def on?(d); true; end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe Flip::FeatureSet do
|
13
|
+
|
14
|
+
let :feature_set_with_null_strategy do
|
15
|
+
Flip::FeatureSet.new.tap do |s|
|
16
|
+
s << Flip::Definition.new(:feature)
|
17
|
+
s.add_strategy NullStrategy
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
let :feature_set_with_null_then_true_strategies do
|
22
|
+
feature_set_with_null_strategy.tap do |s|
|
23
|
+
s.add_strategy TrueStrategy
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe ".instance" do
|
28
|
+
it "returns a singleton instance" do
|
29
|
+
Flip::FeatureSet.instance.should equal(Flip::FeatureSet.instance)
|
30
|
+
end
|
31
|
+
it "can be reset" do
|
32
|
+
instance_before_reset = Flip::FeatureSet.instance
|
33
|
+
Flip::FeatureSet.reset
|
34
|
+
Flip::FeatureSet.instance.should_not equal(instance_before_reset)
|
35
|
+
end
|
36
|
+
it "can be reset multiple times without error" do
|
37
|
+
2.times { Flip::FeatureSet.reset }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "#default= and #on? with null strategy" do
|
42
|
+
subject { feature_set_with_null_strategy }
|
43
|
+
it "defaults to false" do
|
44
|
+
subject.on?(:feature).should be false
|
45
|
+
end
|
46
|
+
it "can default to true" do
|
47
|
+
subject.default = true
|
48
|
+
subject.on?(:feature).should be true
|
49
|
+
end
|
50
|
+
it "accepts a proc returning true" do
|
51
|
+
subject.default = proc { true }
|
52
|
+
subject.on?(:feature).should be true
|
53
|
+
end
|
54
|
+
it "accepts a proc returning false" do
|
55
|
+
subject.default = proc { false }
|
56
|
+
subject.on?(:feature).should be false
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "feature set with null strategy then always-true strategy" do
|
61
|
+
subject { feature_set_with_null_then_true_strategies }
|
62
|
+
it "returns true due to second strategy" do
|
63
|
+
subject.on?(:feature).should be true
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
data/spec/flip_spec.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Flip do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
Class.new do
|
7
|
+
extend Flip::Declarable
|
8
|
+
strategy Flip::DeclarationStrategy
|
9
|
+
default false
|
10
|
+
feature :one, default: true
|
11
|
+
feature :two, default: false
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
after(:all) do
|
16
|
+
Flip.reset
|
17
|
+
end
|
18
|
+
|
19
|
+
describe ".on?" do
|
20
|
+
it "returns true for enabled features" do
|
21
|
+
Flip.on?(:one).should be true
|
22
|
+
end
|
23
|
+
it "returns false for disabled features" do
|
24
|
+
Flip.on?(:two).should be false
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "dynamic predicate methods" do
|
29
|
+
its(:one?) { should be true }
|
30
|
+
its(:two?) { should be false }
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,172 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: flip2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ''
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-12-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '5.1'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.0'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '5.1'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: i18n
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rspec
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '2.5'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '2.5'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rspec-its
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: rake
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
description: Declarative API for specifying features, switchable in declaration, database
|
90
|
+
and cookies.
|
91
|
+
email:
|
92
|
+
- ''
|
93
|
+
executables: []
|
94
|
+
extensions: []
|
95
|
+
extra_rdoc_files: []
|
96
|
+
files:
|
97
|
+
- ".gitignore"
|
98
|
+
- ".rspec"
|
99
|
+
- ".travis.yml"
|
100
|
+
- Gemfile
|
101
|
+
- README.md
|
102
|
+
- Rakefile
|
103
|
+
- TODO
|
104
|
+
- app/assets/stylesheets/flip.css
|
105
|
+
- app/controllers/flip/features_controller.rb
|
106
|
+
- app/controllers/flip/strategies_controller.rb
|
107
|
+
- app/helpers/flip_helper.rb
|
108
|
+
- app/views/flip/features/index.html.erb
|
109
|
+
- config/routes.rb
|
110
|
+
- flip.gemspec
|
111
|
+
- lib/flip/abstract_strategy.rb
|
112
|
+
- lib/flip/cacheable.rb
|
113
|
+
- lib/flip/controller_filters.rb
|
114
|
+
- lib/flip/cookie_strategy.rb
|
115
|
+
- lib/flip/database_strategy.rb
|
116
|
+
- lib/flip/declarable.rb
|
117
|
+
- lib/flip/declaration_strategy.rb
|
118
|
+
- lib/flip/definition.rb
|
119
|
+
- lib/flip/engine.rb
|
120
|
+
- lib/flip/facade.rb
|
121
|
+
- lib/flip/feature_set.rb
|
122
|
+
- lib/flip/forbidden.rb
|
123
|
+
- lib/flip/version.rb
|
124
|
+
- lib/flip2.rb
|
125
|
+
- lib/generators/flip/install/install_generator.rb
|
126
|
+
- lib/generators/flip/migration/USAGE
|
127
|
+
- lib/generators/flip/migration/migration_generator.rb
|
128
|
+
- lib/generators/flip/migration/templates/create_features.rb
|
129
|
+
- lib/generators/flip/model/USAGE
|
130
|
+
- lib/generators/flip/model/model_generator.rb
|
131
|
+
- lib/generators/flip/model/templates/feature.rb
|
132
|
+
- lib/generators/flip/routes/USAGE
|
133
|
+
- lib/generators/flip/routes/routes_generator.rb
|
134
|
+
- lib/generators/flip/views/USAGE
|
135
|
+
- lib/generators/flip/views/templates/index.html.erb
|
136
|
+
- lib/generators/flip/views/views_generator.rb
|
137
|
+
- spec/abstract_strategy_spec.rb
|
138
|
+
- spec/cacheable_spec.rb
|
139
|
+
- spec/controller_filters_spec.rb
|
140
|
+
- spec/cookie_strategy_spec.rb
|
141
|
+
- spec/database_strategy_spec.rb
|
142
|
+
- spec/declarable_spec.rb
|
143
|
+
- spec/declaration_strategy_spec.rb
|
144
|
+
- spec/definition_spec.rb
|
145
|
+
- spec/feature_set_spec.rb
|
146
|
+
- spec/flip_spec.rb
|
147
|
+
- spec/spec_helper.rb
|
148
|
+
homepage: ''
|
149
|
+
licenses:
|
150
|
+
- MIT
|
151
|
+
metadata: {}
|
152
|
+
post_install_message:
|
153
|
+
rdoc_options: []
|
154
|
+
require_paths:
|
155
|
+
- lib
|
156
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
157
|
+
requirements:
|
158
|
+
- - ">="
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: '0'
|
161
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
163
|
+
- - ">="
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0'
|
166
|
+
requirements: []
|
167
|
+
rubyforge_project:
|
168
|
+
rubygems_version: 2.5.1
|
169
|
+
signing_key:
|
170
|
+
specification_version: 4
|
171
|
+
summary: A feature flipper for Rails web applications.
|
172
|
+
test_files: []
|