lib/rails/templates/search_controller_test.rb in elasticsearch-rails-2.0.1 vs lib/rails/templates/search_controller_test.rb in elasticsearch-rails-5.0.0
- old
+ new
@@ -1,10 +1,10 @@
require 'test_helper'
class SearchControllerTest < ActionController::TestCase
setup do
- Time.stubs(:now).returns(Time.parse('2015-03-16 10:00:00 UTC'))
+ Time.stubs(:now).returns(Time.new(2015, 03, 16, 10, 00, 00, 0))
Article.delete_all
articles = [
{ title: 'Article One', abstract: 'One', content: 'One', published_on: 1.day.ago, category_title: 'One', author_first_name: 'John', author_last_name: 'Smith' },
@@ -35,39 +35,39 @@
Article.__elasticsearch__.import force: true
Article.__elasticsearch__.refresh_index!
end
test "should return search results" do
- get :index, q: 'one'
+ get :index, params: { q: 'one' }
assert_response :success
assert_equal 3, assigns(:articles).size
end
test "should return search results in comments" do
- get :index, q: 'one', comments: 'y'
+ get :index, params: { q: 'one', comments: 'y' }
assert_response :success
assert_equal 4, assigns(:articles).size
end
test "should return highlighted snippets" do
- get :index, q: 'one'
+ get :index, params: { q: 'one' }
assert_response :success
assert_match %r{<em class="label label-highlight">One</em>}, assigns(:articles).first.highlight.title.first
end
test "should return suggestions" do
- get :index, q: 'one'
+ get :index, params: { q: 'one' }
assert_response :success
- suggestions = assigns(:articles).response.suggest
+ suggestions = assigns(:articles).response.suggestions
assert_equal 'one', suggestions['suggest_title'][0]['text']
end
test "should return facets" do
- get :index, q: 'one'
+ get :index, params: { q: 'one' }
assert_response :success
aggregations = assigns(:articles).response.response['aggregations']
assert_equal 2, aggregations['categories']['categories']['buckets'].size
@@ -78,31 +78,31 @@
assert_equal 'John Smith', aggregations['authors']['authors']['buckets'][0]['key']
assert_equal 1425254400000, aggregations['published']['published']['buckets'][0]['key']
end
test "should sort on the published date" do
- get :index, q: 'one', s: 'published_on'
+ get :index, params: { q: 'one', s: 'published_on' }
assert_response :success
assert_equal 3, assigns(:articles).size
assert_equal '2015-03-15', assigns(:articles)[0].published_on
assert_equal '2015-03-14', assigns(:articles)[1].published_on
assert_equal '2015-03-06', assigns(:articles)[2].published_on
end
test "should sort on the published date when no query is provided" do
- get :index, q: ''
+ get :index, params: { q: '' }
assert_response :success
assert_equal 5, assigns(:articles).size
assert_equal '2015-03-15', assigns(:articles)[0].published_on
assert_equal '2015-03-14', assigns(:articles)[1].published_on
assert_equal '2015-03-06', assigns(:articles)[2].published_on
end
test "should filter search results and the author and published date facets when user selects a category" do
- get :index, q: 'one', c: 'One'
+ get :index, params: { q: 'one', c: 'One' }
assert_response :success
assert_equal 2, assigns(:articles).size
aggregations = assigns(:articles).response.response['aggregations']
@@ -113,10 +113,10 @@
# Do NOT filter the category facet
assert_equal 2, aggregations['categories']['categories']['buckets'].size
end
test "should filter search results and the category and published date facets when user selects a category" do
- get :index, q: 'one', a: 'Mary Smith'
+ get :index, params: { q: 'one', a: 'Mary Smith' }
assert_response :success
assert_equal 1, assigns(:articles).size
aggregations = assigns(:articles).response.response['aggregations']