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

Automatically reverse out of order boundaries #300

Open
jrochkind opened this issue Dec 2, 2024 · 0 comments
Open

Automatically reverse out of order boundaries #300

jrochkind opened this issue Dec 2, 2024 · 0 comments

Comments

@jrochkind
Copy link
Member

jrochkind commented Dec 2, 2024

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant