Created
October 10, 2011 03:27
-
-
Save yfeldblum/1274575 to your computer and use it in GitHub Desktop.
mongoid-1338
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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