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

convert_value_based_on_datatype won't take "Integer" #258

Conversation

d-m-u
Copy link
Contributor

@d-m-u d-m-u commented Oct 24, 2018

This is the last PR I need to fix https://bugzilla.redhat.com/show_bug.cgi?id=1628224. Custom Buttons on multiple objects aren't being run because the engine won't take "Integer" ... which I think it should. This hackiness seems to be the convention for Time and Symbol.

related

already merged ManageIQ/manageiq#18056

@d-m-u d-m-u changed the title Should take integer regardless of case... convert_value_based_on_datatype won't take "Integer" Oct 24, 2018
@d-m-u
Copy link
Contributor Author

d-m-u commented Oct 24, 2018

@miq-bot add_reviewer @tinaafitz
@miq-bot add_label bug
@miq-bot assign @gmcculloug

@d-m-u
Copy link
Contributor Author

d-m-u commented Oct 24, 2018

@miq-bot add_label hammer/yes

@@ -559,7 +559,7 @@ def self.convert_value_based_on_datatype(value, datatype)
return false if datatype == 'FalseClass'
return Time.parse(value) if datatype == 'time' || datatype == 'Time'
return value.to_sym if datatype == 'symbol' || datatype == 'Symbol'
return value.to_i if datatype == 'integer' || datatype == 'Fixnum'
return value.to_i if datatype == 'integer' || datatype == 'Fixnum' || datatype == 'Integer'
Copy link
Member

Choose a reason for hiding this comment

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

Maybe: datatype.casecmp?('integer')

@d-m-u d-m-u force-pushed the integer_or_Integer_in_object_convert_value_based_on_datatype branch from 1f0fb97 to 6f970b0 Compare October 24, 2018 18:00
return value.gsub(/[\[\]]/, '').strip.split(/\s*,\s*/) if datatype == 'array' && value.class == String
return Time.parse(value) if datatype.casecmp?('time')
return value.to_sym if datatype.casecmp?('symbol')
return value.to_i if datatype.casecmp?('integer') || datatype == 'Fixnum'
Copy link
Member

Choose a reason for hiding this comment

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

The lower-case 'integer' type comes from the Automate class schema which is why we initially had that value and Fixnum. Ruby 2.4 replaced Fixnum with Integer which causes the issue.

Since we still support Ruby 2.3 we will need to retain the Fixnum check here for a bit longer.

@d-m-u d-m-u force-pushed the integer_or_Integer_in_object_convert_value_based_on_datatype branch from 1f1d4a7 to d6ad1a1 Compare October 24, 2018 19:38
@d-m-u
Copy link
Contributor Author

d-m-u commented Oct 24, 2018

@gmcculloug can you please take another look?

@d-m-u d-m-u force-pushed the integer_or_Integer_in_object_convert_value_based_on_datatype branch 5 times, most recently from fd16f2b to 2f1338c Compare October 24, 2018 21:34
Copy link
Member

@gmcculloug gmcculloug left a comment

Choose a reason for hiding this comment

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

How are we set for tests on this method? Should be an easy one to test.

@d-m-u d-m-u force-pushed the integer_or_Integer_in_object_convert_value_based_on_datatype branch 2 times, most recently from 0b919fc to 79acbfc Compare October 25, 2018 12:43
let(:datatype2) { "Fixnum" }

it "returns value to_i" do
expect(described_class.convert_value_based_on_datatype(value, datatype)).to eq(45)
Copy link
Member

Choose a reason for hiding this comment

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

Could we just loop over the different datatypes in one test? There's not a big difference between the first test returns value to_i and the other two returns value to_i so maybe we just combine them.

@d-m-u d-m-u force-pushed the integer_or_Integer_in_object_convert_value_based_on_datatype branch from 79acbfc to 1aaf5fc Compare October 25, 2018 12:56
@miq-bot
Copy link
Member

miq-bot commented Oct 25, 2018

Checked commit d-m-u@1aaf5fc with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
2 files checked, 0 offenses detected
Everything looks fine. 🍪

@gmcculloug gmcculloug merged commit 67488e4 into ManageIQ:master Oct 25, 2018
@gmcculloug gmcculloug added this to the Sprint 98 Ending Nov 5, 2018 milestone Oct 25, 2018
@d-m-u d-m-u deleted the integer_or_Integer_in_object_convert_value_based_on_datatype branch October 25, 2018 13:41
simaishi pushed a commit that referenced this pull request Oct 25, 2018
…rt_value_based_on_datatype

convert_value_based_on_datatype won't take "Integer"

(cherry picked from commit 67488e4)

https://bugzilla.redhat.com/show_bug.cgi?id=1628224
@simaishi
Copy link
Contributor

Hammer backport details:

$ git log -1
commit 58ec9220bc415118cf5ec3c214e6db7f6e72de27
Author: Greg McCullough <[email protected]>
Date:   Thu Oct 25 09:35:51 2018 -0400

    Merge pull request #258 from d-m-u/integer_or_Integer_in_object_convert_value_based_on_datatype
    
    convert_value_based_on_datatype won't take "Integer"
    
    (cherry picked from commit 67488e44a7d3529400f55f34d1a9a8452e8ee0b0)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1628224

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