Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

don't raise exception when trying to freeze nil association

  • Loading branch information...
commit 26c2ceacf174c16c452c229c58fd503466681be0 1 parent c405d2c
@ryanb authored
View
2  CHANGELOG
@@ -1,3 +1,5 @@
+* don't raise exception when trying to freeze nil association
+
* raise an exception when trying to replace frozen association
*0.1.0* (July 14th, 2008)
View
2  lib/association_freezer/belongs_to_freezer.rb
@@ -6,7 +6,7 @@ def initialize(owner, reflection)
end
def freeze
- self.frozen_data = Marshal.dump(nonfrozen.attributes)
+ self.frozen_data = Marshal.dump(nonfrozen.attributes) if nonfrozen
end
def unfreeze
View
18 spec/freezer_spec.rb
@@ -30,13 +30,19 @@
end
it "should freeze association in its current state" do
- @ship_method = ShipMethod.create!(:price => 2)
- @order.ship_method = @ship_method
- @ship_method.price = 3
+ ship_method = ShipMethod.create!(:price => 2)
+ @order.ship_method = ship_method
+ ship_method.price = 3
@order.freeze_ship_method
@order.ship_method.price.should == 3
end
+ it "should do nothing when attempting to freeze a nil association" do
+ @order.ship_method.should be_nil
+ lambda { @order.freeze_ship_method }.should_not raise_error
+ @order.ship_method.should be_nil
+ end
+
describe "when freezing association" do
before(:each) do
@ship_method = ShipMethod.create!(:price => 5)
@@ -80,12 +86,12 @@
end
it "should raise an exception when attempting to save associated model" do
- lambda { @order.ship_method.save }.should raise_error(Exception)
- lambda { @order.ship_method.save! }.should raise_error(Exception)
+ lambda { @order.ship_method.save }.should raise_error
+ lambda { @order.ship_method.save! }.should raise_error
end
it "should raise an exception when attempting to replace association" do
- lambda { @order.ship_method = ShipMethod.new }.should raise_error(Exception)
+ lambda { @order.ship_method = ShipMethod.new }.should raise_error
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.