Sha256: 113da96964df7e670bb22b8c6860bd7c700a99a504fbead41be06cdd5ad1ff52

Contents?: true

Size: 1.28 KB

Versions: 25

Compression:

Stored size: 1.28 KB

Contents

require 'test_helper'
require 'models'

class AssociationsTest < Test::Unit::TestCase
  def setup
    clear_all_collections
  end
    
  should "allow changing class names" do
    class AwesomeUser
      include MongoMapper::Document
      
      many :posts, :class_name => 'AssociationsTest::AwesomePost', :foreign_key => :creator_id
    end
    
    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.clear
    AwesomePost.collection.clear
    
    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

25 entries across 25 versions & 6 rubygems

Version Path
crnixon-mongomapper-0.3.4 test/functional/test_associations.rb
djsun-mongomapper-0.3.3 test/functional/test_associations.rb
djsun-mongomapper-0.3.5.1 test/functional/test_associations.rb
djsun-mongomapper-0.3.5.2 test/functional/test_associations.rb
djsun-mongomapper-0.3.5.4 test/functional/test_associations.rb
djsun-mongomapper-0.3.5.5 test/functional/test_associations.rb
djsun-mongomapper-0.3.5 test/functional/test_associations.rb
hashrocket-mongomapper-0.3.10 test/functional/test_associations.rb
hashrocket-mongomapper-0.3.11 test/functional/test_associations.rb
hashrocket-mongomapper-0.3.12 test/functional/test_associations.rb
hashrocket-mongomapper-0.3.13 test/functional/test_associations.rb
hashrocket-mongomapper-0.3.14 test/functional/test_associations.rb
hashrocket-mongomapper-0.3.15 test/functional/test_associations.rb
hashrocket-mongomapper-0.3.3 test/functional/test_associations.rb
hashrocket-mongomapper-0.3.4.1 test/functional/test_associations.rb
hashrocket-mongomapper-0.3.4 test/functional/test_associations.rb
hashrocket-mongomapper-0.3.5 test/functional/test_associations.rb
hashrocket-mongomapper-0.3.6 test/functional/test_associations.rb
hashrocket-mongomapper-0.3.7 test/functional/test_associations.rb
hashrocket-mongomapper-0.3.8 test/functional/test_associations.rb