| CODENOTIFIER | HelpYou are not signed inSign in |
Project: Ruport-util
Revision: 37
Author: wes
Date: 03 Jan 2008 02:17:46
Changes:Fixed bug that would set the first sheet as the default and not allow the user to change it. Created test to ensure that it works and updated sample file to include a Sheet2.
Files:| ... | ...@@ -63,8 +63,8 @@ | |
| 63 | 63 | |
| 64 | 64 | def get_table_from_ods(oo, options) #:nodoc: |
| 65 | 65 | # Don't need to require 'roo' here because |
| 66 | oo.default_sheet = oo.sheets.first | |
| 67 | 66 | options = {:has_column_names => true, :select_sheet => oo.sheets.first}.merge(options) |
| 67 | oo.default_sheet = options[:select_sheet] | |
| 68 | 68 | start_row = options[:has_column_names] == true ? 2 : 1 |
| 69 | 69 | |
| 70 | 70 | table = self.new(options) do |feeder| |
| ... | ...@@ -6,13 +6,20 @@ | |
| 6 | 6 | |
| 7 | 7 | describe 'Ruport::Data::TableFromODS' do |
| 8 | 8 | before(:each) do |
| 9 | @ods_file_column_names = %w(Name Age DOB) | |
| 10 | 9 | @ods_file = 'test/samples/people.ods' |
| 11 | 10 | @csv_file = 'test/samples/data.csv' |
| 11 | ||
| 12 | @ods_file_column_names = %w(Name Age DOB) | |
| 12 | 13 | @rows = [ ['Andy', 27.0, Date.parse('01/20/1980')], |
| 13 | 14 | ['Bob', 26.0, Date.parse('02/11/1981')], |
| 14 | 15 | ['Charlie', 20.0, Date.parse('03/14/1987')], |
| 15 | 16 | ['David', 73.0, Date.parse('04/26/1997')] ] |
| 17 | ||
| 18 | @ods_file_column_names2 = %w(Name Age Pet_Type) | |
| 19 | @rows2 = [ ['Tigger', 3.0, 'Cat'], | |
| 20 | ['Chai', 4.0, 'Dog'], | |
| 21 | ['Rusky', 6.0, 'Dog'], | |
| 22 | ['Sam', 13.0, 'Dog'] ] | |
| 16 | 23 | end |
| 17 | 24 | |
| 18 | 25 | # ==== File check ==== |
| ... | ...@@ -70,7 +77,7 @@ | |
| 70 | 77 | |
| 71 | 78 | |
| 72 | 79 | # ==== Ruport::Data::Table load check ==== |
| 73 | it "table should be valid without column names loaded from ods file " do | |
| 80 | it "table should be valid without column names loaded from ods file" do | |
| 74 | 81 | # Load data from ods file but do not load column headers. |
| 75 | 82 | table = Ruport::Data::Table(@ods_file, {:has_column_names => false}) |
| 76 | 83 | table.should_not be_nil |
| ... | ...@@ -83,17 +90,26 @@ | |
| 83 | 90 | r.attributes.should == [0, 1, 2] } |
| 84 | 91 | end |
| 85 | 92 | |
| 86 | it "table should be valid with column names loaded from ods file " do | |
| 93 | it "table should be valid with column names loaded from ods file" do | |
| 87 | 94 | # Load data from ods file but do not load column headers. |
| 88 | 95 | table = Ruport::Data::Table(@ods_file) |
| 89 | 96 | table.should_not be_nil |
| 90 | 97 | table.column_names.should == @ods_file_column_names |
| 91 | 98 | |
| 92 | ||
| 93 | 99 | table.each { |r| r.to_a.should == @rows.shift |
| 94 | 100 | r.attributes.should == @ods_file_column_names } |
| 95 | 101 | end |
| 96 | 102 | |
| 103 | it "table should be valid with column names loaded from ods file using Sheet2" do | |
| 104 | # Load data from ods file but do not load column headers. | |
| 105 | table = Ruport::Data::Table(@ods_file, {:select_sheet => 'Sheet2'}) | |
| 106 | table.should_not be_nil | |
| 107 | table.column_names.should == @ods_file_column_names2 | |
| 108 | ||
| 109 | table.each { |r| r.to_a.should == @rows2.shift | |
| 110 | r.attributes.should == @ods_file_column_names2 } | |
| 111 | end | |
| 112 | ||
| 97 | 113 | it "should be valid if an Openoffice object is passed using parse_ods method" do |
| 98 | 114 | oo = Openoffice.new(@ods_file) |
| 99 | 115 | oo.default_sheet = oo.sheets.first |