Sha256: 012871e02751a05199a543ea93a904d07c31f3e2f9f98db64320e1286002f9ef

Contents?: true

Size: 1.89 KB

Versions: 1

Compression:

Stored size: 1.89 KB

Contents

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

describe Comment do
  before(:each) do
    @comment = Comment.create!(:body => 'The body.')
  end
  
  it "should contain a body" do
    @comment.body.should == 'The body.'
  end

  describe "without an author" do
    it "should return a null object for the author" do
      @comment.author.kind_of?(NullAuthor).should be_true
    end
    
    it "should be nil" do
      @comment.author.should be_nil
    end
    
    it "should return nil for the author's name" do
      @comment.author.name.should be_nil
    end
  end
  
  describe "with an author" do
    before(:each) do
      @comment.author = Author.create!(:name => 'James Baker')
    end
    
    it "should return the author object" do
      @comment.author.kind_of?(Author).should be_true
      @comment.author.kind_of?(NullAuthor).should_not be_true
    end
    
    it "should return the author's name" do
      @comment.author.name.should == 'James Baker'
    end
    
    it "should revert to a null object if assigned nil" do
      @comment.author = nil
      @comment.author.name.should be_nil
    end
  end
end

describe Post do
  before(:each) do
    @post = Post.create!(:body => 'The body.')
  end
  
  it "should contain a body" do
    @post.body.should == 'The body.'
  end
  
  it "should not have null object support for the author" do
    @post.author.should be_nil
    @post.author.kind_of?(Author).should be_false
    @post.author.respond_to?(:name).should be_false
  end
end

describe Session do
  before(:each) do
    @session = Session.create!(:description => 'The description.')
  end
  
  it "should contain a description" do
    @session.description.should == 'The description.'
  end
  
  it "should not have null object support for the author" do
    @session.author.should be_nil
    @session.author.kind_of?(Author).should be_false
    @session.author.respond_to?(:name).should be_false
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
westarete-activerecord_null_object-0.0.0 spec/belongs_to_spec.rb