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)
current_user = mock()
current_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)
current_user = mock()
current_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
should_eventually "verify_attribute_disabled" do
@resource = Post
assert !attribute_disabled?('test')
Post.expects(:accessible_attributes).returns(['test'])
assert !attribute_disabled?('test')
Post.expects(:accessible_attributes).returns(['no_test'])
assert attribute_disabled?('test')
end
should_eventually "test_expand_tree_into_select_field" do
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