File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed
lib/rubyXL/convenience_methods Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -268,7 +268,8 @@ def add_hyperlink(url, tooltip = nil)
268268
269269 def add_shared_string ( str )
270270 self . datatype = RubyXL ::DataType ::SHARED_STRING
271- self . raw_value = @workbook . shared_strings_container . add ( str )
271+ workbook . shared_strings_container ||= RubyXL ::SharedStringsTable . new
272+ self . raw_value = workbook . shared_strings_container . add ( str )
272273 end
273274 end
274275
Original file line number Diff line number Diff line change 635635 expect ( @cell . text_rotation ) . to eq ( 45 )
636636 end
637637 end
638+
639+ describe '.add_shared_string' do
640+ let ( :add_shared_string ) { Article . create ( title : 'test' , description : 'test' ) }
641+
642+ it 'should correctly add a new shared string to the list' do
643+ @cell = @worksheet . add_cell ( 7 , 0 , 1 )
644+ expect ( @cell . datatype ) . to be_nil
645+
646+ prior_strings = @workbook . shared_strings_container . strings . dup
647+ @cell . add_shared_string ( 'testTEST' )
648+ expect ( @workbook . shared_strings_container . strings . size ) . to eq ( prior_strings . size + 1 )
649+ expect ( @cell . datatype ) . to eq ( RubyXL ::DataType ::SHARED_STRING )
650+ expect ( @cell . value ) . to eq ( 'testTEST' )
651+ end
652+ end
653+
638654end
You can’t perform that action at this time.
0 commit comments