hydra-access-controls 10.0.0.beta2 → 10.0.0.beta3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/hydra/access_control.rb +3 -2
- data/spec/unit/collection_relationship_spec.rb +101 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 542ba667f390824e6d6da5ef589d841eb3dc2f63
|
4
|
+
data.tar.gz: e4521e7bd863e1c7c05006af99acb75d60f4a54f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0afe21dbac45703ce2348a518dcce5c060dbd3ab347d527c2016b07c2698217480eac8fea7ae9a03cb2e095540c398b666ce2fbea34eee6a1e36db05a7c89e93
|
7
|
+
data.tar.gz: 54cf981570cc20997111048a17a4b87ae96721d15fa47eb821428f87ec9c83384825e025da6bc44526eca1d9469505ccbd1ec0508dc44b197ec5b7694e7ca2b8
|
@@ -44,8 +44,9 @@ module Hydra
|
|
44
44
|
@relationship = @owner.send(reflection)
|
45
45
|
end
|
46
46
|
|
47
|
-
delegate :to_a, :to_ary, :map, :delete, :last, :size, :count, :[],
|
48
|
-
:==, :detect, :empty?,
|
47
|
+
delegate :to_a, :to_ary, :map, :delete, :first, :last, :size, :count, :[],
|
48
|
+
:==, :detect, :empty?, :each, :any?, :all?, :include?, :destroy_all,
|
49
|
+
to: :@relationship
|
49
50
|
|
50
51
|
# TODO: if directly_contained relationships supported find, we could just
|
51
52
|
# delegate find.
|
@@ -11,8 +11,109 @@ describe Hydra::AccessControl::CollectionRelationship do
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
+
describe "#first" do
|
15
|
+
let!(:one) { relationship.build(name: 'user1', type: 'person', access: 'read') }
|
16
|
+
let!(:two) { relationship.build(name: 'user2', type: 'person', access: 'read') }
|
17
|
+
subject { relationship.first }
|
18
|
+
it { is_expected.to be one }
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#last" do
|
22
|
+
let!(:one) { relationship.build(name: 'user1', type: 'person', access: 'read') }
|
23
|
+
let!(:two) { relationship.build(name: 'user2', type: 'person', access: 'read') }
|
24
|
+
subject { relationship.last }
|
25
|
+
it { is_expected.to be two }
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "#include?" do
|
29
|
+
let!(:one) { relationship.build(name: 'user1', type: 'person', access: 'read') }
|
30
|
+
let(:two) { Hydra::AccessControls::Permission.new(name: 'user2', type: 'person', access: 'read') }
|
31
|
+
it 'returns a boolean' do
|
32
|
+
expect(relationship).to include(one)
|
33
|
+
expect(relationship).not_to include(two)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
14
37
|
describe "#empty?" do
|
15
38
|
subject { relationship.empty? }
|
16
39
|
it { is_expected.to be true }
|
17
40
|
end
|
41
|
+
|
42
|
+
describe "#each" do
|
43
|
+
let!(:one) { relationship.build(name: 'user1', type: 'person', access: 'read') }
|
44
|
+
let!(:two) { relationship.build(name: 'user2', type: 'person', access: 'read') }
|
45
|
+
let(:counter) { double }
|
46
|
+
it "invokes the block with each object" do
|
47
|
+
expect(counter).to receive(:check).with(one)
|
48
|
+
expect(counter).to receive(:check).with(two)
|
49
|
+
relationship.each { |o| counter.check(o) }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "#map" do
|
54
|
+
let!(:one) { relationship.build(name: 'user1', type: 'person', access: 'read') }
|
55
|
+
let!(:two) { relationship.build(name: 'user2', type: 'person', access: 'read') }
|
56
|
+
it "maps each element through the block" do
|
57
|
+
expect(relationship.map { |o| o.agent_name }).to eq ['user1', 'user2']
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "#detect" do
|
62
|
+
let!(:one) { relationship.build(name: 'user1', type: 'person', access: 'read') }
|
63
|
+
let!(:two) { relationship.build(name: 'user2', type: 'person', access: 'read') }
|
64
|
+
it "finds the first match" do
|
65
|
+
expect(relationship.detect { |o| o.agent_name == 'user2' }).to eq two
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "#find" do
|
70
|
+
before do
|
71
|
+
access_control.save!
|
72
|
+
end
|
73
|
+
let!(:one) { relationship.create(name: 'user1', type: 'person', access: 'read') }
|
74
|
+
let!(:two) { relationship.create(name: 'user2', type: 'person', access: 'read') }
|
75
|
+
context "when the id is in the set" do
|
76
|
+
it "finds matches by id" do
|
77
|
+
expect(relationship.find(two.id)).to eq two
|
78
|
+
end
|
79
|
+
end
|
80
|
+
context "when the id is not the set" do
|
81
|
+
it "raises an error" do
|
82
|
+
expect { relationship.find('999') }.to raise_error ArgumentError, "requested ACL (999) is not a member of #{access_control.id}"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "#any?" do
|
88
|
+
let!(:one) { relationship.build(name: 'user1', type: 'person', access: 'read') }
|
89
|
+
let!(:two) { relationship.build(name: 'user2', type: 'person', access: 'read') }
|
90
|
+
it "invokes the block with each object" do
|
91
|
+
expect(relationship.any? { |o| o.agent_name == 'user2' }).to be true
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe "#all?" do
|
96
|
+
let!(:one) { relationship.build(name: 'user1', type: 'person', access: 'read') }
|
97
|
+
let!(:two) { relationship.build(name: 'user2', type: 'person', access: 'read') }
|
98
|
+
let(:counter) { double }
|
99
|
+
context "when all members satisfy the condition" do
|
100
|
+
subject { relationship.all? { |o| o.type == 'person' } }
|
101
|
+
it { is_expected.to be true }
|
102
|
+
end
|
103
|
+
context "when some members don't satisfy the condition" do
|
104
|
+
subject { relationship.all? { |o| o.agent_name == 'user1' } }
|
105
|
+
it { is_expected.to be false }
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe "#destroy_all" do
|
110
|
+
before do
|
111
|
+
access_control.save!
|
112
|
+
end
|
113
|
+
let!(:one) { relationship.create(name: 'user1', type: 'person', access: 'read') }
|
114
|
+
let!(:two) { relationship.create(name: 'user2', type: 'person', access: 'read') }
|
115
|
+
it "invokes the block with each object" do
|
116
|
+
expect { relationship.destroy_all }.to change { Hydra::AccessControls::Permission.count}.by(-2)
|
117
|
+
end
|
118
|
+
end
|
18
119
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hydra-access-controls
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 10.0.0.
|
4
|
+
version: 10.0.0.beta3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Beer
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2016-05-
|
13
|
+
date: 2016-05-11 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|