Skip to content

Automatically reverse out of order boundaries #300

@jrochkind

Description

@jrochkind

Right now if you enter begin and end in reverse order, say begin: 1950, end: 1900 -- an exception gets raised, is not caught, resulting in a 500 in an app.

It would be nice if these were just automatically reversed to do the only thing that can be done with them instead. (If infeasible, I guess just ignoring might be better than raising an uncaught exception?)

I started to look at this, but there were a lot of layers, and i wasn't sure of a good way to do it. So prob not to be included in 9.0.0.

In my own app, I detect and reverse them with a before_action, but i'm not sure this is actually the best or right way when we can change code at layers a consuming app doesn't have access to.

https://github.com/sciencehistory/scihist_digicoll/blob/f76ac4e22959fa344226546bb7cd09bda874612c/app/controllers/catalog_controller.rb#L10C18-L10C51

https://github.com/sciencehistory/scihist_digicoll/blob/f76ac4e22959fa344226546bb7cd09bda874612c/app/controllers/catalog_controller.rb#L669-L682

Here is a controller test that could test for it....

require 'spec_helper'

RSpec.describe CatalogController, type: :controller do
  include Devise::Test::ControllerHelpers

  let(:range_facet_field) { "pub_date_si" }

  describe "range value out of order" do
    render_views

    let(:out_of_order_range_params) do
      {
        range: {
          range_facet_field => {
            begin: "2010",
            end: "2000"
          }
        }
      }
    end

    it "treats as if ordered properly" do
      get :index, params: out_of_order_range_params
      expect(response.status).to eq(200)
      expect(response.body).to include("2000 to 2010")
    end
  end
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions