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

Prepend ActionView::Helpers::NumberHelper with our NumberHelper #9119

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jrafanie
Copy link
Member

@jrafanie jrafanie commented Mar 14, 2024

This ensures we prepend our NumberHelper into the existing helper. Previously, there was a loading order problem where the original rails NumberHelper would be used.

For rails 7, this load order was causing these types of errors where the original number helper was being used:

  1) MiqReport::Formatting #format_mhz_to_human_size adds a prefix and suffix to NumberHelper#mhz_to_human_size
     Failure/Error: val = ApplicationController.helpers.mhz_to_human_size(val, options[:precision])

     NoMethodError:
       undefined method `mhz_to_human_size' for #<ActionView::Base:0x000000012e3573c8 @_config=#< {}>, @lookup_context=#<ActionView::LookupContext:0x000000012e357d78 @details_key=nil, @digest_cache=nil, @cache=true, @prefixes=[], @details={:locale=>[:en], :formats=>[:html, :text, :js, :css, :ics, :csv, :vcf, :vtt, :png, :jpeg, :gif, :bmp, :tiff, :svg, :mpeg, :mp3, :ogg, :m4a, :webm, :mp4, :otf, :ttf, :woff, :woff2, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json, :pdf, :zip, :gzip], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby, :haml, :rjs]}, @view_paths=#<ActionView::PathSet:0x000000012e357508 @paths=[]>>, @view_renderer=#<ActionView::Renderer:0x000000012e354fb0 @lookup_context=#<ActionView::LookupContext:0x000000012e357d78 @details_key=nil, @digest_cache=nil, @cache=true, @prefixes=[], @details={:locale=>[:en], :formats=>[:html, :text, :js, :css, :ics, :csv, :vcf, :vtt, :png, :jpeg, :gif, :bmp, :tiff, :svg, :mpeg, :mp3, :ogg, :m4a, :webm, :mp4, :otf, :ttf, :woff, :woff2, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json, :pdf, :zip, :gzip], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby, :haml, :rjs]}, @view_paths=#<ActionView::PathSet:0x000000012e357508 @paths=[]>>>, @current_template=nil, @_assigns={}, @_controller=nil, @view_flow=#<ActionView::OutputFlow:0x000000012e34f6c8 @content={}>, @output_buffer=nil, @virtual_path=nil>

           val = ApplicationController.helpers.mhz_to_human_size(val, options[:precision])
                                              ^^^^^^^^^^^^^^^^^^
       Did you mean?  number_to_human_size
     # ./app/models/miq_report/formatting.rb:165:in `format_mhz_to_human_size'
     # ./spec/models/miq_report/formatting_spec.rb:36:in `block (3 levels) in <main>'
     # /Users/joerafaniello/.gem/ruby/3.1.5/gems/webmock-3.23.0/lib/webmock/rspec.rb:39:in `block (2 levels) in <main>'

  2) MiqReport::Formatting #format formats megabytes value
     Failure/Error: expect(container_report.format(memory_col, 7822)).to eq('7.6 GB')

       expected: "7.6 GB"
            got: "8 GB"

       (compared using ==)
     # ./spec/models/miq_report/formatting_spec.rb:64:in `block (3 levels) in <main>'
     # /Users/joerafaniello/.gem/ruby/3.1.5/gems/webmock-3.23.0/lib/webmock/rspec.rb:39:in `block (2 levels) in <main>'

