I'm unsure whether Bug is the correct issue type however there are a couple of things I wanted to point out.
So it all started with my rspec test failing
it "doesn't override existing method" do expect(string.method(method).super_method).to be_nil end
Where `method` was `numeric?`.
So I investigated and found that `mongoid` gem creates a `#numeric?` method for the String objects.
By documentation it says
# @return [ true, false ] If the string is a number.
However by testing the code in the console it was clear that the method was not returning `true, false` but many other results.
I added some tests to check for `true` and `false` values and I got many errors like
Failure/Error: expect("-Infinity".numeric?).to eq(true) expected: true got: 0
OR
Failure/Error: expect("blah".numeric?).to eq(false) expected: false got: nil
I'm unsure whether the documentation is wrong or the method implementation but there are many things wrong:
1. You should not be adding methods to standard API classes as many companies might be doing that already and it might happen that they override your methods and weird things start happening
2. The documentation / implementation are out of sync
3. Not sure but I think tests should be checking explicitly for the result instead of doing `be_numeric` shouldn't they? I don't see a point in using the same method to check the behaviour of the method itself.
4. `Failure/Error: expect(mongoized).to eq(expected_time)` in `
it_behaves_like 'mongoizes to Time'` is failing due to my timezone being different. If you want developers to contribute you should be making tests compatible with any timezone
5. There's no documentation on how to Create an issue, create a PR, run tests locally, improve code or styling
- is related to
-
MONGOID-4743 String#numeric? incorrectly uses ^ and $ anchors and groups
- Closed
- links to