Skip to content

Commit

Permalink
Order is not guaranteed on ruby <= 1.8.6 or rbx 1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
gaffneyc committed May 29, 2011
1 parent 48284d8 commit 4558dd4
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion test/unit/test_extensions.rb
Expand Up @@ -5,7 +5,7 @@ class SupportTest < Test::Unit::TestCase
should "convert value to_a" do
Array.to_mongo([1, 2, 3, 4]).should == [1, 2, 3, 4]
Array.to_mongo('1').should == ['1']
Array.to_mongo({'1' => '2', '3' => '4'}).should == [['1', '2'], ['3', '4']]
Array.to_mongo({'1' => '2', '3' => '4'}).should include(['1', '2'], ['3', '4'])
end
end

Expand Down

4 comments on commit 4558dd4

@scottmessinger
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this? This seems like a bug.

@bkeepers
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@scottmessinger it's an issue with Ruby itself. The order of a Hash is not guaranteed.

@gaffneyc
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@scottmessinger Yeah, it's ruby itself. In 1.9 hash iteration order is now based on insertion order. But with 1.8 it's not guaranteed and it was kind of a fluke that this was working.

If instead you did: "Array.to_mongo({'1' => '2', '3' => '4', '5' => '6', '7' => '8'}).should == [['1', '2'], ['3', '4'], ['5', '6'], ['7', '8']]" then the test breaks on 1.8 but passes on 1.9

@scottmessinger
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the info. Good to know!

Please sign in to comment.