valkyrie 2.0.0.RC9 → 2.0.0.RC10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/valkyrie/specs/shared_specs/resource.rb +39 -35
- data/lib/valkyrie/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5dcf6397bc2f0966a08294cc83ae1eb2db2f2edf20cb1a2ad84f8ef18fd30174
|
4
|
+
data.tar.gz: 47dd8114e5c60f9fa46c0f2540c89034ea36a902725788f2b9d9fecf19c08c98
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f86188cce9d5800144be914d41fb179abf32409266736e5bf28a13ea3f877ddf38aa1d0d76952d0206a185c1e1f818ffb1d583a344ac8385d6b043938bb8de9
|
7
|
+
data.tar.gz: e08d62b44d62f3981bc51b7b0cb33ab3f4139f409b1ab4f4dd9dccff5e098923bee6e7a5c5a95241ae6f9b1a3ed12c89bb9a0fadf8077ad94661feac8d24e0e0
|
@@ -4,14 +4,17 @@ RSpec.shared_examples 'a Valkyrie::Resource' do
|
|
4
4
|
raise 'resource_klass must be set with `let(:resource_klass)`' unless
|
5
5
|
defined? resource_klass
|
6
6
|
end
|
7
|
+
let(:meta_klass) do
|
8
|
+
Class.new(resource_klass)
|
9
|
+
end
|
7
10
|
describe "#id" do
|
8
11
|
it "can be set via instantiation and casts to a Valkyrie::ID" do
|
9
|
-
resource =
|
12
|
+
resource = meta_klass.new(id: "test")
|
10
13
|
expect(resource.id).to eq Valkyrie::ID.new("test")
|
11
14
|
end
|
12
15
|
|
13
16
|
it "is nil when not set" do
|
14
|
-
resource =
|
17
|
+
resource = meta_klass.new
|
15
18
|
expect(resource.id).to be_nil
|
16
19
|
end
|
17
20
|
|
@@ -23,21 +26,21 @@ RSpec.shared_examples 'a Valkyrie::Resource' do
|
|
23
26
|
|
24
27
|
describe "#has_attribute?" do
|
25
28
|
it "returns true when it has a given attribute" do
|
26
|
-
resource =
|
29
|
+
resource = meta_klass.new
|
27
30
|
expect(resource.has_attribute?(:id)).to eq true
|
28
31
|
end
|
29
32
|
end
|
30
33
|
|
31
34
|
describe "#fields" do
|
32
35
|
it "returns a set of fields" do
|
33
|
-
expect(
|
34
|
-
expect(
|
36
|
+
expect(meta_klass).to respond_to(:fields).with(0).arguments
|
37
|
+
expect(meta_klass.fields).to include(:id)
|
35
38
|
end
|
36
39
|
end
|
37
40
|
|
38
41
|
describe "#attributes" do
|
39
42
|
it "returns a list of all set attributes" do
|
40
|
-
resource =
|
43
|
+
resource = meta_klass.new(id: "test")
|
41
44
|
expect(resource.attributes[:id].to_s).to eq "test"
|
42
45
|
end
|
43
46
|
end
|
@@ -45,8 +48,8 @@ RSpec.shared_examples 'a Valkyrie::Resource' do
|
|
45
48
|
|
46
49
|
describe "#internal_resource" do
|
47
50
|
it "is set to the resource's class on instantiation" do
|
48
|
-
resource =
|
49
|
-
expect(resource.internal_resource).to eq
|
51
|
+
resource = meta_klass.new
|
52
|
+
expect(resource.internal_resource).to eq meta_klass.to_s
|
50
53
|
end
|
51
54
|
end
|
52
55
|
|
@@ -70,97 +73,98 @@ RSpec.shared_examples 'a Valkyrie::Resource' do
|
|
70
73
|
|
71
74
|
describe "#[]" do
|
72
75
|
it "allows access to properties which are set" do
|
73
|
-
|
74
|
-
resource =
|
76
|
+
meta_klass.attribute :my_property unless meta_klass.schema.key?(:my_property)
|
77
|
+
resource = meta_klass.new
|
75
78
|
|
76
79
|
resource.my_property = "test"
|
77
80
|
|
78
81
|
expect(resource[:my_property]).to eq ["test"]
|
79
82
|
|
80
|
-
unset_key(
|
83
|
+
unset_key(meta_klass, :my_property)
|
81
84
|
end
|
82
85
|
it "returns nil for non-existent properties" do
|
83
|
-
resource =
|
86
|
+
resource = meta_klass.new
|
84
87
|
|
85
88
|
expect(resource[:bad_property]).to eq nil
|
86
89
|
end
|
87
90
|
it "can be accessed via a string" do
|
88
|
-
|
89
|
-
resource =
|
91
|
+
meta_klass.attribute :other_property unless meta_klass.schema.key?(:other_property)
|
92
|
+
resource = meta_klass.new
|
90
93
|
|
91
94
|
resource.other_property = "test"
|
92
95
|
|
93
96
|
expect(resource["other_property"]).to eq ["test"]
|
94
97
|
|
95
|
-
unset_key(
|
98
|
+
unset_key(meta_klass, :other_property)
|
96
99
|
end
|
97
100
|
end
|
98
101
|
|
99
|
-
def unset_key(
|
100
|
-
|
101
|
-
|
102
|
-
|
102
|
+
def unset_key(meta_klass, property)
|
103
|
+
meta_klass.schema(Dry::Types::Schema.new(Hash, **meta_klass.schema.options, keys: meta_klass.schema.keys.select { |x| x.name != property }, meta: meta_klass.schema.meta))
|
104
|
+
meta_klass.instance_variable_set(:@attribute_names, nil)
|
105
|
+
meta_klass.allow_nonexistent_keys
|
103
106
|
end
|
104
107
|
|
105
108
|
describe "#set_value" do
|
106
109
|
it "can set a value" do
|
107
|
-
|
108
|
-
resource =
|
110
|
+
meta_klass.attribute :set_value_property unless meta_klass.schema.key?(:set_value_property)
|
111
|
+
resource = meta_klass.new
|
109
112
|
|
110
113
|
resource.set_value(:set_value_property, "test")
|
111
114
|
|
112
115
|
expect(resource.set_value_property).to eq ["test"]
|
113
116
|
resource.set_value("set_value_property", "testing")
|
114
117
|
expect(resource.set_value_property).to eq ["testing"]
|
115
|
-
unset_key(
|
118
|
+
unset_key(meta_klass, :set_value_property)
|
116
119
|
end
|
117
120
|
end
|
118
121
|
|
119
122
|
describe ".new" do
|
120
123
|
it "can set values with symbols" do
|
121
|
-
|
124
|
+
meta_klass.attribute :symbol_property unless meta_klass.schema.key?(:symbol_property)
|
122
125
|
|
123
|
-
resource =
|
126
|
+
resource = meta_klass.new(symbol_property: "bla")
|
124
127
|
|
125
128
|
expect(resource.symbol_property).to eq ["bla"]
|
126
|
-
unset_key(
|
129
|
+
unset_key(meta_klass, :symbol_property)
|
127
130
|
end
|
128
131
|
it "can not set values with string properties" do
|
129
|
-
|
132
|
+
meta_klass.attribute :string_property unless meta_klass.schema.key?(:string_property)
|
130
133
|
|
131
134
|
resource = nil
|
132
135
|
expect(resource).not_to respond_to :string_property
|
133
|
-
unset_key(
|
136
|
+
unset_key(meta_klass, :string_property)
|
134
137
|
end
|
135
138
|
end
|
136
139
|
|
137
140
|
describe "#attributes" do
|
138
141
|
it "returns all defined attributs, including nil keys" do
|
139
|
-
|
142
|
+
meta_klass.attribute :bla unless meta_klass.schema.key?(:bla)
|
140
143
|
|
141
|
-
resource =
|
144
|
+
resource = meta_klass.new
|
142
145
|
|
143
146
|
expect(resource.attributes).to be_frozen
|
144
147
|
expect(resource.attributes).to have_key(:bla)
|
145
|
-
expect(resource.attributes[:internal_resource]).to eq
|
148
|
+
expect(resource.attributes[:internal_resource]).to eq meta_klass.to_s
|
146
149
|
expect { resource.attributes.dup[:internal_resource] = "bla" }.not_to output.to_stderr
|
147
150
|
|
148
|
-
unset_key(
|
149
|
-
resource =
|
151
|
+
unset_key(meta_klass, :bla)
|
152
|
+
resource = meta_klass.new
|
150
153
|
expect(resource.attributes).not_to have_key(:bla)
|
154
|
+
expect(resource.as_json).not_to have_key(:bla)
|
151
155
|
end
|
152
156
|
end
|
153
157
|
|
154
158
|
describe "#__attributes__" do
|
155
159
|
it "returns all defined attributes, but doesn't add nil keys" do
|
156
|
-
|
160
|
+
meta_klass.attribute :bla unless meta_klass.schema.key?(:bla)
|
157
161
|
|
158
|
-
resource =
|
162
|
+
resource = meta_klass.new
|
159
163
|
expect(resource.__attributes__).to be_frozen
|
160
164
|
expect(resource.__attributes__).not_to have_key :bla
|
161
165
|
expect(resource.__attributes__).to have_key :internal_resource
|
162
166
|
|
163
|
-
unset_key(
|
167
|
+
unset_key(meta_klass, :bla)
|
164
168
|
end
|
165
169
|
end
|
166
170
|
end
|
data/lib/valkyrie/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: valkyrie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0.
|
4
|
+
version: 2.0.0.RC10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Trey Pendragon
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-struct
|