From 5e02630be21cf8041d48330e30474e4e4cd736da Mon Sep 17 00:00:00 2001 From: Dan Date: Thu, 5 Apr 2012 14:16:00 -0700 Subject: [PATCH] fixed issue where setting a previously undefined property using dot notation has no effect on the DB --- lib/neography/property.rb | 8 ++++++-- spec/integration/node_spec.rb | 11 ++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/neography/property.rb b/lib/neography/property.rb index 7206f5f..6303e04 100644 --- a/lib/neography/property.rb +++ b/lib/neography/property.rb @@ -41,9 +41,13 @@ def new_ostruct_member(name) end - def self.method_missing(method_sym, *arguments, &block) - if (method_sym.to_s =~ /$=/) != nil + def method_missing(method_sym, *arguments, &block) + if (method_sym.to_s =~ /=$/) != nil new_ostruct_member(method_sym.to_s.chomp("=")) + + # We just defined the getter/setter above, but we haven't actually + # applied them yet. + self.send(method_sym, *arguments) else super end diff --git a/spec/integration/node_spec.rb b/spec/integration/node_spec.rb index fcb0acc..e7ea393 100644 --- a/spec/integration/node_spec.rb +++ b/spec/integration/node_spec.rb @@ -136,7 +136,7 @@ existing_node.eyes.should == "brown" end - it "can change a node's properties that does not already exist" do + it "can change a node's properties that does not already exist using []=" do new_node = Neography::Node.create("weight" => 150, "eyes" => "green") new_node.weight = 200 @@ -149,6 +149,15 @@ existing_node.hair.should == "black" end + it "can change a node's properties that does not already exist" do + new_node = Neography::Node.create + + new_node.hair = "black" + + existing_node = Neography::Node.load(new_node) + existing_node.hair.should == "black" + end + it "can pass issue 18" do n = Neography::Node.create("name" => "Test") n.prop = 1