Skip to content

Resolve "[Rails5] Fix `NoMethodError: undefined method `-' for "3":String`"

What does this MR do?

In Rails 5 the per_page argument came from params is String but an Integer is expected.

This MR explicitly converts per_page to an Integer.

It fixes the errors like:

  1) Groups::ChildrenController GET #index for subgroups filtering children succeeds if multiple pages contain matching subgroups
     Failure/Error:
       hash[page] = second_collection.page(second_collection_page)
                      .per(per_page - paginated_first_collection(page).size)
                      .padding(offset)

     NoMethodError:
       undefined method `-' for "3":String
       Did you mean?  -@
     # ./lib/gitlab/multi_collection_paginator.rb:42:in `block in paginated_second_collection'
     # ./lib/gitlab/multi_collection_paginator.rb:46:in `paginated_second_collection'
     # ./lib/gitlab/multi_collection_paginator.rb:14:in `paginate'
     # ./app/finders/group_descendants_finder.rb:52:in `children'
     # ./app/finders/group_descendants_finder.rb:34:in `execute'
     # ./app/controllers/groups/children_controller.rb:36:in `setup_children'
     # ./app/controllers/groups/children_controller.rb:18:in `index'
     # ./lib/gitlab/i18n.rb:50:in `with_locale'
     # ./lib/gitlab/i18n.rb:56:in `with_user_locale'
     # ./app/controllers/application_controller.rb:351:in `set_locale'
     # ./spec/controllers/groups/children_controller_spec.rb:182:in `block (5 levels) in <top (required)>'
     # ./spec/spec_helper.rb:198:in `block (2 levels) in <top (required)>'

Are there points in the code the reviewer needs to double check?

No.

Why was this MR needed?

Migration to Rails 5.0.

Screenshots (if relevant)

No.

Does this MR meet the acceptance criteria?

What are the relevant issue numbers?

#14286 (closed)

Closes #46233 (closed)

Edited by blackst0ne

Merge request reports

Loading