test/test_model.rb in couchbase-model-0.2.0 vs test/test_model.rb in couchbase-model-0.3.0

- old
+ new

@@ -22,10 +22,19 @@ attribute :body attribute :author, :default => 'Anonymous' attribute :created_at, :default => lambda { Time.utc("2010-01-01") } end +class Brewery < Couchbase::Model + attribute :name +end + +class Beer < Couchbase::Model + attribute :name + belongs_to :brewery +end + class TestModel < MiniTest::Unit::TestCase def setup @mock = start_mock Post.bucket = Couchbase.connect(:hostname => @mock.host, @@ -101,13 +110,13 @@ attribute :name, :email, :body end EOC comment = Comment.new - assert comment.respond_to?(:name) - assert comment.respond_to?(:email) - assert comment.respond_to?(:body) + assert_respond_to comment, :name + assert_respond_to comment, :email + assert_respond_to comment, :body end def test_allows_arbitrary_ids Post.create(:id => uniq_id, :title => "Foo") assert_equal "Foo", Post.find(uniq_id).title @@ -148,8 +157,18 @@ post = Post.new(:title => "Hello") refute post.id assert_raises Couchbase::Error::MissingId do post.delete end + end + + def test_belongs_to_assoc + brewery = Brewery.create(:name => "Anheuser-Busch") + assert_includes Beer.attributes.keys, :brewery_id + beer = Beer.create(:name => "Budweiser", :brewery_id => brewery.id) + assert_respond_to beer, :brewery + assoc = beer.brewery + assert_instance_of Brewery, assoc + assert_equal "Anheuser-Busch", assoc.name end end