Sha256: fb2688c1b411cbce80e03fba18484090ca18f20f8ab8c49aca7c73f1c5cf1bd4

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')

module Recliner
  describe Document do
    describe "has association" do
      define_recliner_document :User
      define_recliner_document :Article do
        has :user
      end
      
      it "should add a reference property" do
        property = Article.properties[:user_id]
        
        property.should_not be_nil
        property.type.should == Recliner::Associations::Reference
      end
      
      context "with a null reference" do
        subject { Article.new }
        
        it "should be nil" do
          subject.user.should be_nil
        end
      end
      
      describe "assigning by id" do
        subject { Article.new }
        
        before(:each) do
          subject.user_id = '123'
        end
        
        it "should create a reference from the id" do
          subject.user_id.should be_an_instance_of(Recliner::Associations::Reference)
        end
      end
      
      it "should be assignable" do
        user = User.new
        article = Article.new
        
        article.user = user
        article.user.should == user
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
recliner-0.0.1 spec/recliner/document/associations/has_spec.rb