Skip to content

Instantly share code, notes, and snippets.

@keithpitty
Created February 11, 2010 11:28
Show Gist options
  • Save keithpitty/301434 to your computer and use it in GitHub Desktop.
Save keithpitty/301434 to your computer and use it in GitHub Desktop.
# order.rb
# == Schema Information
#
# Table name: orders
#
# id :integer(11) not null, primary key
# date_ordered :date
class Order < ActiveRecord::Base
define_index do
indexes date_ordered
end
end
# search_test.rb
require File.dirname(__FILE__) + '/../test_helper'
class SearchTest < ActiveRecord::TestCase
# assume expected_order has been created with date_ordered == '2009-02-11'
def test_should_find_order_based_on_date
# This works.
orders = Order.search "2009-02-11"
assert_equal expected_order, orders.first
end
def test_should_find_order_based_on_explicit_date
# This fails because it returns all orders not just those with date_ordered == '2009-02-11'.
# Why, I do not know.
orders = Order.search :conditions => {:date_ordered => Date.parse('2009-02-11')}
assert_equal expected_order, orders.first
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment