Sha256: 64398cc3c3de72537218b6df1d1a3f9a21d00df112a98c50030f1ef860009cac

Contents?: true

Size: 1.24 KB

Versions: 79

Compression:

Stored size: 1.24 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, ObjectId
      
      belongs_to :post, :class_name => 'AssociationsTest::AwesomeUser'
    end
    
    class AwesomePost
      include MongoMapper::Document
      
      key :creator_id, ObjectId
      
      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 = post1.reload
    post1.tags.should == [tag1]
  end
end

Version data entries

79 entries across 79 versions & 10 rubygems

Version Path
mongo_mapper-0.7.5 test/functional/test_associations.rb
mongo_mapper_ign-0.7.4 test/functional/test_associations.rb
mongo_mapper-0.7.4 test/functional/test_associations.rb
mongo_mapper-0.7.3 test/functional/test_associations.rb
numon-0.0.1 test/functional/test_associations.rb
mongo_mapper-0.7.2 test/functional/test_associations.rb
mongo_mapper-0.7.1 test/functional/test_associations.rb
mongo_mapper-unstable-2010.3.8 test/functional/test_associations.rb
mongo_mapper-unstable-2010.3.5 test/functional/test_associations.rb
mongo_mapper-unstable-2010.3.4 test/functional/test_associations.rb
mongo_mapper-unstable-2010.3.3 test/functional/test_associations.rb
drogus-mongo_mapper-0.6.10 test/functional/test_associations.rb
mongo_mapper-rails3-0.7.0.1 test/functional/test_associations.rb
mongo_mapper-unstable-2010.2.28 test/functional/test_associations.rb
mongo_mapper-unstable-2010.2.27 test/functional/test_associations.rb
mongo_mapper-unstable-2010.2.26 test/functional/test_associations.rb
mongo_mapper-unstable-2010.2.25 test/functional/test_associations.rb
mongo_mapper-unstable-2010.2.24 test/functional/test_associations.rb
mongo_mapper-unstable-2010.2.23 test/functional/test_associations.rb
mongo_mapper-unstable-2010.2.22 test/functional/test_associations.rb