require "test_helper" class Admin::TableHelperTest < ActiveSupport::TestCase include Admin::TableHelper include ActionView::Helpers::UrlHelper include ActionView::Helpers::TagHelper include ActionView::Helpers::TextHelper def render(*args); args; end def raw(*args); args; end setup do default_url_options[:host] = "test.host" end =begin # FIXME def test_build_table @current_user = Factory(:typus_user) 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) expects(:render).once.with('admin/helpers/table_header', { :headers => [ 'Email ', 'Role ', 'Status ', ' ', ' ' ]}) build_table(TypusUser, fields, items) end =end =begin def test_table_header @current_user = mock() @current_user.expects(:can?).with("delete", TypusUser).returns(true) fields = TypusUser.typus_fields_for(:list) params = { :controller => "admin/typus_users", :action => "index" } self.expects(:params).at_least_once.returns(params) output = table_header(TypusUser, fields) expected = [ "admin/helpers/table_header", { :headers=> [ %(Email), %(Role), %(Status), " "] } ] assert_equal expected, output end =end =begin def test_table_header_with_params @current_user = mock() @current_user.expects(:can?).with("delete", TypusUser).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 = table_header(TypusUser, fields) expected = [ "admin/helpers/table_header", { :headers => [ %(Email), %(Role), %(Status), %( ) ] } ] assert_equal expected, output end =end =begin def test_table_header_when_user_cannot_delete_items @current_user = mock() @current_user.expects(:can?).with("delete", TypusUser).returns(false) fields = TypusUser.typus_fields_for(:list) params = { :controller => "admin/typus_users", :action => "index" } self.expects(:params).at_least_once.returns(params) output = table_header(TypusUser, fields) expected = [ "admin/helpers/table_header", { :headers => [ %(Email), %(Role), %(Status) ] } ] assert_equal expected, output end =end =begin def test_table_header_when_user_cannot_delete_items_with_params @current_user = mock() @current_user.expects(:can?).with("delete", TypusUser).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 = table_header(TypusUser, fields) expected = [ "admin/helpers/table_header", { :headers => [ %(Email), %(Role), %(Status) ] } ] assert_equal expected, output end =end =begin def test_table_belongs_to_field @current_user = Factory(:typus_user) comment = comments(:without_post_id) output = table_belongs_to_field("post", comment) expected = "" assert_equal expected, output default_url_options[:host] = "test.host" comment = comments(:with_post_id) output = table_belongs_to_field("post", comment) expected = %(Post#1) assert_equal expected.strip, output end =end =begin def test_table_has_and_belongs_to_many_field post = Factory(:post) output = table_has_and_belongs_to_many_field("comments", post) expected = %(John, Me, Me) assert_equal expected.strip, output end =end should "test_table_string_field" do post = Factory(:post) output = table_string_field(:title, post, :created_at) expected = %(#{post.title}) assert_equal expected.strip, output end should "test_table_string_field_with_link" do post = Factory(:post) output = table_string_field(:title, post, :title) expected = %(#{post.title}) assert_equal expected.strip, output end should "table_tree_field_when_displays_a_parent" do page = Factory(:page) output = table_tree_field("test", page) expected = "—" assert_equal expected, output end should "table_tree_field_when_displays_a_children" do page = Factory(:page, :status => "unpublished") output = table_tree_field("test", page) expected = "—" assert_equal expected, output end should "test_table_datetime_field" do post = Factory(:post) Time::DATE_FORMATS[:post_short] = "%m/%y" output = table_datetime_field(:created_at, post) expected = %(#{post.created_at.strftime("%m/%y")}) assert_equal expected.strip, output end should "test_table_datetime_field_with_link" do post = Factory(:post) Time::DATE_FORMATS[:post_short] = "%m/%y" output = table_datetime_field(:created_at, post, :created_at) expected = %(#{post.created_at.strftime("%m/%y")}) assert_equal expected.strip, output end =begin # FIXME: NameError: undefined local variable or method `controller' for def test_table_boolean_field post = Factory(:typus_user) output = table_boolean_field("status", post) expected = <<-HTML Active HTML assert_equal expected.strip, output post = Factory(:typus_user, :status => false) output = table_boolean_field("status", post) expected = <<-HTML Inactive HTML assert_equal expected.strip, output end =end end