test/test_document.rb in couchpillow-0.3.6 vs test/test_document.rb in couchpillow-0.3.7
- old
+ new
@@ -46,9 +46,41 @@
end.new
assert_equal "test", d._type
end
+ def test_update
+ d = Class.new(Document) do
+ type 'test'
+ end.new
+ hash = {
+ 'me' => 'too',
+ :batman => 'robin',
+ 'apple' => 123
+ }
+ d.update(hash)
+ assert_equal 'too', d[:me]
+ assert_equal 'robin', d[:batman]
+ assert_equal 123, d[:apple]
+ assert d.save!
+ end
+
+
+ def test_update_existing_fields
+ d = Class.new(Document) do
+ type 'test'
+ end.new({ a: 1, b: 2})
+ assert_equal 1, d[:a]
+ hash = {
+ 'a' => 'too',
+ }
+ d.update(hash)
+ assert_equal 'too', d[:a]
+ assert_equal 2, d[:b]
+ assert d.save!
+ end
+
+
def test_validate_presence
d = Class.new(Document) do
validate_presence :xyz
end.new
assert_raises Document::ValidationError do