Browse Source

return schemes with no location when searching

pull/784/head
Kat 3 years ago
parent
commit
be28233fb0
  1. 2
      app/models/scheme.rb
  2. 7
      spec/features/schemes_spec.rb
  3. 10
      spec/requests/schemes_controller_spec.rb

2
app/models/scheme.rb

@ -6,7 +6,7 @@ class Scheme < ApplicationRecord
scope :filter_by_id, ->(id) { where(id: (id.start_with?("S") ? id[1..] : id)) }
scope :search_by_service_name, ->(name) { where("service_name ILIKE ?", "%#{name}%") }
scope :search_by_postcode, ->(postcode) { joins(:locations).where("locations.postcode ILIKE ?", "%#{postcode.delete(' ')}%") }
scope :search_by_postcode, ->(postcode) { joins("LEFT JOIN locations ON locations.scheme_id = schemes.id").where("locations.postcode ILIKE ?", "%#{postcode.delete(' ')}%") }
scope :search_by, ->(param) { search_by_postcode(param).or(search_by_service_name(param)).or(filter_by_id(param)).distinct }
validate :validate_confirmed

7
spec/features/schemes_spec.rb

@ -119,6 +119,13 @@ RSpec.describe "Schemes scheme Features" do
expect(page).to have_content(scheme_to_search.id_to_display)
end
it "returns results with no location" do
scheme_to_search.locations.each { |location| location.destroy }
scheme_to_search.reload
click_button("Search")
expect(page).to have_content(scheme_to_search.id_to_display)
end
it "allows clearing the search results" do
fill_in("search", with: scheme_to_search.id_to_display)
click_button("Search")

10
spec/requests/schemes_controller_spec.rb

@ -179,6 +179,16 @@ RSpec.describe SchemesController, type: :request do
end
end
it "returns results with no location" do
searched_scheme.locations.each { |location| location.destroy }
searched_scheme.reload
get "/schemes?search=#{search_param}"
expect(page).to have_content(searched_scheme.id_to_display)
schemes.each do |scheme|
expect(page).not_to have_content(scheme.id_to_display)
end
end
it "updates the table caption" do
expect(page).to have_content("1 scheme found matching ‘#{search_param}")
end

Loading…
Cancel
Save