Skip to content

Instantly share code, notes, and snippets.

@yfeldblum
Created October 10, 2011 03:27
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 yfeldblum/1274575 to your computer and use it in GitHub Desktop.
Save yfeldblum/1274575 to your computer and use it in GitHub Desktop.
mongoid-1338
Mongoid.identity_map_enabled = true
class Post
include Mongoid::Document
belongs_to :blog
end
class Blog
include Mongoid::Document
has_many :posts
end
describe "scope.find" do
let!(:lifehacker) { Blog.create! }
let!(:techcrunch) { Blog.create! }
before do
3.times { lifehacker.posts.create! }
end
it "should raise" do
expect { techcrunch.posts.find(lifehacker.posts.first.id) }
.to raise_error(Mongoid::Errors::DocumentNotFound)
end
it "should be nil when rescued" do
post = techcrunch.posts.find(lifehacker.posts.first.id) rescue nil
post.should be_nil
end
it "should not be the document when rescued" do
post = techcrunch.posts.find(lifehacker.posts.first.id) rescue nil
post.should_not == lifehacker.posts.first
end
end
FFF
Failures:
1) blah should raise
Failure/Error: expect { techcrunch.posts.find(lifehacker.posts.first.id) }
expected Mongoid::Errors::DocumentNotFound but nothing was raised
# ./spec/models/widget_spec.rb:25:in `block (2 levels) in <top (required)>'
2) blah should be nil when rescued
Failure/Error: post.should be_nil
expected: nil
got: #<Post _id: 4e926526b2bc077793000008, _type: nil, blog_id: BSON::ObjectId('4e926526b2bc077793000006')>
# ./spec/models/widget_spec.rb:31:in `block (2 levels) in <top (required)>'
3) blah should not be the document when rescued
Failure/Error: post.should_not == lifehacker.posts.first
expected not: == #<Post _id: 4e926526b2bc07779300000d, _type: nil, blog_id: BSON::ObjectId('4e926526b2bc07779300000b')>
got: #<Post _id: 4e926526b2bc07779300000d, _type: nil, blog_id: BSON::ObjectId('4e926526b2bc07779300000b')>
Diff:
# ./spec/models/widget_spec.rb:36:in `block (2 levels) in <top (required)>'
Finished in 0.02861 seconds
3 examples, 3 failures
Failed examples:
rspec ./spec/models/widget_spec.rb:24 # blah should raise
rspec ./spec/models/widget_spec.rb:29 # blah should be nil when rescued
rspec ./spec/models/widget_spec.rb:34 # blah should not be the document when rescued
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment