Permalink
Browse files

Updated tests.

  • Loading branch information...
1 parent d4e3737 commit 9c676dd1aafbfdc5630e986b207e4780347312b0 @treeder treeder committed Feb 8, 2011
Showing with 29 additions and 14 deletions.
  1. +10 −10 lib/simple_record.rb
  2. +1 −1 test/my_model.rb
  3. +13 −0 test/my_simple_model.rb
  4. +5 −3 test/test_simple_record.rb
View
@@ -457,7 +457,7 @@ def save(options={})
is_create = self[:id].nil?
ok = pre_save(options) # Validates and sets ID
if ok
- puts 'ok'
+# puts 'ok'
begin
dirty = @dirty
# puts 'dirty before=' + @dirty.inspect
@@ -475,17 +475,17 @@ def save(options={})
if @@active_model
x = save_super(dirty, is_create, options, to_delete)
- puts 'save_super result = ' + x.to_s
+# puts 'save_super result = ' + x.to_s
return x
else
- puts 'not activemodel callbacks'
+# puts 'not activemodel callbacks'
return save_super(dirty, is_create, options, to_delete)
end
rescue Aws::AwsError => ex
raise ex
end
else
- puts 'returning false'
+# puts 'returning false'
return false
end
end
@@ -494,19 +494,19 @@ def save(options={})
alias_method :old_save, :save
def save(options={})
- puts 'extended save'
+# puts 'extended save'
x = create_or_update
- puts 'save x=' + x.to_s
+# puts 'save x=' + x.to_s
x
end
end
def create_or_update #:nodoc:
- puts 'create_or_update'
+# puts 'create_or_update'
ret = true
_run_save_callbacks do
result = new_record? ? create : update
- puts 'save_callbacks result=' + result.inspect
+# puts 'save_callbacks result=' + result.inspect
ret = result
end
ret
@@ -517,7 +517,7 @@ def create #:nodoc:
ret = true
_run_create_callbacks do
x = old_save
- puts 'create old_save result=' + x.to_s
+# puts 'create old_save result=' + x.to_s
ret = x
end
ret
@@ -529,7 +529,7 @@ def update(*) #:nodoc:
ret = true
_run_update_callbacks do
x = old_save
- puts 'update old_save result=' + x.to_s
+# puts 'update old_save result=' + x.to_s
ret = x
end
ret
View
@@ -75,7 +75,7 @@ def validate_on_create
def validate_on_update
puts 'MyModel.validate_on_update'
# puts 'save_count = ' + save_count.to_s
- errors.add("save_count", "should not be zero.") if save_count.blank? || save_count == 0
+# errors.add("save_count", "should not be zero.") if save_count.blank? || save_count == 0
end
def atts
View
@@ -0,0 +1,13 @@
+require File.expand_path(File.dirname(__FILE__) + "/../lib/simple_record")
+require_relative 'my_base_model'
+require_relative 'my_sharded_model'
+
+class MySimpleModel < SimpleRecord::Base
+
+ has_strings :name, :nickname, :s1, :s2
+ has_ints :age, :save_count
+ has_booleans :cool
+ has_dates :birthday, :date1, :date2, :date3
+
+
+end
@@ -7,6 +7,7 @@
require_relative 'my_model'
require_relative 'my_child_model'
require_relative 'model_with_enc'
+require_relative 'my_simple_model'
# Tests for SimpleRecord
#
@@ -50,7 +51,7 @@ def test_save_get
sleep 1
mm2 = MyModel.find(id)
puts mm2.inspect
- assert mm2.age.nil?, "doh, age is " + mm2.age.inspect
+ assert mm2.age.nil?, "doh, age should be nil, but it's " + mm2.age.inspect
end
@@ -79,7 +80,7 @@ def test_updates
assert mm.s1 == "", "mm.s1 is not empty string, it is " + mm.s1.inspect
mm = MyModel.find(id)
- assert mm.name == "Travis2"
+ assert mm.name == "Travis2", "Name was not Travis2, it was #{mm.name}"
assert mm.age == 10
assert mm.cool == false
assert mm.s1 == "", "mm.s1 is not empty string, it is #{mm.s1.inspect}"
@@ -268,13 +269,14 @@ def test_dirty
# http://api.rubyonrails.org/classes/ActiveRecord/Dirty.html#M002136
def test_changed
- mm = MyModel.new
+ mm = MySimpleModel.new
mm.name = "Travis"
mm.age = 32
mm.cool = true
mm.save
puts 'changed?=' + mm.changed?.to_s
+ p mm.changed
assert !mm.changed?
assert mm.changed.size == 0
assert mm.changes.size == 0

0 comments on commit 9c676dd

Please sign in to comment.