Sha256: 5e27e4a199f7b6ffd2afca25fbe6a7fb89dd97892906094d14418d3a268fea78

Contents?: true

Size: 1.82 KB

Versions: 53

Compression:

Stored size: 1.82 KB

Contents

require 'test_helper'

class StringIdCompatibilityTest < Test::Unit::TestCase
  def setup
    @note_class = EDoc do
      key :_id, String
    end

    @task_class = Doc do
      key :_id, String
      key :project_id, String
      belongs_to :project
    end

    @project_class = Doc do
      include MongoMapper::Document
      key :_id, String
    end

    @task_class.belongs_to :project, :class => @project_class
    @project_class.many :notes, :class => @note_class
    @project_class.many :tasks, :class => @task_class, :foreign_key => 'project_id', :order => :position.asc
  end

  should "assign correct _id for documents" do
    project = @project_class.create
    project._id.should == project.id
    project._id.should be_instance_of(String)
    project.id.size.should == 24
    lambda {
      BSON::ObjectID.from_string(project.id)
    }.should_not raise_error
  end

  should "assign correct _id for embedded documents" do
    note = @note_class.new
    note.id.should == note._id
    note.id.size.should == 24
  end

  should "find records" do
    project = @project_class.create
    @project_class.find(project.id).should == project
  end

  should "save embedded docs" do
    n1 = @note_class.new
    n2 = @note_class.new
    n3 = @note_class.new
    project = @project_class.create(:notes => [n1, n2, n3])

    project = project.reload
    project.notes.size.should == 3
    project.notes.should == [n1, n2, n3]
  end

  should "be able to associate records" do
    t1 = @task_class.new(:body => 'First task', :position => 1)
    t2 = @task_class.new(:body => 'Second task', :position => 2)
    t3 = @task_class.new(:body => 'Third task', :position => 3)
    project = @project_class.create(:name => 'MM', :tasks => [t1, t2, t3])

    project = project.reload
    project.tasks.count.should == 3
    project.tasks.should == [t1, t2, t3]
  end
end

Version data entries

53 entries across 53 versions & 4 rubygems

Version Path
mongo_mapper-unstable-2010.08.19 test/functional/test_string_id_compatibility.rb
mongo_mapper-unstable-2010.08.18 test/functional/test_string_id_compatibility.rb
mongo_mapper-unstable-2010.08.17 test/functional/test_string_id_compatibility.rb
mongo_mapper-unstable-2010.08.16 test/functional/test_string_id_compatibility.rb
mongo_mapper-unstable-2010.08.15 test/functional/test_string_id_compatibility.rb
mongo_mapper-unstable-2010.08.14 test/functional/test_string_id_compatibility.rb
mongo_mapper-unstable-2010.08.13 test/functional/test_string_id_compatibility.rb
mongo_mapper-unstable-2010.08.12 test/functional/test_string_id_compatibility.rb
mongo_mapper-unstable-2010.08.11 test/functional/test_string_id_compatibility.rb
mongo_mapper-unstable-2010.08.10 test/functional/test_string_id_compatibility.rb
mongo_mapper-unstable-2010.08.09 test/functional/test_string_id_compatibility.rb
mongo_mapper-0.8.3 test/functional/test_string_id_compatibility.rb
mongo_mapper-unstable-2010.08.08 test/functional/test_string_id_compatibility.rb
mongo_mapper-unstable-2010.08.06 test/functional/test_string_id_compatibility.rb
mongo_mapper-unstable-2010.08.05 test/functional/test_string_id_compatibility.rb
mongo_mapper-unstable-2010.08.04 test/functional/test_string_id_compatibility.rb
mongo_mapper-unstable-2010.08.03 test/functional/test_string_id_compatibility.rb
mongo_mapper-unstable-2010.08.02 test/functional/test_string_id_compatibility.rb
mongo_mapper-unstable-2010.08.01 test/functional/test_string_id_compatibility.rb
mongo_mapper-unstable-2010.07.31 test/functional/test_string_id_compatibility.rb