test/test_soulmate.rb in soulmate-0.0.3 vs test/test_soulmate.rb in soulmate-0.0.4

- old
+ new

@@ -1,7 +1,45 @@ require 'helper' class TestSoulmate < Test::Unit::TestCase - should "probably rename this file and start testing for real" do - flunk "hey buddy, you should probably rename this file and start testing for real" + def test_integration_can_load_values_and_query + items = [] + venues = File.open(File.expand_path(File.dirname(__FILE__)) + '/samples/venues.json', "r") + venues.each_line do |venue| + items << JSON.parse(venue) + end + + items_loaded = Soulmate::Loader.new('venues').load(items) + + assert_equal 6, items_loaded + + matcher = Soulmate::Matcher.new('venues') + results = matcher.matches_for_term('stad', :limit => 5) + + assert_equal 5, results.size + assert_equal 'Citi Field', results[0]['term'] + end + + def test_integration_can_load_values_and_query_via_aliases + items = [] + venues = File.open(File.expand_path(File.dirname(__FILE__)) + '/samples/venues.json', "r") + venues.each_line do |venue| + items << JSON.parse(venue) + end + + items_loaded = Soulmate::Loader.new('venues').load(items) + + assert_equal 6, items_loaded + + matcher = Soulmate::Matcher.new('venues') + results = matcher.matches_for_term('land shark stadium', :limit => 5) + + assert_equal 1, results.size + assert_equal 'Sun Life Stadium', results[0]['term'] + + # Make sure we don't get dupes between aliases and the original term + # this shouldn't happen due to Redis doing an intersect, but just in case! + + results = matcher.matches_for_term('stadium', :limit => 5) + assert_equal 5, results.size end end