Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make sure freeze does not have side effects, #235

Needed by carrierwave-neo4j
  • Loading branch information...
commit 2ba75012b736324c54c00c754cdea67e6fa143f7 1 parent a1a2243
Andreas Ronge andreasronge authored
3  lib/neo4j/rails/attributes.rb
View
@@ -231,9 +231,6 @@ def read_attribute(key)
if @_properties.has_key?(key)
@_properties[key]
else
- #puts "@_properties #{@_properties}"
- #puts "attribute_defaults #{attribute_defaults.inspect}"
- #puts "Key #{key}, self #{self}"
@_properties[key] = (!new_record? && _java_entity.has_property?(key)) ? read_property_from_db(key) : attribute_defaults[key]
end
end
9 lib/neo4j/rails/node_persistance.rb
View
@@ -41,6 +41,15 @@ def reload(options = nil)
self
end
+ def freeze_if_deleted
+ unless new_record?
+ Neo4j::IdentityMap.remove_node_by_id(neo_id)
+ unless self.class.load_entity(neo_id)
+ set_deleted_properties
+ freeze
+ end
+ end
+ end
def reload_from_database
Neo4j::IdentityMap.remove_node_by_id(neo_id)
2  lib/neo4j/rails/persistence.rb
View
@@ -74,7 +74,7 @@ def freeze
# Returns +true+ if the properties hash has been frozen.
def frozen?
- reload unless new_record?
+ freeze_if_deleted
@_properties.frozen?
end
9 lib/neo4j/rails/relationship_persistence.rb
View
@@ -73,6 +73,15 @@ def reload(options = nil)
self
end
+ def freeze_if_deleted
+ unless new_record?
+ Neo4j::IdentityMap.remove_rel_by_id(neo_id)
+ unless self.class.load_entity(neo_id)
+ set_deleted_properties
+ freeze
+ end
+ end
+ end
def reload_from_database
Neo4j::IdentityMap.remove_rel_by_id(id) if persisted?
33 spec/regressions/issue_235_spec.rb
View
@@ -0,0 +1,33 @@
+module Regressions
+ require 'spec_helper'
+
+ class Issue235 < Neo4j::Rails::Model
+ property :thing
+ end
+
+ class IssueRel235 < Neo4j::Rails::Relationship
+ property :thing
+ end
+
+ describe "Issue 235, make sure frozen? does not have side effects" do
+ it "works for Neo4j::Rails::Model" do
+ a = Issue235.create(:thing => 2)
+ a.reload
+ a.thing = 42
+ a.frozen?
+ a.thing.should == 42
+ end
+
+ it "works for Neo4j::Rails::Relationship" do
+ a = Issue235.create!
+ b = Issue235.create!
+ r = IssueRel235.create(:friends, a, b, :things => 2)
+
+ r.reload
+ r.thing = 42
+ r.frozen?
+ r.thing.should == 42
+ end
+
+ end
+end
2  spec/unit/rails_relationship_spec.rb
View
@@ -56,7 +56,7 @@
its(:new_record?) { should be_false }
describe "frozen?" do
it "reloads the node and returns false" do
- subject.should_receive(:reload).and_return(true)
+ subject.should_receive(:freeze_if_deleted).and_return(true)
subject.frozen?.should be_false
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.