Sha256: b0f5e421fbfb0dcf8df541cd404477117ed63c632cd141626c7c9485bbdb0b4a

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

require 'test_helper'

class TestRailsCompatibility < Test::Unit::TestCase
  class Item
    include MongoMapper::EmbeddedDocument
    key :for_all, String
  end

  class FirstItem < Item  
    key :first_only, String
    many :second_items
  end

  class SecondItem < Item
    key :second_only, String
  end
  
  context "EmbeddedDocument" do
    should "raise error for to_param as embedded do not have id's" do
      lambda { Item.new.to_param }.should raise_error
    end
    
    should "alias many to has_many" do
      FirstItem.should respond_to(:has_many)
      FirstItem.method(:has_many).should == FirstItem.method(:many)
    end
    
    should "have column names" do
      Item.column_names.sort.should == ['_id', 'for_all']
      FirstItem.column_names.sort.should == ['_id', 'first_only', 'for_all']
      SecondItem.column_names.sort.should == ['_id', 'for_all', 'second_only']
    end
    
    should "alias new to new_record?" do
      instance = Item.new
      instance.new_record?.should == instance.new?
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
djsun-mongomapper-0.4.1.2 test/unit/test_rails_compatibility.rb