Sha256: 32291d48a208b2966e39e6a2c523cc5a399fad82276a8e7aaed003b80e830f8b

Contents?: true

Size: 1.69 KB

Versions: 9

Compression:

Stored size: 1.69 KB

Contents

require 'test_helper'



class ResultItemTest < ActiveSupport::TestCase
  ResultItem = BentoSearch::ResultItem
  
  def test_has_custom_data
    r = ResultItem.new
    
    assert_not_nil r.custom_data
    assert_kind_of Hash, r.custom_data
  end
  
  def test_can_dup_and_set_attributes
    # Need to be able to dup and set at least basic attributes without
    # changing original. Used by SummonEngine for making sure
    # openurl does not have highlighting tags in it when generated. 
    
    r = ResultItem.new(:title => "original")
    
    assert_equal "original", r.title
    
    dup = r.dup
    dup.title = "new"
    
    assert_equal "new", dup.title
    assert_equal "original", r.title
    
    assert_not_same dup, r        
  end
      
  def test_language
    r = ResultItem.new(:title => "something", :language_code => "en")    
    assert_equal "en",      r.language_code
    assert_equal "English", r.language_str
    
    r = ResultItem.new(:title => "something", :language_code => "eng")
    assert_equal "eng",      r.language_code
    assert_equal "English", r.language_str
    
    # language_str override
    r = ResultItem.new(:title => "something", :language_code => "en", :language_str => "Weird English")
    assert_equal "en",            r.language_code
    assert_equal "Weird English", r.language_str
    
    # language_str only
    r = ResultItem.new(:title => "something", :language_str => "English")
    assert_nil r.language_code
    assert_equal "English", r.language_str
    
  end
  
  def test_bad_language_code
    r = ResultItem.new(:title => "something", :language_code => "not_valid")
    
    assert_equal "not_valid", r.language_code
    assert_nil r.language_str
  end
  
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
bento_search-1.0.6 test/unit/result_item_test.rb
bento_search-1.0.4 test/unit/result_item_test.rb
bento_search-1.0.3 test/unit/result_item_test.rb
bento_search-1.0.2 test/unit/result_item_test.rb
bento_search-1.0.1 test/unit/result_item_test.rb
bento_search-1.0.0 test/unit/result_item_test.rb
bento_search-0.9.0 test/unit/result_item_test.rb
bento_search-0.8.0 test/unit/result_item_test.rb
bento_search-0.7.0 test/unit/result_item_test.rb