Skip to content
Browse files

adding freeze and unfreeze association methods when enabling freezing

  • Loading branch information...
1 parent 3f3efcb commit a9206d6d3110b191133f99ae30d17035c9585454 @ryanb committed Jul 11, 2008
Showing with 22 additions and 3 deletions.
  1. +3 −3 README
  2. +9 −0 lib/association_freezer/model_additions.rb
  3. +10 −0 spec/association_freezer/model_additions_spec.rb
View
6 README
@@ -68,8 +68,8 @@ Now you can freeze the association at will:
# in order
def purchase
#...
- freeze_association :billing_address
- freeze_association :shipping_address
+ freeze_billing_address
+ freeze_shipping_address
save!
end
@@ -88,7 +88,7 @@ accidentally altering the data.
You can also unfreeze an already frozen association if you want it to
use the database record instead.
- unfreeze_association :billing_address
+ unfreeze_billing_address
You can then freeze it again to use the updated attributes.
View
9 lib/association_freezer/model_additions.rb
@@ -1,6 +1,15 @@
module AssociationFreezer
module ModelAdditions
def enable_association_freezer
+ reflect_on_all_associations(:belongs_to).each do |association|
+ define_method "freeze_#{association.name}" do
+
+ end
+
+ define_method "unfreeze_#{association.name}" do
+
+ end
+ end
end
end
end
View
10 spec/association_freezer/model_additions_spec.rb
@@ -4,4 +4,14 @@
it "should add enable_association_freezer method to model class" do
Order.should respond_to(:enable_association_freezer)
end
+
+ it "should add a freeze association method when enabling freezing" do
+ Order.enable_association_freezer
+ Order.new.should respond_to(:freeze_ship_method)
+ end
+
+ it "should add an unfreeze association method when enabling freezing" do
+ Order.enable_association_freezer
+ Order.new.should respond_to(:unfreeze_ship_method)
+ end
end

0 comments on commit a9206d6

Please sign in to comment.
Something went wrong with that request. Please try again.