require 'test/helper'
class Admin::TableHelperTest < ActiveSupport::TestCase
include Admin::TableHelper
include ActionView::Helpers::UrlHelper
include ActionController::UrlWriter
include ActionView::Helpers::TagHelper
include ActionView::Helpers::TextHelper
def setup
default_url_options[:host] = 'test.host'
end
def test_build_typus_table
# FIXME
return
@current_user = typus_users(:admin)
params = { :controller => 'admin/typus_users', :action => 'index' }
self.expects(:params).at_least_once.returns(params)
fields = TypusUser.typus_fields_for(:list)
items = TypusUser.find(:all)
output = build_typus_table(TypusUser, fields, items)
expected = <<-HTML
Email |
Role |
Status |
|
HTML
assert_equal expected, output
end
def test_typus_table_header
@current_user = mock()
@current_user.expects(:can_perform?).with(TypusUser, 'delete').returns(true)
fields = TypusUser.typus_fields_for(:list)
params = { :controller => 'admin/typus_users', :action => 'index' }
self.expects(:params).at_least_once.returns(params)
output = typus_table_header(TypusUser, fields)
expected = <<-HTML
Email |
Role |
Status |
|
HTML
assert_equal expected, output
end
def test_typus_table_header_with_params
@current_user = mock()
@current_user.expects(:can_perform?).with(TypusUser, 'delete').returns(true)
fields = TypusUser.typus_fields_for(:list)
params = { :controller => 'admin/typus_users', :action => 'index', :search => 'admin' }
self.expects(:params).at_least_once.returns(params)
output = typus_table_header(TypusUser, fields)
expected = <<-HTML
Email |
Role |
Status |
|
HTML
assert_equal expected, output
end
def test_typus_table_header_when_user_cannot_delete_items
@current_user = mock()
@current_user.expects(:can_perform?).with(TypusUser, 'delete').returns(false)
fields = TypusUser.typus_fields_for(:list)
params = { :controller => 'admin/typus_users', :action => 'index' }
self.expects(:params).at_least_once.returns(params)
output = typus_table_header(TypusUser, fields)
expected = <<-HTML
Email |
Role |
Status |
HTML
assert_equal expected, output
end
def test_typus_table_header_when_user_cannot_delete_items_with_params
@current_user = mock()
@current_user.expects(:can_perform?).with(TypusUser, 'delete').returns(false)
fields = TypusUser.typus_fields_for(:list)
params = { :controller => 'admin/typus_users', :action => 'index', :search => 'admin' }
self.expects(:params).at_least_once.returns(params)
output = typus_table_header(TypusUser, fields)
expected = <<-HTML
Email |
Role |
Status |
HTML
assert_equal expected, output
end
def test_typus_table_belongs_to_field
comment = comments(:without_post_id)
output = typus_table_belongs_to_field('post', comment)
expected = <<-HTML
|
HTML
assert_equal expected, output
default_url_options[:host] = 'test.host'
comment = comments(:with_post_id)
output = typus_table_belongs_to_field('post', comment)
expected = <<-HTML
Post#1 |
HTML
assert_equal expected, output
end
def test_typus_table_has_and_belongs_to_many_field
post = Post.find(1)
output = typus_table_has_and_belongs_to_many_field('comments', post)
expected = <<-HTML
John Me Me |
HTML
assert_equal expected, output
end
def test_typus_table_string_field
post = posts(:published)
output = typus_table_string_field(:title, post, :created_at)
expected = <<-HTML
#{post.title} |
HTML
assert_equal expected, output
end
def test_typus_table_string_field_with_link
post = posts(:published)
output = typus_table_string_field(:title, post, :title)
expected = <<-HTML
#{post.title} |
HTML
assert_equal expected, output
end
def test_typus_table_tree_field
return if !defined?(ActiveRecord::Acts::Tree)
page = pages(:published)
output = typus_table_tree_field('test', page)
expected = <<-HTML
|
HTML
assert_equal expected, output
page = pages(:unpublished)
output = typus_table_tree_field('test', page)
expected = <<-HTML
Page#1 |
HTML
assert_equal expected, output
end
def test_typus_table_datetime_field
post = posts(:published)
Time::DATE_FORMATS[:post_short] = '%m/%y'
output = typus_table_datetime_field(:created_at, post)
expected = <<-HTML
#{post.created_at.strftime('%m/%y')} |
HTML
assert_equal expected, output
end
def test_typus_table_datetime_field_with_link
post = posts(:published)
Time::DATE_FORMATS[:post_short] = '%m/%y'
output = typus_table_datetime_field(:created_at, post, :created_at)
expected = <<-HTML
#{post.created_at.strftime('%m/%y')} |
HTML
assert_equal expected, output
end
def test_typus_table_boolean_field
options = { :toggle => false }
Typus::Configuration.stubs(:options).returns(options)
post = posts(:published)
output = typus_table_boolean_field('status', post)
expected = <<-HTML
True |
HTML
assert_equal expected, output
post = posts(:unpublished)
output = typus_table_boolean_field('status', post)
expected = <<-HTML
False |
HTML
assert_equal expected, output
end
end