safety-pin 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/safety_pin/node.rb +12 -5
- data/lib/safety_pin/version.rb +1 -1
- data/spec/node_spec.rb +12 -2
- metadata +1 -1
data/lib/safety_pin/node.rb
CHANGED
@@ -199,23 +199,30 @@ module SafetyPin
|
|
199
199
|
properties.has_key?(name) and properties[name].is_a?(Array)
|
200
200
|
end
|
201
201
|
|
202
|
+
def has_property?(name)
|
203
|
+
j_node.has_property(name)
|
204
|
+
end
|
205
|
+
|
206
|
+
def remove_property(name)
|
207
|
+
j_node.get_property(name).remove if has_property?(name)
|
208
|
+
end
|
209
|
+
|
202
210
|
def write_attribute(name, value)
|
203
211
|
raise PropertyError.new("Illegal operation: cannot change jcr:primaryType property") if name == "jcr:primaryType"
|
204
212
|
name = name.to_s
|
205
213
|
|
206
|
-
if value.nil?
|
214
|
+
if value.nil?
|
215
|
+
remove_property(name)
|
207
216
|
return nil
|
208
217
|
end
|
209
218
|
|
210
219
|
# when going from multi to single value
|
211
220
|
if property_multi_valued?(name) and !value.is_a?(Array)
|
212
|
-
|
221
|
+
remove_property(name)
|
213
222
|
end
|
214
223
|
|
215
224
|
if value.is_a? Array
|
216
|
-
|
217
|
-
j_node.set_property(name, nil)
|
218
|
-
end
|
225
|
+
remove_property(name)
|
219
226
|
values = value
|
220
227
|
val_fact = value_factory
|
221
228
|
j_values = []
|
data/lib/safety_pin/version.rb
CHANGED
data/spec/node_spec.rb
CHANGED
@@ -302,7 +302,7 @@ describe SafetyPin::Node do
|
|
302
302
|
end
|
303
303
|
|
304
304
|
context "when changing a property from a single value to a multivalue" do
|
305
|
-
it "
|
305
|
+
it "doesn't throw exceptions" do
|
306
306
|
node.write_attribute(:foo, "bar")
|
307
307
|
node.save
|
308
308
|
node.reload
|
@@ -321,7 +321,17 @@ describe SafetyPin::Node do
|
|
321
321
|
node.write_attribute("foo", "not bar")
|
322
322
|
node.save
|
323
323
|
node.reload
|
324
|
-
node["foo"].should ==
|
324
|
+
node["foo"].should == "not bar"
|
325
|
+
end
|
326
|
+
|
327
|
+
it "doesn't wrap nil" do
|
328
|
+
node.write_attribute("foo", ["bar"])
|
329
|
+
node.save
|
330
|
+
node.reload
|
331
|
+
node.write_attribute("foo", nil)
|
332
|
+
node.save
|
333
|
+
node.reload
|
334
|
+
node["foo"].should be_nil
|
325
335
|
end
|
326
336
|
end
|
327
337
|
end
|