[205] | 1 | require File.dirname(__FILE__) + '/../../../../../spec_helper'
|
---|
| 2 |
|
---|
| 3 | include OpenEhr::RM::DataStructures::ItemStructure
|
---|
| 4 | include OpenEhr::RM::DataStructures::ItemStructure::Representation
|
---|
| 5 | include OpenEhr::RM::DataTypes::Text
|
---|
| 6 |
|
---|
| 7 | def row(args)
|
---|
| 8 | return args.collect do |n|
|
---|
| 9 | Element.new(:name => DvText.new(n),
|
---|
| 10 | :archetype_node_id => 'test')
|
---|
| 11 | end
|
---|
| 12 | end
|
---|
| 13 |
|
---|
| 14 | def cluster_builder(name,rows)
|
---|
| 15 | return Cluster.new(:name => DvText.new(name),
|
---|
| 16 | :archetype_node_id => 'test',
|
---|
| 17 | :items => rows)
|
---|
| 18 | end
|
---|
| 19 |
|
---|
| 20 | describe ItemTable do
|
---|
| 21 | before(:each) do
|
---|
| 22 | row1 = row(%w{one two three})
|
---|
| 23 | row2 = row(%w{four five six})
|
---|
| 24 | rows = [row1, row2].collect{|r| cluster_builder('cluster',r)}
|
---|
| 25 | @item_table = ItemTable.new(:name => DvText.new('item table'),
|
---|
| 26 | :archetype_node_id => 'test',
|
---|
[206] | 27 | :rows => rows)
|
---|
[205] | 28 | end
|
---|
| 29 |
|
---|
| 30 | it 'should be an instance of ItemTable' do
|
---|
| 31 | @item_table.should be_an_instance_of ItemTable
|
---|
| 32 | end
|
---|
| 33 |
|
---|
[207] | 34 | it 's row count should be 2' do
|
---|
[205] | 35 | @item_table.row_count.should be_equal 2
|
---|
| 36 | end
|
---|
[206] | 37 |
|
---|
[207] | 38 | it 's row_count should be 0 when rows are nil' do
|
---|
| 39 | @item_table.rows = nil
|
---|
| 40 | @item_table.row_count.should be_equal 0
|
---|
| 41 | end
|
---|
| 42 |
|
---|
| 43 | it 's column_count should be 3' do
|
---|
[206] | 44 | @item_table.column_count.should be_equal 3
|
---|
| 45 | end
|
---|
| 46 |
|
---|
[207] | 47 |
|
---|
| 48 | it 's row_names should be cluster cluster' do
|
---|
[206] | 49 | @item_table.row_names.should == %w{cluster cluster}.collect{|n| DvText.new(n)}
|
---|
| 50 | end
|
---|
[207] | 51 |
|
---|
| 52 | it 's row_names should be empty when items are nil' do
|
---|
| 53 | @item_table.rows = nil
|
---|
| 54 | @item_table.row_names.should == []
|
---|
| 55 | end
|
---|
| 56 |
|
---|
| 57 | it 's column_names should one two three' do
|
---|
| 58 | @item_table.column_names.should == %w{one two three}.collect{|s| DvText.new(s)}
|
---|
| 59 | end
|
---|
| 60 |
|
---|
| 61 | it 's column_names should empty when items aer nil' do
|
---|
| 62 | @item_table.rows = nil
|
---|
| 63 | @item_table.column_names.should == []
|
---|
| 64 | end
|
---|
| 65 |
|
---|
| 66 | it 's ith_row(integer) should be ith row' do
|
---|
| 67 | @item_table.ith_row(2).items[1].name.value.should == 'five'
|
---|
| 68 | end
|
---|
| 69 |
|
---|
| 70 | it 'should be invalid index under 0' do
|
---|
| 71 | lambda {@item_table.ith_row(0) }.should raise_error(ArgumentError)
|
---|
| 72 | end
|
---|
[208] | 73 |
|
---|
| 74 | it 'should be true because it has_row_with_name cluster' do
|
---|
| 75 | @item_table.has_row_with_name?('one').should be_true
|
---|
| 76 | end
|
---|
| 77 |
|
---|
| 78 | it 'should be true because it does not have_row_with_name key' do
|
---|
| 79 | @item_table.has_row_with_name?('two').should_not be_true
|
---|
| 80 | end
|
---|
| 81 |
|
---|
| 82 | it 'should raise argument error key is nil' do
|
---|
| 83 | lambda {@item_table.has_row_with_name?(nil)
|
---|
| 84 | }.should raise_error(ArgumentError)
|
---|
| 85 | end
|
---|
| 86 |
|
---|
| 87 | it 'should raise argument error key is empty' do
|
---|
| 88 | lambda {@item_table.has_row_with_name?('')
|
---|
| 89 | }.should raise_error(ArgumentError)
|
---|
| 90 | end
|
---|
| 91 |
|
---|
| 92 | it 'should be true because it has_column_with_name one' do
|
---|
| 93 | @item_table.has_column_with_name?('one').should be_true
|
---|
| 94 | end
|
---|
| 95 |
|
---|
| 96 | it 'second row should be named_row four' do
|
---|
| 97 | @item_table.named_row('four').items[1].name.value = 'five'
|
---|
| 98 | end
|
---|
[209] | 99 |
|
---|
| 100 | it 'should be true if row has key' do
|
---|
| 101 | @item_table.has_row_with_key?(Set['one','two']).should be_true
|
---|
| 102 | end
|
---|
| 103 |
|
---|
| 104 | it 'should not be true if row has not key' do
|
---|
| 105 | @item_table.has_row_with_key?(Set['two','five']).should be_false
|
---|
| 106 | end
|
---|
[210] | 107 |
|
---|
| 108 | it 'should be a first row that has one' do
|
---|
| 109 | @item_table.row_with_key(Set['one', 'two']).items[0].name.value.should =='one'
|
---|
| 110 | end
|
---|
| 111 |
|
---|
| 112 | it 'should raise argument error if row has no key' do
|
---|
| 113 | lambda {
|
---|
| 114 | @item_table.row_with_key(Set['two','five'])}.should raise_error(ArgumentError)
|
---|
| 115 | end
|
---|
[211] | 116 |
|
---|
| 117 | it 'should be element at cell ij' do
|
---|
| 118 | @item_table.element_at_cell_ij(2,2).name.value.should == 'five'
|
---|
| 119 | end
|
---|
| 120 |
|
---|
| 121 | it 'should not be element at cell with wrong ij' do
|
---|
| 122 | @item_table.element_at_cell_ij(2,3).name.value.should_not == 'five'
|
---|
| 123 | end
|
---|
[205] | 124 | end
|
---|