toggles 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/features/nested_attributes.yml +12 -0
- data/lib/toggles/feature/permissions/operation/attribute.rb +6 -2
- data/lib/toggles/feature/permissions.rb +2 -6
- data/lib/toggles/feature/subject.rb +1 -1
- data/spec/toggles/feature/base_spec.rb +2 -1
- data/spec/toggles/feature/nested_attributes_spec.rb +25 -0
- data/spec/toggles/feature/permissions_spec.rb +2 -2
- data/spec/toggles/feature/subject_spec.rb +1 -1
- data/toggles.gemspec +1 -1
- metadata +5 -4
- data/spec/toggles_spec.rb +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 667d45b0572c3986b8f26a65f9d875c29418fb5f
|
4
|
+
data.tar.gz: dcf2a50e338291a73cb2ce901a1eed0d5b12cdec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b40d286dd30e05530d36cab7fde5cb9a1ac78fafb152130bd58428f0648099b44567d8b8b3ab23bcb2122142d819d5c08e251a3135c7d9e74671b217725ec5e
|
7
|
+
data.tar.gz: 7d8fb44ef3432bafbfe5a7e47eb75e59c7498f210bbca9ff092164654aba4e07dbce2aa411b1adc742c035c0022a5a8538e79b8751bf1eae02146b9cc2d00e7d
|
@@ -4,8 +4,12 @@ module Feature
|
|
4
4
|
class Attribute
|
5
5
|
def self.call(entity, attr_name, expected)
|
6
6
|
if expected.kind_of? Hash
|
7
|
-
expected.all? do |operation,
|
8
|
-
OPERATIONS
|
7
|
+
expected.all? do |operation, rules|
|
8
|
+
if OPERATIONS.include? operation.to_sym
|
9
|
+
OPERATIONS[operation.to_sym].call(entity, attr_name, rules)
|
10
|
+
else
|
11
|
+
Operation::Attribute.call(entity.send(attr_name), operation, rules)
|
12
|
+
end
|
9
13
|
end
|
10
14
|
else
|
11
15
|
entity.send(attr_name) == expected
|
@@ -4,16 +4,12 @@ module Feature
|
|
4
4
|
class Permissions
|
5
5
|
extend Forwardable
|
6
6
|
|
7
|
-
attr_reader :
|
7
|
+
attr_reader :rules
|
8
8
|
|
9
9
|
def_delegators :rules, :all?, :keys
|
10
10
|
|
11
11
|
def initialize(path)
|
12
|
-
@
|
13
|
-
end
|
14
|
-
|
15
|
-
def rules
|
16
|
-
@rules ||= YAML.load(File.read(path))
|
12
|
+
@rules = YAML.load(File.read(path))
|
17
13
|
end
|
18
14
|
|
19
15
|
def subjects
|
@@ -18,7 +18,8 @@ describe Feature::Base do
|
|
18
18
|
|
19
19
|
specify "invalid permissions" do
|
20
20
|
expect { Feature::Test.enabled_for?(widget: double) }.
|
21
|
-
to raise_error Feature::Subject::Invalid,
|
21
|
+
to raise_error Feature::Subject::Invalid,
|
22
|
+
"Invalid or missing subjects for permissions: [:user]"
|
22
23
|
end
|
23
24
|
|
24
25
|
specify "collection" do
|
@@ -0,0 +1,25 @@
|
|
1
|
+
describe "nested_attributes.yml" do
|
2
|
+
specify do
|
3
|
+
expect(
|
4
|
+
Feature::NestedAttributes.enabled_for?(
|
5
|
+
foo: double(bar: :two, baz: double(id: 51))
|
6
|
+
)
|
7
|
+
).to eq true
|
8
|
+
expect(
|
9
|
+
Feature::NestedAttributes.enabled_for?(
|
10
|
+
foo: double(bar: :two, baz: double(id: 10))
|
11
|
+
)
|
12
|
+
).to eq true
|
13
|
+
|
14
|
+
expect(
|
15
|
+
Feature::NestedAttributes.enabled_for?(
|
16
|
+
foo: double(bar: :one, baz: double(id: 51))
|
17
|
+
)
|
18
|
+
).to eq false
|
19
|
+
expect(
|
20
|
+
Feature::NestedAttributes.enabled_for?(
|
21
|
+
foo: double(bar: :two, baz: double(id: 50))
|
22
|
+
)
|
23
|
+
).to eq false
|
24
|
+
end
|
25
|
+
end
|
@@ -3,7 +3,6 @@ describe Feature::Permissions do
|
|
3
3
|
|
4
4
|
subject { Feature::Permissions.new(path) }
|
5
5
|
|
6
|
-
its(:path) { is_expected.to eq path }
|
7
6
|
its(:rules) { is_expected.to eq({"user"=>{"id"=>1, "logged_in?"=>true},
|
8
7
|
"widget"=>{"id"=>2}}) }
|
9
8
|
its(:subjects) { [:user, :widget] }
|
@@ -18,7 +17,8 @@ describe Feature::Permissions do
|
|
18
17
|
|
19
18
|
specify "invalid subjects" do
|
20
19
|
expect { subject.valid_for?(user: double) }.
|
21
|
-
to raise_error Feature::Subject::Invalid,
|
20
|
+
to raise_error Feature::Subject::Invalid,
|
21
|
+
"Invalid or missing subjects for permissions: [:widget]"
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -2,7 +2,7 @@ describe Feature::Subject do
|
|
2
2
|
describe Feature::Subject::Invalid do
|
3
3
|
subject { Feature::Subject::Invalid.new([:user]) }
|
4
4
|
|
5
|
-
its(:message) { is_expected.to eq "Invalid subjects for permissions: [:user]" }
|
5
|
+
its(:message) { is_expected.to eq "Invalid or missing subjects for permissions: [:user]" }
|
6
6
|
end
|
7
7
|
|
8
8
|
describe "#difference" do
|
data/toggles.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: toggles
|
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
|
- Andrew Tribone
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -119,6 +119,7 @@ files:
|
|
119
119
|
- Gemfile
|
120
120
|
- Rakefile
|
121
121
|
- features/collection.yml
|
122
|
+
- features/nested_attributes.yml
|
122
123
|
- features/test.yml
|
123
124
|
- lib/toggles.rb
|
124
125
|
- lib/toggles/feature.rb
|
@@ -136,6 +137,7 @@ files:
|
|
136
137
|
- lib/toggles/feature/subject.rb
|
137
138
|
- spec/spec_helper.rb
|
138
139
|
- spec/toggles/feature/base_spec.rb
|
140
|
+
- spec/toggles/feature/nested_attributes_spec.rb
|
139
141
|
- spec/toggles/feature/permissions/operation/and_spec.rb
|
140
142
|
- spec/toggles/feature/permissions/operation/attribute_spec.rb
|
141
143
|
- spec/toggles/feature/permissions/operation/gt_spec.rb
|
@@ -146,7 +148,6 @@ files:
|
|
146
148
|
- spec/toggles/feature/permissions/operation/range_spec.rb
|
147
149
|
- spec/toggles/feature/permissions_spec.rb
|
148
150
|
- spec/toggles/feature/subject_spec.rb
|
149
|
-
- spec/toggles_spec.rb
|
150
151
|
- toggles.gemspec
|
151
152
|
homepage: ''
|
152
153
|
licenses:
|
@@ -175,6 +176,7 @@ summary: YAML backed feature toggles
|
|
175
176
|
test_files:
|
176
177
|
- spec/spec_helper.rb
|
177
178
|
- spec/toggles/feature/base_spec.rb
|
179
|
+
- spec/toggles/feature/nested_attributes_spec.rb
|
178
180
|
- spec/toggles/feature/permissions/operation/and_spec.rb
|
179
181
|
- spec/toggles/feature/permissions/operation/attribute_spec.rb
|
180
182
|
- spec/toggles/feature/permissions/operation/gt_spec.rb
|
@@ -185,4 +187,3 @@ test_files:
|
|
185
187
|
- spec/toggles/feature/permissions/operation/range_spec.rb
|
186
188
|
- spec/toggles/feature/permissions_spec.rb
|
187
189
|
- spec/toggles/feature/subject_spec.rb
|
188
|
-
- spec/toggles_spec.rb
|
data/spec/toggles_spec.rb
DELETED
File without changes
|