Skip to content

Instantly share code, notes, and snippets.

@ktkaushik
Created March 27, 2012 17:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ktkaushik/2218004 to your computer and use it in GitHub Desktop.
Save ktkaushik/2218004 to your computer and use it in GitHub Desktop.
Specs for testing MongoDB's Embedded and Referenced association with Mongoid.
require 'spec_helper'
describe Client do
context "With valid client info" do
context "Associations" do
it "should embed many projects" do
association = Client.relations['projects']
association.klass.should == Project
association.relation.should == Mongoid::Relations::Embedded::Many
end
end
end
end
require 'spec_helper'
describe Developer do
describe "With valid Developer information" do
context "Checking Mongoid's Referenced association between project and developer" do
it "should be referenced in a project" do
association = Developer.associations['project']
association.klass.should == Project
association.relation.should == Mongoid::Relations::Referenced::In
end
end
end
end
require 'spec_helper'
describe Project do
describe "With valid Project information" do
context "Checking Mongoid's embedded association between project and client" do
it "should be embedded in a client" do
association = Project.associations['client']
association.klass.should == Client
association.relation.should == Mongoid::Relations::Embedded::In
end
it "should reference many developers" do
association = Project.associations['developers']
association.klass.should == Developer
association.relation.should == Mongoid::Relations::Referenced::Many
end
end
end
end
@ktkaushik
Copy link
Author

Models specs for Embedded and Referenced association in MongoDB using Mongoid.
A Client embeds_many :projects
Project is embedded_in :client
whereas a Project references_many :developers and a
Developer is referenced_in :project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment