Permalink
Browse files

frozen record keeps id attribute of original

  • Loading branch information...
1 parent 26c2cea commit 3d99ad926388f879da82127d604b3a8328d65b90 @ryanb committed Jul 14, 2008
Showing with 12 additions and 3 deletions.
  1. +2 −0 CHANGELOG
  2. +4 −1 lib/association_freezer/belongs_to_freezer.rb
  3. +6 −2 spec/freezer_spec.rb
View
@@ -1,3 +1,5 @@
+* frozen record keeps id attribute of old record
+
* don't raise exception when trying to freeze nil association
* raise an exception when trying to replace frozen association
@@ -29,7 +29,10 @@ def frozen
end
def load_frozen
- target_class.new(Marshal.load(frozen_data).except('id')).freeze
+ attributes = Marshal.load(frozen_data)
+ target = target_class.new(attributes.except('id'))
+ target.id = attributes['id']
+ target.freeze
end
def nonfrozen(*args)
View
@@ -11,11 +11,11 @@
@order = Order.new
end
- it "should add a freeze association method when enabling freezing" do
+ it "should add a freeze association method" do
@order.should respond_to(:freeze_ship_method)
end
- it "should add an unfreeze association method when enabling freezing" do
+ it "should add an unfreeze association method" do
@order.should respond_to(:unfreeze_ship_method)
end
@@ -93,6 +93,10 @@
it "should raise an exception when attempting to replace association" do
lambda { @order.ship_method = ShipMethod.new }.should raise_error
end
+
+ it "should keep id attribute for association" do
+ @order.ship_method.id.should == @ship_method.id
+ end
end
end
end

0 comments on commit 3d99ad9

Please sign in to comment.