robust_excel_ole 1.35 → 1.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,6 +5,8 @@ require_relative '../spec_helper'
5
5
 
6
6
  $VERBOSE = nil
7
7
 
8
+ using ToReoRefinement
9
+
8
10
  include RobustExcelOle
9
11
  include General
10
12
 
@@ -30,6 +32,7 @@ describe Workbook do
30
32
  @sub_file = @dir + '/workbook_linked_sub.xlsm'
31
33
  @simple_file_xlsm = @dir + '/workbook.xlsm'
32
34
  @simple_file_xlsx = @dir + '/workbook.xlsx'
35
+ @unsaved_file = @dir + '/workbook_unsaved.xlsm'
33
36
  @simple_file1 = @simple_file
34
37
  end
35
38
 
@@ -457,6 +460,10 @@ describe Workbook do
457
460
  it "should unobtrusively open, modify, and not save the changes" do
458
461
  @book.unobtrusively(:writable => false) do |book|
459
462
  book.sheet(1)[1,1] = "bla"
463
+ book.ReadOnly.should be false
464
+ book.visible.should be true
465
+ book.writable.should be true
466
+ book.saved.should be false
460
467
  end
461
468
  @book.saved.should be false
462
469
  @book.visible.should be true
@@ -482,6 +489,76 @@ describe Workbook do
482
489
 
483
490
  end
484
491
 
492
+ context "with an writable and from the very beginning on unsaved workbook" do
493
+
494
+ before do
495
+ @ole_e1 = WIN32OLE.new('Excel.Application')
496
+ ws = @ole_e1.Workbooks
497
+ @abs_filename = General.absolute_path(@unsaved_file)
498
+ @ole_wb = ws.Open(@abs_filename)
499
+ @ole_e1.Visible = true
500
+ @ole_wb.Windows(@ole_wb.Name).Visible = true
501
+ @ole_wb.Saved.should be false
502
+ @old_value = @ole_wb.Worksheets.Item(1).Cells.Item(1,1).Value
503
+ #@ole_wb.Worksheets.Item(1).Cells.Item(1,1).Value = @old_value = "foo" #== "foo" ? "bar" : "foo"
504
+ #@new_value = @ole_wb.Worksheets.Item(1).Cells.Item(1,1)
505
+ @ole_wb.Saved.should be false
506
+ @book = @ole_wb.to_reo
507
+ end
508
+
509
+ after do
510
+ @book.close(:if_unsaved => :forget) if @book && @book.alive?
511
+ end
512
+
513
+ it "should unobtrusively open, modify, and retain the status" do
514
+ @book.unobtrusively do |book|
515
+ book.saved.should be false
516
+ book.visible.should be true
517
+ book.writable.should be true
518
+ book.sheet(1)[1,1] = book.sheet(1)[1,1] == "foo" ? "bar" : "foo"
519
+ end
520
+ @book.saved.should be false
521
+ @book.visible.should be true
522
+ @book.writable.should be true
523
+ @book.sheet(1)[1,1].should_not == @old_value
524
+ @book.close(:if_unsaved => :forget)
525
+ @new_book = Workbook.open(@unsaved_file)
526
+ @new_book.sheet(1)[1,1].should_not == @old_value
527
+ end
528
+
529
+ it "should unobtrusively open, modify, and not save the changes" do
530
+ @book.unobtrusively(:writable => false) do |book|
531
+ book.sheet(1)[1,1] = "bla"
532
+ book.ReadOnly.should be false
533
+ book.visible.should be true
534
+ book.writable.should be true
535
+ book.saved.should be false
536
+ end
537
+ @book.saved.should be false
538
+ @book.visible.should be true
539
+ @book.writable.should be true
540
+ @book.sheet(1)[1,1].should == "bla"
541
+ @book.close(:if_unsaved => :forget)
542
+ new_book = Workbook.open(@unsaved_file)
543
+ new_book.sheet(1)[1,1].should == @old_value
544
+ end
545
+
546
+ it "should unobtrusively open, modify, and save the changes" do
547
+ @book.unobtrusively(:writable => true) do |book|
548
+ book.sheet(1)[1,1] = book.sheet(1)[1,1] == "foo" ? "bar" : "foo"
549
+ end
550
+ @book.saved.should be false
551
+ @book.visible.should be true
552
+ @book.writable.should be true
553
+ @book.sheet(1)[1,1].should_not == @old_value
554
+ @book.close(:if_unsaved => :forget)
555
+ new_book = Workbook.open(@unsaved_file)
556
+ new_book.sheet(1)[1,1].should_not == @old_value
557
+ end
558
+
559
+ end
560
+
561
+
485
562
  context "with a closed workbook" do
486
563
 
487
564
  before do
@@ -732,6 +809,18 @@ describe Workbook do
732
809
  @ole_wb.Saved.should be false
733
810
  end
734
811
 
