Skip to content
Browse files

bit further

  • Loading branch information...
1 parent fb953cb commit d2a1e96094b368859c2c69a8c4831c363a0a966b @treeder treeder committed Jan 26, 2011
Showing with 20 additions and 13 deletions.
  1. +13 −6 test/my_model.rb
  2. +7 −7 test/test_validations.rb
View
19 test/my_model.rb
@@ -19,33 +19,40 @@ class MyModel < MyBaseModel
has_clobs :clob1, :clob2
- attr_accessor :after_create, :after_save, :before_create
+ attr_accessor :attr_before_save, :attr_after_save, :attr_before_create, :attr_after_create,
+
#callbacks
before_create :set_nickname
after_create :after_create
- before_save :bump_save_count
+ before_save :before_save
after_save :after_save
def set_nickname
puts 'before_create set nickname'
- @before_create = true
+ @attr_before_create = true
self.nickname = name if self.nickname.blank?
end
+ def before_save
+ puts 'before_save'
+ @attr_before_save = true
+ end
+
def after_create
puts 'after_create'
- @after_create = true
+ @attr_after_create = true
end
def after_save
puts "after_save"
- @after_save = true
+ @attr_after_save = true
+ bump_save_count
end
def bump_save_count
- puts 'before_save bump save_count=' + save_count.to_s
+ puts 'after_save bump save_count=' + save_count.to_s
if save_count.nil?
self.save_count = 1
else
View
14 test/test_validations.rb
@@ -17,13 +17,13 @@ def test_validations
mm = MyModel.new()
assert mm.invalid?, "mm is valid. invalid? returned #{mm.invalid?}"
assert mm.errors.size == 1
- assert !mm.before_create
+ assert !mm.attr_before_create
assert mm.save == false, mm.errors.inspect
- assert mm.before_create
- assert !mm.after_save
- assert !mm.after_create
+ assert mm.attr_before_create
+ assert !mm.attr_after_save
+ assert !mm.attr_after_create
mm.name = "abcd"
- assert mm.valid?
+ assert mm.valid?, mm.errors.inspect
assert mm.errors.size == 0
mm.save_count = 2
@@ -33,8 +33,8 @@ def test_validations
assert mm.valid?
assert mm.save, mm.errors.inspect
- assert mm.after_save
- assert mm.after_create
+ assert mm.attr_after_save
+ assert mm.attr_after_create
assert mm.valid?, mm.errors.inspect
assert mm.save_count == 1

0 comments on commit d2a1e96

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