Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'test_helper'
- class Project
- include MongoMapper::Document
- key :name, String
- key :context_id, String
- many :tasks
- many :collaborators
- end
- class Task
- include MongoMapper::EmbeddedDocument
- key :name, String
- end
- class Collaborator
- include MongoMapper::EmbeddedDocument
- belongs_to :user
- belongs_to :project
- key :user_id, String
- key :project_id, String
- end
- class User
- include MongoMapper::Document
- key :username, String
- many :projects, :as => :collaborator
- end
- class ProjectTest < Test::Unit::TestCase
- context "A project instance" do
- setup do
- MongoMapper.connection.drop_database("mongo_sandbox")
- @project = Project.create(:name=>"Foo")
- @task = Task.new(:name=>"Foo")
- @project.tasks << @task
- @project.save
- @user = User.create(:username=>"FooUser")
- @project.collaborators << Collaborator.new(:user=>@user,:project=>@project)
- @project.save
- end
- should "should find the collaborator" do
- assert_equal(@project.tasks.first, @task)
- end
- should "find a project by task name" do
- project = Project.find(:first,:conditions=>{
- "tasks.name"=>"Foo"
- })
- assert_equal(@project, project)
- end
- should "find a project by array of names" do
- project = Project.find(:first,:conditions=>{
- "tasks.name"=> {"$in"=>["Foo","Bar"]}
- })
- assert_equal(@project, project)
- end
- should "find a project by size of tasks" do
- project = Project.find(:first,:conditions=>{
- "tasks"=> {"$size"=> 1}
- })
- assert_equal(@project, project)
- end
- should "find by collaborator" do
- project = Project.find(:first,:conditions=>{
- "collaborators.user_id"=>@user._id
- })
- assert_equal(@project, project)
- end
- end
- end
Add Comment
Please, Sign In to add comment