require 'test/helper' class Admin::FormHelperTest < ActiveSupport::TestCase include Admin::FormHelper include ActionView::Helpers::FormHelper include ActionView::Helpers::FormOptionsHelper include ActionView::Helpers::DateHelper include ActionView::Helpers::UrlHelper include ActionView::Helpers::TagHelper include ActionController::UrlWriter def test_build_form assert true end def test_typus_belongs_to_field params = { :controller => 'admin/post', :id => 1, :action => :create } self.expects(:params).at_least_once.returns(params) @current_user = mock() @current_user.expects(:can_perform?).with(Post, 'create').returns(false) expected = <<-HTML
  • HTML assert_equal expected, typus_belongs_to_field('post', Comment) end def test_typus_belongs_to_field_with_different_attribute_name default_url_options[:host] = 'test.host' params = { :controller => 'admin/post', :id => 1, :action => :edit } self.expects(:params).at_least_once.returns(params) @current_user = mock() @current_user.expects(:can_perform?).with(Comment, 'create').returns(true) expected = <<-HTML
  • HTML assert_equal expected, typus_belongs_to_field('favorite_comment', Post) end def test_typus_boolean_field output = typus_boolean_field('test', Post) expected = <<-HTML
  • Checked if active
  • HTML assert_equal expected, output end def test_typus_date_field output = typus_date_field('test', {}, Post) expected = <<-HTML
  • HTML assert_match expected, output end def test_typus_datetime_field output = typus_datetime_field('test', {}, Post) expected = <<-HTML
  • HTML assert_match expected, output end def test_typus_file_field output = typus_file_field('asset_file_name', Post) expected = <<-HTML
  • HTML assert_equal expected, output end def test_typus_password_field output = typus_password_field('test', Post) expected = <<-HTML
  • HTML assert_equal expected, output end def test_typus_selector_field @resource = { :class => Post } @item = posts(:published) output = typus_selector_field('status') expected = <<-HTML
  • HTML assert_equal expected, output end def test_typus_text_field output = typus_text_field('test', Post) expected = <<-HTML
  • HTML assert_equal expected, output end def test_typus_time_field output = typus_time_field('test', {}, Post) expected = <<-HTML
  • HTML assert_match expected, output end def test_typus_tree_field return if !defined?(ActiveRecord::Acts::Tree) self.stubs(:expand_tree_into_select_field).returns('expand_tree_into_select_field') @resource = { :class => Page } items = @resource[:class].roots output = typus_tree_field('parent', items) expected = <<-HTML
  • HTML assert_equal expected, output end def test_typus_string_field output = typus_string_field('test', Post) expected = <<-HTML
  • HTML assert_equal expected, output end def test_typus_relationships assert true end def test_typus_form_has_many_with_items @current_user = typus_users(:admin) @resource = { :class => Post, :self => 'posts' } @item = Post.find(1) params = { :controller => 'admin/posts', :id => 1, :action => 'edit' } self.expects(:params).at_least_once.returns(params) self.stubs(:build_list).returns('') output = typus_form_has_many('comments') expected = <<-HTML

    Comments Add new

    HTML assert_equal expected, output end def test_typus_form_has_many_without_items @current_user = typus_users(:admin) @resource = { :class => Post, :self => 'posts' } @item = Post.find(1) @item.comments.destroy_all params = { :controller => 'admin/posts', :id => 1, :action => 'edit' } self.expects(:params).at_least_once.returns(params) output = typus_form_has_many('comments') expected = <<-HTML

    Comments Add new

    There are no comments.

    HTML assert_equal expected, output end def test_typus_form_has_and_belongs_to_many assert true end def test_typus_template_field assert true end def test_attribute_disabled assert !attribute_disabled?('test', Post) Post.expects(:accessible_attributes).returns(['test']) assert !attribute_disabled?('test', Post) Post.expects(:accessible_attributes).returns(['no_test']) assert attribute_disabled?('test', Post) end def test_expand_tree_into_select_field return if !defined?(ActiveRecord::Acts::Tree) items = Page.roots # Page#1 is a root. @item = Page.find(1) output = expand_tree_into_select_field(items, 'parent_id') expected = <<-HTML HTML assert_equal expected, output # Page#4 is a children. @item = Page.find(4) output = expand_tree_into_select_field(items, 'parent_id') expected = <<-HTML HTML assert_equal expected, output end end