Browse Source

CLDC-2816 scheme filter bug 2 (#1946)

* feat: move ordering after filtering to avoid ORDER BY using expressions not in SELECT DISTINCT list

* feat: add multiple schemes so tests will fail if this bug appears again

* feat: include schemes and locations with nil confirmed values in incomplete scopes

* refactor: lint
CLDC-2835-review-app-branch
natdeanlewissoftwire 1 year ago committed by GitHub
parent
commit
3aee2923a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      app/models/location.rb
  2. 1
      app/models/scheme.rb
  3. 6
      spec/models/location_spec.rb
  4. 7
      spec/models/scheme_spec.rb

1
app/models/location.rb

@ -49,6 +49,7 @@ class Location < ApplicationRecord
scope :incomplete, lambda {
where.not(confirmed: true)
.or(where(confirmed: nil))
}
scope :deactivated, lambda {

1
app/models/scheme.rb

@ -42,6 +42,7 @@ class Scheme < ApplicationRecord
scope :incomplete, lambda {
where.not(confirmed: true)
.or(where(confirmed: nil))
.or(where.not(id: Location.select(:scheme_id).where(confirmed: true).distinct))
.where.not(id: joins(:scheme_deactivation_periods).reactivating_soon.pluck(:id))
.where.not(id: joins(:scheme_deactivation_periods).deactivated.pluck(:id))

6
spec/models/location_spec.rb

@ -932,6 +932,7 @@ RSpec.describe Location, type: :model do
describe "filter by status" do
let!(:incomplete_location) { FactoryBot.create(:location, :incomplete, startdate: Time.zone.local(2022, 4, 1)) }
let!(:incomplete_location_with_nil_confirmed) { FactoryBot.create(:location, :incomplete, startdate: Time.zone.local(2022, 4, 1), confirmed: nil) }
let!(:active_location) { FactoryBot.create(:location, startdate: Time.zone.local(2022, 4, 1)) }
let(:deactivating_soon_location) { FactoryBot.create(:location, startdate: Time.zone.local(2022, 4, 1)) }
let(:deactivated_location) { FactoryBot.create(:location, startdate: Time.zone.local(2022, 4, 1)) }
@ -954,8 +955,9 @@ RSpec.describe Location, type: :model do
context "when filtering by incomplete status" do
it "returns only incomplete locations" do
expect(described_class.filter_by_status(%w[incomplete]).count).to eq(1)
expect(described_class.filter_by_status(%w[incomplete]).first).to eq(incomplete_location)
expect(described_class.filter_by_status(%w[incomplete]).count).to eq(2)
expect(described_class.filter_by_status(%w[incomplete])).to include(incomplete_location)
expect(described_class.filter_by_status(%w[incomplete])).to include(incomplete_location_with_nil_confirmed)
end
end

7
spec/models/scheme_spec.rb

@ -112,6 +112,7 @@ RSpec.describe Scheme, type: :model do
context "when filtering by status" do
let!(:incomplete_scheme) { FactoryBot.create(:scheme, :incomplete, service_name: "name") }
let!(:incomplete_scheme_2) { FactoryBot.create(:scheme, :incomplete, service_name: "name") }
let!(:incomplete_scheme_with_nil_confirmed) { FactoryBot.create(:scheme, :incomplete, service_name: "name", confirmed: nil) }
let(:active_scheme) { FactoryBot.create(:scheme) }
let(:active_scheme_2) { FactoryBot.create(:scheme) }
let(:deactivating_soon_scheme) { FactoryBot.create(:scheme) }
@ -143,17 +144,19 @@ RSpec.describe Scheme, type: :model do
context "when filtering by incomplete status" do
it "returns only incomplete schemes" do
expect(described_class.filter_by_status(%w[incomplete]).count).to eq(2)
expect(described_class.filter_by_status(%w[incomplete]).count).to eq(3)
expect(described_class.filter_by_status(%w[incomplete])).to include(incomplete_scheme)
expect(described_class.filter_by_status(%w[incomplete])).to include(incomplete_scheme_2)
expect(described_class.filter_by_status(%w[incomplete])).to include(incomplete_scheme_with_nil_confirmed)
end
end
context "when filtering by incomplete status and searching" do
it "returns only incomplete schemes" do
expect(described_class.search_by("name").filter_by_status(%w[incomplete]).count).to eq(2)
expect(described_class.search_by("name").filter_by_status(%w[incomplete]).count).to eq(3)
expect(described_class.search_by("name").filter_by_status(%w[incomplete])).to include(incomplete_scheme)
expect(described_class.search_by("name").filter_by_status(%w[incomplete])).to include(incomplete_scheme_2)
expect(described_class.search_by("name").filter_by_status(%w[incomplete])).to include(incomplete_scheme_with_nil_confirmed)
end
end

Loading…
Cancel
Save