...
  1) MiqReportResult::ResultSetOperations.result_set_for_reporting filters with one column
     Failure/Error: expect(subject[:result_set]).to match_array(expected_result_set)

       expected collection contained:  [{"name"=>"TEST_VM2", "size"=>"112.8 KB", "type"=>"small"}, {"name"=>"TEST_VM1", "size"=>"324.4 KB", "type"=>"large"}]
       actual collection contained:    [{"name"=>"TEST_VM1", "size"=>"300 KB", "type"=>"large"}, {"name"=>"TEST_VM2", "size"=>"100 KB", "type"=>"small"}]
       the missing elements were:      [{"name"=>"TEST_VM2", "size"=>"112.8 KB", "type"=>"small"}, {"name"=>"TEST_VM1", "size"=>"324.4 KB", "type"=>"large"}]
       the extra elements were:        [{"name"=>"TEST_VM1", "size"=>"300 KB", "type"=>"large"}, {"name"=>"TEST_VM2", "size"=>"100 KB", "type"=>"small"}]
     # ./spec/models/miq_report_result/result_set_operations_spec.rb:38:in `block (3 levels) in <main>'
     # /Users/joerafaniello/.gem/ruby/3.1.5/gems/webmock-3.23.0/lib/webmock/rspec.rb:39:in `block (2 levels) in <main>'

  2) MiqReportResult::ResultSetOperations.result_set_for_reporting with more columns filters
     Failure/Error: expect(subject[:result_set]).to match_array(expected_result_set)

       expected collection contained:  [{"name"=>"TEST_VM2", "size"=>"112.8 KB", "type"=>"small"}]
       actual collection contained:    [{"name"=>"TEST_VM2", "size"=>"100 KB", "type"=>"small"}]
       the missing elements were:      [{"name"=>"TEST_VM2", "size"=>"112.8 KB", "type"=>"small"}]
       the extra elements were:        [{"name"=>"TEST_VM2", "size"=>"100 KB", "type"=>"small"}]
     # ./spec/models/miq_report_result/result_set_operations_spec.rb:51:in `block (4 levels) in <main>'
     # /Users/joerafaniello/.gem/ruby/3.1.5/gems/webmock-3.23.0/lib/webmock/rspec.rb:39:in `block (2 levels) in <main>'

  3) MiqReportResult::ResultSetOperations.result_set_for_reporting with more columns with various order of parameters filters
     Failure/Error: expect(subject[:result_set]).to match_array(expected_result_set)

       expected collection contained:  [{"name"=>"TEST_VM2", "size"=>"112.8 KB", "type"=>"small"}]
       actual collection contained:    [{"name"=>"TEST_VM2", "size"=>"100 KB", "type"=>"small"}]
       the missing elements were:      [{"name"=>"TEST_VM2", "size"=>"112.8 KB", "type"=>"small"}]
       the extra elements were:        [{"name"=>"TEST_VM2", "size"=>"100 KB", "type"=>"small"}]
     # ./spec/models/miq_report_result/result_set_operations_spec.rb:60:in `block (5 levels) in <main>'
     # /Users/joerafaniello/.gem/ruby/3.1.5/gems/webmock-3.23.0/lib/webmock/rspec.rb:39:in `block (2 levels) in <main>'

@jrafanie jrafanie added the wip label Mar 14, 2024
@jrafanie jrafanie requested a review from a team as a code owner March 14, 2024 19:31
@jrafanie jrafanie changed the title Prepend ActionView::Helpers::NumberHelper withour NumberHelper Prepend ActionView::Helpers::NumberHelper with our NumberHelper Mar 14, 2024
@miq-bot miq-bot removed the wip label Mar 14, 2024
@Fryguy Fryguy changed the title Prepend ActionView::Helpers::NumberHelper with our NumberHelper [WIP] Prepend ActionView::Helpers::NumberHelper with our NumberHelper Mar 27, 2024
@Fryguy Fryguy added the wip label Apr 10, 2024
@miq-bot
Copy link
Member

miq-bot commented May 14, 2024

Checked commit jrafanie@6712f2c with ruby 2.7.8, rubocop 1.56.3, haml-lint 0.51.0, and yamllint
2 files checked, 0 offenses detected
Everything looks fine. 🏆

@jrafanie jrafanie removed the wip label May 14, 2024
@jrafanie jrafanie changed the title [WIP] Prepend ActionView::Helpers::NumberHelper with our NumberHelper Prepend ActionView::Helpers::NumberHelper with our NumberHelper May 14, 2024
@@ -10,7 +10,7 @@ module ApplicationHelper
include StiRoutingHelper
include ToolbarHelper
include TextualSummaryHelper
include NumberHelper
ActionView::Helpers::NumberHelper.prepend NumberHelper # override rails number helper with our needs for number_to_human_size
Copy link
Member Author

Choose a reason for hiding this comment

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

Previously, we included the rails number helper first in the controller...

then, we included ours in the application helper which was then included in the controller.

This change ensures we prepend our NumberHelper on the rails ones and do it directly in the application helper to ensure we're not including the original one directly.

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.

None yet

4 participants