Skip to content

Instantly share code, notes, and snippets.

@kruszczynski
Created May 27, 2014 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kruszczynski/f771f73fa2b4df80223e to your computer and use it in GitHub Desktop.
Save kruszczynski/f771f73fa2b4df80223e to your computer and use it in GitHub Desktop.
Sunspot #with method bug
Project.search do
case params[:type]
when 'healthy'
with(:health_score, 80..100)
# => [80, 81, ... , 99, 100]
when 'at_risk'
with(:health_score, 50...80)
# => [50, 51, ... , 79, 80] - should not inlcude 80, inner Sunspot Range evaluation error
end
# possible fix:
case params[:type]
when 'healthy'
with(:health_score, (80..100).to_a)
# => [80, 81, ... , 99, 100]
when 'at_risk'
with(:health_score, (50...80).to_a)
# => [50, 51, ... , 79] - all good when preventing sunspot from evaluating Range object
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment