Sha256: 70232ab360e2a8db66fd1c6b6d67c19f0f9adac5eff1c9328dd92718c43ac95b

Contents?: true

Size: 1.84 KB

Versions: 1

Compression:

Stored size: 1.84 KB

Contents

require 'test_helper'



class StandardDecoratorTest < ActionView::TestCase
  include BentoSearch
  
  def decorator(hash = {})
    StandardDecorator.new(
      ResultItem.new(hash), nil
    )
  end
  
  
  test "author with first and last" do
    author = Author.new(:last => "Smith", :first => "John")
    
    str = decorator.author_display(author)
    
    assert_equal "Smith, J", str    
  end
  
  test "author with display form and just last" do
    author = Author.new(:last => "Smith", :display => "Display Form")
    
    str = decorator.author_display(author)
    
    assert_equal "Display Form", str
  end
  
  test "Author with just last" do
    author = Author.new(:last => "Johnson")
    
    str = decorator.author_display(author)
    
    assert_equal "Johnson", str
    
  end
  
  test "Missing title" do
    assert_equal I18n.translate("bento_search.missing_title"), decorator.complete_title
  end
  
  test "language label nil if default" do
    I18n.with_locale(:'en-GB') do
      item = decorator(:language_code => 'en')      
      assert_nil item.display_language
      
      item = decorator(:language_code => 'es')
      assert_equal "Spanish", item.display_language      
    end
  end
  
  test "display_format with nil format" do
    item = decorator(:format => nil, :format_str => nil)
    
    display_format = item.display_format
    
    assert_nil display_format  
  end
  
  test "display_date" do
    item = decorator(:year => 1900)    
    assert_equal "1900", item.display_date
    
    d = Date.new(2010, 5, 5)
    item = decorator(:publication_date => d)
    assert_equal I18n.l(d, :format => "%d %b %Y"), item.display_date
    
    # if volume and issue, only prints out year
    item = decorator(:publication_date => d, :volume => "101", :issue => "2")
    assert_equal I18n.l(d, :format => "%Y"), item.display_date
  end
    
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bento_search-1.0.3 test/decorator/standard_decorator_test.rb