Sha256: e4d00b745e7dae0e807a2d2775aa282449e1b674b974ad67afc2d83507496193

Contents?: true

Size: 1.21 KB

Versions: 13

Compression:

Stored size: 1.21 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.reload
    user.posts.should == [post1, post2]

    post1 = post1.reload
    post1.tags.should == [tag1]
  end
end

Version data entries

13 entries across 13 versions & 4 rubygems

Version Path
mongo_mapper-0.12.0 test/functional/test_associations.rb
lookout-mongo_mapper-0.11.3 test/functional/test_associations.rb
mongo_mapper-0.11.2 test/functional/test_associations.rb
jamieorc-mongo_mapper-0.11.1.1 test/functional/test_associations.rb
mongo_mapper-0.11.1 test/functional/test_associations.rb
mongo_mapper-0.11.0 test/functional/test_associations.rb
mongo_mapper-0.10.1 test/functional/test_associations.rb
mongo_mapper-0.10.0 test/functional/test_associations.rb
mongo_mapper-0.9.2 test/functional/test_associations.rb
mongo_mapper-0.9.1 test/functional/test_associations.rb
mongo_mapper-0.9.0 test/functional/test_associations.rb
ign-mongo_mapper-0.8.6.2 test/functional/test_associations.rb
ign-mongo_mapper-0.8.6.1 test/functional/test_associations.rb