gc_feature 0.1.0 → 0.1.1

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: 6236d11dc915cc89796a37af66249e7042ec92f7
4
- data.tar.gz: 98dbec8f839afaac094b0ae374be00d7fec7a1d0
3
+ metadata.gz: 7c90998fd597fd87517a277484f5a39ccc47ae00
4
+ data.tar.gz: c69e6385c85ceb340e52cb8501e323a67bead6f2
5
5
  SHA512:
6
- metadata.gz: efa2c92794a0d65024bc3959fb0bafe7f4248adf39f07d5cfa042de29ccbd17ec3aac13b7712158f4d2bc626b1ddb0b3ecf5a1ef257830b6eef6e938a9fce2bc
7
- data.tar.gz: 17079bf0e911a6f56257e4ec81392f6bbe51e0500f949986a75f17acbce16a460972c2117b338e3fec904a7f5111d129c0a29fa34a708bcd891e72083e3b2f6f
6
+ metadata.gz: 1363247971532d67446182e722d90a4d7886a955b5fd0d0517f535777333183327fcd9601df498d13db6fabc8452e7bce4b2a7456527e75b0ea8ea203e0e147e
7
+ data.tar.gz: c58e4f405350569c844be64f02588a61a3c7c8ca15d8f04d8e677293311978022cb6facf14688a722b89f48073ff8fa605038f84b5a3946e612722edd3b4c035
@@ -0,0 +1,6 @@
1
+ rvm:
2
+ - 2.0.0
3
+ - 1.9.3
4
+ services: redis-server
5
+ script:
6
+ - bundle exec rspec
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
data/README.md CHANGED
@@ -1,11 +1,13 @@
1
1
  # Feature
