forked from cldwalker/hirb
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
104 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
require File.join(File.dirname(__FILE__), 'test_helper') | ||
|
||
class Hirb::Helpers::ActiveRecordTableTest < Test::Unit::TestCase | ||
context "activerecord table" do | ||
test "with no select renders" do | ||
expected_table = <<-TABLE.unindent | ||
+-----+-------+ | ||
| age | name | | ||
+-----+-------+ | ||
| 7 | rufus | | ||
| 101 | alf | | ||
+-----+-------+ | ||
2 rows in set | ||
TABLE | ||
@pets = [stub(:name=>'rufus', :age=>7, :attributes=>{"name"=>'rufus', 'age'=>7}, :class=>stub(:column_names=>%w{age name})), | ||
stub(:name=>'alf', :age=>101)] | ||
Hirb::Helpers::ActiveRecordTable.render(@pets).should == expected_table | ||
end | ||
|
||
test "with select renders" do | ||
expected_table = <<-TABLE.unindent | ||
+-------+ | ||
| name | | ||
+-------+ | ||
| rufus | | ||
| alf | | ||
+-------+ | ||
2 rows in set | ||
TABLE | ||
@pets = [stub(:name=>'rufus', :age=>7, :attributes=>{'name'=>'rufus'}, :class=>stub(:column_names=>%w{age name})), | ||
stub(:name=>'alf', :age=>101)] | ||
Hirb::Helpers::ActiveRecordTable.render(@pets).should == expected_table | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require File.join(File.dirname(__FILE__), 'test_helper') | ||
|
||
class Hirb::Helpers::AutoTableTest < Test::Unit::TestCase | ||
context "auto table" do | ||
test "converts nonarrays to arrays and renders" do | ||
require 'set' | ||
expected_table = <<-TABLE.unindent | ||
+-------+ | ||
| value | | ||
+-------+ | ||
| 1 | | ||
| 2 | | ||
| 3 | | ||
+-------+ | ||
3 rows in set | ||
TABLE | ||
Hirb::Helpers::AutoTable.render(::Set.new([1,2,3])).should == expected_table | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
require File.join(File.dirname(__FILE__), 'test_helper') | ||
|
||
class Hirb::Helpers::ObjectTableTest < Test::Unit::TestCase | ||
context "object table" do | ||
before(:all) { | ||
@pets = [stub(:name=>'rufus', :age=>7, :to_s=>'rufus'), stub(:name=>'alf', :age=>101, :to_s=>'alf')] | ||
} | ||
test "renders" do | ||
expected_table = <<-TABLE.unindent | ||
+-------+-----+ | ||
| name | age | | ||
+-------+-----+ | ||
| rufus | 7 | | ||
| alf | 101 | | ||
+-------+-----+ | ||
2 rows in set | ||
TABLE | ||
Hirb::Helpers::ObjectTable.render(@pets, :fields=>[:name, :age]).should == expected_table | ||
end | ||
|
||
test "with no options defaults to to_s field" do | ||
expected_table = <<-TABLE.unindent | ||
+-------+ | ||
| value | | ||
+-------+ | ||
| rufus | | ||
| alf | | ||
+-------+ | ||
2 rows in set | ||
TABLE | ||
Hirb::Helpers::ObjectTable.render(@pets).should == expected_table | ||
end | ||
|
||
test "renders simple arrays" do | ||
expected_table = <<-TABLE.unindent | ||
+-------+ | ||
| value | | ||
+-------+ | ||
| 1 | | ||
| 2 | | ||
| 3 | | ||
| 4 | | ||
+-------+ | ||
4 rows in set | ||
TABLE | ||
Hirb::Helpers::ObjectTable.render([1,2,3,4]).should == expected_table | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters