0
@@ -53,10 +53,41 @@ class Person < Record
0
class ConditionalPerson < Record
0
before_save Proc.new { |r| r.history << [:before_save, :proc] }, :if => Proc.new { |r| true }
0
before_save Proc.new { |r| r.history << "b00m" }, :if => Proc.new { |r| false }
0
before_save Proc.new { |r| r.history << [:before_save, :proc] }, :unless => Proc.new { |r| false }
0
before_save Proc.new { |r| r.history << "b00m" }, :unless => Proc.new { |r| true }
0
+ before_save Proc.new { |r| r.history << [:before_save, :symbol] }, :if => :yes
0
+ before_save Proc.new { |r| r.history << "b00m" }, :if => :no
0
+ before_save Proc.new { |r| r.history << [:before_save, :symbol] }, :unless => :no
0
+ before_save Proc.new { |r| r.history << "b00m" }, :unless => :yes
0
+ before_save Proc.new { |r| r.history << [:before_save, :string] }, :if => 'yes'
0
+ before_save Proc.new { |r| r.history << "b00m" }, :if => 'no'
0
+ before_save Proc.new { |r| r.history << [:before_save, :string] }, :unless => 'no'
0
+ before_save Proc.new { |r| r.history << "b00m" }, :unless => 'yes'
0
+ # Array with conditions
0
+ before_save Proc.new { |r| r.history << [:before_save, :symbol_array] }, :if => [:yes, :other_yes]
0
+ before_save Proc.new { |r| r.history << "b00m" }, :if => [:yes, :no]
0
+ before_save Proc.new { |r| r.history << [:before_save, :symbol_array] }, :unless => [:no, :other_no]
0
+ before_save Proc.new { |r| r.history << "b00m" }, :unless => [:yes, :no]
0
+ # Combined if and unless
0
+ before_save Proc.new { |r| r.history << [:before_save, :combined_symbol] }, :if => :yes, :unless => :no
0
+ before_save Proc.new { |r| r.history << "b00m" }, :if => :yes, :unless => :yes
0
+ # Array with different types of conditions
0
+ before_save Proc.new { |r| r.history << [:before_save, :symbol_proc_string_array] }, :if => [:yes, Proc.new { |r| true }, 'yes']
0
+ before_save Proc.new { |r| r.history << "b00m" }, :if => [:yes, Proc.new { |r| true }, 'no']
0
+ # Array with different types of conditions comibned if and unless
0
+ before_save Proc.new { |r| r.history << [:before_save, :combined_symbol_proc_string_array] },
0
+ :if => [:yes, Proc.new { |r| true }, 'yes'], :unless => [:no, 'no']
0
+ before_save Proc.new { |r| r.history << "b00m" }, :if => [:yes, Proc.new { |r| true }, 'no'], :unless => [:no, 'no']
0
+ def other_yes; true; end
0
+ def other_no; false; end
0
run_callbacks(:before_save)
0
@@ -90,7 +121,16 @@ class ConditionalCallbackTest < Test::Unit::TestCase
0
+ [:before_save, :proc],
0
+ [:before_save, :symbol],
0
+ [:before_save, :symbol],
0
+ [:before_save, :string],
0
+ [:before_save, :string],
0
+ [:before_save, :symbol_array],
0
+ [:before_save, :symbol_array],
0
+ [:before_save, :combined_symbol],
0
+ [:before_save, :symbol_proc_string_array],
0
+ [:before_save, :combined_symbol_proc_string_array]