Skip to content

Instantly share code, notes, and snippets.

@nerdyworm
Created July 19, 2012 21:42
Show Gist options
  • Save nerdyworm/3147040 to your computer and use it in GitHub Desktop.
Save nerdyworm/3147040 to your computer and use it in GitHub Desktop.
require 'mongoid'
ENV["RACK_ENV"] = 'test'
Mongoid.load!("./config/mongoid.yml")
class Tag
include Mongoid:: Document
end
class Post
include Mongoid:: Document
has_and_belongs_to_many :tags, inverse_of: nil
end
describe "HBTM" do
it "returns tags" do
tag = Tag.create
post = Post.create
post.tag_ids = [tag.id]
post.save
post.reload
post.tags.should == [tag]
end
it "return tags" do
tag = Tag.create
post = Post.create
post.tags << tag
post.reload
post.tags.should == [tag]
end
it "return tags" do
post = Post.create
tag = post.tags.create
post.reload
post.tags.should == [tag]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment