test/unit/header_test.rb in table_helper-0.2.0 vs test/unit/header_test.rb in table_helper-0.2.1
- old
+ new
@@ -248,5 +248,23 @@
</thead>
end_str
assert_html_equal expected, @header.html
end
end
+
+class HeaderWithModelsTest < ActiveRecord::TestCase
+ def setup
+ Person.create(:first_name => 'John', :last_name => 'Smith')
+ end
+
+ def test_should_include_all_columns_if_not_selecting_columns
+ table = TableHelper::CollectionTable.new(Person.all)
+ @header = TableHelper::Header.new(table)
+ assert_equal %w(first_name id last_name), @header.column_names.sort
+ end
+
+ def test_should_only_include_selected_columns_if_specified_in_query
+ table = TableHelper::CollectionTable.new(Person.all(:select => 'first_name'))
+ @header = TableHelper::Header.new(table)
+ assert_equal %w(first_name), @header.column_names.sort
+ end
+end