Sha256: 26de6eda4be873e18d971ddf40d513ef91870f0f931d6796db6aae8a41f7b4e3

Contents?: true

Size: 1.19 KB

Versions: 59

Compression:

Stored size: 1.19 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

59 entries across 59 versions & 7 rubygems

Version Path
jonbell-mongo_mapper-0.8.6 test/functional/test_associations.rb
ssherman-mongo_mapper-0.8.6 test/functional/test_associations.rb
mongo_mapper-0.8.6 test/functional/test_associations.rb
mongo_mapper-0.8.5 test/functional/test_associations.rb
honkster-mongo_mapper-0.8.4 test/functional/test_associations.rb
mongo_mapper-0.8.4 test/functional/test_associations.rb
mongo_mapper-unstable-2010.08.19 test/functional/test_associations.rb
mongo_mapper-unstable-2010.08.18 test/functional/test_associations.rb
mongo_mapper-unstable-2010.08.17 test/functional/test_associations.rb
mongo_mapper-unstable-2010.08.16 test/functional/test_associations.rb
mongo_mapper-unstable-2010.08.15 test/functional/test_associations.rb
mongo_mapper-unstable-2010.08.14 test/functional/test_associations.rb
mongo_mapper-unstable-2010.08.13 test/functional/test_associations.rb
mongo_mapper-unstable-2010.08.12 test/functional/test_associations.rb
mongo_mapper-unstable-2010.08.11 test/functional/test_associations.rb
mongo_mapper-unstable-2010.08.10 test/functional/test_associations.rb
mongo_mapper-unstable-2010.08.09 test/functional/test_associations.rb
mongo_mapper-0.8.3 test/functional/test_associations.rb
mongo_mapper-unstable-2010.08.08 test/functional/test_associations.rb
mongo_mapper-unstable-2010.08.06 test/functional/test_associations.rb