require "test_helper"
class Admin::FormHelperTest < ActiveSupport::TestCase
include Admin::FormHelper
# include Admin::ResourcesHelper
should_eventually "verify_belongs_to_field" do
params = { :controller => '/admin/post', :id => 1, :action => :create }
self.stubs(:params).returns(params)
admin_user = mock
admin_user.stubs(:can?).with('create', Post).returns(false)
@resource = Comment
expected = <<-HTML
HTML
assert_equal expected, typus_belongs_to_field('post')
end
should_eventually "test_typus_belongs_to_field_with_different_attribute_name" do
params = { :controller => '/admin/post', :id => 1, :action => :edit }
self.stubs(:params).returns(params)
admin_user = mock
admin_user.stubs(:can?).with('create', Comment).returns(true)
@resource = Post
expected = <<-HTML
HTML
assert_equal expected, typus_belongs_to_field('favorite_comment')
end
should_eventually "test_typus_tree_field" do
self.stubs(:expand_tree_into_select_field).returns('expand_tree_into_select_field')
@resource = Page
expected = <<-HTML
HTML
assert_equal expected, typus_tree_field('parent')
end
context "attribute_disabled?" do
setup do
@resource = Post
end
should "work for non protected_attributes" do
assert !attribute_disabled?('test')
end
should "work for protected_attributes" do
Post.expects(:protected_attributes).returns(['test'])
assert attribute_disabled?('test')
end
end
context "expand_tree_into_select_field" do
setup do
@page = Factory(:page)
@children = Factory(:page, :parent => @page)
@subchildren = Factory(:page, :parent => @children)
@items = Page.roots
end
should "verify it works" do
@item = Page.first
expected = <<-HTML
HTML
assert_equal expected, expand_tree_into_select_field(@items, 'parent_id')
end
should "verify if selects an item" do
@item = Page.last
expected = <<-HTML
HTML
assert_equal expected, expand_tree_into_select_field(@items, 'parent_id')
end
end
end