Skip to content

Commit ee7a6e9

Browse files
Test for #469
1 parent 6412531 commit ee7a6e9

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/rubyXL/convenience_methods/cell.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff 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

spec/lib/cell_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,4 +635,20 @@
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+
638654
end

0 commit comments

Comments
 (0)