spec/support/models.rb in amoeba-1.0.0 vs spec/support/models.rb in amoeba-1.1.0
- old
+ new
@@ -21,10 +21,45 @@
enable
clone [:widgets, :notes]
prepend :title => "Copy of "
append :contents => " (copied version)"
regex :contents => {:replace => /dog/, :with => 'cat'}
+ customize([
+ lambda do |orig_obj,copy_of_obj|
+ orig_obj.comments.each do |oc|
+ if oc.nerf == "ratatat"
+ hash = oc.attributes
+ hash[:id] = nil
+ hash[:post_id] = nil
+ hash[:contents] = nil
+
+ cc = Comment.new(hash)
+
+ copy_of_obj.comments << cc
+ end
+ end
+ end,
+ lambda do |orig_obj,copy_of_obj|
+ orig_obj.comments.each do |oc|
+ if oc.nerf == "bonk"
+ hash = oc.attributes
+ hash[:id] = nil
+ hash[:post_id] = nil
+ hash[:contents] = nil
+ hash[:nerf] = "bonkers"
+
+ cc = Comment.new(hash)
+
+ copy_of_obj.comments << cc
+ end
+ end
+ end
+ ])
end
+end
+
+class CustomThing < ActiveRecord::Base
+ belongs_to :post
end
class Account < ActiveRecord::Base
belongs_to :post
has_one :history