test/test_model.rb in couchbase-model-0.5.1 vs test/test_model.rb in couchbase-model-0.5.2
- old
+ new
@@ -43,10 +43,15 @@
class Attachment < Couchbase::Model
defaults :format => :plain
end
+class Comments < Couchbase::Model
+ include Enumerable
+ attribute :comments, :default => []
+end
+
class TestModel < MiniTest::Unit::TestCase
def setup
@mock = start_mock
bucket = Couchbase.connect(:hostname => @mock.host, :port => @mock.port)
@@ -124,16 +129,16 @@
orig.reload
assert_equal "Good bye, world", orig.title
end
def test_it_raises_not_found_exception
- assert_raises Couchbase::Error::MissingId do
+ assert_raises Couchbase::Error::NotFound do
Post.find("missing_key")
end
end
- def test_it_raises_not_found_exception
+ def test_it_returns_nil_when_key_not_found
refute Post.find_by_id("missing_key")
end
def test_doesnt_raise_if_the_attribute_redefined
eval <<-EOC
@@ -219,10 +224,20 @@
def test_to_param
assert_equal "the-id", Post.new(:id => "the-id").to_param
assert_equal "the-key", Post.new(:key => ["the", "key"]).to_param
end
+ def test_as_json
+ require 'active_support/json/encoding'
+
+ response = {'id' => 'the-id'}
+ assert_equal response, Post.new(:id => "the-id").as_json
+
+ response = {}
+ assert_equal response, Post.new(:id => "the-id").as_json(:except => :id)
+ end
+
def test_validation
post = ValidPost.create(:title => 'Hello, World!')
assert post.valid?, "post with title should be valid"
post.title = nil
refute post.save
@@ -238,8 +253,12 @@
def test_blob_documents
contents = File.read(__FILE__)
id = Attachment.create(:raw => contents).id
blob = Attachment.find(id)
assert_equal contents, blob.raw
+ end
+
+ def test_couchbase_ancestor
+ assert_equal Couchbase::Model, Comments.couchbase_ancestor
end
end