Last active
December 10, 2015 00:38
-
-
Save bernd/4352389 to your computer and use it in GitHub Desktop.
Show broken boolean coercion with the mongoid gem loaded. See: https://github.com/solnic/virtus/issues/132
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
require 'virtus' | |
require 'minitest/spec' | |
require 'minitest/autorun' | |
class A | |
include Virtus | |
attribute :foo, Boolean | |
end | |
describe 'without mongoid' do | |
it 'is works' do | |
A.new(:foo => 'true').foo.must_equal true | |
end | |
end | |
class B | |
include Virtus | |
puts "==> before mongoid: #{Boolean.ancestors}" | |
require 'mongoid' | |
puts "==> after mongoid: #{Boolean.ancestors}" | |
attribute :foo, Boolean | |
# Using Virtus::Attribute::Boolean instead of Boolean is a workaround here. | |
end | |
describe 'with mongoid' do | |
it 'is broken' do | |
B.new(:foo => 'true').foo.must_equal true | |
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
$ ruby -v; gem list; ruby broken_boolean_coercion.rb | |
ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-linux] | |
*** LOCAL GEMS *** | |
activemodel (3.2.9) | |
activesupport (3.2.9) | |
backports (2.6.5) | |
builder (3.0.4) | |
bundler (1.2.3) | |
descendants_tracker (0.0.1) | |
i18n (0.6.1) | |
mongoid (3.0.15) | |
moped (1.3.1) | |
multi_json (1.5.0) | |
origin (1.0.11) | |
rake (10.0.3) | |
rubygems-bundler (1.1.0) | |
rubygems-tasks (0.2.3) | |
rvm (1.11.3.5) | |
tzinfo (0.3.35) | |
virtus (0.5.4) | |
==> before mongoid: [Virtus::Attribute::Boolean, Virtus::Attribute::Object, Virtus::Attribute, #<Virtus::Equalizer:0x000000009d56c0>, Virtus::Equalizer::Methods, Object, MiniTest::Expectations, Kernel, BasicObject] | |
==> after mongoid: [Boolean, Object, Mongoid::Extensions::Object, Moped::BSON::Extensions::Object, Origin::Extensions::Object, JSON::Ext::Generator::GeneratorMethods::Object, MiniTest::Expectations, Kernel, BasicObject] | |
Run options: --seed 46930 | |
# Running tests: | |
F. | |
Finished tests in 0.020978s, 95.3366 tests/s, 95.3366 assertions/s. | |
1) Failure: | |
test_0001_is_broken(with mongoid) [broken_boolean_coercion.rb:29]: | |
Expected: true | |
Actual: "true" | |
2 tests, 2 assertions, 1 failures, 0 errors, 0 skips | |
$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment