Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #32099: Check if an Integer for integer data_type #326

Merged
merged 1 commit into from
Mar 16, 2021

Conversation

ehelms
Copy link
Member

@ehelms ehelms commented Mar 15, 2021

This fixes a deprecation warning present in Ruby 2.7:

warning: deprecated Object#=~ is called on Integer; it always returns nil

@wbclark
Copy link
Contributor

wbclark commented Mar 15, 2021

hmmm,

"foo".to_i
=> 0

is happening somehow in test/kafo/data_types/hash_test.rb ?

@ehelms
Copy link
Member Author

ehelms commented Mar 15, 2021

Hrmm, means this method is not used how I thought it was used. I'll take another crack at modifying the original.

@ehelms ehelms changed the title Fixes #32099: Call to_i in all cases for Integer data type Fixes #32099: Check if an Integer for integer data_type Mar 15, 2021
@ehelms
Copy link
Member Author

ehelms commented Mar 15, 2021

Updated. I did change one assertion because it seemed odd to me that "1foo" should be consider an Integer and return "1". If you mix letters and numbers, that ought to be a string. An integer should be clearly an integer.

@@ -19,7 +19,9 @@ def to_s
end

def typecast(value)
value =~ /\d+/ ? value.to_i : value
Integer(value)
rescue
Copy link
Member

Choose a reason for hiding this comment

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

Isn't it better to catch ArgumentError explicitly? Catching all exceptions is generally a bad practice.

test/kafo/data_types/integer_test.rb Show resolved Hide resolved
@ehelms
Copy link
Member Author

ehelms commented Mar 15, 2021

Additional to this, I think having theforeman/jenkins-jobs#5 in place would help catch these outside of runtime testing.

@ehelms
Copy link
Member Author

ehelms commented Mar 15, 2021

This required some additional cleanup to get everything to work properly.

Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

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

The commit message should also mention Float, other than 👍

…ta_type

This fixes a deprecation warning present in Ruby 2.7:
warning: deprecated Object#=~ is called on Integer; it always returns nil

The change removes Kafo's custom TypeError exception as there was
no use of it inside the project and it had the effect of shadowing
the built in Ruby TypeError.
@ehelms ehelms merged commit 06e843d into theforeman:master Mar 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants