Sha256: a1942653bf15a78becdc92ed414819a6c427c062d1db6c92c76a5743b34de28f

Contents?: true

Size: 1.27 KB

Versions: 7

Compression:

Stored size: 1.27 KB

Contents

require 'test_helper'
require 'models'

class AssociationsTest < Test::Unit::TestCase    
  should "allow changing class names" do
    class AwesomeUser
      include MongoMapper::Document
      
      many :posts, :class_name => 'AssociationsTest::AwesomePost', :foreign_key => :creator_id
    end
    AwesomeUser.collection.remove
    
    class AwesomeTag
      include MongoMapper::EmbeddedDocument
      
      key :name, String
      key :post_id, String
      
      belongs_to :post, :class_name => 'AssociationsTest::AwesomeUser'
    end
    
    class AwesomePost
      include MongoMapper::Document
      
      key :creator_id, String
      
      belongs_to :creator, :class_name => 'AssociationsTest::AwesomeUser'
      many :tags, :class_name => 'AssociationsTest::AwesomeTag', :foreign_key => :post_id
    end
    
    AwesomeUser.collection.remove
    AwesomePost.collection.remove
    
    user = AwesomeUser.create
    tag1 = AwesomeTag.new(:name => 'awesome')
    tag2 = AwesomeTag.new(:name => 'grand')
    post1 = AwesomePost.create(:creator => user, :tags => [tag1])
    post2 = AwesomePost.create(:creator => user, :tags => [tag2])
    user.posts.should == [post1, post2]
    
    post1_from_db = AwesomePost.find(post1.id)
    post1_from_db.tags.should == [tag1]
  end  
end

Version data entries

7 entries across 7 versions & 3 rubygems

Version Path
mongo_mapper-unstable-2009.11.8 test/functional/test_associations.rb
mongo_mapper-unstable-2009.11.6 test/functional/test_associations.rb
djsun-mongo_mapper-0.5.8.2 test/functional/test_associations.rb
djsun-mongo_mapper-0.5.8.1 test/functional/test_associations.rb
mongo_mapper-unstable-2009.11.2 test/functional/test_associations.rb
mongo_mapper-unstable-2009.10.31 test/functional/test_associations.rb
mongo_mapper-0.5.8 test/functional/test_associations.rb