require 'rubygems' require 'bundler' Bundler.require(:test) require 'test/unit' require 'action_controller' require 'active_support/core_ext/string/output_safety' require 'action_dispatch/testing/assertions' require 'crummy' require 'crummy/standard_renderer' class StandardRendererTest < Test::Unit::TestCase include ActionDispatch::Assertions::DomAssertions include Crummy def test_classes renderer = StandardRenderer.new assert_dom_equal('name', renderer.render_crumbs([['name', 'url']], :first_class => 'first', :last_class => 'last', :format => :html)) assert_equal('', renderer.render_crumbs([['name', 'url']], :first_class => 'first', :last_class => 'last', :format => :html_list)) assert_equal('name', renderer.render_crumbs([['name', 'url']], :first_class => 'first', :last_class => 'last', :format => :xml)) assert_dom_equal('name1 » name2', renderer.render_crumbs([['name1', 'url1'], ['name2', 'url2']], :first_class => 'first', :last_class => 'last', :format => :html)) assert_equal('', renderer.render_crumbs([['name1', 'url1'], ['name2', 'url2'], ['name3', 'url3']], :li_class => "li_class", :first_class => 'first', :last_class => 'last', :format => :html_list)) assert_equal('', renderer.render_crumbs([['name1', 'url1'], ['name2', 'url2'], ['name3', 'url3']], :li_class => "li_class", :first_class => 'first', :last_class => 'last', :format => :html_list, :separator => " / ")) assert_equal('name1name2', renderer.render_crumbs([['name1', 'url1'], ['name2', 'url2']], :first_class => 'first', :last_class => 'last', :format => :xml)) assert_dom_equal('
', renderer.render_crumbs([['name', 'url']], :first_class => 'first', :last_class => 'last', :format => :html, :microdata => true)) assert_equal('', renderer.render_crumbs([['name', 'url']], :first_class => 'first', :last_class => 'last', :format => :html_list, :microdata => true)) assert_equal('', renderer.render_crumbs([['name', 'url']], :format => :html_list, :ul_id => "crumbid", :ul_class => "crumbclass", :li_class => "liclass")) end def test_classes_last_crumb_not_linked renderer = StandardRenderer.new assert_equal('name', renderer.render_crumbs([['name', 'url']], :first_class => 'first', :last_class => 'last', :format => :html, :last_crumb_linked => false)) assert_equal('', renderer.render_crumbs([['name', 'url']], :first_class => 'first', :last_class => 'last', :format => :html_list, :last_crumb_linked => false)) assert_equal('name', renderer.render_crumbs([['name', 'url']], :first_class => 'first', :last_class => 'last', :format => :xml, :last_crumb_linked => false)) assert_dom_equal('name1 » name2', renderer.render_crumbs([['name1', 'url1'], ['name2', 'url2']], :first_class => 'first', :last_class => 'last', :format => :html, :last_crumb_linked => false)) assert_equal('', renderer.render_crumbs([['name1', 'url1'], ['name2', 'url2'], ['name3', 'url3']], :li_class => "li_class", :first_class => 'first', :last_class => 'last', :format => :html_list, :last_crumb_linked => false)) assert_equal('', renderer.render_crumbs([['name1', 'url1'], ['name2', 'url2'], ['name3', 'url3']], :li_class => "li_class", :first_class => 'first', :last_class => 'last', :format => :html_list, :separator => " / ", :last_crumb_linked => false)) assert_equal('name1name2', renderer.render_crumbs([['name1', 'url1'], ['name2', 'url2']], :first_class => 'first', :last_class => 'last', :format => :xml, :last_crumb_linked => false)) assert_equal('
name
', renderer.render_crumbs([['name', 'url']], :first_class => 'first', :last_class => 'last', :format => :html, :microdata => true, :last_crumb_linked => false)) assert_equal('', renderer.render_crumbs([['name', 'url']], :first_class => 'first', :last_class => 'last', :format => :html_list, :microdata => true, :last_crumb_linked => false)) assert_equal('', renderer.render_crumbs([['name', 'url']], :format => :html_list, :ul_id => "crumbid", :ul_class => "crumbclass", :li_class => "liclass", :last_crumb_linked => false)) end def test_link_html_options renderer = StandardRenderer.new Crummy.configure do |config| config.microdata = false end assert_equal('name', renderer.render_crumbs([['name', 'url', {:link_html_options => {:title => 'link title'}}]], :first_class => 'first', :last_class => 'last', :format => :html)) assert_equal('name', renderer.render_crumbs([['name', 'url', {:link_html_options => {:title => 'link title'}}]], :first_class => 'first', :last_class => 'last', :format => :html, :last_crumb_linked => false)) assert_equal('', renderer.render_crumbs([['name', 'url', {:link_html_options => {:title => 'link title'}}]], :first_class => 'first', :last_class => 'last', :format => :html_list)) assert_equal('', renderer.render_crumbs([['name', 'url', {:link_html_options => {:title => 'link title'}}]], :first_class => 'first', :last_class => 'last', :format => :html_list, :last_crumb_linked => false)) end def test_link_html_options_with_microdata renderer = StandardRenderer.new Crummy.configure do |config| config.microdata = true end assert_equal('
', renderer.render_crumbs([['name', 'url', {:link_html_options => {:title => 'link title'}}]], :first_class => 'first', :last_class => 'last', :format => :html)) assert_equal('
name
', renderer.render_crumbs([['name', 'url', {:link_html_options => {:title => 'link title'}}]], :first_class => 'first', :last_class => 'last', :format => :html, :last_crumb_linked => false)) assert_equal('', renderer.render_crumbs([['name', 'url', {:link_html_options => {:title => 'link title'}}]], :first_class => 'first', :last_class => 'last', :format => :html_list)) assert_equal('', renderer.render_crumbs([['name', 'url', {:link_html_options => {:title => 'link title'}}]], :first_class => 'first', :last_class => 'last', :format => :html_list, :last_crumb_linked => false)) end def test_configuration renderer = StandardRenderer.new # check defaults assert_equal " » ", Crummy.configuration.html_separator # adjust configuration Crummy.configure do |config| config.html_separator = " / " end assert_equal " / ", Crummy.configuration.html_separator end def test_configured_renderer renderer = StandardRenderer.new Crummy.configure do |config| config.html_separator = " / " end # using configured separator assert_dom_equal('name1 / name2', renderer.render_crumbs([['name1', 'url1'], ['name2', 'url2']])) # overriding configured separator assert_dom_equal('name1 | name2', renderer.render_crumbs([['name1', 'url1'], ['name2', 'url2']], :separator => " | ")) end def test_configured_renderer_with_microdata renderer = StandardRenderer.new Crummy.configure do |config| config.microdata = true end # using configured microdata setting assert_dom_equal('
', renderer.render_crumbs([['name', 'url']], :first_class => 'first', :last_class => 'last', :format => :html)) # last crumb not linked assert_equal('
name
', renderer.render_crumbs([['name', 'url']], :first_class => 'first', :last_class => 'last', :format => :html, :last_crumb_linked => false)) end end