Created
December 10, 2011 15:36
-
-
Save dougalcorn/1455417 to your computer and use it in GitHub Desktop.
Simplified example of failing any_in criteria for mongoid using string id fields
This file contains 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
Failures: | |
1) Mongoid inclusion criteria | |
Failure/Error: @criteria.selector.should == {"$in" => {:from_id => [from_port.id, to_port.id]}} | |
expected: {"$in"=>{:from_id=>["6055df90-0572-012f-2043-388d1201202c", "60562bc0-0572-012f-2043-388d1201202c"]}}, | |
got: {:from_id=>"{\"$in\"=>[\"6055df90-0572-012f-2043-388d1201202c\", \"60562bc0-0572-012f-2043-388d1201202c\"]}"} (using ==) | |
Diff: | |
@@ -1,5 +1,3 @@ | |
-{"$in"=> | |
- {:from_id=> | |
- ["6055df90-0572-012f-2043-388d1201202c", | |
- "60562bc0-0572-012f-2043-388d1201202c"]}} | |
+{:from_id=> | |
+ "{\"$in\"=>[\"6055df90-0572-012f-2043-388d1201202c\", \"60562bc0-0572-012f-2043-388d1201202c\"]}"} | |
# ./spec/mongoid_inclusion_spec.rb:34:in `block (2 levels) in <top (required)>' |
This file contains 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
require 'rspec' | |
require 'mongoid' | |
require 'uuid' | |
Mongoid.configure do |config| | |
config.master = Mongo::Connection.new.db("godfather") | |
end | |
class GUIDObject | |
include Mongoid::Document | |
field :guid | |
key :guid | |
end | |
class Connection < GUIDObject | |
referenced_in :from, :class_name => "Port", :inverse_of => nil | |
referenced_in :to, :class_name => "Port", :inverse_of => nil | |
end | |
class Port < GUIDObject | |
end | |
describe "Mongoid inclusion criteria" do | |
let(:from_port) { Port.create(:guid => UUID.generate) } | |
let(:to_port) { Port.create(:guid => UUID.generate) } | |
let(:connection) { Connection.create(:guid => UUID.generate, :from => from_port, :to => to_port) } | |
before do | |
@criteria = Connection.any_in(:from_id => [from_port.id, to_port.id]) | |
end | |
it do | |
@criteria.selector.should == {"$in" => {:from_id => [from_port.id, to_port.id]}} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment