safety_pin 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/safety_pin/node.rb +10 -0
- data/lib/safety_pin/version.rb +1 -1
- data/spec/node_spec.rb +39 -0
- metadata +2 -2
data/lib/safety_pin/node.rb
CHANGED
@@ -18,6 +18,7 @@ module SafetyPin
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def self.build(path, node_type = nil)
|
21
|
+
path = path.to_s
|
21
22
|
node_type ||= "nt:unstructured"
|
22
23
|
rel_path = nil
|
23
24
|
if path.start_with?("/")
|
@@ -73,6 +74,7 @@ module SafetyPin
|
|
73
74
|
end
|
74
75
|
|
75
76
|
def read_attribute(name)
|
77
|
+
name = name.to_s
|
76
78
|
property = j_node.get_property(name)
|
77
79
|
if property_is_multi_valued?(property)
|
78
80
|
retrieve_property_multi_value(property)
|
@@ -120,6 +122,8 @@ module SafetyPin
|
|
120
122
|
|
121
123
|
def write_attribute(name, value)
|
122
124
|
raise PropertyError.new("Illegal operation: cannot change jcr:primaryType property") if name == "jcr:primaryType"
|
125
|
+
|
126
|
+
name = name.to_s
|
123
127
|
|
124
128
|
if value.is_a? Array
|
125
129
|
values = value
|
@@ -233,6 +237,12 @@ module SafetyPin
|
|
233
237
|
def primary_type
|
234
238
|
self["jcr:primaryType"]
|
235
239
|
end
|
240
|
+
|
241
|
+
# Create and return a child node with a given name
|
242
|
+
def create(name, type = nil)
|
243
|
+
path = Pathname(self.path) + name
|
244
|
+
Node.create(path, type)
|
245
|
+
end
|
236
246
|
end
|
237
247
|
|
238
248
|
class NodeError < Exception; end
|
data/lib/safety_pin/version.rb
CHANGED
data/spec/node_spec.rb
CHANGED
@@ -165,6 +165,13 @@ describe SafetyPin::Node do
|
|
165
165
|
@node.read_attribute("foo").should eql(["one", "two"])
|
166
166
|
end
|
167
167
|
end
|
168
|
+
|
169
|
+
context "given a non-string name" do
|
170
|
+
it "should co-erce the name into a string and retrieve the property" do
|
171
|
+
@node["foo"] = "bar"
|
172
|
+
@node.read_attribute(:foo).should eql("bar")
|
173
|
+
end
|
174
|
+
end
|
168
175
|
end
|
169
176
|
|
170
177
|
it "should return the string value of a name property" do
|
@@ -197,6 +204,15 @@ describe SafetyPin::Node do
|
|
197
204
|
@node["foo"].to_s.should eql(time.to_s)
|
198
205
|
end
|
199
206
|
end
|
207
|
+
|
208
|
+
context "given a non-string name" do
|
209
|
+
it "should co-erce name into string before setting property" do
|
210
|
+
@node.write_attribute(:foo, "bar")
|
211
|
+
@node.save
|
212
|
+
@node.reload
|
213
|
+
@node["foo"].should eql("bar")
|
214
|
+
end
|
215
|
+
end
|
200
216
|
end
|
201
217
|
|
202
218
|
context "given an array of values" do
|
@@ -390,6 +406,12 @@ describe SafetyPin::Node do
|
|
390
406
|
lambda { SafetyPin::Node.build("/content") }.should raise_error(SafetyPin::NodeError)
|
391
407
|
end
|
392
408
|
end
|
409
|
+
|
410
|
+
it "should coerce path to a string" do
|
411
|
+
node = SafetyPin::Node.build(Pathname("/content/foo"))
|
412
|
+
node.should be_new
|
413
|
+
node.properties.should eql({})
|
414
|
+
end
|
393
415
|
end
|
394
416
|
|
395
417
|
context "given an absolute path with a non-existent parent node" do
|
@@ -491,4 +513,21 @@ describe SafetyPin::Node do
|
|
491
513
|
@node.primary_type.should eql("nt:unstructured")
|
492
514
|
end
|
493
515
|
end
|
516
|
+
|
517
|
+
describe "#create" do
|
518
|
+
before { @node = SafetyPin::Node.create("/content/foo") }
|
519
|
+
after { @node.destroy }
|
520
|
+
|
521
|
+
it "should create a child node with a given name" do
|
522
|
+
@node.create("bar")
|
523
|
+
SafetyPin::Node.find("/content/foo/bar").should be_a(SafetyPin::Node)
|
524
|
+
end
|
525
|
+
|
526
|
+
it "should create a child node with a given name and node type" do
|
527
|
+
@node.create("bar", "nt:folder")
|
528
|
+
child_node = SafetyPin::Node.find("/content/foo/bar")
|
529
|
+
child_node.should be_a(SafetyPin::Node)
|
530
|
+
child_node.primary_type.should eql("nt:folder")
|
531
|
+
end
|
532
|
+
end
|
494
533
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: safety_pin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jordan Raine
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-05-
|
13
|
+
date: 2012-05-11 00:00:00 Z
|
14
14
|
dependencies: []
|
15
15
|
|
16
16
|
description: An easy-to-use JCR connector for JRuby
|