812
+ it "should keep the read-only status" do
813
+ Workbook.unobtrusively(@simple_file1, :writable => false) do |book|
814
+ book.saved.should be false
815
+ book.visible.should be true
816
+ book.writable.should be true
817
+ end
818
+ ole_wb = WIN32OLE.connect(@abs_filename)
819
+ ole_wb.Saved.should be false
820
+ @ole_e1.Visible.should be true
821
+ ole_wb.ReadOnly.should be false
822
+ end
823
+
735
824
  it "should connect and remain unsaved" do
736
825
  Workbook.unobtrusively(@simple_file1) do |book|
737
826
  book.saved.should be false
@@ -807,6 +896,111 @@ describe Workbook do
807
896
 
808
897
  end
809
898
 
899
+ context "with one from beginning on unsaved writable workbook" do
900
+
901
+ before do
902
+ @ole_e1 = WIN32OLE.new('Excel.Application')
903
+ ws = @ole_e1.Workbooks
904
+ @abs_filename = General.absolute_path(@unsaved_file)
905
+ @ole_wb = ws.Open(@abs_filename)
906
+ @ole_e1.Visible = true
907
+ @ole_wb.Windows(@ole_wb.Name).Visible = true
908
+ @ole_wb.Saved.should be false
909
+ @old_value = @ole_wb.Worksheets.Item(1).Cells.Item(1,1)
910
+ @ole_wb.Worksheets.Item(1).Cells.Item(1,1).Value = @old_value = "foo" #== "foo" ? "bar" : "foo"
911
+ @new_value = @ole_wb.Worksheets.Item(1).Cells.Item(1,1)
912
+ @ole_wb.Saved.should be false
913
+ end
914
+
915
+ it "should keep the read-only status" do
916
+ Workbook.unobtrusively(@unsaved_file, :writable => false) do |book|
917
+ book.saved.should be false
918
+ book.visible.should be true
919
+ book.writable.should be true
920
+ end
921
+ ole_wb = WIN32OLE.connect(@abs_filename)
922
+ ole_wb.Saved.should be false
923
+ @ole_e1.Visible.should be true
924
+ ole_wb.ReadOnly.should be false
925
+ end
926
+
927
+ it "should connect and remain unsaved" do
928
+ Workbook.unobtrusively(@unsaved_file) do |book|
929
+ book.saved.should be false
930
+ book.visible.should be true
931
+ book.writable.should be true
932
+ end
933
+ ole_wb = WIN32OLE.connect(@abs_filename)
934
+ ole_wb.Saved.should be false
935
+ @ole_e1.Visible.should be true
936
+ ole_wb.ReadOnly.should be false
937
+ end
938
+
939
+ it "should raise error" do
940
+ expect{
941
+ Workbook.unobtrusively(@unsaved_file, :read_only => true) do |book|
942
+ book.saved.should be false
943
+ book.visible.should be true
944
+ book.writable.should be false
945
+ end
946
+ }.to raise_error(WorkbookNotSaved)
947
+ end
948
+
949
+ =begin
950
+ it "should remain writable" do
951
+ Workbook.unobtrusively(@unsaved_file, :read_only => true, :if_unsaved => :save) do |book|
952
+ book.saved.should be true
953
+ book.visible.should be true
954
+ book.writable.should be false
955
+ end
956
+ ole_wb = WIN32OLE.connect(@abs_filename)
957
+ ole_wb.Saved.should be false
958
+ @ole_e1.Visible.should be true
959
+ ole_wb.ReadOnly.should be false
960
+ end
961
+ =end
962
+
963
+ it "should remain unsaved when modifying" do
964
+ Workbook.unobtrusively(@unsaved_file) do |book|
965
+ book.sheet(1)[1,1] = "bar" #book.sheet(1)[1,1] == "foo" ? "bar" : "foo"
966
+ @new_value = book.sheet(1)[1,1]
967
+ book.saved.should be false
968
+ book.visible.should be true
969
+ book.writable.should be true
970
+ end
971
+ ole_wb = WIN32OLE.connect(@abs_filename)
972
+ ole_wb.Saved.should be false
973
+ @ole_e1.Visible.should be true
974
+ ole_wb.ReadOnly.should be false
975
+ Excel.kill_all
976
+ book2 = Workbook.open(@unsaved_file)
977
+ book2.sheet(1)[1,1].should_not == @old_value
978
+ book2.sheet(1)[1,1].should == @new_value
979
+ end
980
+
981
+ it "should not write with :writable => false" do
982
+ @ole_wb.Worksheets.Item(1).Cells.Item(1,1).Value = @old_value = "foo"
983
+ @ole_wb.Save
984
+ @ole_wb.Worksheets.Item(1).Cells.Item(1,1).Value = @old_value = "foo"
985
+ Workbook.unobtrusively(@unsaved_file, :writable => false) do |book|
986
+ book.sheet(1)[1,1] = "bar" #book.sheet(1)[1,1] == "foo" ? "bar" : "foo"
987
+ @new_value = book.sheet(1)[1,1]
988
+ book.saved.should be false
989
+ book.visible.should be true
990
+ book.writable.should be true
991
+ end
992
+ ole_wb = WIN32OLE.connect(@abs_filename)
993
+ ole_wb.Saved.should be false
994
+ @ole_e1.Visible.should be true
995
+ ole_wb.ReadOnly.should be false
996
+ Excel.kill_all
997
+ book2 = Workbook.open(@simple_file1)
998
+ book2.sheet(1)[1,1].should == @old_value
999
+ book2.sheet(1)[1,1].should_not == @new_value
1000
+ end
1001
+
1002
+ end
1003
+
810
1004
  context "with one read-only workbook" do
