Skip to content

Instantly share code, notes, and snippets.

@jaigouk
Created October 30, 2014 05:22
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 jaigouk/d9b36e6cdb30c674f393 to your computer and use it in GitHub Desktop.
Save jaigouk/d9b36e6cdb30c674f393 to your computer and use it in GitHub Desktop.
example
require 'test_helper'
describe SearchEngine::Searchable do
it "should accept partial path" do
end
it "should accept page param and return cached results" do
end
it "should have data end tag to the search result" do
end
it "should find saved search params" do
end
it "should find saved search params and return cached partials" do
end
it "should be able to mix Search params with `or` operation option" do
result = Search.for({keywords: "iphone, website", operation: "or"})
end
it "should parse yml file as default settings" do
Search.settings("cross_search").must_equal "view_parts_design_skills"
Search.settings("sort_keys").must_equal ["view_parts_ranking_score", "view_parts_budget"]
Search.settings("primary_filter").must_equal "category"
Search.settings("group_model").must_equal "dummy_user"
Search.settings("target_model").must_equal "dummy_portfolio"
Search.settings("filters")["availability"].must_equal ["this_week", "next_week", "this_month", "next_month"]
end
it "should be initialized with models pointed out" do
Search.sort_keys.must_equal ["view_parts_ranking_score", "view_parts_budget"]
Search.filter_keys.must_equal ["category", "sub_category", "budget", "availability"]
Search.item_count.must_equal 8
end
it "should have sets with given primary filter" do
result = ["iphone", "website", "android", "ipad", "windows", "icon", "logo","illustration"] - Search.primary_filters
result.size.must_equal 0
end
it "should be able to return search result which is sorted_by sort_keys by default" do
result = Search.for(keywords: "website")
result[:all_data_count].must_equal 2 # 2 users
result[:data][0]["view_parts_ranking_score"].must_equal 10
result[:data][1]["view_parts_ranking_score"].must_equal 5
q = result[:data][0]["view_parts_image_url"].include?("https://testinghq.s3.amazonaws.com/testing_production/5102b6524768ab2e9d000001/portfolios/51ca1599477020a853000001/modified/w660/w660_8c049df52082beee3c95ca17836fb8e6.jpg")
q.must_equal true
end
it "should return search sorted" do
# need to be clear and / or operation. for now we use or operation
result = Search.for({keywords: "website", operation: "and"})
result[:all_data_count].must_equal 2
result[:data][0]["view_parts_ranking_score"].must_equal 10
result[:data][1]["view_parts_ranking_score"].must_equal 5
end
it "can return results with partials" do
result = Search.for({keywords: "iphone, website", operation: "and", with_partial: true})
result[:all_data_count].must_equal 1
check = result[:data].include? "iphone, website"
check.must_equal true
url_check = result[:data].include? 'https://testing.com/users/517366a045b83d272a00008b'
url_check.must_equal true
img_check = result[:data].include? 'https://testinghq.s3.amazonaws.com/testing_production/5103990ac45d43b4f2000001/portfolios/515880f8fa8b29943a000001/modified/w660/w660_8c069df52082beee3c95ca17836fb8e2.png'
img_check.must_equal true
end
it "should return the results if one portfolio has multiple design skills and included in the cross search arguments" do
result = Search.for({keywords: "iphone", dev_skills: ["frontend_dev", "product_dev"], operation: "and", with_partial: false})
result[:all_data_count].must_equal 2
result[:data][0]["view_parts_ranking_score"].must_equal 10
result[:data][1]["view_parts_ranking_score"].must_equal 6
result[:data][0]["view_parts_image_url"].size.must_equal 3
q = result[:data][0]["view_parts_image_url"].include?("https://testinghq.s3.amazonaws.com/testing_production/5103990ac45d43b4f2000001/portfolios/515880f8fa8b29943a000001/modified/w660/w660_8c069df52082beee3c95ca17836fb8e2.png")
q.must_equal true
end
it "should accept availability as argument" do
result = Search.for({keywords: "iphone", available: "this_week", operation: "and", with_partial: false})
result[:all_data_count].must_equal 2
result[:data][0]["view_parts_availability"].must_equal "this_week"
result[:data][1]["view_parts_availability"].must_equal "this_week"
end
it 'should return previous results when updating search data' do
search = Search.instance
# create iphone_or_website search result
result = Search.for({keywords: "website", operation: "and"})
result[:all_data_count].must_equal 2
result[:data][0]["view_parts_ranking_score"].must_equal 10
result[:data][1]["view_parts_ranking_score"].must_equal 5
# will copy iphone_or_website
Search.started_updating!
Search.clean_up_old_data
Search.updating?.must_equal true
Search.copy_redis_data
# will use copied data for search. result should be the same as before
result = Search.for({keywords: "website", operation: "and"})
result[:all_data_count].must_equal 2
result[:data][0]["view_parts_ranking_score"].must_equal 10
result[:data][1]["view_parts_ranking_score"].must_equal 5
Search.finished_updating!
Search.updating?.must_equal false
# delete copied data
Search.clean_up_old_data
result = Search.for({keywords: "website", operation: "and"})
result[:all_data_count].must_equal 2
result[:data][0]["view_parts_ranking_score"].must_equal 10
result[:data][1]["view_parts_ranking_score"].must_equal 5
end
end
# heper will load next page results to clients
# https://github.com/javve/list.js
# it "can load next page to "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment