require 'test_helper' class ActionView::TestCase; include Titlezilla::Helpers::Title; end module Titlezilla module Helpers describe Title do describe 'integration' do before do load_translations({ application: 'App', main: { new: 'New', edit: 'Edit' } }) end it '#title' do @controller.controller_path = :main @controller.action_name = :new title.must_equal 'New' end it '#title using view assigns' do load_translations({ main: { new: 'New: %{name}' } }) @controller.controller_path = :main @controller.action_name = :new @controller.view_assigns = { name: 'John' } title.must_equal 'New: John' end it '#application_title' do @controller.controller_path = :main @controller.action_name = :new application_title.must_equal 'App' end it '#meta_title' do @controller.controller_path = :main @controller.action_name = :new meta_title.must_equal 'New | App' end it 'should render title tag' do @controller.controller_path = :main @controller.action_name = :new title_tag.must_equal 'New | App' end end describe 'configurable' do describe 'defaults' do before do load_translations({ main: { new: 'New', edit: 'Edit' } }) @controller.controller_path = :main end it '#new' do @controller.action_name = :create title.must_equal 'New' end it '#create' do @controller.action_name = :update title.must_equal 'Edit' end end describe 'custom' do before do ::Titlezilla.configure { |c| c.action_map.merge!({ do_parse: :parse }) } load_translations({ main: { parse: 'Parse' } }) @controller.controller_path = :main end it '#parse' do @controller.action_name = :do_parse title.must_equal 'Parse' end end end end end end