2
+ [![Gem Version](https://badge.fury.io/rb/gc_feature.png)](http://badge.fury.io/rb/gc_feature)
3
+ [![Build Status](https://travis-ci.org/gocardless/feature.png?branch=master)](https://travis-ci.org/gocardless/feature)
2
4
 
3
5
  A group based feature switching framework.
4
6
 
5
7
  ## Installation
6
8
 
7
9
  ```console
8
- $ gem install feature
10
+ $ gem install gc_feature
9
11
  ```
10
12
 
11
13
  ## Usage
@@ -67,9 +69,9 @@ Just call `enable` or `disable` on a `Feature`.
67
69
 
68
70
  ```ruby
69
71
  Feature(:v2_design).enable
70
- Feature(:v2_design).enabled? # => true
72
+ Feature(:v2_design).enabled? # => true
71
73
  Feature(:v2_design).disable
72
- Feature(:v2_design).enabled? # => false
74
+ Feature(:v2_design).enabled? # => false
73
75
  ```
74
76
 
75
77
  ### Changing Groups membership at runtime
@@ -9,10 +9,14 @@ Gem::Specification.new do |gem|
9
9
  gem.homepage = 'https://github.com/gocardless/feature'
10
10
 
11
11
  gem.add_dependency 'redis-namespace', '~> 1.2'
12
- gem.add_dependency 'sinatra', '~> 1.3.2'
12
+ gem.add_dependency 'sinatra', '~> 1.3'
13
+ # See https://github.com/sinatra/sinatra/pull/907
14
+ # Remove when sinatra hits 1.4.6
15
+ gem.add_dependency 'rack', '< 1.6.0'
13
16
 
14
- gem.add_development_dependency 'rspec', '~> 2.11'
15
- gem.add_development_dependency 'mocha', '~> 0.12'
17
+ gem.add_development_dependency 'rspec', '~> 3.1'
18
+ gem.add_development_dependency 'mocha', '~> 1.1'
19
+ gem.add_development_dependency 'rack-test', '~> 0.6.2'
16
20
 
17
21
  gem.files = `git ls-files`.split("\n")
18
22
  gem.test_files = `git ls-files -- spec/*`.split("\n")
@@ -55,6 +55,11 @@ module Feature
55
55
  redirect to("/groups/#{@group}")
56
56
  end
57
57
 
58
+ not_found do
59
+ status 404
60
+ 'Not found.'
61
+ end
62
+
58
63
  private
59
64
 
60
65
  def set_group
@@ -18,7 +18,7 @@
18
18
  <a href="<%= url("groups/#{group}") %>">
19
19
  <code>:<%= group %></code>
20
20
  </a>
21
- <% end -%>
21
+ <% end %>
22
22
  <% else %>
23
23
  <span class="muted">-</span>
24
24
  <% end %>
@@ -1,3 +1,3 @@
1
1
  module Feature
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.1.1'.freeze
3
3
  end
@@ -14,12 +14,12 @@ describe Feature::Config do
14
14
 
15
15
  it "adds features to the feature definitions list" do
16
16
  subject.feature :foo, default: :on
17
- subject.features.should include :foo
17
+ expect(subject.features).to include :foo
18
18
  end
19
19
 
20
20
  it "defaults 'default' to true" do
21
21
  subject.feature :foo
22
- subject.features[:foo][:default].should be_true
22
+ expect(subject.features[:foo][:default]).to eq(true)
23
23
  end
24
24
 
25
25
  it "accepts definitions with no options" do
@@ -29,7 +29,7 @@ describe Feature::Config do
29
29
  it "sets backend_obj to the given backend" do
30
30
  backend = stub
31
31
  subject.backend backend
32
- subject.backend_obj.should == backend
32
+ expect(subject.backend_obj).to eq(backend)
33
33
  end
34
34
  end
35
35
  end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+ require 'feature/dashboard'
3
+ require 'rack/test'
4
+
5
+ describe 'The Dashboard App' do
6
+ include Rack::Test::Methods
7
+
8
+ def app
9
+ Feature::Dashboard
10
+ end
11
+
12
+ before do
13
+ Feature.configure do
14
+ backend Feature::RedisBackend.new($redis)
15
+ feature :foo, default: false, groups: %w(beta_users employees)
16
+ end
17
+ end
18
+
19
+ context "index" do
20
+ subject { get '/' }
21
+ specify { expect(subject.status).to eq(200) }
22
+ end
23
+
24
+ context "when the page can't be found" do
25
+ subject { get '/groups' }
26
+ specify { expect(subject.status).to eq(404) }
27
+ end
28
+ end
@@ -12,11 +12,11 @@ describe Feature::RedisBackend do
12
12
  describe "#initialize" do
13
13
  context "with a namespaced redis connection" do
14
14
  subject do
15
- ns = Redis::Namespace.new "ns", $redis
15
+ ns = Redis::Namespace.new("ns", redis: $redis)
16
16
  Feature::RedisBackend.new(ns)
17
17
  end
18
18
  it "uses the namespaced connection" do
19
- redis.namespace.should == "ns"
19
+ expect(redis.namespace).to eq("ns")
20
20
  end
21
21
  end
22
22
 
@@ -25,7 +25,7 @@ describe Feature::RedisBackend do
25
25
  Feature::RedisBackend.new($redis, namespace: 'feature-test')
26
26
  end
27
27
  it "creates a new namespaced connection" do
28
- redis.namespace.should == "feature-test"
28
+ expect(redis.namespace).to eq("feature-test")
29
29
  end
30
30
  end
31
31
 
@@ -40,7 +40,7 @@ describe Feature::RedisBackend do
40
40
  it "clears out any set keys" do
41
41
  redis.set('foo', 'bar')
42
42
  subject.reset!
43
- redis.get('foo').should be_nil
43
+ expect(redis.get('foo')).to be_nil
44
44
  end
45
45
  end
46
46
 
@@ -49,11 +49,11 @@ describe Feature::RedisBackend do
49
49
  before { redis.set('foo', 'enabled') }
50
50
 
51
51
  it "returns true with true as the default" do
52
- subject.enabled?(:foo, default: true).should be_true
52
+ expect(subject.enabled?(:foo, default: true)).to eq(true)
53
53
  end
54
54
 
55
55
  it "returns true with false as the default" do
56
- subject.enabled?(:foo, default: false).should be_true
56
+ expect(subject.enabled?(:foo, default: false)).to eq(true)
57
57
  end
58
58
  end
59
59
 
@@ -61,21 +61,21 @@ describe Feature::RedisBackend do
61
61
  before { redis.set('foo', 'disabled') }
62
62
 
63
63
  it "returns false with true as the default" do
64
- subject.enabled?(:foo, default: true).should be_false
64
+ expect(subject.enabled?(:foo, default: true)).to eq(false)
65
65
  end
66
66
 
67
67
  it "returns false with false as the default" do
68
- subject.enabled?(:foo, default: false).should be_false
68
+ expect(subject.enabled?(:foo, default: false)).to eq(false)
69
69
  end
70
70
  end
71
71
 
72
72
  context "when the feature is missing from redis" do
73
73
  it "returns true with true as the default" do
74
- subject.enabled?(:foo, default: true).should be_true
74
+ expect(subject.enabled?(:foo, default: true)).to eq(true)
75
75
  end
76
76
 
77
77
  it "returns false with false as the default" do
78
- subject.enabled?(:foo, default: false).should be_false
78
+ expect(subject.enabled?(:foo, default: false)).to eq(false)
79
79
  end
80
80
  end
81
81
 
@@ -85,7 +85,7 @@ describe Feature::RedisBackend do
85
85
 
86
86
  result = subject.enabled?(:foo, groups: [:employees],
87
87
  for: 'alan')
88
- result.should be_true
88
+ expect(result).to eq(true)
89
89
  end
90
90
 
91
91
  context "when globally disabled" do
@@ -94,7 +94,7 @@ describe Feature::RedisBackend do
94
94
  context "with groups passed" do
95
95
  it "returns false with no group members passed" do
96
96
  result = subject.enabled?(:foo, groups: ["foo"], default: false)
97
- result.should be_false
97
+ expect(result).to eq(false)
98
98
  end
99
99
  end
100
100
 
@@ -102,26 +102,26 @@ describe Feature::RedisBackend do
102
102
  subject.add_to_group('employees', 'alan')
103
103
  result = subject.enabled?(:foo, groups: [:employees, :beta],
104
104
  for: 'alan')
105
- result.should be_true
105
+ expect(result).to eq(true)
106
106
  end
107
107
 
108
108
  it "returns false if not enabled in any of the groups" do
109
109
  result = subject.enabled?(:foo, groups: [:employees, :beta],
110
110
  for: 'alan')
111
- result.should be_false
111
+ expect(result).to eq(false)
112
112
  end
113
113
 
114
114
  context "when for_any option is passed" do
115
115
  it "returns false if not enabled for any items" do
116
- subject.enabled?(:foo, for_any: true, for_any: ["a", "b"])
117
- .should be_false
116
+ expect(subject.enabled?(:foo, for_any: true, for_any: ["a", "b"])).
117
+ to eq(false)
118
118
  end
119
119
 
120
120
  it "returns true if enabled for one item" do
121
121
  subject.add_to_group('employees', 'alan')
122
122
  result = subject.enabled?(:foo, groups: [:employees],
123
123
  for_any: ["alan", "andy"])
124
- result.should be_true
124
+ expect(result).to eq(true)
125
125
  end
126
126
  end
127
127
 
@@ -132,26 +132,26 @@ describe Feature::RedisBackend do
132
132
  describe "#enable" do
133
133
  it "enables a previously unspecified feature" do
134
134
  subject.enable(:foo)
135
- subject.enabled?(:foo, default: false).should be_true
135
+ expect(subject.enabled?(:foo, default: false)).to eq(true)
136
136
  end
137
137
 
138
138
  it "enables a previously disabled feature" do
139
139
  redis.set('foo', 'disabled')
140
140
  subject.enable(:foo)
141
- subject.enabled?(:foo, default: false).should be_true
141
+ expect(subject.enabled?(:foo, default: false)).to eq(true)
142
142
  end
143
143
  end
144
144
 
145
145
  describe "#disable" do
146
146
  it "disables a previously unspecified feature" do
147
147
  subject.disable(:foo)
148
- subject.enabled?(:foo, default: true).should be_false
148
+ expect(subject.enabled?(:foo, default: true)).to eq(false)
149
149
  end
150
150
 
151
151
  it "enables a previously disabled feature" do
152
152
  redis.set('foo', 'enabled')
153
153
  subject.disable(:foo)
154
- subject.enabled?(:foo, default: true).should be_false
154
+ expect(subject.enabled?(:foo, default: true)).to eq(false)
155
155
  end
156
156
  end
157
157
 
@@ -161,7 +161,7 @@ describe Feature::RedisBackend do
161
161
  subject.add_to_group('admin', 'a')
162
162
  subject.add_to_group('admin', 'b')
163
163
 
164
- redis.smembers(subject.group_key('admin')).should include('a', 'b')
164
+ expect(redis.smembers(subject.group_key('admin'))).to include('a', 'b')
165
165
  end
166
166
  end
167
167
 
@@ -172,7 +172,7 @@ describe Feature::RedisBackend do
172
172
  subject.add_to_group('admin', 'b')
173
173
 
174
174
  subject.remove_from_group('admin', 'b')
175
- redis.smembers(subject.group_key('admin')).should == ['a']
175
+ expect(redis.smembers(subject.group_key('admin'))).to eq(['a'])
176
176
  end
177
177
  end
178
178
 
@@ -183,32 +183,32 @@ describe Feature::RedisBackend do
183
183
  end
184
184
 
185
185
  it "lists group members" do
186
- subject.get_group_members("admin").should == %w(1 2)
186
+ expect(subject.get_group_members("admin")).to eq(%w(1 2))
187
187
  end
188
188
  end
189
189
 
190
190
  describe "#group_key" do
191
191
  it "prefixes the redis key with 'group:'" do
192
- subject.group_key('admin').should start_with('group:')
192
+ expect(subject.group_key('admin')).to start_with('group:')
193
193
  end
194
194
  end
195
195
 
196
196
  describe "#in_group?" do
197
197
  it "returns false if the group is not defined" do
198
- subject.in_group?('admin', '1').should be_false
198
+ expect(subject.in_group?('admin', '1')).to eq(false)
199
199
  end
200
200
 
201
201
  context "with one item" do
202
202
  it "returns false if is not the group" do
203
203
  subject.add_to_group('admin', '1')
204
204
 
205
- subject.in_group?('admin', '2').should be_false
205
+ expect(subject.in_group?('admin', '2')).to eq(false)
206
206
  end
207
207
 
208
208
  it "returns true if is in the group" do
209
209
  subject.add_to_group('admin', '1')
210
210
 
211
- subject.in_group?('admin', '1').should be_true
211
+ expect(subject.in_group?('admin', '1')).to eq(true)
212
212
  end
213
213
  end
214
214
 
@@ -216,34 +216,34 @@ describe Feature::RedisBackend do
216
216
  it "returns false if all are not in the group" do
217
217
  subject.add_to_group('admin', '1')
218
218
 
219
- subject.in_group?('admin', ['1', '2']).should be_false
219
+ expect(subject.in_group?('admin', ['1', '2'])).to eq(false)
220
220
  end
221
221
 
222
222
  it "returns true if all are in the group" do
223
223
  subject.add_to_group('admin', '1')
224
224
  subject.add_to_group('admin', '2')
225
225
 
226
- subject.in_group?('admin', ['1', '2']).should be_true
226
+ expect(subject.in_group?('admin', ['1', '2'])).to eq(true)
227
227
  end
228
228
  end
229
229
  end
230
230
 
231
231
  describe "#any_in_group?" do
232
232
  it "returns false if the group is not defined" do
233
- subject.any_in_group?('admin', ['1']).should be_false
233
+ expect(subject.any_in_group?('admin', ['1'])).to eq(false)
234
234
  end
235
235
 
236
236
  it "returns true if one is in the group" do
237
237
  subject.add_to_group('admin', '1')
238
238
 
239
- subject.any_in_group?('admin', ['1', '2']).should be_true
239
+ expect(subject.any_in_group?('admin', ['1', '2'])).to eq(true)
240
240
  end
241
241
 
242
242
  it "returns true if all are in the group" do
243
243
  subject.add_to_group('admin', '1')
244
244
  subject.add_to_group('admin', '2')
245
245
 
246
- subject.any_in_group?('admin', ['1', '2']).should be_true
246
+ expect(subject.any_in_group?('admin', ['1', '2'])).to eq(true)
247
247
  end
248
248
  end
249
249
  end
@@ -36,7 +36,7 @@ describe Feature do
36
36
 
37
37
  describe ".features" do
38
38
  it "returns the feature definition hash" do
39
- described_class.features.should include(foo: {default: true})
39
+ expect(described_class.features).to include(foo: {default: true})
40
40
  end
41
41
  end
42
42
 
@@ -68,7 +68,7 @@ describe Feature do
68
68
  end
69
69
 
70
70
  context "given an valid name" do
71
- specify { Feature(:foo).should be_a Feature::Feature }
71
+ specify { expect(Feature(:foo)).to be_a Feature::Feature }
72
72
  end
73
73
  end
74
74
  end
@@ -1,4 +1,4 @@
1
- require 'mocha_standalone'
1
+ require 'mocha/api'
2
2
  require 'redis'
3
3
  require 'feature'
4
4
 
metadata CHANGED
@@ -1,71 +1,99 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gc_feature
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Harry Marr
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-13 00:00:00.000000000 Z
11
+ date: 2015-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis-namespace
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: sinatra
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.3.2
33
+ version: '1.3'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 1.3.2
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rack
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "<"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.6.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "<"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.6.0
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rspec
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
- - - ~>
59
+ - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: '2.11'
61
+ version: '3.1'
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
- - - ~>
66
+ - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: '2.11'
68
+ version: '3.1'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: mocha
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
- - - ~>
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.1'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.1'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rack-test
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
60
88
  - !ruby/object:Gem::Version
61
- version: '0.12'
89
+ version: 0.6.2
62
90
  type: :development
63
91
  prerelease: false
64
92
  version_requirements: !ruby/object:Gem::Requirement
65
93
  requirements:
66
- - - ~>
94
+ - - "~>"
67
95
  - !ruby/object:Gem::Version
68
- version: '0.12'
96
+ version: 0.6.2
69
97
  description:
70
98
  email:
71
99
  - developers@gocardless.com
@@ -73,7 +101,8 @@ executables: []
73
101
  extensions: []
74
102
  extra_rdoc_files: []
75
103
  files:
76
- - .gitignore
104
+ - ".gitignore"
105
+ - ".travis.yml"
77
106
  - Gemfile
78
107
  - README.md
79
108
  - circle.yml
@@ -91,6 +120,7 @@ files:
91
120
  - lib/feature/version.rb
92
121
  - lib/gc_feature.rb
93
122
  - spec/feature/config_spec.rb
123
+ - spec/feature/dashboard_spec.rb
94
124
  - spec/feature/feature_spec.rb
95
125
  - spec/feature/redis_backend_spec.rb
96
126
  - spec/feature_spec.rb
@@ -104,22 +134,23 @@ require_paths:
104
134
  - lib
105
135
  required_ruby_version: !ruby/object:Gem::Requirement
106
136
  requirements:
107
- - - '>='
137
+ - - ">="
108
138
  - !ruby/object:Gem::Version
109
139
  version: '0'
110
140
  required_rubygems_version: !ruby/object:Gem::Requirement
111
141
  requirements:
112
- - - '>='
142
+ - - ">="
113
143
  - !ruby/object:Gem::Version
114
144
  version: '0'
115
145
  requirements: []
116
146
  rubyforge_project:
117
- rubygems_version: 2.0.3
147
+ rubygems_version: 2.2.2
118
148
  signing_key:
119
149
  specification_version: 4
120
150
  summary: A basic feature switching framework
121
151
  test_files:
122
152
  - spec/feature/config_spec.rb
153
+ - spec/feature/dashboard_spec.rb
123
154
  - spec/feature/feature_spec.rb
124
155
  - spec/feature/redis_backend_spec.rb
125
156
  - spec/feature_spec.rb