test/results_test.rb in inquisitio-1.5.0 vs test/results_test.rb in inquisitio-2.0.0

- old
+ new

@@ -4,21 +4,28 @@ class ResultsTest < Minitest::Test def setup super @search_endpoint = 'http://my.search-endpoint.com' Inquisitio.config.search_endpoint = @search_endpoint - Inquisitio.config.api_version = nil - @result_1 = {'data' => {'id' => ['1'], 'title' => ["Foobar"], 'type' => ["Cat"]}} - @result_2 = {'data' => {'id' => ['2'], 'title' => ["Foobar"], 'type' => ["Cat"]}} - @result_3 = {'data' => {'id' => ['20'], 'title' => ["Foobar2"], 'type' => ["Module_Dog"]}} + @result_1 = {'data' => {'id' => ['1'], 'title' => ['Foobar'], 'type' => ['Cat']}} + @result_2 = {'data' => {'id' => ['2'], 'title' => ['Foobar'], 'type' => ['Cat']}} + @result_3 = {'data' => {'id' => ['20'], 'title' => ['Foobar2'], 'type' => ['Module_Dog']}} @expected_results = [@result_1, @result_2, @result_3] @start = 5 @found = 8 - @body = <<-EOS - {"rank":"-text_relevance","match-expr":"(label 'star wars')","hits":{"found":#{@found},"start":#{@start},"hit":#{@expected_results.to_json}},"info":{"rid":"9d3b24b0e3399866dd8d376a7b1e0f6e930d55830b33a474bfac11146e9ca1b3b8adf0141a93ecee","time-ms":3,"cpu-time-ms":0}} - EOS + @body = { + 'status' => { + 'rid' => '9d3b24b0e3399866dd8d376a7b1e0f6e930d55830b33a474bfac11146e9ca1b3b8adf0141a93ecee', + 'time-ms' => 3 + }, + 'hits' => { + 'found' => @found, + 'start' => @start, + 'hit' => @expected_results, + } + }.to_json Excon.defaults[:mock] = true Excon.stub({}, {body: @body, status: 200}) end @@ -26,34 +33,27 @@ super Excon.stubs.clear end def test_should_return_total_count - searcher = Searcher.where("star_wars") + searcher = Searcher.where('star_wars') searcher.search assert_equal @found, searcher.total_entries end - def test_should_return_time_taken_for_2011 - searcher = Searcher.where("star_wars") - searcher.search - assert_equal 3, searcher.time_ms - end - - def test_should_return_time_taken_for_2013 - Inquisitio.config.api_version = '2013-01-01' + def test_should_return_time_taken body = "{\"status\": {\"rid\" : \"u9aP4eYo8gIK0csK\", \"time-ms\": 4}, \"hits\" : {\"#{@found}\": 33, \"#{@start}\": 0, \"hit\":#{@expected_results.to_json} }}" Excon.stubs.clear Excon.stub({}, {body: body, status: 200}) - searcher = Searcher.where("star_wars") + searcher = Searcher.where('star_wars') searcher.search assert_equal 4, searcher.time_ms end def test_total_entries_should_proxy - searcher = Searcher.where("star_wars") + searcher = Searcher.where('star_wars') searcher.search assert_equal @found, searcher.total_count end def test_should_return_results_per_page @@ -99,10 +99,10 @@ end def test_nums_pages_should_proxy per = 3 searcher = Searcher.per(per) - searcher.search + # searcher.search assert_equal 3, searcher.num_pages end def test_last_page_before results = Inquisitio::Results.new([], 1, nil, nil, 7)