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.
@@ -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? and not j_node.has_property(name)
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
- value = [value]
221
+ remove_property(name)
213
222
  end
214
223
 
215
224
  if value.is_a? Array
216
- if properties.has_key?(name) and property_single_valued?(name) # when going from single to multi value
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 = []
@@ -1,3 +1,3 @@
1
1
  module SafetyPin
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -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 "should work" do
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 == ["not bar"]
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
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: safety-pin
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.4
5
+ version: 0.1.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jordan Raine