811
1005
 
812
1006
  before do
@@ -1322,46 +1516,6 @@ describe Workbook do
1322
1516
  book2.sheet(1)[1,1].should_not == @old_value
1323
1517
  end
1324
1518
 
1325
- =begin
1326
- it "should force to read-write" do
1327
- e1 = Excel.create
1328
- Workbook.unobtrusively(@simple_file1, :writable => true, :rw_change_excel => e1) do |book|
1329
- book.Readonly.should be false
1330
- book.filename.should == @book.filename
1331
- book.excel.should == e1
1332
- book.sheet(1)[1,1] = book.sheet(1)[1,1] == "foo" ? "bar" : "foo"
1333
- end
1334
- @book.close
1335
- book2 = Workbook.open(@simple_file1)
1336
- book2.sheet(1)[1,1].should_not == @old_value
1337
- end
1338
-
1339
- it "should force to read-write" do
1340
- Workbook.unobtrusively(@simple_file1, :writable => true, :rw_change_excel => :current) do |book|
1341
- book.Readonly.should be false
1342
- book.should == @book
1343
- book.filename.should == @book.filename
1344
- book.excel.should == @book.excel
1345
- book.sheet(1)[1,1] = book.sheet(1)[1,1] == "foo" ? "bar" : "foo"
1346
- end
1347
- @book.close
1348
- book2 = Workbook.open(@simple_file1)
1349
- book2.sheet(1)[1,1].should_not == @old_value
1350
- end
1351
-
1352
- it "should force to read-write" do
1353
- Workbook.unobtrusively(@simple_file1, :writable => true, :rw_change_excel => :new) do |book|
1354
- book.Readonly.should be false
1355
- book.filename.should == @book.filename
1356
- book.excel.should_not == @book.excel
1357
- book.sheet(1)[1,1] = book.sheet(1)[1,1] == "foo" ? "bar" : "foo"
1358
- end
1359
- @book.close
1360
- book2 = Workbook.open(@simple_file1)
1361
- book2.sheet(1)[1,1].should_not == @old_value
1362
- end
1363
- =end
1364
-
1365
1519
  it "should force to read-write" do
1366
1520
  Workbook.unobtrusively(@simple_file1, :writable => true, :read_only => false) do |book|
1367
1521
  book.Readonly.should be false
@@ -1957,7 +2111,7 @@ describe Workbook do
1957
2111
 
1958
2112
  it "should let an open Workbook open if it has been closed and opened again" do
1959
2113
  @book.close
1960
- @book.reopen
2114
+ @book.open
1961
2115
  Workbook.unobtrusively(@simple_file1) do |book|
1962
2116
  book.should be_a Workbook
1963
2117
  book.should be_alive
@@ -1971,7 +2125,7 @@ describe Workbook do
1971
2125
  book2 = Workbook.open(@different_file, :force_excel => :new)
1972
2126
  @book.close
1973
2127
  book2.close
1974
- @book.reopen
2128
+ @book.open
1975
2129
  Workbook.unobtrusively(@simple_file1) do |book|
1976
2130
  book.should be_a Workbook
1977
2131
  book.should be_alive
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: robust_excel_ole
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.35'
4
+ version: '1.36'
5
5
  platform: ruby
6
6
  authors:
7
7
  - traths
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-25 00:00:00.000000000 Z
11
+ date: 2021-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: win32api
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '0.1'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '0.1'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: pry
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -202,8 +188,10 @@ files:
202
188
  - spec/data/workbook.xlsx
203
189
  - spec/data/workbook_connected.xlsm
204
190
  - spec/data/workbook_linked.xlsm
191
+ - spec/data/workbook_linked3.xlsm
205
192
  - spec/data/workbook_linked_sub.xlsm
206
193
  - spec/data/workbook_listobjects.xlsx
194
+ - spec/data/workbook_unsaved.xlsm
207
195
  - spec/excel_spec.rb
208
196
  - spec/general_spec.rb
209
197
  - spec/helpers/create_temporary_dir.rb